MDL-74144 user: add cancel button to user private files form.
This commit is contained in:
Vendored
+1
-1
@@ -5,6 +5,6 @@ define("core_user/private_files",["exports","core_form/dynamicform","core_form/m
|
||||
* @module core_user/private_files
|
||||
* @copyright 2020 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.initModal=_exports.initDynamicForm=void 0,_dynamicform=_interopRequireDefault(_dynamicform),_modalform=_interopRequireDefault(_modalform);_exports.initDynamicForm=(containerSelector,formClass)=>{const form=new _dynamicform.default(document.querySelector(containerSelector),formClass);form.addEventListener(form.events.FORM_SUBMITTED,(()=>{form.load(),(0,_str.get_string)("changessaved").then(_toast.add).catch(null)}))};_exports.initModal=(elementSelector,formClass)=>{document.querySelector(elementSelector).addEventListener("click",(function(e){e.preventDefault();const form=new _modalform.default({formClass:formClass,args:{nosubmit:!0},modalConfig:{title:(0,_str.get_string)("privatefilesmanage")},returnFocus:e.target});form.addEventListener(form.events.FORM_SUBMITTED,(()=>window.location.reload())),form.show()}))}}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.initModal=_exports.initDynamicForm=void 0,_dynamicform=_interopRequireDefault(_dynamicform),_modalform=_interopRequireDefault(_modalform);_exports.initDynamicForm=(containerSelector,formClass)=>{const form=new _dynamicform.default(document.querySelector(containerSelector),formClass);form.addEventListener(form.events.FORM_SUBMITTED,(()=>{form.load(),(0,_str.get_string)("changessaved").then(_toast.add).catch(null)})),form.addEventListener(form.events.CANCEL_BUTTON_PRESSED,(()=>window.location.reload()))};_exports.initModal=(elementSelector,formClass)=>{document.querySelector(elementSelector).addEventListener("click",(function(e){e.preventDefault();const form=new _modalform.default({formClass:formClass,args:{nosubmit:!0},modalConfig:{title:(0,_str.get_string)("privatefilesmanage")},returnFocus:e.target});form.addEventListener(form.events.FORM_SUBMITTED,(()=>window.location.reload())),form.show()}))}}));
|
||||
|
||||
//# sourceMappingURL=private_files.min.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"private_files.min.js","sources":["../src/private_files.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 * Module to handle AJAX interactions with user private files\n *\n * @module core_user/private_files\n * @copyright 2020 Marina Glancy\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport DynamicForm from 'core_form/dynamicform';\nimport ModalForm from 'core_form/modalform';\nimport {get_string as getString} from 'core/str';\nimport {add as addToast} from 'core/toast';\n\n/**\n * Initialize private files form as AJAX form\n *\n * @param {String} containerSelector\n * @param {String} formClass\n */\nexport const initDynamicForm = (containerSelector, formClass) => {\n const form = new DynamicForm(document.querySelector(containerSelector), formClass);\n // When form is saved, refresh it to remove validation errors, if any:\n form.addEventListener(form.events.FORM_SUBMITTED, () => {\n form.load();\n getString('changessaved')\n .then(addToast)\n .catch(null);\n });\n};\n\n/**\n * Initialize private files form as Modal form\n *\n * @param {String} elementSelector\n * @param {String} formClass\n */\nexport const initModal = (elementSelector, formClass) => {\n document.querySelector(elementSelector).addEventListener('click', function(e) {\n e.preventDefault();\n const form = new ModalForm({\n formClass,\n args: {nosubmit: true},\n modalConfig: {title: getString('privatefilesmanage')},\n returnFocus: e.target,\n });\n form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());\n form.show();\n });\n};\n"],"names":["containerSelector","formClass","form","DynamicForm","document","querySelector","addEventListener","events","FORM_SUBMITTED","load","then","addToast","catch","elementSelector","e","preventDefault","ModalForm","args","nosubmit","modalConfig","title","returnFocus","target","window","location","reload","show"],"mappings":";;;;;;;yOAiC+B,CAACA,kBAAmBC,mBACzCC,KAAO,IAAIC,qBAAYC,SAASC,cAAcL,mBAAoBC,WAExEC,KAAKI,iBAAiBJ,KAAKK,OAAOC,gBAAgB,KAC9CN,KAAKO,2BACK,gBACTC,KAAKC,YACLC,MAAM,6BAUU,CAACC,gBAAiBZ,aACvCG,SAASC,cAAcQ,iBAAiBP,iBAAiB,SAAS,SAASQ,GACvEA,EAAEC,uBACIb,KAAO,IAAIc,mBAAU,CACvBf,UAAAA,UACAgB,KAAM,CAACC,UAAU,GACjBC,YAAa,CAACC,OAAO,mBAAU,uBAC/BC,YAAaP,EAAEQ,SAEnBpB,KAAKI,iBAAiBJ,KAAKK,OAAOC,gBAAgB,IAAMe,OAAOC,SAASC,WACxEvB,KAAKwB"}
|
||||
{"version":3,"file":"private_files.min.js","sources":["../src/private_files.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 * Module to handle AJAX interactions with user private files\n *\n * @module core_user/private_files\n * @copyright 2020 Marina Glancy\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport DynamicForm from 'core_form/dynamicform';\nimport ModalForm from 'core_form/modalform';\nimport {get_string as getString} from 'core/str';\nimport {add as addToast} from 'core/toast';\n\n/**\n * Initialize private files form as AJAX form\n *\n * @param {String} containerSelector\n * @param {String} formClass\n */\nexport const initDynamicForm = (containerSelector, formClass) => {\n const form = new DynamicForm(document.querySelector(containerSelector), formClass);\n\n // When form is saved, refresh it to remove validation errors, if any:\n form.addEventListener(form.events.FORM_SUBMITTED, () => {\n form.load();\n getString('changessaved')\n .then(addToast)\n .catch(null);\n });\n\n // Reload the page on cancel.\n form.addEventListener(form.events.CANCEL_BUTTON_PRESSED, () => window.location.reload());\n};\n\n/**\n * Initialize private files form as Modal form\n *\n * @param {String} elementSelector\n * @param {String} formClass\n */\nexport const initModal = (elementSelector, formClass) => {\n document.querySelector(elementSelector).addEventListener('click', function(e) {\n e.preventDefault();\n const form = new ModalForm({\n formClass,\n args: {nosubmit: true},\n modalConfig: {title: getString('privatefilesmanage')},\n returnFocus: e.target,\n });\n form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());\n form.show();\n });\n};\n"],"names":["containerSelector","formClass","form","DynamicForm","document","querySelector","addEventListener","events","FORM_SUBMITTED","load","then","addToast","catch","CANCEL_BUTTON_PRESSED","window","location","reload","elementSelector","e","preventDefault","ModalForm","args","nosubmit","modalConfig","title","returnFocus","target","show"],"mappings":";;;;;;;yOAiC+B,CAACA,kBAAmBC,mBACzCC,KAAO,IAAIC,qBAAYC,SAASC,cAAcL,mBAAoBC,WAGxEC,KAAKI,iBAAiBJ,KAAKK,OAAOC,gBAAgB,KAC9CN,KAAKO,2BACK,gBACTC,KAAKC,YACLC,MAAM,SAIXV,KAAKI,iBAAiBJ,KAAKK,OAAOM,uBAAuB,IAAMC,OAAOC,SAASC,+BAS1D,CAACC,gBAAiBhB,aACvCG,SAASC,cAAcY,iBAAiBX,iBAAiB,SAAS,SAASY,GACvEA,EAAEC,uBACIjB,KAAO,IAAIkB,mBAAU,CACvBnB,UAAAA,UACAoB,KAAM,CAACC,UAAU,GACjBC,YAAa,CAACC,OAAO,mBAAU,uBAC/BC,YAAaP,EAAEQ,SAEnBxB,KAAKI,iBAAiBJ,KAAKK,OAAOC,gBAAgB,IAAMM,OAAOC,SAASC,WACxEd,KAAKyB"}
|
||||
@@ -33,6 +33,7 @@ import {add as addToast} from 'core/toast';
|
||||
*/
|
||||
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();
|
||||
@@ -40,6 +41,9 @@ export const initDynamicForm = (containerSelector, formClass) => {
|
||||
.then(addToast)
|
||||
.catch(null);
|
||||
});
|
||||
|
||||
// Reload the page on cancel.
|
||||
form.addEventListener(form.events.CANCEL_BUTTON_PRESSED, () => window.location.reload());
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,8 +60,10 @@ class private_files extends \core_form\dynamic_form {
|
||||
}
|
||||
$mform->setType('returnurl', PARAM_LOCALURL);
|
||||
|
||||
// The 'nosubmit' param (default false) determines whether we should show the standard form action buttons (save/cancel).
|
||||
// This value is set when the form is displayed within a modal, which adds the action buttons itself.
|
||||
if (!$this->optional_param('nosubmit', false, PARAM_BOOL)) {
|
||||
$this->add_action_buttons(false, get_string('savechanges'));
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user