mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-61133 core_question: move all selectors to a new module
This commit is contained in:
parent
fd5e2ead95
commit
d1db765a64
2
question/amd/build/edit_tags.min.js
vendored
2
question/amd/build/edit_tags.min.js
vendored
@ -1 +1 @@
|
||||
define(["jquery","core/fragment","core/str","core/modal_events","core/modal_factory","core/notification","core/custom_interaction_events","core_question/repository"],function(a,b,c,d,e,f,g,h){var i={TAGS_LINK:'[data-action="edittags"]',SAVE_BUTTON:'[data-action="save"]',LOADING_ICON:'[data-region="overlay-icon-container"]'},j=function(a){a.find(i.SAVE_BUTTON).prop("disabled",!1)},k=function(a){a.find(i.SAVE_BUTTON).prop("disabled",!0)},l=function(a){return a.getBody().find("form").serialize()},m=function(a){var b=a.find(i.LOADING_ICON);b.removeClass("hidden")},n=function(a){var b=a.find(i.LOADING_ICON);b.addClass("hidden")},o=function(h){var l=e.create({type:e.types.SAVE_CANCEL,large:!1},[h,i.TAGS_LINK]).then(function(a){return c.get_string("questiontags","question").then(function(b){return a.setTitle(b),b}).fail(f.exception),a.getRoot().on(d.save,function(b){var c=a.getBody().find("form");c.submit(),b.preventDefault()}),a.getRoot().on("submit","form",function(b){p(a,h).then(function(){a.hide()}).fail(f.exception),b.preventDefault(),b.stopPropagation()}),a});h.on(g.events.activate,i.TAGS_LINK,function(c){var d=a(c.currentTarget),e=d.data("questionid"),g=!!d.data("canedit"),o=d.data("contextid");l.then(function(a){k(h),m(h);var c={id:e},d=b.loadFragment("question","tags_form",o,c);return a.setBody(d),d.then(function(){j(h)}).always(function(){n(h)}).fail(f.exception),g?a.getRoot().find(i.SAVE_BUTTON).show():a.getRoot().find(i.SAVE_BUTTON).hide(),a}).fail(f.exception),c.preventDefault()})},p=function(a,b){k(b),m(b);var c=l(a);return h.submitTagCreateUpdateForm(c).always(function(){n(b),j(b)}).fail(f.exception)};return{init:function(b){b=a(b),o(b)}}});
|
||||
define(["jquery","core/fragment","core/str","core/modal_events","core/modal_factory","core/notification","core/custom_interaction_events","core_question/repository","core_question/selectors"],function(a,b,c,d,e,f,g,h,i){var j=function(a){a.find(i.actions.save).prop("disabled",!1)},k=function(a){a.find(i.actions.save).prop("disabled",!0)},l=function(a){return a.getBody().find("form").serialize()},m=function(a){var b=a.find(i.containers.loadingIcon);b.removeClass("hidden")},n=function(a){var b=a.find(i.containers.loadingIcon);b.addClass("hidden")},o=function(h){var l=e.create({type:e.types.SAVE_CANCEL,large:!1},[h,i.actions.edittags]).then(function(a){return c.get_string("questiontags","question").then(function(b){return a.setTitle(b),b}).fail(f.exception),a.getRoot().on(d.save,function(b){var c=a.getBody().find("form");c.submit(),b.preventDefault()}),a.getRoot().on("submit","form",function(b){p(a,h).then(function(){a.hide()}).fail(f.exception),b.preventDefault(),b.stopPropagation()}),a});h.on(g.events.activate,i.actions.edittags,function(c){var d=a(c.currentTarget),e=d.data("questionid"),g=!!d.data("canedit"),o=d.data("contextid");l.then(function(a){k(h),m(h);var c={id:e},d=b.loadFragment("question","tags_form",o,c);return a.setBody(d),d.then(function(){j(h)}).always(function(){n(h)}).fail(f.exception),g?a.getRoot().find(i.actions.save).show():a.getRoot().find(i.actions.save).hide(),a}).fail(f.exception),c.preventDefault()})},p=function(a,b){k(b),m(b);var c=l(a);return h.submitTagCreateUpdateForm(c).always(function(){n(b),j(b)}).fail(f.exception)};return{init:function(b){b=a(b),o(b)}}});
|
1
question/amd/build/selectors.min.js
vendored
Normal file
1
question/amd/build/selectors.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
define([],function(){return{actions:{save:'[data-action="save"]',edittags:'[data-action="edittags"]'},containers:{loadingIcon:'[data-region="overlay-icon-container"]'}}});
|
@ -29,6 +29,7 @@ define([
|
||||
'core/notification',
|
||||
'core/custom_interaction_events',
|
||||
'core_question/repository',
|
||||
'core_question/selectors',
|
||||
],
|
||||
function(
|
||||
$,
|
||||
@ -38,15 +39,10 @@ define([
|
||||
ModalFactory,
|
||||
Notification,
|
||||
CustomEvents,
|
||||
Repository
|
||||
Repository,
|
||||
QuestionSelectors
|
||||
) {
|
||||
|
||||
var SELECTORS = {
|
||||
TAGS_LINK: '[data-action="edittags"]',
|
||||
SAVE_BUTTON: '[data-action="save"]',
|
||||
LOADING_ICON: '[data-region="overlay-icon-container"]',
|
||||
};
|
||||
|
||||
/**
|
||||
* Enable the save button in the footer.
|
||||
*
|
||||
@ -54,7 +50,7 @@ define([
|
||||
* @method enableSaveButton
|
||||
*/
|
||||
var enableSaveButton = function(root) {
|
||||
root.find(SELECTORS.SAVE_BUTTON).prop('disabled', false);
|
||||
root.find(QuestionSelectors.actions.save).prop('disabled', false);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -64,7 +60,7 @@ define([
|
||||
* @method disableSaveButton
|
||||
*/
|
||||
var disableSaveButton = function(root) {
|
||||
root.find(SELECTORS.SAVE_BUTTON).prop('disabled', true);
|
||||
root.find(QuestionSelectors.actions.save).prop('disabled', true);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -85,7 +81,7 @@ define([
|
||||
* @method startLoading
|
||||
*/
|
||||
var startLoading = function(root) {
|
||||
var loadingIconContainer = root.find(SELECTORS.LOADING_ICON);
|
||||
var loadingIconContainer = root.find(QuestionSelectors.containers.loadingIcon);
|
||||
|
||||
loadingIconContainer.removeClass('hidden');
|
||||
};
|
||||
@ -97,7 +93,7 @@ define([
|
||||
* @method stopLoading
|
||||
*/
|
||||
var stopLoading = function(root) {
|
||||
var loadingIconContainer = root.find(SELECTORS.LOADING_ICON);
|
||||
var loadingIconContainer = root.find(QuestionSelectors.containers.loadingIcon);
|
||||
|
||||
loadingIconContainer.addClass('hidden');
|
||||
};
|
||||
@ -113,7 +109,7 @@ define([
|
||||
type: ModalFactory.types.SAVE_CANCEL,
|
||||
large: false
|
||||
},
|
||||
[root, SELECTORS.TAGS_LINK]
|
||||
[root, QuestionSelectors.actions.edittags]
|
||||
).then(function(modal) {
|
||||
// All of this code only executes once, when the modal is
|
||||
// first created. This allows us to add any code that should
|
||||
@ -149,7 +145,7 @@ define([
|
||||
// We need to add an event handler to the tags link because there are
|
||||
// multiple links on the page and without adding a listener we don't know
|
||||
// which one the user clicked on the show the modal.
|
||||
root.on(CustomEvents.events.activate, SELECTORS.TAGS_LINK, function(e) {
|
||||
root.on(CustomEvents.events.activate, QuestionSelectors.actions.edittags, function(e) {
|
||||
var currentTarget = $(e.currentTarget);
|
||||
|
||||
var questionId = currentTarget.data('questionid'),
|
||||
@ -185,9 +181,9 @@ define([
|
||||
// Show or hide the save button depending on whether the user
|
||||
// has the capability to edit the tags.
|
||||
if (canEdit) {
|
||||
modal.getRoot().find(SELECTORS.SAVE_BUTTON).show();
|
||||
modal.getRoot().find(QuestionSelectors.actions.save).show();
|
||||
} else {
|
||||
modal.getRoot().find(SELECTORS.SAVE_BUTTON).hide();
|
||||
modal.getRoot().find(QuestionSelectors.actions.save).hide();
|
||||
}
|
||||
|
||||
return modal;
|
||||
|
34
question/amd/src/selectors.js
Normal file
34
question/amd/src/selectors.js
Normal file
@ -0,0 +1,34 @@
|
||||
// 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/>.
|
||||
|
||||
/**
|
||||
* The purpose of this module is to centralize selectors related to question.
|
||||
*
|
||||
* @module core_question/question_selectors
|
||||
* @package core_question
|
||||
* @copyright 2018 Simey Lameze <lameze@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define([], function() {
|
||||
return {
|
||||
actions: {
|
||||
save: '[data-action="save"]',
|
||||
edittags: '[data-action="edittags"]',
|
||||
},
|
||||
containers: {
|
||||
loadingIcon: '[data-region="overlay-icon-container"]',
|
||||
},
|
||||
};
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user