mirror of
https://github.com/moodle/moodle.git
synced 2025-04-12 03:52:16 +02:00
MDL-81745 mod_feedback: Refactor edit amd module
This commit is contained in:
parent
269a8a8a1b
commit
53c89cb985
2
mod/feedback/amd/build/edit.min.js
vendored
2
mod/feedback/amd/build/edit.min.js
vendored
@ -1,3 +1,3 @@
|
||||
define("mod_feedback/edit",["jquery","core/ajax","core/str","core/notification"],(function($,ajax,str,notification){var manager={deleteItem:function(e){e.preventDefault();var targetUrl=$(e.currentTarget).attr("href");str.get_strings([{key:"confirmation",component:"admin"},{key:"confirmdeleteitem",component:"mod_feedback"},{key:"yes",component:"moodle"},{key:"no",component:"moodle"}]).then((function(s){notification.confirm(s[0],s[1],s[2],s[3],(function(){window.location=targetUrl}))})).catch()},setup:function(){$("body").delegate('[data-action="delete"]',"click",manager.deleteItem)}};return{setup:manager.setup}}));
|
||||
define("mod_feedback/edit",["exports","core/prefetch","core/str","core/notification"],(function(_exports,_prefetch,_str,_notification){var obj;Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_notification=(obj=_notification)&&obj.__esModule?obj:{default:obj};const Selectors_deleteQuestionButton='[data-action="delete"]';let initialized=!1;_exports.init=()=>{initialized||((0,_prefetch.prefetchStrings)("core",["yes","no"]),(0,_prefetch.prefetchStrings)("admin",["confirmation"]),(0,_prefetch.prefetchStrings)("mod_feedback",["confirmdeleteitem"]),document.addEventListener("click",(async event=>{const deleteButton=event.target.closest(Selectors_deleteQuestionButton);if(deleteButton){event.preventDefault();const confirmationStrings=await(0,_str.getStrings)([{key:"confirmation",component:"admin"},{key:"confirmdeleteitem",component:"mod_feedback"},{key:"yes",component:"core"},{key:"no",component:"core"}]);_notification.default.confirm(...confirmationStrings,(()=>{window.location=deleteButton.getAttribute("href")}))}else;})),initialized=!0)}}));
|
||||
|
||||
//# sourceMappingURL=edit.min.js.map
|
@ -1 +1 @@
|
||||
{"version":3,"file":"edit.min.js","sources":["../src/edit.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 * Edit items in feedback module\n *\n * @module mod_feedback/edit\n * @copyright 2016 Marina Glancy\n */\ndefine(['jquery', 'core/ajax', 'core/str', 'core/notification'],\nfunction($, ajax, str, notification) {\n var manager = {\n deleteItem: function(e) {\n e.preventDefault();\n var targetUrl = $(e.currentTarget).attr('href');\n\n str.get_strings([\n {\n key: 'confirmation',\n component: 'admin'\n },\n {\n key: 'confirmdeleteitem',\n component: 'mod_feedback'\n },\n {\n key: 'yes',\n component: 'moodle'\n },\n {\n key: 'no',\n component: 'moodle'\n }\n ])\n .then(function(s) {\n notification.confirm(s[0], s[1], s[2], s[3], function() {\n window.location = targetUrl;\n });\n\n return;\n })\n .catch();\n },\n\n setup: function() {\n $('body').delegate('[data-action=\"delete\"]', 'click', manager.deleteItem);\n }\n };\n\n return {\n setup: manager.setup\n };\n});\n"],"names":["define","$","ajax","str","notification","manager","deleteItem","e","preventDefault","targetUrl","currentTarget","attr","get_strings","key","component","then","s","confirm","window","location","catch","setup","delegate"],"mappings":"AAqBAA,2BAAO,CAAC,SAAU,YAAa,WAAY,sBAC3C,SAASC,EAAGC,KAAMC,IAAKC,kBACfC,QAAU,CACVC,WAAY,SAASC,GACjBA,EAAEC,qBACEC,UAAYR,EAAEM,EAAEG,eAAeC,KAAK,QAExCR,IAAIS,YAAY,CACZ,CACIC,IAAY,eACZC,UAAY,SAEhB,CACID,IAAY,oBACZC,UAAY,gBAEhB,CACID,IAAY,MACZC,UAAY,UAEhB,CACID,IAAY,KACZC,UAAY,YAGnBC,MAAK,SAASC,GACXZ,aAAaa,QAAQD,EAAE,GAAIA,EAAE,GAAIA,EAAE,GAAIA,EAAE,IAAI,WACzCE,OAAOC,SAAWV,gBAKzBW,SAGLC,MAAO,WACHpB,EAAE,QAAQqB,SAAS,yBAA0B,QAASjB,QAAQC,oBAI/D,CACHe,MAAOhB,QAAQgB"}
|
||||
{"version":3,"file":"edit.min.js","sources":["../src/edit.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 * Edit items in feedback module\n *\n * @module mod_feedback/edit\n * @copyright 2016 Marina Glancy\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\"use strict\";\n\nimport {prefetchStrings} from 'core/prefetch';\nimport {getStrings} from 'core/str';\nimport Notification from 'core/notification';\n\nconst Selectors = {\n deleteQuestionButton: '[data-action=\"delete\"]',\n};\n\nlet initialized = false;\n\n/**\n * Initialise editor and all it's modules\n */\nexport const init = () => {\n // Ensure we only add our listeners once (can be called multiple times).\n if (initialized) {\n return;\n }\n\n prefetchStrings('core', [\n 'yes',\n 'no',\n ]);\n prefetchStrings('admin', [\n 'confirmation',\n ]);\n prefetchStrings('mod_feedback', [\n 'confirmdeleteitem',\n ]);\n\n document.addEventListener('click', async event => {\n\n // Delete question.\n const deleteButton = event.target.closest(Selectors.deleteQuestionButton);\n if (deleteButton) {\n event.preventDefault();\n const confirmationStrings = await getStrings([\n {key: 'confirmation', component: 'admin'},\n {key: 'confirmdeleteitem', component: 'mod_feedback'},\n {key: 'yes', component: 'core'},\n {key: 'no', component: 'core'},\n ]);\n Notification.confirm(...confirmationStrings, () => {\n window.location = deleteButton.getAttribute('href');\n });\n return;\n }\n });\n\n initialized = true;\n};\n"],"names":["Selectors","initialized","document","addEventListener","async","deleteButton","event","target","closest","preventDefault","confirmationStrings","key","component","confirm","window","location","getAttribute"],"mappings":"sSA6BMA,+BACoB,6BAGtBC,aAAc,gBAKE,KAEZA,4CAIY,OAAQ,CACpB,MACA,qCAEY,QAAS,CACrB,+CAEY,eAAgB,CAC5B,sBAGJC,SAASC,iBAAiB,SAASC,MAAAA,cAGzBC,aAAeC,MAAMC,OAAOC,QAAQR,mCACtCK,cACAC,MAAMG,uBACAC,0BAA4B,mBAAW,CACzC,CAACC,IAAK,eAAgBC,UAAW,SACjC,CAACD,IAAK,oBAAqBC,UAAW,gBACtC,CAACD,IAAK,MAAOC,UAAW,QACxB,CAACD,IAAK,KAAMC,UAAW,gCAEdC,WAAWH,qBAAqB,KACzCI,OAAOC,SAAWV,aAAaW,aAAa,oBAMxDf,aAAc"}
|
@ -18,48 +18,59 @@
|
||||
*
|
||||
* @module mod_feedback/edit
|
||||
* @copyright 2016 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery', 'core/ajax', 'core/str', 'core/notification'],
|
||||
function($, ajax, str, notification) {
|
||||
var manager = {
|
||||
deleteItem: function(e) {
|
||||
e.preventDefault();
|
||||
var targetUrl = $(e.currentTarget).attr('href');
|
||||
|
||||
str.get_strings([
|
||||
{
|
||||
key: 'confirmation',
|
||||
component: 'admin'
|
||||
},
|
||||
{
|
||||
key: 'confirmdeleteitem',
|
||||
component: 'mod_feedback'
|
||||
},
|
||||
{
|
||||
key: 'yes',
|
||||
component: 'moodle'
|
||||
},
|
||||
{
|
||||
key: 'no',
|
||||
component: 'moodle'
|
||||
}
|
||||
])
|
||||
.then(function(s) {
|
||||
notification.confirm(s[0], s[1], s[2], s[3], function() {
|
||||
window.location = targetUrl;
|
||||
});
|
||||
"use strict";
|
||||
|
||||
return;
|
||||
})
|
||||
.catch();
|
||||
},
|
||||
import {prefetchStrings} from 'core/prefetch';
|
||||
import {getStrings} from 'core/str';
|
||||
import Notification from 'core/notification';
|
||||
|
||||
setup: function() {
|
||||
$('body').delegate('[data-action="delete"]', 'click', manager.deleteItem);
|
||||
const Selectors = {
|
||||
deleteQuestionButton: '[data-action="delete"]',
|
||||
};
|
||||
|
||||
let initialized = false;
|
||||
|
||||
/**
|
||||
* Initialise editor and all it's modules
|
||||
*/
|
||||
export const init = () => {
|
||||
// Ensure we only add our listeners once (can be called multiple times).
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
prefetchStrings('core', [
|
||||
'yes',
|
||||
'no',
|
||||
]);
|
||||
prefetchStrings('admin', [
|
||||
'confirmation',
|
||||
]);
|
||||
prefetchStrings('mod_feedback', [
|
||||
'confirmdeleteitem',
|
||||
]);
|
||||
|
||||
document.addEventListener('click', async event => {
|
||||
|
||||
// Delete question.
|
||||
const deleteButton = event.target.closest(Selectors.deleteQuestionButton);
|
||||
if (deleteButton) {
|
||||
event.preventDefault();
|
||||
const confirmationStrings = await getStrings([
|
||||
{key: 'confirmation', component: 'admin'},
|
||||
{key: 'confirmdeleteitem', component: 'mod_feedback'},
|
||||
{key: 'yes', component: 'core'},
|
||||
{key: 'no', component: 'core'},
|
||||
]);
|
||||
Notification.confirm(...confirmationStrings, () => {
|
||||
window.location = deleteButton.getAttribute('href');
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
setup: manager.setup
|
||||
};
|
||||
});
|
||||
initialized = true;
|
||||
};
|
||||
|
@ -580,9 +580,5 @@ class mod_feedback_complete_form extends moodleform {
|
||||
}
|
||||
|
||||
$this->_form->display();
|
||||
|
||||
if ($this->mode == self::MODE_EDIT) {
|
||||
$PAGE->requires->js_call_amd('mod_feedback/edit', 'setup');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,6 +86,7 @@ $PAGE->activityheader->set_attrs([
|
||||
'description' => ''
|
||||
]);
|
||||
$PAGE->add_body_class('limitedwidth');
|
||||
$PAGE->requires->js_call_amd('mod_feedback/edit', 'init');
|
||||
|
||||
//Adding the javascript module for the items dragdrop.
|
||||
if (count($feedbackitems) > 1) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user