fix: Only allow images in Attach Image

This commit is contained in:
Faris Ansari 2018-11-01 19:38:07 +05:30
parent 86e5201384
commit 10c2e8f262
4 changed files with 44 additions and 14 deletions

View file

@ -18,13 +18,14 @@
"is_standard": 1,
"login_required": 1,
"max_attachment_size": 0,
"modified": "2018-06-12 22:24:21.913166",
"modified": "2018-11-01 19:35:43.552429",
"modified_by": "Administrator",
"module": "Core",
"name": "edit-profile",
"owner": "Administrator",
"published": 1,
"route": "update-profile",
"show_in_grid": 0,
"show_sidebar": 1,
"sidebar_items": [],
"success_message": "Profile updated successfully.",
@ -32,6 +33,7 @@
"title": "Update Profile",
"web_form_fields": [
{
"allow_read_on_all_link_options": 0,
"fieldname": "first_name",
"fieldtype": "Data",
"hidden": 0,
@ -39,9 +41,11 @@
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 1
"reqd": 1,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "middle_name",
"fieldtype": "Data",
"hidden": 0,
@ -49,9 +53,11 @@
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "last_name",
"fieldtype": "Data",
"hidden": 0,
@ -59,29 +65,35 @@
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"description": "",
"fieldname": "user_image",
"fieldtype": "Attach",
"fieldtype": "Attach Image",
"hidden": 0,
"label": "User Image",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldtype": "Section Break",
"hidden": 0,
"label": "More Information",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "phone",
"fieldtype": "Data",
"hidden": 0,
@ -89,9 +101,11 @@
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "mobile_no",
"fieldtype": "Data",
"hidden": 0,
@ -99,9 +113,11 @@
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"description": "",
"fieldname": "language",
"fieldtype": "Link",
@ -111,9 +127,11 @@
"max_value": 0,
"options": "Language",
"read_only": 0,
"reqd": 0
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "roles",
"fieldtype": "Table",
"hidden": 0,
@ -122,7 +140,8 @@
"max_value": 0,
"options": "Has Role",
"read_only": 0,
"reqd": 0
"reqd": 0,
"show_in_filter": 0
}
]
}

View file

@ -62,5 +62,9 @@ frappe.ui.form.ControlAttachImage = frappe.ui.form.ControlAttach.extend({
this.img_container.toggle(false);
this.remove_image_link.toggle(false);
}
},
set_upload_options() {
this._super();
this.upload_options.restrict_to_images = true;
}
});

View file

@ -41,6 +41,11 @@ frappe.upload = {
$upload.find(".btn-browse").on("click",
function() { $file_input.click(); });
// restrict to images
if (opts.restrict_to_images) {
$file_input.prop('accept', 'image/*');
}
// dropzone upload
const $dropzone = $('<div style="padding: 20px 10px 0px 10px;"/>');
new frappe.ui.DropZone($dropzone, {

View file

@ -1,5 +1,6 @@
{
"allow_copy": 0,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
@ -61,7 +62,7 @@
"label": "Fieldtype",
"length": 0,
"no_copy": 0,
"options": "Attach\nCheck\nData\nDate\nDatetime\nFloat\nHTML\nInt\nLink\nSelect\nSmall Text\nText\nText Editor\nTable\nSection Break\nColumn Break\nPage Break",
"options": "Attach\nAttach Image\nCheck\nData\nDate\nDatetime\nFloat\nHTML\nInt\nLink\nSelect\nSmall Text\nText\nText Editor\nTable\nSection Break\nColumn Break\nPage Break",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
@ -554,7 +555,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2018-09-20 10:01:13.346598",
"modified": "2018-11-01 19:35:17.742547",
"modified_by": "Administrator",
"module": "Website",
"name": "Web Form Field",
@ -568,5 +569,6 @@
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 0,
"track_seen": 0
"track_seen": 0,
"track_views": 0
}