From 16d8b84472638c4096753ca1fe68d9d049a46a01 Mon Sep 17 00:00:00 2001 From: Thach Le Huy Date: Thu, 3 Jun 2021 07:29:27 +0700 Subject: [PATCH] =?UTF-8?q?MDL-71814=20Atto:=20File=20picker=20=E2=80=93?= =?UTF-8?q?=20file=20info=20panel=20focus=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/form/filemanager.js | 68 ++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/lib/form/filemanager.js b/lib/form/filemanager.js index eb6ee68af91..10ef102bc8a 100644 --- a/lib/form/filemanager.js +++ b/lib/form/filemanager.js @@ -216,7 +216,7 @@ M.form_filemanager.init = function(Y, options) { this.filemanager.removeClass('fm-maxfiles'); } }, - refresh: function(filepath) { + refresh: function(filepath, action) { var scope = this; this.currentpath = filepath; if (!filepath) { @@ -233,7 +233,7 @@ M.form_filemanager.init = function(Y, options) { scope.options = obj; scope.lazyloading = {}; scope.check_buttons(); - scope.render(obj); + scope.render(obj, action); } }, true); }, @@ -458,7 +458,7 @@ M.form_filemanager.init = function(Y, options) { // Do something here args.scope.filecount -= params.length; if (obj && obj.length) { - args.scope.refresh(obj[0]); + args.scope.refresh(obj[0], {action: 'delete'}); } if (typeof M.core_formchangechecker != 'undefined') { M.core_formchangechecker.set_form_changed(); @@ -622,10 +622,14 @@ M.form_filemanager.init = function(Y, options) { this.processingimages = false; }, this), 200) }, - view_files: function(appendfiles) { + view_files: function(appendfiles, actionfiles) { this.filemanager.removeClass('fm-updating').removeClass('fm-noitems'); if ((appendfiles == null) && (!this.options.list || this.options.list.length == 0) && this.viewmode != 2) { this.filemanager.addClass('fm-noitems'); + // This is used to focus after refreshing the list files is empty by deletion file action. + if (actionfiles !== undefined && actionfiles.action == 'delete') { + this.filemanager.one('.fp-btn-add a').focus(); + } return; } var list = (appendfiles != null) ? appendfiles : this.options.list; @@ -653,6 +657,11 @@ M.form_filemanager.init = function(Y, options) { if (node.type == 'folder') { this.refresh(node.filepath); } else { + // This is used to focus on file after dialogue closed. + var previousActiveElement = e.target.ancestor('a', true); + this.options.previousActiveElement = previousActiveElement; + this.selectui.set('focusOnPreviousTargetAfterHide', true); + this.selectui.set('focusAfterHide', previousActiveElement); this.select_file(node); } }, @@ -697,6 +706,10 @@ M.form_filemanager.init = function(Y, options) { this.print_path(); } this.currentpath = node.filepath; + var previousActiveElement = Y.Node(e.event.target).ancestor('a', true); + this.options.previousActiveElement = previousActiveElement; + this.selectui.set('focusOnPreviousTargetAfterHide', true); + this.selectui.set('focusAfterHide', previousActiveElement); this.select_file(node); } else { // save current path and filelist (in case we want to jump to other viewmode) @@ -712,7 +725,25 @@ M.form_filemanager.init = function(Y, options) { this.lazyloading={}; } this.filemanager.one('.fp-content').fp_display_filelist(options, list, this.lazyloading); - this.content_scrolled(); + if (this.viewmode != 2) { + this.content_scrolled(); + } + // This is used to focus after refreshing the list files by update file and set main file action. + if (actionfiles !== undefined) { + if (actionfiles.action == 'updatefile' || actionfiles.action == 'setmainfile') { + var fileslist = this.filemanager.one('.fp-content'); + fileslist.all('a').each(function(parentnode) { + parentnode.all('.fp-filename').each(function(childnode) { + if (childnode.get('innerHTML') == actionfiles.newfilename) { + parentnode.focus(); + } + }); + }); + } + if (actionfiles.action == 'delete') { + this.filemanager.one('.fp-btn-delete a').focus(); + } + } }, populateLicensesSelect: function(licensenode, filenode) { if (!licensenode) { @@ -852,7 +883,8 @@ M.form_filemanager.init = function(Y, options) { args.scope.print_msg(obj.error, 'error'); } else { args.scope.selectui.hide(); - args.scope.refresh((obj && obj.filepath) ? obj.filepath : '/'); + var actionfile = {action: action, newfilename: newfilename}; + args.scope.refresh((obj && obj.filepath) ? obj.filepath : '/', actionfile); if (typeof M.core_formchangechecker != 'undefined') { M.core_formchangechecker.set_form_changed(); } @@ -870,12 +902,6 @@ M.form_filemanager.init = function(Y, options) { this.confirm_dlg_node = Y.Node.create(M.form_filemanager.templates.confirmdialog); var node = this.confirm_dlg_node; node.generateID(); - - var previousActiveElement = null; - if (typeof dialog_options.previousActiveElement != 'undefined') { - previousActiveElement = dialog_options.previousActiveElement; - } - this.confirm_dlg = new M.core.dialogue({ draggable : true, bodyContent : node, @@ -883,7 +909,6 @@ M.form_filemanager.init = function(Y, options) { modal : true, visible : false, buttons : {}, - focusAfterHide: previousActiveElement, }); var handle_confirm = function(ev) { var dlgopt = this.confirm_dlg.dlgopt; @@ -904,6 +929,10 @@ M.form_filemanager.init = function(Y, options) { node.one('.fp-dlg-butconfirm').on('click', handle_confirm, this); node.one('.fp-dlg-butcancel').on('click', handle_cancel, this); } + // This used to focus on before active element after confirm dialogue closed. + if (typeof dialog_options.previousActiveElement != 'undefined') { + this.confirm_dlg.set('focusAfterHide', dialog_options.previousActiveElement); + } this.confirm_dlg.dlgopt = dialog_options; if (typeof dialog_options.header != 'undefined') { this.confirm_dlg.set('headerContent', dialog_options.header); @@ -969,7 +998,7 @@ M.form_filemanager.init = function(Y, options) { callback: function(id, obj, args) { //args.scope.selectui.hide(); args.scope.filecount--; - args.scope.refresh(obj.filepath); + args.scope.refresh(obj.filepath, {action: 'delete'}); if (typeof M.core_formchangechecker != 'undefined') { M.core_formchangechecker.set_form_changed(); } @@ -977,6 +1006,10 @@ M.form_filemanager.init = function(Y, options) { }); }; this.selectui.hide(); // TODO remove this after confirm dialog is replaced with YUI3 + // This is used to focus on before active element after confirm dialogue closed. + if (this.options.previousActiveElement !== undefined) { + dialog_options.previousActiveElement = this.options.previousActiveElement; + } this.show_confirm_dialog(dialog_options); }, this); selectnode.one('.fp-file-zip').on('click', function(e) { @@ -1045,7 +1078,8 @@ M.form_filemanager.init = function(Y, options) { params: params, callback: function(id, obj, args) { args.scope.selectui.hide(); - args.scope.refresh(fileinfo.filepath); + var actionfile = {action: 'setmainfile', newfilename: fileinfo.fullname}; + args.scope.refresh(fileinfo.filepath, actionfile); } }); }, this); @@ -1181,9 +1215,9 @@ M.form_filemanager.init = function(Y, options) { this.selectui.show(); Y.one('#'+selectnode.get('id')).focus(); }, - render: function() { + render: function(obj, action) { this.print_path(); - this.view_files(); + this.view_files(null, action); }, has_folder: function(foldername) { var element;