feat: Use Feature Flag to enable new upload
This commit is contained in:
parent
b4ae975313
commit
7fbe08b0bc
8 changed files with 174 additions and 24 deletions
0
frappe/custom/doctype/feature_flags/__init__.py
Normal file
0
frappe/custom/doctype/feature_flags/__init__.py
Normal file
8
frappe/custom/doctype/feature_flags/feature_flags.js
Normal file
8
frappe/custom/doctype/feature_flags/feature_flags.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// Copyright (c) 2019, Frappe Technologies and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Feature Flags', {
|
||||
refresh: function(frm) {
|
||||
frm.set_intro(__('Enable experimental features. These features may be removed before they end up in the core.'))
|
||||
}
|
||||
});
|
||||
93
frappe/custom/doctype/feature_flags/feature_flags.json
Normal file
93
frappe/custom/doctype/feature_flags/feature_flags.json
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
{
|
||||
"allow_copy": 0,
|
||||
"allow_events_in_timeline": 0,
|
||||
"allow_guest_to_view": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"beta": 0,
|
||||
"creation": "2019-04-10 10:31:38.372238",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "",
|
||||
"editable_grid": 0,
|
||||
"engine": "InnoDB",
|
||||
"fields": [
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "new_upload_dialog",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "New Upload Dialog",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"has_web_view": 0,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 0,
|
||||
"in_create": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 1,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2019-04-10 10:31:38.372238",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Custom",
|
||||
"name": "Feature Flags",
|
||||
"name_case": "",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"amend": 0,
|
||||
"cancel": 0,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 0,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 0,
|
||||
"role": "System Manager",
|
||||
"set_user_permissions": 0,
|
||||
"share": 1,
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"quick_entry": 1,
|
||||
"read_only": 0,
|
||||
"show_name_in_global_search": 0,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "ASC",
|
||||
"track_changes": 1,
|
||||
"track_seen": 0,
|
||||
"track_views": 0
|
||||
}
|
||||
10
frappe/custom/doctype/feature_flags/feature_flags.py
Normal file
10
frappe/custom/doctype/feature_flags/feature_flags.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2019, Frappe Technologies and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class FeatureFlags(Document):
|
||||
pass
|
||||
|
|
@ -47,6 +47,7 @@ frappe.Application = Class.extend({
|
|||
this.setup_analytics();
|
||||
|
||||
this.setup_energy_point_listeners();
|
||||
this.setup_feature_flags();
|
||||
|
||||
frappe.ui.keys.setup();
|
||||
this.set_rtl();
|
||||
|
|
@ -556,6 +557,10 @@ frappe.Application = Class.extend({
|
|||
frappe.realtime.on('energy_point_alert', (message) => {
|
||||
frappe.show_alert(message);
|
||||
});
|
||||
},
|
||||
|
||||
setup_feature_flags() {
|
||||
frappe.model.with_doc('Feature Flags', 'Feature Flags');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -63,12 +63,12 @@ frappe.ui.form.Attachments = Class.extend({
|
|||
|
||||
var me = this;
|
||||
|
||||
var $attach = $(frappe.render_template("attachment", {
|
||||
var $attach = $(frappe.render_template("attachment", {
|
||||
"file_path": "/desk#Form/File/" + fileid,
|
||||
"icon": attachment.is_private ? "fa fa-lock" : "fa fa-unlock-alt",
|
||||
"file_name": file_name,
|
||||
"file_url": frappe.urllib.get_full_url(file_url)
|
||||
})).insertAfter(this.attachments_label.addClass("has-attachments"));
|
||||
})).insertAfter(this.attachments_label.addClass("has-attachments"));
|
||||
|
||||
var $close =
|
||||
$attach.find(".close")
|
||||
|
|
@ -146,13 +146,25 @@ frappe.ui.form.Attachments = Class.extend({
|
|||
this.dialog.$wrapper.remove();
|
||||
}
|
||||
|
||||
// make upload dialog
|
||||
this.dialog = frappe.ui.get_upload_dialog({
|
||||
"args": me.get_args(),
|
||||
"callback": function(attachment, r) { me.attachment_uploaded(attachment, r) },
|
||||
"max_width": me.frm.cscript ? me.frm.cscript.attachment_max_width : null,
|
||||
"max_height": me.frm.cscript ? me.frm.cscript.attachment_max_height : null
|
||||
});
|
||||
let flags = frappe.get_doc('Feature Flags');
|
||||
if (flags.new_upload_dialog) {
|
||||
new frappe.ui.FileUploader({
|
||||
doctype: this.frm.doctype,
|
||||
docname: this.frm.docname,
|
||||
on_success: (r) => {
|
||||
this.attachment_uploaded(r.message, r);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// make upload dialog
|
||||
this.dialog = frappe.ui.get_upload_dialog({
|
||||
"args": me.get_args(),
|
||||
"callback": function(attachment, r) { me.attachment_uploaded(attachment, r) },
|
||||
"max_width": me.frm.cscript ? me.frm.cscript.attachment_max_width : null,
|
||||
"max_height": me.frm.cscript ? me.frm.cscript.attachment_max_height : null
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
get_args: function() {
|
||||
return {
|
||||
|
|
@ -263,7 +275,7 @@ frappe.ui.get_upload_dialog = function(opts){
|
|||
dialog.show();
|
||||
var upload_area = $('<div></div>').prependTo(dialog.body);
|
||||
|
||||
|
||||
|
||||
|
||||
frappe.upload.make({
|
||||
parent: upload_area,
|
||||
|
|
|
|||
|
|
@ -325,13 +325,22 @@ frappe.views.FileView = class FileView extends frappe.views.ListView {
|
|||
}
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
frappe.upload.make({
|
||||
files: dataTransfer.files,
|
||||
"args": {
|
||||
"folder": this.current_folder,
|
||||
"from_form": 1
|
||||
}
|
||||
});
|
||||
|
||||
let flags = frappe.get_doc('Feature Flags');
|
||||
if (flags.new_upload_dialog) {
|
||||
new frappe.ui.FileUploader({
|
||||
files: dataTransfer.files,
|
||||
folder: this.current_folder
|
||||
});
|
||||
} else {
|
||||
frappe.upload.make({
|
||||
files: dataTransfer.files,
|
||||
"args": {
|
||||
"folder": this.current_folder,
|
||||
"from_form": 1
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -142,13 +142,26 @@ _f.Frm.prototype.setup_drag_drop = function() {
|
|||
throw "attach error";
|
||||
}
|
||||
|
||||
frappe.upload.make({
|
||||
args: me.attachments.get_args(),
|
||||
files: dataTransfer.files,
|
||||
callback: function(attachment, r) {
|
||||
me.attachments.attachment_uploaded(attachment, r);
|
||||
}
|
||||
});
|
||||
let flags = frappe.get_doc('Feature Flags');
|
||||
|
||||
if (flags.new_upload_dialog) {
|
||||
new frappe.ui.FileUploader({
|
||||
doctype: me.doctype,
|
||||
docname: me.docname,
|
||||
files: dataTransfer.files,
|
||||
on_success(r) {
|
||||
me.attachments.attachment_uploaded(r.message, r);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
frappe.upload.make({
|
||||
args: me.attachments.get_args(),
|
||||
files: dataTransfer.files,
|
||||
callback: function(attachment, r) {
|
||||
me.attachments.attachment_uploaded(attachment, r);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue