-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
20 additions
and
26 deletions.
There are no files selected for viewing
46 changes: 20 additions & 26 deletions
46
frappe_better_attach_control/public/js/better_attach_image.bundle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
} | ||
}; |