Skip to content

Commit

Permalink
MDL-64554 user: make private files editor modal/ajax form
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Feb 17, 2021
1 parent aa33a22 commit 440073f
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 144 deletions.
10 changes: 8 additions & 2 deletions blocks/private_files/block_private_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ function get_content() {
$this->content->text = $renderer->private_files_tree();
if (has_capability('moodle/user:manageownfiles', $this->context)) {
$this->content->footer = html_writer::link(
new moodle_url('/user/files.php', array('returnurl' => $this->page->url->out())),
get_string('privatefilesmanage') . '...');
new moodle_url('/user/files.php'),
get_string('privatefilesmanage') . '...',
['data-action' => 'manageprivatefiles']);
$this->page->requires->js_call_amd(
'core_user/private_files',
'initModal',
['[data-action=manageprivatefiles]', \core_user\form\private_files::class]
);
}

}
Expand Down
4 changes: 2 additions & 2 deletions files/tests/behat/license_help_modal.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Feature: View licence links
@javascript @_file_upload
Scenario: Altering a file should display licence list modal
Given I log in as "admin"
And I follow "Manage private files..."
And I follow "Private files"
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
And I press "Save changes"
And I follow "Manage private files..."
And I follow "Private files"
And I click on "empty.txt" "link"
And I click on "Help with Choose licence" "icon"
Then I should see "Follow these links for further information on the available licence options:"
Expand Down
1 change: 1 addition & 0 deletions lib/behat/classes/partial_named_selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public function __construct() {
XPATH
, 'dialogue' => <<<XPATH
.//div[contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue ') and
not(contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue-hidden ')) and
normalize-space(descendant::div[
contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue-hd ')
]) = %locator%] |
Expand Down
20 changes: 10 additions & 10 deletions repository/tests/behat/delete_files.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@ Feature: Delete files and folders from the file manager
@javascript @_bug_phantomjs
Scenario: Delete a file and a folder
Given I log in as "admin"
And I follow "Manage private files"
And I follow "Private files"
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
And I create "Delete me" folder in "Files" filemanager
And I press "Save changes"
And I follow "Manage private files"
When I delete "empty.txt" from "Files" filemanager
And I press "Save changes"
Then I should not see "empty.txt"
And I follow "Manage private files"
And I delete "Delete me" from "Files" filemanager
And I press "Save changes"
And I should not see "Delete me"

@javascript
Scenario: Delete a file and a folder using bulk functionality (individually)
Given I log in as "admin"
And I follow "Manage private files"
And I follow "Private files"
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
And I create "Delete me later" folder in "Files" filemanager
And I press "Save changes"
And I follow "Manage private files"
And I click on "Display folder with file details" "link"
And I set the field "Select file 'empty.txt'" to "1"
When I click on "Delete" "link"
Expand All @@ -36,7 +33,6 @@ Feature: Delete files and folders from the file manager
Then I should not see "empty.txt"
But I should see "Delete me later"
When I press "Save changes"
And I follow "Manage private files"
Then I should not see "empty.txt"
But I should see "Delete me later"
And I set the field "Select file 'Delete me later'" to "1"
Expand All @@ -49,12 +45,11 @@ Feature: Delete files and folders from the file manager
@javascript
Scenario: Delete a file and a folder using bulk functionality (multiple)
Given I log in as "admin"
And I follow "Manage private files"
And I follow "Private files"
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
And I create "Delete me" folder in "Files" filemanager
And I create "Do not delete me" folder in "Files" filemanager
And I press "Save changes"
And I follow "Manage private files"
And I click on "Display folder with file details" "link"
And I set the field "Select file 'empty.txt'" to "1"
And I set the field "Select file 'Delete me'" to "1"
Expand All @@ -65,19 +60,21 @@ Feature: Delete files and folders from the file manager
And I should not see "empty.txt"
But I should see "Do not delete me"
When I press "Save changes"
Then I should not see "Delete me"
And I should not see "empty.txt"
And I am on homepage
Then I should not see "Delete me" in the "Private files" "block"
And I should not see "empty.txt" in the "Private files" "block"
But I should see "Do not delete me" in the "Private files" "block"

@javascript
Scenario: Delete files using the select all checkbox
Given I log in as "admin"
And I follow "Manage private files"
And I follow "Private files"
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
And I create "Delete me" folder in "Files" filemanager
And I create "Delete me too" folder in "Files" filemanager
And I press "Save changes"
And I follow "Manage private files"
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:
Expand All @@ -91,6 +88,9 @@ Feature: Delete files and folders from the file manager
And I should not see "empty.txt"
And I should not see "Delete me too"
When I press "Save changes"
Then I should not see "Delete me"
And I should not see "empty.txt"
And I am on homepage
Then I should not see "Delete me" in the "Private files" "block"
And I should not see "empty.txt" in the "Private files" "block"
And I should not see "Delete me too" in the "Private files" "block"
3 changes: 1 addition & 2 deletions repository/upload/tests/behat/upload_file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Upload files
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And I log in as "admin"
When I follow "Manage private files..."
When I follow "Private files"
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
Then I should see "1" elements in "Files" filemanager
And I should see "empty.txt" in the "div.fp-content" "css_element"
Expand All @@ -19,4 +19,3 @@ Feature: Upload files
Then I should see "2" elements in "Files" filemanager
And I should see "empty.txt"
And I should see "empty_copy.txt"
And I press "Cancel"
2 changes: 2 additions & 0 deletions user/amd/build/private_files.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions user/amd/build/private_files.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions user/amd/src/private_files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Module to handle AJAX interactions with user private files
*
* @module core_user/private_files
* @copyright 2020 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import DynamicForm from 'core_form/dynamicform';
import ModalForm from 'core_form/modalform';
import {get_string as getString} from 'core/str';
import {add as addToast} from 'core/toast';

/**
* Initialize private files form as AJAX form
*
* @param {String} containerSelector
* @param {String} formClass
*/
export const initDynamicForm = (containerSelector, formClass) => {
const form = new DynamicForm(document.querySelector(containerSelector), formClass);
// When form is saved, refresh it to remove validation errors, if any:
form.addEventListener(form.events.FORM_SUBMITTED, () => {
form.load();
getString('changessaved')
.then(addToast)
.catch(null);
});
};

/**
* Initialize private files form as Modal form
*
* @param {String} elementSelector
* @param {String} formClass
*/
export const initModal = (elementSelector, formClass) => {
document.querySelector(elementSelector).addEventListener('click', function(e) {
e.preventDefault();
const form = new ModalForm({
formClass,
args: {nosubmit: true},
modalConfig: {title: getString('privatefilesmanage')},
returnFocus: e.target,
});
form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
form.show();
});
};
Loading

0 comments on commit 440073f

Please sign in to comment.