diff --git a/frappe_better_attach_control/public/js/better_attach_webform.js b/frappe_better_attach_control/public/js/better_attach_webform.js
index b382445..cb6ae50 100644
--- a/frappe_better_attach_control/public/js/better_attach_webform.js
+++ b/frappe_better_attach_control/public/js/better_attach_webform.js
@@ -1958,6 +1958,9 @@
this._allow_remove = true;
this._display_ready = false;
this._unprocessed_files = [];
+ frappe.realtime.on("better_attach_console", function(ret) {
+ console.log(ret);
+ });
}
_update_options() {
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 @@
_add_list_file(file, idx) {
if (!this._allow_multiple || !this._$list)
return;
- let meta = "";
+ let meta = "", rem = !this._allow_remove ? " ba-hidden" : "";
if (file.size && file.size_str) {
meta = '
' + file.size_str + "
";
}
this._$list_group.append($(
- ''
+ ''
));
}
_remove_files(data, callback, error2) {
+ if (!isArray(data))
+ data = [data];
request("remove_files", { files: data }, callback, error2);
}
_remove_file_by_idx(idx) {
@@ -2319,15 +2324,13 @@
this._remove_file_by_url(url);
}
_remove_file_by_url(url) {
- if (!this.frm) {
- this._remove_files([url], function(ret) {
+ if (!this.frm || !this.frm.attachments) {
+ this._remove_files(url, function(ret) {
if (!cint(ret))
error("Unable to remove the uploaded attachment ({0}).", [url]);
});
return;
}
- if (!this.frm.attachments)
- return;
var me = this;
this.frm.attachments.remove_attachment_by_filename(
url,
@@ -2349,6 +2352,20 @@
''
).appendTo(this.input_area);
this._$list_group = this._$list.find("ul.list-group");
+ this._$list_group.click(".ba-remove", function() {
+ let $el = $(this);
+ if (!$el.hasClass("ba-remove"))
+ return;
+ let $parent = $el.parents(".ba-attachment");
+ if (!$parent.length)
+ return;
+ let idx = $parent.attr("data-file-idx");
+ if (!idx || !/[0-9]+/.test("" + idx))
+ return;
+ idx = cint(idx);
+ if (idx >= 0)
+ _remove_file_by_idx(idx);
+ });
}
_destroy_list() {
if (this._$list) {
diff --git a/frappe_better_attach_control/public/js/better_attach_webform_v12.js b/frappe_better_attach_control/public/js/better_attach_webform_v12.js
index 15feb16..b77c517 100644
--- a/frappe_better_attach_control/public/js/better_attach_webform_v12.js
+++ b/frappe_better_attach_control/public/js/better_attach_webform_v12.js
@@ -1886,6 +1886,9 @@
this._allow_remove = true;
this._display_ready = false;
this._unprocessed_files = [];
+ frappe.realtime.on("better_attach_console", function(ret) {
+ console.log(ret);
+ });
},
_update_options: function() {
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 @@
_add_list_file: function(file, idx) {
if (!this._allow_multiple || !this._$list)
return;
- var meta = "";
+ var meta = "", rem = !this._allow_remove ? " ba-hidden" : "";
if (file.size && file.size_str) {
meta = '' + file.size_str + "
";
}
this._$list_group.append($(
- ''
+ ''
));
},
_remove_files: function(data, callback, error2) {
+ if (!isArray(data))
+ data = [data];
request("remove_files", { files: data }, callback, error2);
},
_remove_file_by_idx: function(idx) {
@@ -2236,15 +2241,13 @@
this._remove_file_by_url(url);
},
_remove_file_by_url: function(url) {
- if (!this.frm) {
- this._remove_files([url], function(ret) {
+ if (!this.frm || !this.frm.attachments) {
+ this._remove_files(url, function(ret) {
if (!cint(ret))
error("Unable to remove the uploaded attachment ({0}).", [url]);
});
return;
}
- if (!this.frm.attachments)
- return;
var me = this;
this.frm.attachments.remove_attachment_by_filename(
url,
@@ -2265,6 +2268,20 @@
''
).appendTo(this.input_area);
this._$list_group = this._$list.find("ul.list-group");
+ this._$list_group.click(".ba-remove", function() {
+ var $el = $(this);
+ if (!$el.hasClass("ba-remove"))
+ return;
+ var $parent = $el.parents(".ba-attachment");
+ if (!$parent.length)
+ return;
+ var idx = $parent.attr("data-file-idx");
+ if (!idx || !/[0-9]+/.test("" + idx))
+ return;
+ idx = cint(idx);
+ if (idx >= 0)
+ _remove_file_by_idx(idx);
+ });
},
_destroy_list: function() {
if (this._$list) {
diff --git a/frappe_better_attach_control/public/js/better_attach_webform_v13.js b/frappe_better_attach_control/public/js/better_attach_webform_v13.js
index 9c4c185..9f465b5 100644
--- a/frappe_better_attach_control/public/js/better_attach_webform_v13.js
+++ b/frappe_better_attach_control/public/js/better_attach_webform_v13.js
@@ -1937,6 +1937,9 @@
this._allow_remove = true;
this._display_ready = false;
this._unprocessed_files = [];
+ frappe.realtime.on("better_attach_console", function(ret) {
+ console.log(ret);
+ });
},
_update_options: function() {
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 @@
_add_list_file: function(file, idx) {
if (!this._allow_multiple || !this._$list)
return;
- var meta = "";
+ var meta = "", rem = !this._allow_remove ? " ba-hidden" : "";
if (file.size && file.size_str) {
meta = '' + file.size_str + "
";
}
this._$list_group.append($(
- ''
+ ''
));
},
_remove_files: function(data, callback, error2) {
+ if (!isArray(data))
+ data = [data];
request("remove_files", { files: data }, callback, error2);
},
_remove_file_by_idx: function(idx) {
@@ -2294,15 +2299,13 @@
this._remove_file_by_url(url);
},
_remove_file_by_url: function(url) {
- if (!this.frm) {
- this._remove_files([url], function(ret) {
+ if (!this.frm || !this.frm.attachments) {
+ this._remove_files(url, function(ret) {
if (!cint(ret))
error("Unable to remove the uploaded attachment ({0}).", [url]);
});
return;
}
- if (!this.frm.attachments)
- return;
var me = this;
this.frm.attachments.remove_attachment_by_filename(
url,
@@ -2323,6 +2326,20 @@
''
).appendTo(this.input_area);
this._$list_group = this._$list.find("ul.list-group");
+ this._$list_group.click(".ba-remove", function() {
+ var $el = $(this);
+ if (!$el.hasClass("ba-remove"))
+ return;
+ var $parent = $el.parents(".ba-attachment");
+ if (!$parent.length)
+ return;
+ var idx = $parent.attr("data-file-idx");
+ if (!idx || !/[0-9]+/.test("" + idx))
+ return;
+ idx = cint(idx);
+ if (idx >= 0)
+ _remove_file_by_idx(idx);
+ });
},
_destroy_list: function() {
if (this._$list) {