diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index d1a76099d2..fff4a5e344 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -290,6 +290,8 @@ class File(NestedSet): zip_path = frappe.get_site_path(self.file_url.strip('/')) base_url = os.path.dirname(self.file_url) + + files = [] with zipfile.ZipFile(zip_path) as zf: zf.extractall(os.path.dirname(zip_path)) for info in zf.infolist(): @@ -308,8 +310,10 @@ class File(NestedSet): file_doc.attached_to_doctype = self.attached_to_doctype file_doc.attached_to_name = self.attached_to_name file_doc.save() + files.append(file_doc) frappe.delete_doc('File', self.name) + return files def get_file_url(self): @@ -888,7 +892,8 @@ def get_random_filename(extn=None, content_type=None): def unzip_file(name): '''Unzip the given file and make file records for each of the extracted files''' file_obj = frappe.get_doc('File', name) - file_obj.unzip() + files = file_obj.unzip() + return len(files) @frappe.whitelist() diff --git a/frappe/public/js/frappe/chat.js b/frappe/public/js/frappe/chat.js index 3dc6fe6505..533ca90856 100644 --- a/frappe/public/js/frappe/chat.js +++ b/frappe/public/js/frappe/chat.js @@ -2132,10 +2132,11 @@ class extends Component { icon: "file", label: "File", onclick: ( ) => { - const dialog = frappe.upload.make({ - args: { doctype: "Chat Room", docname: props.name }, - callback: (a, b, args) => { - const { file_url, filename } = args + new frappe.ui.FileUploader({ + doctype: "Chat Room", + docname: props.name, + on_success(file_doc) { + const { file_url, filename } = file_doc frappe.chat.message.send(props.name, { path: file_url, name: filename }, "File") } }) diff --git a/frappe/public/js/frappe/form/footer/attachments.js b/frappe/public/js/frappe/form/footer/attachments.js index 07e8fdc4ab..7ffd6a3c2c 100644 --- a/frappe/public/js/frappe/form/footer/attachments.js +++ b/frappe/public/js/frappe/form/footer/attachments.js @@ -146,25 +146,13 @@ frappe.ui.form.Attachments = Class.extend({ this.dialog.$wrapper.remove(); } - 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 - }); - } - + new frappe.ui.FileUploader({ + doctype: this.frm.doctype, + docname: this.frm.docname, + on_success: (file_doc) => { + this.attachment_uploaded(file_doc); + } + }); }, get_args: function() { return { @@ -173,7 +161,7 @@ frappe.ui.form.Attachments = Class.extend({ docname: this.frm.docname, } }, - attachment_uploaded: function(attachment, r) { + attachment_uploaded: function(attachment) { this.dialog && this.dialog.hide(); this.update_attachment(attachment); this.frm.reload_docinfo(); diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index 027f1fd1b7..15d456bff0 100755 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -359,33 +359,25 @@ frappe.views.CommunicationComposer = Class.extend({ var fields = this.dialog.fields_dict; var attach = $(fields.select_attachments.wrapper); - var me = this - if (!me.attachments){ - me.attachments = [] + if (!this.attachments) { + this.attachments = [] } - var args = { - args: { - from_form: 1, - folder:"Home/Attachments" - }, - callback: function(attachment, r) { me.attachments.push(attachment); }, - max_width: null, - max_height: null + let args = { + folder: 'Home/Attachments', + on_success: attachment => this.attachments.push(attachment) }; - if(me.frm) { + if(this.frm) { args = { - args: (me.frm.attachments.get_args - ? me.frm.attachments.get_args() - : { from_form: 1,folder:"Home/Attachments" }), - callback: function (attachment, r) { - me.frm.attachments.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 + doctype: this.frm.doctype, + docname: this.frm.docname, + folder: 'Home/Attachments', + on_success: attachment => { + this.frm.attachments.attachment_uploaded(attachment); + this.render_attach(); + } } - } $("
" @@ -393,11 +385,10 @@ frappe.views.CommunicationComposer = Class.extend({

\ " +__("Add Attachment")+"

").appendTo(attach.empty()) - attach.find(".add-more-attachments a").on('click',this,function() { - me.upload = frappe.ui.get_upload_dialog(args); - }) - me.render_attach() - + attach + .find(".add-more-attachments a") + .on('click',() => new frappe.ui.FileUploader(args)); + this.render_attach(); }, render_attach:function(){ var fields = this.dialog.fields_dict; diff --git a/frappe/public/js/frappe/views/file/file_view.js b/frappe/public/js/frappe/views/file/file_view.js index a1eaedcac1..8d4e47a65c 100644 --- a/frappe/public/js/frappe/views/file/file_view.js +++ b/frappe/public/js/frappe/views/file/file_view.js @@ -103,25 +103,20 @@ frappe.views.FileView = class FileView extends frappe.views.ListView { { label: __('Import Zip'), action: () => { - // make upload dialog - frappe.ui.get_upload_dialog({ - args: { - folder: this.current_folder, - from_form: 1 + new frappe.ui.FileUploader({ + folder: this.current_folder, + restrictions: { + allowed_file_types: ['.zip'] }, - callback: (attachment, r) => { - frappe.call({ - method: 'frappe.core.doctype.file.file.unzip_file', - args: { - name: r.message.name, - }, - callback: function (r) { - if(r.exc) { - frappe.msgprint(__('Error in uploading files' + r.exc)); + on_success: file => { + frappe.show_alert(__('Unzipping files...')); + frappe.call('frappe.core.doctype.file.file.unzip_file', { name: file.name }) + .then((r) => { + if (r.message) { + frappe.show_alert(__('Unzipped {0} files', [r.message])); } - } - }); - }, + }); + } }); } } @@ -302,12 +297,9 @@ frappe.views.FileView = class FileView extends frappe.views.ListView { } make_new_doc() { - frappe.ui.get_upload_dialog({ - "args": { - "folder": this.current_folder, - "from_form": 1 - }, - callback:() => this.refresh() + new frappe.ui.FileUploader({ + folder: this.current_folder, + on_success: () => this.refresh() }); } @@ -326,21 +318,10 @@ frappe.views.FileView = class FileView extends frappe.views.ListView { e.stopPropagation(); e.preventDefault(); - 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 - } - }); - } + new frappe.ui.FileUploader({ + files: dataTransfer.files, + folder: this.current_folder + }); }); } diff --git a/frappe/public/js/frappe/views/interaction.js b/frappe/public/js/frappe/views/interaction.js index 36de959a6a..25490446e2 100644 --- a/frappe/public/js/frappe/views/interaction.js +++ b/frappe/public/js/frappe/views/interaction.js @@ -115,50 +115,39 @@ frappe.views.InteractionComposer = class InteractionComposer { } setup_attach() { - let fields = this.dialog.fields_dict; - let attach = $(fields.select_attachments.wrapper); + var fields = this.dialog.fields_dict; + var attach = $(fields.select_attachments.wrapper); - let me = this; - if (!me.attachments){ - me.attachments = []; + if (!this.attachments) { + this.attachments = [] } let args = { - args: { - from_form: 1, - folder:"Home/Attachments" - }, - callback: function(attachment){ - me.attachments.push(attachment); - }, - max_width: null, - max_height: null + folder: 'Home/Attachments', + on_success: attachment => this.attachments.push(attachment) }; - if(me.frm) { + if (this.frm) { args = { - args: (me.frm.attachments.get_args - ? me.frm.attachments.get_args() - : { from_form: 1,folder:"Home/Attachments" }), - callback: function(attachment, r){ - me.frm.attachments.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 - }; - + doctype: this.frm.doctype, + docname: this.frm.docname, + folder: 'Home/Attachments', + on_success: attachment => { + this.frm.attachments.attachment_uploaded(attachment); + this.render_attach(); + } + } } $("
" +__("Select Attachments")+"
\

\ " - +__("Add Attachment")+"

").appendTo(attach.empty()); - attach.find(".add-more-attachments a").on('click',this,function() { - me.upload = frappe.ui.get_upload_dialog(args); - }); - me.render_attach(); - + +__("Add Attachment")+"

").appendTo(attach.empty()) + attach + .find(".add-more-attachments a") + .on('click',() => new frappe.ui.FileUploader(args)); + this.render_attach(); } render_attach(){ diff --git a/frappe/public/js/legacy/form.js b/frappe/public/js/legacy/form.js index c5da20b39e..4c89e05a6b 100644 --- a/frappe/public/js/legacy/form.js +++ b/frappe/public/js/legacy/form.js @@ -142,26 +142,14 @@ _f.Frm.prototype.setup_drag_drop = function() { throw "attach error"; } - 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); - } - }); - } + new frappe.ui.FileUploader({ + doctype: me.doctype, + docname: me.docname, + files: dataTransfer.files, + on_success(file_doc) { + me.attachments.attachment_uploaded(file_doc); + } + }); }); };