From 56260354b119c50bde5e2f37eecf4f9e63e2eb67 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 10 Feb 2023 13:06:42 +0800 Subject: [PATCH] MDL-77174 filemanager: Switch from YUI dialogue to utility modal --- lib/form/filemanager.js | 55 +++++-------------- lib/javascript-static.js | 9 +-- .../tests/behat/file_type_restriction.feature | 16 +++--- repository/tests/behat/behat_filepicker.php | 2 +- repository/tests/behat/delete_files.feature | 20 +++---- 5 files changed, 34 insertions(+), 68 deletions(-) diff --git a/lib/form/filemanager.js b/lib/form/filemanager.js index 057aee314ee..6c1ad93a281 100644 --- a/lib/form/filemanager.js +++ b/lib/form/filemanager.js @@ -826,6 +826,7 @@ M.form_filemanager.init = function(Y, options) { if (!confirmed) { dialog_options.message = M.util.get_string('confirmrenamefolder', 'repository'); this.show_confirm_dialog(dialog_options); + this.selectui.hide(); return; } params = {filepath:fileinfo.filepath, newdirname:newfilename, newfilepath:targetpath}; @@ -903,49 +904,19 @@ M.form_filemanager.init = function(Y, options) { * Displays a confirmation dialog * Expected attributes in dialog_options: message, callback, callbackargs(optional), scope(optional) */ - show_confirm_dialog: function(dialog_options) { - // instead of M.util.show_confirm_dialog(e, dialog_options); - if (!this.confirm_dlg) { - this.confirm_dlg_node = Y.Node.create(M.form_filemanager.templates.confirmdialog); - var node = this.confirm_dlg_node; - node.generateID(); - this.confirm_dlg = new M.core.dialogue({ - draggable : true, - bodyContent : node, - centered : true, - modal : true, - visible : false, - buttons : {}, + show_confirm_dialog: function(dialogOptions) { + require(['core/notification', 'core/str'], function(Notification, Str) { + Notification.saveCancelPromise( + Str.get_string('confirm', 'moodle'), + dialogOptions.message, + Str.get_string('yes', 'moodle') + ).then(function() { + dialogOptions.callback.apply(dialogOptions.scope, dialogOptions.callbackargs); + return; + }).catch(function() { + // User cancelled. }); - var handle_confirm = function(ev) { - var dlgopt = this.confirm_dlg.dlgopt; - ev.preventDefault(); - this.confirm_dlg.hide(); - if (dlgopt.callback) { - if (dlgopt.callbackargs) { - dlgopt.callback.apply(dlgopt.scope || this, dlgopt.callbackargs); - } else { - dlgopt.callback.apply(dlgopt.scope || this); - } - } - } - var handle_cancel = function(ev) { - ev.preventDefault(); - this.confirm_dlg.hide(); - } - 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); - } - this.confirm_dlg_node.one('.fp-dlg-text').setContent(dialog_options.message); - this.confirm_dlg.show(); + }); }, setup_select_file: function() { var selectnode = this.selectnode; diff --git a/lib/javascript-static.js b/lib/javascript-static.js index d55e0c27ed6..02c9f333181 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -57,13 +57,8 @@ M.util.image_url = function(imagename, component) { return url; }; -M.util.in_array = function(item, array){ - for( var i = 0; iperform_on_element('delete', $exception); // Yes, we are sure. - $this->execute('behat_general::i_click_on_in_the', [get_string('ok'), 'button', get_string('confirm'), 'dialogue']); + $this->execute('behat_general::i_click_on_in_the', [get_string('yes'), 'button', get_string('confirm'), 'dialogue']); } /** diff --git a/repository/tests/behat/delete_files.feature b/repository/tests/behat/delete_files.feature index feea3258122..91716c71b73 100644 --- a/repository/tests/behat/delete_files.feature +++ b/repository/tests/behat/delete_files.feature @@ -1,8 +1,8 @@ @core @core_filepicker @_file_upload Feature: Delete files and folders from the file manager - In order to clean the file manager contents - As a user - I need to delete files from file areas + In order to clean the file manager contents + As a user + I need to delete files from file areas Background: Given the following "blocks" exist: @@ -38,7 +38,7 @@ Feature: Delete files and folders from the file manager And I set the field "Select file 'empty.txt'" to "1" When I click on "Delete" "link" Then I should see "Are you sure you want to delete the selected 1 file(s)?" - When I click on "OK" "button" in the "Confirm" "dialogue" + When I click on "Yes" "button" in the "Confirm" "dialogue" Then I should not see "empty.txt" in the "Manage private files" "dialogue" But I should see "Delete me later" in the "Manage private files" "dialogue" When I press "Save changes" @@ -47,7 +47,7 @@ Feature: Delete files and folders from the file manager But I should see "Delete me later" in the "Manage private files" "dialogue" And I set the field "Select file 'Delete me later'" to "1" And I click on "Delete" "link" - And I click on "OK" "button" in the "Confirm" "dialogue" + And I click on "Yes" "button" in the "Confirm" "dialogue" Then I should not see "Delete me later" in the "Manage private files" "dialogue" When I press "Save changes" And I follow "Manage private files..." @@ -67,7 +67,7 @@ Feature: Delete files and folders from the file manager And I set the field "Select file 'Delete me'" to "1" When I click on "Delete" "link" Then I should see "Are you sure you want to delete the selected 2 file(s)?" - When I click on "OK" "button" in the "Confirm" "dialogue" + When I click on "Yes" "button" in the "Confirm" "dialogue" Then I should not see "Delete me" in the "Manage private files" "dialogue" And I should not see "empty.txt" in the "Manage private files" "dialogue" But I should see "Do not delete me" in the "Manage private files" "dialogue" @@ -92,12 +92,12 @@ Feature: Delete files and folders from the file manager And I click on "Display folder with file details" "link" When I click on "Select all/none" "checkbox" Then the following fields match these values: - | Select file 'empty.txt' | 1 | - | Select file 'Delete me' | 1 | + | Select file 'empty.txt' | 1 | + | Select file 'Delete me' | 1 | | Select file 'Delete me too' | 1 | When I click on "Delete" "link" Then I should see "Are you sure you want to delete the selected 3 file(s)?" - When I click on "OK" "button" in the "Confirm" "dialogue" + When I click on "Yes" "button" in the "Confirm" "dialogue" Then I should not see "Delete me" in the "Manage private files" "dialogue" And I should not see "empty.txt" in the "Manage private files" "dialogue" And I should not see "Delete me too" in the "Manage private files" "dialogue" @@ -121,7 +121,7 @@ Feature: Delete files and folders from the file manager And I set the field "Select file 'one'" to "1" And I click on "Delete" "link" And I should see "Are you sure you want to delete the selected 1 file(s)?" - And I click on "OK" "button" in the "Confirm" "dialogue" + And I click on "Yes" "button" in the "Confirm" "dialogue" And I click on "Save changes" "button" And I am on the "System logs report" page And I click on "Get these logs" "button"