mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-66911 core files: Add license help to file selector
This improvement adds a help icon to the 'Choose license' option providing links to further information on each license. Utilise templates for license links to avoid code reuse.
This commit is contained in:
parent
68fd8d8bdf
commit
2228ca31a2
@ -250,7 +250,9 @@ class core_files_renderer extends plugin_renderer_base {
|
||||
*/
|
||||
protected function fm_js_template_fileselectlayout() {
|
||||
$context = [
|
||||
'helpicon' => $this->help_icon('setmainfile', 'repository')
|
||||
'helpicon' => $this->help_icon('setmainfile', 'repository'),
|
||||
'licensehelpicon' => $this->create_license_help_icon_context(),
|
||||
'columns' => true
|
||||
];
|
||||
return $this->render_from_template('core/filemanager_fileselect', $context);
|
||||
}
|
||||
@ -403,7 +405,10 @@ class core_files_renderer extends plugin_renderer_base {
|
||||
* @return string
|
||||
*/
|
||||
protected function fp_js_template_selectlayout() {
|
||||
return $this->render_from_template('core/filemanager_selectlayout', []);
|
||||
$context = [
|
||||
'licensehelpicon' => $this->create_license_help_icon_context()
|
||||
];
|
||||
return $this->render_from_template('core/filemanager_selectlayout', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -412,7 +417,10 @@ class core_files_renderer extends plugin_renderer_base {
|
||||
* @return string
|
||||
*/
|
||||
protected function fp_js_template_uploadform() {
|
||||
return $this->render_from_template('core/filemanager_uploadform', []);
|
||||
$context = [
|
||||
'licensehelpicon' => $this->create_license_help_icon_context()
|
||||
];
|
||||
return $this->render_from_template('core/filemanager_uploadform', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -519,6 +527,34 @@ class core_files_renderer extends plugin_renderer_base {
|
||||
public function repository_default_searchform() {
|
||||
return $this->render_from_template('core/filemanager_default_searchform', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the context for rendering help icon with license links displaying all licenses and sources.
|
||||
*
|
||||
* @return \stdClass $iconcontext the context for rendering license help info.
|
||||
*/
|
||||
protected function create_license_help_icon_context() : stdClass {
|
||||
$licensecontext = new stdClass();
|
||||
|
||||
$licenses = [];
|
||||
// Discard licenses without a name or source from enabled licenses.
|
||||
foreach (license_manager::get_licenses(['enabled' => 1]) as $license) {
|
||||
if (!empty($license->fullname) && !empty($license->source)) {
|
||||
// Get license fullname strings using the shortname for internationalisation.
|
||||
$license->fullname = get_string($license->shortname, 'license');
|
||||
$licenses[] = $license;
|
||||
}
|
||||
}
|
||||
|
||||
$licensecontext->licenses = $licenses;
|
||||
$helptext = $this->render_from_template('core/filemanager_licenselinks', $licensecontext);
|
||||
|
||||
$iconcontext = new stdClass();
|
||||
$iconcontext->text = $helptext;
|
||||
$iconcontext->alt = get_string('helpprefix2', 'moodle', get_string('chooselicense', 'repository'));
|
||||
|
||||
return $iconcontext;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
52
files/tests/behat/license_help_modal.feature
Normal file
52
files/tests/behat/license_help_modal.feature
Normal file
@ -0,0 +1,52 @@
|
||||
@core @core_files
|
||||
Feature: View license links
|
||||
In order to get select the applicable license when uploading a file
|
||||
As a user
|
||||
I need to be able to navigate to a page containing license terms from the file manager
|
||||
|
||||
@javascript
|
||||
Scenario: Uploading a file displays license list modal
|
||||
Given I log in as "admin"
|
||||
And I follow "Manage private files..."
|
||||
And I wait until the page is ready
|
||||
And I follow "Add..."
|
||||
And I follow "Upload a file"
|
||||
And I click on "Help with Choose license" "icon" in the "File picker" "dialogue"
|
||||
Then I should see "Follow these links for further information on the available license options:"
|
||||
|
||||
@javascript @_file_upload
|
||||
Scenario: Altering a file should display license list modal
|
||||
Given I log in as "admin"
|
||||
And I follow "Manage 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 click on "empty.txt" "link"
|
||||
And I click on "Help with Choose license" "icon"
|
||||
Then I should see "Follow these links for further information on the available license options:"
|
||||
|
||||
@javascript @_file_upload
|
||||
Scenario: Recent files should display license list modal
|
||||
Given I log in as "admin"
|
||||
And I follow "Manage 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 "Add..."
|
||||
And I click on "Recent files" "link" in the "File picker" "dialogue"
|
||||
And I click on "empty.txt" "link" in the "File picker" "dialogue"
|
||||
And I click on "Help with Choose license" "icon" in the ".fp-setlicense" "css_element"
|
||||
Then I should see "Follow these links for further information on the available license options:"
|
||||
|
||||
@javascript @_file_upload
|
||||
Scenario: Private files should display license list modal
|
||||
Given I log in as "admin"
|
||||
And I follow "Manage 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 "Add..."
|
||||
And I click on "Private files" "link" in the "File picker" "dialogue"
|
||||
And I click on "empty.txt" "link" in the "File picker" "dialogue"
|
||||
And I click on "Help with Choose license" "icon" in the ".fp-setlicense" "css_element"
|
||||
Then I should see "Follow these links for further information on the available license options:"
|
@ -137,6 +137,7 @@ $string['getfiletimeout'] = 'Get file timeout';
|
||||
$string['help'] = 'Help';
|
||||
$string['choosealink'] = 'Choose a link...';
|
||||
$string['chooselicense'] = 'Choose license';
|
||||
$string['chooselicense_help'] = 'Follow these links for further information on the available license options:';
|
||||
$string['createfolder'] = 'Create folder';
|
||||
$string['iconview'] = 'View as icons';
|
||||
$string['imagesize'] = '{$a->width} x {$a->height} px';
|
||||
@ -179,6 +180,7 @@ $string['noenter'] = 'Nothing entered';
|
||||
$string['nofilesattached'] = 'No files attached';
|
||||
$string['nofilesavailable'] = 'No files available';
|
||||
$string['nofilesselected'] = 'No files selected';
|
||||
$string['nolicenses'] = 'There are no licences available';
|
||||
$string['nomorefiles'] = 'No more attachments allowed';
|
||||
$string['nopathselected'] = 'No destination path select yet (double click tree node to select)';
|
||||
$string['nopermissiontoaccess'] = 'No permission to access this repository.';
|
||||
|
39
lib/templates/filemanager_chooselicense.mustache
Normal file
39
lib/templates/filemanager_chooselicense.mustache
Normal file
@ -0,0 +1,39 @@
|
||||
{{!
|
||||
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/>.
|
||||
}}
|
||||
{{!
|
||||
@template core/filemanager_chooselicense
|
||||
|
||||
This template renders the form label and select element for choosing a license associated with a file.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"licensehelpicon": {
|
||||
"text": "<ul><li><a href='http://en.wikipedia.org/wiki/All_rights_reserved'>All rights reserved</a></li></ul>",
|
||||
"alt": "Help with Choose license"
|
||||
},
|
||||
"columns": true
|
||||
}
|
||||
}}
|
||||
<div class="col-form-label form-control-label px-0 {{#columns}}col-4{{/columns}}">
|
||||
<label for="choose-license-{{uniqid}}">
|
||||
{{#str}}chooselicense, repository{{/str}}
|
||||
</label>
|
||||
{{#licensehelpicon}}{{>core/help_icon}}{{/licensehelpicon}}
|
||||
</div>
|
||||
<div {{#columns}}class="col-8"{{/columns}}>
|
||||
<select id="choose-license-{{uniqid}}" class="form-control"></select>
|
||||
</div>
|
@ -21,7 +21,12 @@
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"helpicon": "<a class='btn ..'><i class='icon fa fa-question-circle ..'></i></a>"
|
||||
"helpicon": "<a class='btn ..'><i class='icon fa fa-question-circle ..'></i></a>",
|
||||
"licensehelpicon": {
|
||||
"text": "<ul><li><a href='http://en.wikipedia.org/wiki/All_rights_reserved'>All rights reserved</a></li></ul>",
|
||||
"alt": "Help with Choose license"
|
||||
},
|
||||
"columns": true
|
||||
}
|
||||
}}
|
||||
<div class="filemanager fp-select">
|
||||
@ -48,10 +53,7 @@
|
||||
|
||||
</div>
|
||||
<div class="fp-license form-group row mx-0">
|
||||
<label class="form-control-label col-4 px-0">{{#str}}chooselicense, repository{{/str}}</label>
|
||||
<div class="col-8 form-inline pr-0">
|
||||
<select class="custom-select form-control"></select>
|
||||
</div>
|
||||
{{>core/filemanager_chooselicense}}
|
||||
</div>
|
||||
<div class="fp-path form-group row mx-0">
|
||||
<label class="form-control-label col-4 px-0">{{#str}}path, repository{{/str}}</label>
|
||||
|
74
lib/templates/filemanager_licenselinks.mustache
Normal file
74
lib/templates/filemanager_licenselinks.mustache
Normal file
@ -0,0 +1,74 @@
|
||||
{{!
|
||||
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/>.
|
||||
}}
|
||||
{{!
|
||||
@template core/filemanager_licenselinks
|
||||
|
||||
This template renders the window with file information/actions.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"licenses":[
|
||||
{
|
||||
"fullname":"All rights reserved",
|
||||
"source":"http:\/\/en.wikipedia.org\/wiki\/All_rights_reserved"
|
||||
},
|
||||
{
|
||||
"fullname":"Public Domain",
|
||||
"source":"http:\/\/creativecommons.org\/licenses\/publicdomain\/"
|
||||
},
|
||||
{
|
||||
"fullname":"Creative Commons",
|
||||
"source":"http:\/\/creativecommons.org\/licenses\/by\/3.0\/"
|
||||
},
|
||||
{
|
||||
"fullname":"Creative Commons - NoDerivs",
|
||||
"source":"http:\/\/creativecommons.org\/licenses\/by-nd\/3.0\/"
|
||||
},
|
||||
{
|
||||
"fullname":"Creative Commons - No Commercial NoDerivs",
|
||||
"source":"http:\/\/creativecommons.org\/licenses\/by-nc-nd\/3.0\/"
|
||||
},
|
||||
{
|
||||
"fullname":"Creative Commons - No Commercial",
|
||||
"source":"http:\/\/creativecommons.org\/licenses\/by-nc\/3.0\/"
|
||||
},
|
||||
{
|
||||
"fullname":"Creative Commons - No Commercial ShareAlike",
|
||||
"source":"http:\/\/creativecommons.org\/licenses\/by-nc-sa\/3.0\/"
|
||||
},
|
||||
{
|
||||
"fullname":"Creative Commons - ShareAlike",
|
||||
"source":"http:\/\/creativecommons.org\/licenses\/by-sa\/3.0\/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}}
|
||||
<p class="mb-1">
|
||||
{{#str}}chooselicense_help, repository{{/str}}
|
||||
</p>
|
||||
<ul>
|
||||
{{#licenses}}
|
||||
<li>
|
||||
<a href="{{source}}" target="_blank">{{fullname}}</a>
|
||||
</li>
|
||||
{{/licenses}}
|
||||
{{^licenses}}
|
||||
<li>
|
||||
{{#str}}nolicenses, repository{{/str}}
|
||||
</li>
|
||||
{{/licenses}}
|
||||
</ul>
|
@ -64,8 +64,7 @@
|
||||
<input class="form-control" type="text">
|
||||
</div>
|
||||
<div class="fp-setlicense form-group row">
|
||||
<label class="col-form-label">{{#str}}chooselicense, repository{{/str}}</label>
|
||||
<select class="custom-select"></select>
|
||||
{{>core/filemanager_chooselicense}}
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="fp-select-buttons">
|
||||
|
@ -40,9 +40,8 @@
|
||||
<label>{{#str}}author, repository{{/str}}</label>
|
||||
<input type="text" class="form-control"/>
|
||||
</div>
|
||||
<div class="fp-setlicense control-group">
|
||||
<label>{{#str}}chooselicense, repository{{/str}}</label>
|
||||
<select class="custom-select"></select>
|
||||
<div class="fp-setlicense form-group">
|
||||
{{>core/filemanager_chooselicense}}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user