From 726632ddb472df69e4fc972e16b5ea2f89c8a066 Mon Sep 17 00:00:00 2001 From: Ameen Ahmed Date: Sun, 14 Aug 2022 00:22:08 +0300 Subject: [PATCH] Update to v1.1.1 --- .../public/js/better_attach.bundle.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/frappe_better_attach_control/public/js/better_attach.bundle.js b/frappe_better_attach_control/public/js/better_attach.bundle.js index 97a0ae6..c68085c 100644 --- a/frappe_better_attach_control/public/js/better_attach.bundle.js +++ b/frappe_better_attach_control/public/js/better_attach.bundle.js @@ -8,6 +8,7 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro if (frappe.utils.is_json(this.df.options)) { let opts = frappe.utils.parse_json(this.df.options); this.df.options = {}; + this.df.__is_custom = true; if (opts) { let keys = ['upload_notes', 'allow_multiple', 'max_file_size', 'allowed_file_types', 'max_number_of_files', 'crop_image_aspect_ratio']; for (var k in opts) { @@ -20,17 +21,18 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro } } } + this.__allow_multiple = this.df.options.allow_multiple; } if (!Object.keys(this.df.options).length) this.df.options = null; } else { - this.df.options = null; + if (!this.df.__is_custom) this.df.options = null; } } - if ((this.df.options || {}).allow_multiple) this.value_list = []; + if (this.__allow_multiple) this.__value_list = []; } make_input() { super.make_input(); - if (this.value_list) { + if (this.__allow_multiple) { // @todo: make upload inputs list this.$value } } @@ -39,11 +41,11 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro if (this.frm) { me.parse_validate_and_set_in_model(null); me.refresh(); - if (me.value_list) { + if (me.__allow_multiple) { var promises = []; - for (var i = 0, l = me.value_list.length; i < l; i++) { + for (var i = 0, l = me.__value_list.length; i < l; i++) { promises.push(new Promise((resolve, reject) => { - me.frm.attachments.remove_attachment_by_filename(me.value_list[i], resolve); + me.frm.attachments.remove_attachment_by_filename(me.__value_list[i], resolve); })); } Promise.all(promises) @@ -78,12 +80,12 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro this.file_uploader = new frappe.ui.FileUploader(this.upload_options); } set_input(value, dataurl) { - if (value && this.value_list) { - this.value_list.push(value); + if (value && this.__allow_multiple) { + this.__value_list.push(value); } super.set_input(value, dataurl); } get_value() { - return this.value_list ? JSON.stringify(this.value_list) : this.value || null; + return this.__allow_multiple ? JSON.stringify(this.__value_list) : this.value || null; } };