MDL-77174 filemanager: Switch from YUI dialogue to utility modal

This commit is contained in:
Andrew Nicols 2023-02-10 13:06:42 +08:00
parent 10838ef878
commit 56260354b1
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
5 changed files with 34 additions and 68 deletions

View File

@ -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;

View File

@ -57,13 +57,8 @@ M.util.image_url = function(imagename, component) {
return url;
};
M.util.in_array = function(item, array){
for( var i = 0; i<array.length; i++){
if(item==array[i]){
return true;
}
}
return false;
M.util.in_array = function(item, array) {
return array.indexOf(item) !== -1;
};
/**

View File

@ -1,18 +1,18 @@
@mod @mod_workshop
Feature: File types of the submission and feedback attachments can be limitted
In order to constrain student submission and feedback attachments
As a teacher
I need to be able to specify the list of allowed file types
In order to constrain student submission and feedback attachments
As a teacher
I need to be able to specify the list of allowed file types
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| username | firstname | lastname | email |
| teacher1 | Terry1 | Teacher1 | teacher1@example.com |
| student1 | Sam1 | Student1 | student1@example.com |
| student2 | Sam2 | Student2 | student2@example.com |
And the following "courses" exist:
| fullname | shortname |
| Course1 | c1 |
| fullname | shortname |
| Course1 | c1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | c1 | editingteacher |
@ -44,7 +44,7 @@ Feature: File types of the submission and feedback attachments can be limitted
And I set the field "Name" to "testable.php"
And I press "Update"
And I should see "The original file extension has been modified as a part of the file name change. Changing the extension from \".png\" to \".php\" may result in a file which cannot be opened."
And I click on "OK" "button" in the ".moodle-dialogue-base[aria-hidden='false']" "css_element"
And I click on "Yes" "button" in the "Confirm" "dialogue"
When I press "Save changes"
Then I should see "Some files (testable.php) cannot be uploaded. Only file types image are allowed."
# Remove the invalid file and attach an image instead.
@ -96,7 +96,7 @@ Feature: File types of the submission and feedback attachments can be limitted
And I set the field "Name" to "renamed.png"
And I press "Update"
And I should see "The original file extension has been modified as a part of the file name change. Changing the extension from \".php\" to \".png\" may result in a file which cannot be opened."
And I click on "OK" "button" in the ".moodle-dialogue-base[aria-hidden='false']" "css_element"
And I click on "Yes" "button" in the "Confirm" "dialogue"
When I press "Save and close"
Then I should see "Some files (renamed.png) cannot be uploaded. Only file types .php are allowed."
And I should not see "Assigned submissions to assess"

View File

@ -172,7 +172,7 @@ class behat_filepicker extends behat_base {
$this->perform_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']);
}
/**

View File

@ -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"