Skip to content

Commit 944f96b

Browse files
committed
v2-Beta12 release
1 parent 0c2460a commit 944f96b

File tree

3 files changed

+69
-18
lines changed

3 files changed

+69
-18
lines changed

frappe_better_attach_control/public/js/better_attach_webform.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,9 @@
19581958
this._allow_remove = true;
19591959
this._display_ready = false;
19601960
this._unprocessed_files = [];
1961+
frappe.realtime.on("better_attach_console", function(ret) {
1962+
console.log(ret);
1963+
});
19611964
}
19621965
_update_options() {
19631966
if (isEmpty(this._options) && isEmpty(this.df.better_attach_options) || !isEmpty(this._options) && this._latest_options === this.df.better_attach_options)
@@ -2290,15 +2293,17 @@
22902293
_add_list_file(file, idx) {
22912294
if (!this._allow_multiple || !this._$list)
22922295
return;
2293-
let meta = "";
2296+
let meta = "", rem = !this._allow_remove ? " ba-hidden" : "";
22942297
if (file.size && file.size_str) {
22952298
meta = '<div class="ba-meta">' + file.size_str + "</div>";
22962299
}
22972300
this._$list_group.append($(
2298-
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
2301+
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0' + rem + '"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
22992302
));
23002303
}
23012304
_remove_files(data, callback, error2) {
2305+
if (!isArray(data))
2306+
data = [data];
23022307
request("remove_files", { files: data }, callback, error2);
23032308
}
23042309
_remove_file_by_idx(idx) {
@@ -2319,15 +2324,13 @@
23192324
this._remove_file_by_url(url);
23202325
}
23212326
_remove_file_by_url(url) {
2322-
if (!this.frm) {
2323-
this._remove_files([url], function(ret) {
2327+
if (!this.frm || !this.frm.attachments) {
2328+
this._remove_files(url, function(ret) {
23242329
if (!cint(ret))
23252330
error("Unable to remove the uploaded attachment ({0}).", [url]);
23262331
});
23272332
return;
23282333
}
2329-
if (!this.frm.attachments)
2330-
return;
23312334
var me = this;
23322335
this.frm.attachments.remove_attachment_by_filename(
23332336
url,
@@ -2349,6 +2352,20 @@
23492352
'<div class="attached-file row align-center mt-4 ba-hidden"><div class="col-12"><ul class="list-group"></ul></div></div>'
23502353
).appendTo(this.input_area);
23512354
this._$list_group = this._$list.find("ul.list-group");
2355+
this._$list_group.click(".ba-remove", function() {
2356+
let $el = $(this);
2357+
if (!$el.hasClass("ba-remove"))
2358+
return;
2359+
let $parent = $el.parents(".ba-attachment");
2360+
if (!$parent.length)
2361+
return;
2362+
let idx = $parent.attr("data-file-idx");
2363+
if (!idx || !/[0-9]+/.test("" + idx))
2364+
return;
2365+
idx = cint(idx);
2366+
if (idx >= 0)
2367+
_remove_file_by_idx(idx);
2368+
});
23522369
}
23532370
_destroy_list() {
23542371
if (this._$list) {

frappe_better_attach_control/public/js/better_attach_webform_v12.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,9 @@
18861886
this._allow_remove = true;
18871887
this._display_ready = false;
18881888
this._unprocessed_files = [];
1889+
frappe.realtime.on("better_attach_console", function(ret) {
1890+
console.log(ret);
1891+
});
18891892
},
18901893
_update_options: function() {
18911894
if (isEmpty(this._options) && isEmpty(this.df.better_attach_options) || !isEmpty(this._options) && this._latest_options === this.df.better_attach_options)
@@ -2207,15 +2210,17 @@
22072210
_add_list_file: function(file, idx) {
22082211
if (!this._allow_multiple || !this._$list)
22092212
return;
2210-
var meta = "";
2213+
var meta = "", rem = !this._allow_remove ? " ba-hidden" : "";
22112214
if (file.size && file.size_str) {
22122215
meta = '<div class="ba-meta">' + file.size_str + "</div>";
22132216
}
22142217
this._$list_group.append($(
2215-
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
2218+
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0' + rem + '"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
22162219
));
22172220
},
22182221
_remove_files: function(data, callback, error2) {
2222+
if (!isArray(data))
2223+
data = [data];
22192224
request("remove_files", { files: data }, callback, error2);
22202225
},
22212226
_remove_file_by_idx: function(idx) {
@@ -2236,15 +2241,13 @@
22362241
this._remove_file_by_url(url);
22372242
},
22382243
_remove_file_by_url: function(url) {
2239-
if (!this.frm) {
2240-
this._remove_files([url], function(ret) {
2244+
if (!this.frm || !this.frm.attachments) {
2245+
this._remove_files(url, function(ret) {
22412246
if (!cint(ret))
22422247
error("Unable to remove the uploaded attachment ({0}).", [url]);
22432248
});
22442249
return;
22452250
}
2246-
if (!this.frm.attachments)
2247-
return;
22482251
var me = this;
22492252
this.frm.attachments.remove_attachment_by_filename(
22502253
url,
@@ -2265,6 +2268,20 @@
22652268
'<div class="attached-file row align-center mt-4 ba-hidden"><div class="col-12"><ul class="list-group"></ul></div></div>'
22662269
).appendTo(this.input_area);
22672270
this._$list_group = this._$list.find("ul.list-group");
2271+
this._$list_group.click(".ba-remove", function() {
2272+
var $el = $(this);
2273+
if (!$el.hasClass("ba-remove"))
2274+
return;
2275+
var $parent = $el.parents(".ba-attachment");
2276+
if (!$parent.length)
2277+
return;
2278+
var idx = $parent.attr("data-file-idx");
2279+
if (!idx || !/[0-9]+/.test("" + idx))
2280+
return;
2281+
idx = cint(idx);
2282+
if (idx >= 0)
2283+
_remove_file_by_idx(idx);
2284+
});
22682285
},
22692286
_destroy_list: function() {
22702287
if (this._$list) {

frappe_better_attach_control/public/js/better_attach_webform_v13.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,9 @@
19371937
this._allow_remove = true;
19381938
this._display_ready = false;
19391939
this._unprocessed_files = [];
1940+
frappe.realtime.on("better_attach_console", function(ret) {
1941+
console.log(ret);
1942+
});
19401943
},
19411944
_update_options: function() {
19421945
if (isEmpty(this._options) && isEmpty(this.df.better_attach_options) || !isEmpty(this._options) && this._latest_options === this.df.better_attach_options)
@@ -2265,15 +2268,17 @@
22652268
_add_list_file: function(file, idx) {
22662269
if (!this._allow_multiple || !this._$list)
22672270
return;
2268-
var meta = "";
2271+
var meta = "", rem = !this._allow_remove ? " ba-hidden" : "";
22692272
if (file.size && file.size_str) {
22702273
meta = '<div class="ba-meta">' + file.size_str + "</div>";
22712274
}
22722275
this._$list_group.append($(
2273-
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
2276+
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0' + rem + '"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
22742277
));
22752278
},
22762279
_remove_files: function(data, callback, error2) {
2280+
if (!isArray(data))
2281+
data = [data];
22772282
request("remove_files", { files: data }, callback, error2);
22782283
},
22792284
_remove_file_by_idx: function(idx) {
@@ -2294,15 +2299,13 @@
22942299
this._remove_file_by_url(url);
22952300
},
22962301
_remove_file_by_url: function(url) {
2297-
if (!this.frm) {
2298-
this._remove_files([url], function(ret) {
2302+
if (!this.frm || !this.frm.attachments) {
2303+
this._remove_files(url, function(ret) {
22992304
if (!cint(ret))
23002305
error("Unable to remove the uploaded attachment ({0}).", [url]);
23012306
});
23022307
return;
23032308
}
2304-
if (!this.frm.attachments)
2305-
return;
23062309
var me = this;
23072310
this.frm.attachments.remove_attachment_by_filename(
23082311
url,
@@ -2323,6 +2326,20 @@
23232326
'<div class="attached-file row align-center mt-4 ba-hidden"><div class="col-12"><ul class="list-group"></ul></div></div>'
23242327
).appendTo(this.input_area);
23252328
this._$list_group = this._$list.find("ul.list-group");
2329+
this._$list_group.click(".ba-remove", function() {
2330+
var $el = $(this);
2331+
if (!$el.hasClass("ba-remove"))
2332+
return;
2333+
var $parent = $el.parents(".ba-attachment");
2334+
if (!$parent.length)
2335+
return;
2336+
var idx = $parent.attr("data-file-idx");
2337+
if (!idx || !/[0-9]+/.test("" + idx))
2338+
return;
2339+
idx = cint(idx);
2340+
if (idx >= 0)
2341+
_remove_file_by_idx(idx);
2342+
});
23262343
},
23272344
_destroy_list: function() {
23282345
if (this._$list) {

0 commit comments

Comments
 (0)