mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-75410 mod_data: reset all templates feature
This commit is contained in:
parent
5877ae306e
commit
151b0ba350
10
mod/data/amd/build/resetalltemplates.min.js
vendored
Normal file
10
mod/data/amd/build/resetalltemplates.min.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
define("mod_data/resetalltemplates",["exports","core/notification","core/prefetch","core/str"],(function(_exports,_notification,_prefetch,_str){var obj;
|
||||
/**
|
||||
* Javascript module for reseting all templates.
|
||||
*
|
||||
* @module mod_data/resetalltemplates
|
||||
* @copyright 2022 Ferran Recio <ferran@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_notification=(obj=_notification)&&obj.__esModule?obj:{default:obj};const selectors_resetAllTemplatesAction='[data-action="resetalltemplates"]';_exports.init=()=>{(0,_prefetch.prefetchStrings)("mod_data",["resetalltemplatesconfirmtitle","resetalltemplatesconfirm"]),(0,_prefetch.prefetchStrings)("core",["reset"]),registerEventListeners()};const registerEventListeners=()=>{document.addEventListener("click",(event=>{const actionLink=event.target.closest(selectors_resetAllTemplatesAction);actionLink&&(event.preventDefault(),resetAllTemplatesConfirm(actionLink))}))},resetAllTemplatesConfirm=async actionLink=>{try{await _notification.default.saveCancelPromise((0,_str.get_string)("resetalltemplatesconfirmtitle","mod_data"),(0,_str.get_string)("resetalltemplatesconfirm","mod_data"),(0,_str.get_string)("reset","core")),window.location=actionLink.href}catch(error){return}}}));
|
||||
|
||||
//# sourceMappingURL=resetalltemplates.min.js.map
|
1
mod/data/amd/build/resetalltemplates.min.js.map
Normal file
1
mod/data/amd/build/resetalltemplates.min.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"resetalltemplates.min.js","sources":["../src/resetalltemplates.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Javascript module for reseting all templates.\n *\n * @module mod_data/resetalltemplates\n * @copyright 2022 Ferran Recio <ferran@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Notification from 'core/notification';\nimport {prefetchStrings} from 'core/prefetch';\nimport {get_string as getString} from 'core/str';\n\nconst selectors = {\n resetAllTemplatesAction: '[data-action=\"resetalltemplates\"]',\n};\n\n/**\n * Initialize module\n */\nexport const init = () => {\n prefetchStrings('mod_data', [\n 'resetalltemplatesconfirmtitle',\n 'resetalltemplatesconfirm',\n ]);\n prefetchStrings('core', [\n 'reset',\n ]);\n registerEventListeners();\n};\n\n/**\n * Register events for option in action menu.\n */\nconst registerEventListeners = () => {\n document.addEventListener('click', (event) => {\n const actionLink = event.target.closest(selectors.resetAllTemplatesAction);\n if (actionLink) {\n event.preventDefault();\n resetAllTemplatesConfirm(actionLink);\n }\n });\n};\n\n/**\n * Show the confirmation modal to reset all the templates.\n *\n * @param {HTMLElement} actionLink the element that triggers the action.\n */\nconst resetAllTemplatesConfirm = async(actionLink) => {\n try {\n await Notification.saveCancelPromise(\n getString('resetalltemplatesconfirmtitle', 'mod_data'),\n getString('resetalltemplatesconfirm', 'mod_data'),\n getString('reset', 'core'),\n );\n window.location = actionLink.href;\n } catch (error) {\n return;\n }\n};\n"],"names":["selectors","registerEventListeners","document","addEventListener","event","actionLink","target","closest","preventDefault","resetAllTemplatesConfirm","async","Notification","saveCancelPromise","window","location","href","error"],"mappings":";;;;;;;4JA2BMA,kCACuB,kDAMT,mCACA,WAAY,CACxB,gCACA,2DAEY,OAAQ,CACpB,UAEJC,gCAMEA,uBAAyB,KAC3BC,SAASC,iBAAiB,SAAUC,cAC1BC,WAAaD,MAAME,OAAOC,QAAQP,mCACpCK,aACAD,MAAMI,iBACNC,yBAAyBJ,iBAU/BI,yBAA2BC,MAAAA,uBAEnBC,sBAAaC,mBACf,mBAAU,gCAAiC,aAC3C,mBAAU,2BAA4B,aACtC,mBAAU,QAAS,SAEvBC,OAAOC,SAAWT,WAAWU,KAC/B,MAAOC"}
|
5
mod/data/amd/build/templateseditor.min.js
vendored
5
mod/data/amd/build/templateseditor.min.js
vendored
@ -1,11 +1,10 @@
|
||||
define("mod_data/templateseditor",["exports","core/str","core/prefetch","core/url","core/notification"],(function(_exports,_str,_prefetch,_url,_notification){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,
|
||||
define("mod_data/templateseditor",["exports","core/str","core/prefetch","core/url","core/notification","core/templates"],(function(_exports,_str,_prefetch,_url,_notification,_templates){var obj;
|
||||
/**
|
||||
* Javascript module to control the template editor.
|
||||
*
|
||||
* @module mod_data/templateseditor
|
||||
* @copyright 2021 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
(0,_prefetch.prefetchStrings)("admin",["confirmation"]),(0,_prefetch.prefetchStrings)("mod_data",["resettemplateconfirmtitle","resettemplateconfirm","resettemplate","enabletemplateeditorcheck","editorenable"]);const selectors_toggleTemplateEditor='input[name="useeditor"]',selectors_resetTemplate='input[name="defaultform"]',selectors_resetButton='input[name="resetbutton"]',selectors_editForm="#edittemplateform",registerResetButton=()=>{const editForm=document.querySelector(selectors_editForm),resetButton=document.querySelector(selectors_resetButton),resetTemplate=document.querySelector(selectors_resetTemplate);resetButton&&resetTemplate&&editForm&&resetButton.addEventListener("click",(async event=>{event.preventDefault(),(0,_notification.saveCancel)((0,_str.get_string)("resettemplateconfirmtitle","mod_data"),(0,_str.get_string)("resettemplateconfirm","mod_data"),(0,_str.get_string)("resettemplate","mod_data"),(()=>{resetTemplate.value="true",editForm.submit()}),null,{triggerElement:event.target})}))},registerEditorToggler=(instanceId,mode)=>{const toggleTemplateEditor=document.querySelector(selectors_toggleTemplateEditor);toggleTemplateEditor&&toggleTemplateEditor.addEventListener("click",(async event=>{event.preventDefault();event.target.checked?(0,_notification.saveCancel)((0,_str.get_string)("confirmation","admin"),(0,_str.get_string)("enabletemplateeditorcheck","mod_data"),(0,_str.get_string)("editorenable","mod_data"),(()=>{window.location=(0,_url.relativeUrl)("/mod/data/templates.php",{d:instanceId,mode:mode,useeditor:!0})}),null,{triggerElement:event.target}):window.location=(0,_url.relativeUrl)("/mod/data/templates.php",{d:instanceId,mode:mode,useeditor:!1})}))};_exports.init=(instanceId,mode)=>{((instanceId,mode)=>{registerResetButton(),registerEditorToggler(instanceId,mode)})(instanceId,mode)}}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_templates=(obj=_templates)&&obj.__esModule?obj:{default:obj},(0,_prefetch.prefetchStrings)("admin",["confirmation"]),(0,_prefetch.prefetchStrings)("mod_data",["resettemplateconfirmtitle","resettemplateconfirm","enabletemplateeditorcheck","editorenable"]),(0,_prefetch.prefetchStrings)("core",["reset"]);const selectors_toggleTemplateEditor='input[name="useeditor"]',selectors_resetTemplate='input[name="defaultform"]',selectors_resetAllTemplates='input[name="resetall"]',selectors_resetButton='input[name="resetbutton"]',selectors_resetAllCheck='input[name="resetallcheck"]',selectors_editForm="#edittemplateform",registerResetButton=()=>{const editForm=document.querySelector(selectors_editForm),resetButton=document.querySelector(selectors_resetButton),resetTemplate=document.querySelector(selectors_resetTemplate),resetAllTemplates=document.querySelector(selectors_resetAllTemplates);resetButton&&resetTemplate&&editForm&&(resetButton.addEventListener("click",(async event=>{event.preventDefault(),(0,_notification.saveCancel)((0,_str.get_string)("resettemplateconfirmtitle","mod_data"),_templates.default.render("mod_data/template_editor_resetmodal",{resetallname:"resetallcheck"}),(0,_str.get_string)("reset","core"),(()=>{resetTemplate.value="true",editForm.submit()}),null,{triggerElement:event.target})})),resetAllTemplates&&document.addEventListener("change",(event=>{event.target.matches(selectors_resetAllCheck)&&(resetAllTemplates.value=event.target.checked?"true":"")})))},registerEditorToggler=(instanceId,mode)=>{const toggleTemplateEditor=document.querySelector(selectors_toggleTemplateEditor);toggleTemplateEditor&&toggleTemplateEditor.addEventListener("click",(async event=>{event.preventDefault();event.target.checked?(0,_notification.saveCancel)((0,_str.get_string)("confirmation","admin"),(0,_str.get_string)("enabletemplateeditorcheck","mod_data"),(0,_str.get_string)("editorenable","mod_data"),(()=>{window.location=(0,_url.relativeUrl)("/mod/data/templates.php",{d:instanceId,mode:mode,useeditor:!0})}),null,{triggerElement:event.target}):window.location=(0,_url.relativeUrl)("/mod/data/templates.php",{d:instanceId,mode:mode,useeditor:!1})}))};_exports.init=(instanceId,mode)=>{((instanceId,mode)=>{registerResetButton(),registerEditorToggler(instanceId,mode)})(instanceId,mode)}}));
|
||||
|
||||
//# sourceMappingURL=templateseditor.min.js.map
|
File diff suppressed because one or more lines are too long
75
mod/data/amd/src/resetalltemplates.js
Normal file
75
mod/data/amd/src/resetalltemplates.js
Normal file
@ -0,0 +1,75 @@
|
||||
// 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/>.
|
||||
|
||||
/**
|
||||
* Javascript module for reseting all templates.
|
||||
*
|
||||
* @module mod_data/resetalltemplates
|
||||
* @copyright 2022 Ferran Recio <ferran@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
import Notification from 'core/notification';
|
||||
import {prefetchStrings} from 'core/prefetch';
|
||||
import {get_string as getString} from 'core/str';
|
||||
|
||||
const selectors = {
|
||||
resetAllTemplatesAction: '[data-action="resetalltemplates"]',
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize module
|
||||
*/
|
||||
export const init = () => {
|
||||
prefetchStrings('mod_data', [
|
||||
'resetalltemplatesconfirmtitle',
|
||||
'resetalltemplatesconfirm',
|
||||
]);
|
||||
prefetchStrings('core', [
|
||||
'reset',
|
||||
]);
|
||||
registerEventListeners();
|
||||
};
|
||||
|
||||
/**
|
||||
* Register events for option in action menu.
|
||||
*/
|
||||
const registerEventListeners = () => {
|
||||
document.addEventListener('click', (event) => {
|
||||
const actionLink = event.target.closest(selectors.resetAllTemplatesAction);
|
||||
if (actionLink) {
|
||||
event.preventDefault();
|
||||
resetAllTemplatesConfirm(actionLink);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the confirmation modal to reset all the templates.
|
||||
*
|
||||
* @param {HTMLElement} actionLink the element that triggers the action.
|
||||
*/
|
||||
const resetAllTemplatesConfirm = async(actionLink) => {
|
||||
try {
|
||||
await Notification.saveCancelPromise(
|
||||
getString('resetalltemplatesconfirmtitle', 'mod_data'),
|
||||
getString('resetalltemplatesconfirm', 'mod_data'),
|
||||
getString('reset', 'core'),
|
||||
);
|
||||
window.location = actionLink.href;
|
||||
} catch (error) {
|
||||
return;
|
||||
}
|
||||
};
|
@ -25,15 +25,18 @@ import {get_string as getString} from 'core/str';
|
||||
import {prefetchStrings} from 'core/prefetch';
|
||||
import {relativeUrl} from 'core/url';
|
||||
import {saveCancel} from 'core/notification';
|
||||
import Templates from 'core/templates';
|
||||
|
||||
prefetchStrings('admin', ['confirmation']);
|
||||
prefetchStrings('mod_data', [
|
||||
'resettemplateconfirmtitle',
|
||||
'resettemplateconfirm',
|
||||
'resettemplate',
|
||||
'enabletemplateeditorcheck',
|
||||
'editorenable'
|
||||
]);
|
||||
prefetchStrings('core', [
|
||||
'reset',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Template editor constants.
|
||||
@ -41,7 +44,9 @@ prefetchStrings('mod_data', [
|
||||
const selectors = {
|
||||
toggleTemplateEditor: 'input[name="useeditor"]',
|
||||
resetTemplate: 'input[name="defaultform"]',
|
||||
resetAllTemplates: 'input[name="resetall"]',
|
||||
resetButton: 'input[name="resetbutton"]',
|
||||
resetAllCheck: 'input[name="resetallcheck"]',
|
||||
editForm: '#edittemplateform',
|
||||
};
|
||||
|
||||
@ -60,6 +65,7 @@ const registerResetButton = () => {
|
||||
const editForm = document.querySelector(selectors.editForm);
|
||||
const resetButton = document.querySelector(selectors.resetButton);
|
||||
const resetTemplate = document.querySelector(selectors.resetTemplate);
|
||||
const resetAllTemplates = document.querySelector(selectors.resetAllTemplates);
|
||||
|
||||
if (!resetButton || !resetTemplate || !editForm) {
|
||||
return;
|
||||
@ -69,8 +75,8 @@ const registerResetButton = () => {
|
||||
event.preventDefault();
|
||||
saveCancel(
|
||||
getString('resettemplateconfirmtitle', 'mod_data'),
|
||||
getString('resettemplateconfirm', 'mod_data'),
|
||||
getString('resettemplate', 'mod_data'),
|
||||
Templates.render('mod_data/template_editor_resetmodal', {resetallname: "resetallcheck"}),
|
||||
getString('reset', 'core'),
|
||||
() => {
|
||||
resetTemplate.value = "true";
|
||||
editForm.submit();
|
||||
@ -79,6 +85,16 @@ const registerResetButton = () => {
|
||||
{triggerElement: event.target}
|
||||
);
|
||||
});
|
||||
|
||||
// The reset all checkbox is inside a modal so we need to capture at document level.
|
||||
if (!resetAllTemplates) {
|
||||
return;
|
||||
}
|
||||
document.addEventListener('change', (event) => {
|
||||
if (event.target.matches(selectors.resetAllCheck)) {
|
||||
resetAllTemplates.value = (event.target.checked) ? "true" : "";
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const registerEditorToggler = (instanceId, mode) => {
|
||||
|
@ -372,6 +372,39 @@ class manager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all templates.
|
||||
*
|
||||
* @return bool if the reset is done or not
|
||||
*/
|
||||
public function reset_all_templates(): bool {
|
||||
$newtemplates = new stdClass();
|
||||
foreach (self::TEMPLATES_LIST as $templatename => $templatefile) {
|
||||
$newtemplates->{$templatename} = '';
|
||||
}
|
||||
return $this->update_templates($newtemplates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all templates related to a specific template.
|
||||
*
|
||||
* @param string $templatename the template name
|
||||
* @return bool if the reset is done or not
|
||||
*/
|
||||
public function reset_template(string $templatename): bool {
|
||||
$newtemplates = new stdClass();
|
||||
// Reset the template to default.
|
||||
$newtemplates->{$templatename} = '';
|
||||
if ($templatename == 'listtemplate') {
|
||||
$newtemplates->listtemplateheader = '';
|
||||
$newtemplates->listtemplatefooter = '';
|
||||
}
|
||||
if ($templatename == 'rsstemplate') {
|
||||
$newtemplates->rsstitletemplate = '';
|
||||
}
|
||||
return $this->update_templates($newtemplates);
|
||||
}
|
||||
|
||||
/** Check if the user can view a specific preset.
|
||||
*
|
||||
* @param preset $preset the preset instance.
|
||||
|
@ -178,7 +178,20 @@ class action_bar {
|
||||
$selectmenu->set_label(get_string('templatesnavigation', 'mod_data'), ['class' => 'sr-only']);
|
||||
|
||||
$renderer = $PAGE->get_renderer('mod_data');
|
||||
|
||||
$presetsactions = $this->get_presets_actions_select(false);
|
||||
|
||||
// Reset all templates action.
|
||||
$resetallurl = new moodle_url($this->currenturl);
|
||||
$resetallurl->param('action', 'resetalltemplates');
|
||||
$presetsactions->add(new \action_menu_link(
|
||||
$resetallurl,
|
||||
null,
|
||||
get_string('resetalltemplates', 'mod_data'),
|
||||
false,
|
||||
['data-action' => 'resetalltemplates', 'data-dataid' => $this->id]
|
||||
));
|
||||
|
||||
$templatesactionbar = new templates_action_bar($this->id, $selectmenu, null, null, $presetsactions);
|
||||
|
||||
return $renderer->render_templates_action_bar($templatesactionbar);
|
||||
|
@ -383,6 +383,9 @@ $string['requiredentriestoview_help'] = 'The number of entries a student is requ
|
||||
|
||||
Note: If entries are required before viewing, the database auto-linking filter should be disabled. This is because the database auto-linking filter can\'t determine whether a user has submitted the required number of entries.';
|
||||
$string['requiredfield'] = 'Required field';
|
||||
$string['resetalltemplates'] = 'Reset all templates';
|
||||
$string['resetalltemplatesconfirmtitle'] = 'Reset all templates?';
|
||||
$string['resetalltemplatesconfirm'] = 'You\'re about to remove all templates for your current preset. If you want to restore the templates later, you need to choose the preset again in the \'Presets\' tab.';
|
||||
$string['resetsettings'] = 'Reset filters';
|
||||
$string['resettemplate'] = 'Reset template';
|
||||
$string['resettemplateconfirmtitle'] = 'Reset template?';
|
||||
@ -424,6 +427,7 @@ $string['tagsdeleted'] = 'Database tags have been deleted';
|
||||
$string['teachersandstudents'] = '{$a->teachers} and {$a->students}';
|
||||
$string['templates'] = 'Templates';
|
||||
$string['templatereset'] = 'Template reset';
|
||||
$string['templateresetall'] = 'All templates reset';
|
||||
$string['templatesnavigation'] = 'Templates tertiary navigation';
|
||||
$string['templatesaved'] = 'Template saved';
|
||||
$string['text'] = 'Text';
|
||||
|
@ -31,6 +31,7 @@ require_once('lib.php');
|
||||
$id = optional_param('id', 0, PARAM_INT); // course module id
|
||||
$d = optional_param('d', 0, PARAM_INT); // database id
|
||||
$mode = optional_param('mode', 'addtemplate', PARAM_ALPHA);
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$useeditor = optional_param('useeditor', null, PARAM_BOOL);
|
||||
|
||||
$url = new moodle_url('/mod/data/templates.php');
|
||||
@ -85,27 +86,31 @@ if (!$manager->has_fields()) {
|
||||
$actionbar = new \mod_data\output\action_bar($instance->id, $url);
|
||||
echo $actionbar->get_templates_action_bar();
|
||||
|
||||
if ($action == 'resetalltemplates') {
|
||||
$manager->reset_all_templates();
|
||||
$notificationstr = get_string('templateresetall', 'mod_data');
|
||||
}
|
||||
|
||||
if (($formdata = data_submitted()) && confirm_sesskey()) {
|
||||
$notificationstr = get_string('templatesaved', 'data');
|
||||
if (!empty($formdata->defaultform)) {
|
||||
// Reset the template to default.
|
||||
$formdata->{$mode} = '';
|
||||
if ($mode == 'listtemplate') {
|
||||
$formdata->listtemplateheader = '';
|
||||
$formdata->listtemplatefooter = '';
|
||||
if (!empty($formdata->resetall)) {
|
||||
$manager->reset_all_templates();
|
||||
$notificationstr = get_string('templateresetall', 'mod_data');
|
||||
} else {
|
||||
$manager->reset_template($mode);
|
||||
$notificationstr = get_string('templatereset', 'data');
|
||||
}
|
||||
if ($mode == 'rsstemplate') {
|
||||
$formdata->rsstitletemplate = '';
|
||||
}
|
||||
$notificationstr = get_string('templatereset', 'data');
|
||||
}
|
||||
if ($manager->update_templates($formdata)) {
|
||||
// Reload instance.
|
||||
$instance = $manager->get_instance();
|
||||
echo $OUTPUT->notification($notificationstr, 'notifysuccess');
|
||||
} else {
|
||||
$manager->update_templates($formdata);
|
||||
$notificationstr = get_string('templatesaved', 'data');
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($notificationstr)) {
|
||||
echo $OUTPUT->notification($notificationstr, 'notifysuccess');
|
||||
}
|
||||
|
||||
$templateeditor = new \mod_data\output\template_editor($manager, $mode);
|
||||
echo $renderer->render($templateeditor);
|
||||
|
||||
|
@ -69,6 +69,7 @@
|
||||
<form id="edittemplateform" action="{{{url}}}" method="post">
|
||||
<input name="sesskey" value="{{sesskey}}" type="hidden" />
|
||||
<input name="defaultform" type="hidden" value=""/>
|
||||
<input name="resetall" type="hidden" value=""/>
|
||||
<div class="d-flex flex-row align-items-center">
|
||||
{{#toolbar}}
|
||||
{{> mod_data/template_editor_tools }}
|
||||
|
28
mod/data/templates/template_editor_resetmodal.mustache
Normal file
28
mod/data/templates/template_editor_resetmodal.mustache
Normal file
@ -0,0 +1,28 @@
|
||||
{{!
|
||||
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 mod_data/template_editor_resetmodal
|
||||
|
||||
Reset template modal content.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"resetallname": "resetallcheck"
|
||||
}
|
||||
}}
|
||||
<p>{{#str}} resetalltemplatesconfirm, mod_data {{/str}}</p>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" id="modalcheckbox" name="{{resetallname}}">
|
||||
<label class="form-check-label" for="modalcheckbox">{{#str}} resetalltemplates, mod_data {{/str}}</label>
|
||||
</div>
|
@ -98,7 +98,8 @@
|
||||
</div>
|
||||
<hr/>
|
||||
{{#js}}
|
||||
require(['mod_data/saveaspreset'], function(saveAsPreset) {
|
||||
require(['mod_data/saveaspreset', 'mod_data/resetalltemplates'], function(saveAsPreset, resetAll) {
|
||||
saveAsPreset.init();
|
||||
resetAll.init();
|
||||
});
|
||||
{{/js}}
|
||||
|
@ -143,7 +143,7 @@ Feature: Users can use mod_data without editing the templates
|
||||
When I navigate to "Templates" in current page administration
|
||||
And I set the field "Templates tertiary navigation" to "List view template"
|
||||
And I click on "Reset" "button" in the "sticky-footer" "region"
|
||||
And I click on "Reset template" "button" in the "Reset template?" "dialogue"
|
||||
And I click on "Reset" "button" in the "Reset template?" "dialogue"
|
||||
And I should see "Template reset"
|
||||
And I navigate to "Database" in current page administration
|
||||
And I should not see "New header!"
|
||||
|
@ -124,7 +124,7 @@ Feature: Users can edit the database templates
|
||||
When I navigate to "Templates" in current page administration
|
||||
And I set the field "Templates tertiary navigation" to "List view template"
|
||||
And I click on "Reset" "button" in the "sticky-footer" "region"
|
||||
And I click on "Reset template" "button" in the "Reset template?" "dialogue"
|
||||
And I click on "Reset" "button" in the "Reset template?" "dialogue"
|
||||
Then I should see "Template reset"
|
||||
And I navigate to "Database" in current page administration
|
||||
And I should not see "New header!"
|
||||
@ -132,3 +132,79 @@ Feature: Users can edit the database templates
|
||||
And I should not see "New footer!"
|
||||
And I should see "Student entry 1"
|
||||
And I should see "Some content 1"
|
||||
|
||||
@javascript
|
||||
Scenario: Reset all database templates using the action menu
|
||||
Given the following "mod_data > templates" exist:
|
||||
| database | name | content |
|
||||
| data1 | singletemplate | Initial single |
|
||||
| data1 | listtemplate | Initial list |
|
||||
| data1 | addtemplate | Initial add |
|
||||
| data1 | asearchtemplate | Initial search |
|
||||
And I navigate to "Database" in current page administration
|
||||
And I should see "Initial list"
|
||||
And I should not see "Student entry 1"
|
||||
And I should not see "Some content 1"
|
||||
And I click on "Advanced search" "checkbox"
|
||||
And I should see "Initial search"
|
||||
And I set the field "View mode tertiary navigation" to "Single view"
|
||||
And I should see "Initial single"
|
||||
And I should not see "Student entry 1"
|
||||
And I should not see "Some content 1"
|
||||
And I click on "Add entry" "button"
|
||||
And I should see "Initial add"
|
||||
When I navigate to "Templates" in current page administration
|
||||
And I click on "Actions" "button"
|
||||
And I choose "Reset all templates" in the open action menu
|
||||
And I click on "Reset" "button" in the "Reset all templates?" "dialogue"
|
||||
Then I should see "All templates reset"
|
||||
And I navigate to "Database" in current page administration
|
||||
And I should not see "Initial list"
|
||||
And I should see "Student entry 1"
|
||||
And I should see "Some content 1"
|
||||
And I click on "Advanced search" "checkbox"
|
||||
And I should not see "Initial search"
|
||||
And I set the field "View mode tertiary navigation" to "Single view"
|
||||
And I should not see "Initial single"
|
||||
And I should see "Student entry 1"
|
||||
And I should see "Some content 1"
|
||||
And I click on "Add entry" "button"
|
||||
And I should not see "Initial add"
|
||||
|
||||
@javascript
|
||||
Scenario: Reset all database templates using the reset template button
|
||||
Given the following "mod_data > templates" exist:
|
||||
| database | name | content |
|
||||
| data1 | singletemplate | Initial single |
|
||||
| data1 | listtemplate | Initial list |
|
||||
| data1 | addtemplate | Initial add |
|
||||
| data1 | asearchtemplate | Initial search |
|
||||
And I navigate to "Database" in current page administration
|
||||
And I should see "Initial list"
|
||||
And I should not see "Student entry 1"
|
||||
And I should not see "Some content 1"
|
||||
And I click on "Advanced search" "checkbox"
|
||||
And I should see "Initial search"
|
||||
And I set the field "View mode tertiary navigation" to "Single view"
|
||||
And I should see "Initial single"
|
||||
And I should not see "Student entry 1"
|
||||
And I should not see "Some content 1"
|
||||
And I click on "Add entry" "button"
|
||||
And I should see "Initial add"
|
||||
When I navigate to "Templates" in current page administration
|
||||
And I click on "Reset" "button" in the "sticky-footer" "region"
|
||||
And I click on "Reset all templates" "checkbox"
|
||||
And I click on "Reset" "button" in the "Reset template?" "dialogue"
|
||||
Then I should see "All templates reset"
|
||||
And I navigate to "Database" in current page administration
|
||||
And I should not see "Initial list"
|
||||
And I should see "Student entry 1"
|
||||
And I should see "Some content 1"
|
||||
And I click on "Advanced search" "checkbox"
|
||||
And I should not see "Initial search"
|
||||
And I set the field "View mode tertiary navigation" to "Single view"
|
||||
And I should not see "Initial single"
|
||||
And I should see "Student entry 1"
|
||||
And I should see "Some content 1"
|
||||
And I click on "Add entry" "button"
|
||||
And I should not see "Initial add"
|
||||
|
@ -19,6 +19,7 @@ namespace mod_data;
|
||||
use context_module;
|
||||
use moodle_url;
|
||||
use core_component;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Manager tests class for mod_data.
|
||||
@ -609,4 +610,137 @@ class manager_test extends \advanced_testcase {
|
||||
$result = $manager->can_export_entries();
|
||||
$this->assertEquals(true, $result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test reset_all_templates.
|
||||
*
|
||||
* @covers ::reset_all_templates
|
||||
*/
|
||||
public function test_reset_all_templates() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Setup test data.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$instance = $this->getDataGenerator()->create_module(
|
||||
'data',
|
||||
['course' => $course->id]
|
||||
);
|
||||
$manager = manager::create_from_instance($instance);
|
||||
|
||||
// Create some initial templates.
|
||||
$initialtemplates = new stdClass();
|
||||
foreach (manager::TEMPLATES_LIST as $templatename => $unused) {
|
||||
$initialtemplates->$templatename = "Initial $templatename";
|
||||
}
|
||||
$manager->update_templates($initialtemplates);
|
||||
$instance = $manager->get_instance();
|
||||
$record = $DB->get_record('data', ['id' => $instance->id]);
|
||||
foreach (manager::TEMPLATES_LIST as $templatename => $unused) {
|
||||
$this->assertEquals($initialtemplates->$templatename, $instance->$templatename);
|
||||
$this->assertEquals($initialtemplates->$templatename, $record->$templatename);
|
||||
}
|
||||
|
||||
// Reset all templates.
|
||||
$result = $manager->reset_all_templates();
|
||||
$this->assertTrue($result);
|
||||
$instance = $manager->get_instance();
|
||||
$record = $DB->get_record('data', ['id' => $instance->id]);
|
||||
foreach (manager::TEMPLATES_LIST as $templatename => $unused) {
|
||||
$this->assertEquals('', $instance->$templatename);
|
||||
$this->assertEquals('', $record->$templatename);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test reset_template.
|
||||
*
|
||||
* @covers ::reset_template
|
||||
* @dataProvider reset_template_provider
|
||||
* @param string $templatetoreset the template to reset
|
||||
* @param string[] $expected the expected templates to be reset
|
||||
*/
|
||||
public function test_reset_template(string $templatetoreset, array $expected) {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Setup test data.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$instance = $this->getDataGenerator()->create_module(
|
||||
'data',
|
||||
['course' => $course->id]
|
||||
);
|
||||
$manager = manager::create_from_instance($instance);
|
||||
|
||||
// Create some initial templates.
|
||||
$initialtemplates = new stdClass();
|
||||
foreach (manager::TEMPLATES_LIST as $templatename => $unused) {
|
||||
$initialtemplates->$templatename = "Initial $templatename";
|
||||
}
|
||||
$manager->update_templates($initialtemplates);
|
||||
$instance = $manager->get_instance();
|
||||
$record = $DB->get_record('data', ['id' => $instance->id]);
|
||||
foreach (manager::TEMPLATES_LIST as $templatename => $unused) {
|
||||
$this->assertEquals($initialtemplates->$templatename, $instance->$templatename);
|
||||
$this->assertEquals($initialtemplates->$templatename, $record->$templatename);
|
||||
}
|
||||
|
||||
// Reset template.
|
||||
$result = $manager->reset_template($templatetoreset);
|
||||
$this->assertTrue($result);
|
||||
$instance = $manager->get_instance();
|
||||
$record = $DB->get_record('data', ['id' => $instance->id]);
|
||||
foreach (manager::TEMPLATES_LIST as $templatename => $unused) {
|
||||
if (in_array($templatename, $expected)) {
|
||||
$this->assertEquals('', $instance->$templatename);
|
||||
$this->assertEquals('', $record->$templatename);
|
||||
} else {
|
||||
$this->assertEquals($initialtemplates->$templatename, $instance->$templatename);
|
||||
$this->assertEquals($initialtemplates->$templatename, $record->$templatename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_reset_templatet.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function reset_template_provider(): array {
|
||||
return [
|
||||
// User presets.
|
||||
'listtemplate' => [
|
||||
'templatename' => 'listtemplate',
|
||||
'expected' => ['listtemplate', 'listtemplateheader', 'listtemplatefooter'],
|
||||
],
|
||||
'singletemplate' => [
|
||||
'templatename' => 'singletemplate',
|
||||
'expected' => ['singletemplate'],
|
||||
],
|
||||
'asearchtemplate' => [
|
||||
'templatename' => 'asearchtemplate',
|
||||
'expected' => ['asearchtemplate'],
|
||||
],
|
||||
'addtemplate' => [
|
||||
'templatename' => 'addtemplate',
|
||||
'expected' => ['addtemplate'],
|
||||
],
|
||||
'rsstemplate' => [
|
||||
'templatename' => 'rsstemplate',
|
||||
'expected' => ['rsstemplate', 'rsstitletemplate'],
|
||||
],
|
||||
'csstemplate' => [
|
||||
'templatename' => 'csstemplate',
|
||||
'expected' => ['csstemplate'],
|
||||
],
|
||||
'jstemplate' => [
|
||||
'templatename' => 'jstemplate',
|
||||
'expected' => ['jstemplate'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user