Skip to content

Commit

Permalink
Upgrade to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kid1194 authored Aug 12, 2022
1 parent 992aa5a commit a701d39
Showing 1 changed file with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
frappe.ui.form.ControlAttachImage = class ControlAttachImage extends frappe.ui.form.ControlAttachImage {
on_attach_click() {
this.set_upload_options();
this.file_uploader = new frappe.ui.FileUploader(this.upload_options);
}
on_attach_doc_image() {
this.set_upload_options();
if (this.upload_options.restrictions.allowed_file_types == null) {
this.upload_options.restrictions.allowed_file_types = ['image/*'];
}
if (this.upload_options.restrictions.crop_image_aspect_ratio == null) {
this.upload_options.restrictions.crop_image_aspect_ratio = 1;
make_input() {
super.make_input();
if (!this.__is_custom) {
console.error('The Attach Image control doesn\'t extend the plugin Attach control.');
}
this.file_uploader = new frappe.ui.FileUploader(this.upload_options);

// @todo: Bellow support for multiple files upload
/*let $file_link = this.$value.find('.attached-file-link');
$file_link.popover({
trigger: 'hover',
placement: 'top',
content: () => {
return `<div>
<img src="${this.get_value()}"
width="150px"
style="object-fit: contain;"
/>
</div>`;
},
html: true
});*/
}
set_upload_options() {
super.set_upload_options();
let options = this._JSON_options;
if (!options && this.df.options && typeof this.df.options === 'string'
&& this.df.options.length > 2 && this.df.options[0] === '{'
&& this.df.options[this.df.options.length - 1] === '}') {
try {
this._JSON_options = JSON.parse(this.df.options);
} catch(e) {}
}
if (options) {
let keys = ['upload_notes', 'allow_multiple', 'max_file_size', 'allowed_file_types', 'max_number_of_files', 'crop_image_aspect_ratio'];
for (var k in options) {
if (keys.indexOf(k) >= 0) this.upload_options.restrictions[k] = options[k];
}
}
}
};

0 comments on commit a701d39

Please sign in to comment.