Skip to content

Commit

Permalink
Update to v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kid1194 authored Aug 13, 2022
1 parent 0522473 commit 726632d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions frappe_better_attach_control/public/js/better_attach.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
};

0 comments on commit 726632d

Please sign in to comment.