From b95dd8c5dbb883719a8db36b362531ace18659d6 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 1 Jul 2021 20:37:38 +0100 Subject: [PATCH] MDL-72071 message: preserve window scroll opening processor modal. --- .../build/preferences_notifications_list_controller.min.js | 2 +- .../preferences_notifications_list_controller.min.js.map | 2 +- message/amd/src/preferences_notifications_list_controller.js | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/message/amd/build/preferences_notifications_list_controller.min.js b/message/amd/build/preferences_notifications_list_controller.min.js index 1cc4ef29e19b3..e6c81afd751a5 100644 --- a/message/amd/build/preferences_notifications_list_controller.min.js +++ b/message/amd/build/preferences_notifications_list_controller.min.js @@ -1,2 +1,2 @@ -define ("core_message/preferences_notifications_list_controller",["jquery","core/ajax","core/notification","core/custom_interaction_events","core_message/notification_preference","core_message/notification_processor_settings","core/modal_factory"],function(a,b,c,d,f,g,h){var i={DISABLE_NOTIFICATIONS:"[data-region=\"disable-notification-container\"] [data-disable-notifications]",DISABLE_NOTIFICATIONS_CONTAINER:"[data-region=\"disable-notification-container\"]",PREFERENCE:"[data-state]",PREFERENCE_ROW:"[data-region=\"preference-row\"]",PREFERENCE_INPUT:"[data-state] input",PROCESSOR_SETTING:"[data-processor-setting]"},j=function(b){this.root=a(b);this.userId=this.root.attr("data-user-id");this.registerEventListeners()};j.prototype.isDisabled=function(){return this.root.hasClass("disabled")};j.prototype.setDisabled=function(){this.root.addClass("disabled");this.root.find(i.PREFERENCE_INPUT).prop("disabled",!0)};j.prototype.setEnabled=function(){this.root.removeClass("disabled");this.root.find(i.PREFERENCE_INPUT).prop("disabled",!1)};j.prototype.toggleDisableAllStatus=function(){var d=a(i.DISABLE_NOTIFICATIONS),e=a(i.DISABLE_NOTIFICATIONS_CONTAINER),f=d.prop("checked");if(e.hasClass("loading")){return a.Deferred().resolve()}e.addClass("loading");var g={methodname:"core_user_update_user_preferences",args:{userid:this.userId,emailstop:f?1:0}};return b.call([g])[0].done(function(){if(f){this.setDisabled()}else{this.setEnabled()}}.bind(this)).always(function(){e.removeClass("loading")}).fail(c.exception)};j.prototype.registerEventListeners=function(){var b=a(i.DISABLE_NOTIFICATIONS);d.define(this.root,[d.events.activate]);this.root.on("change",function(b){if(!this.isDisabled()){var c=a(b.target).closest(i.PREFERENCE),d=a(b.target).closest(i.PREFERENCE_ROW),e=new f(d,this.userId);c.addClass("loading");e.save().always(function(){c.removeClass("loading")})}}.bind(this));var j=h.create({type:g.TYPE});this.root.on(d.events.activate,i.PROCESSOR_SETTING,function(b){var d=a(b.target).closest(i.PROCESSOR_SETTING);b.preventDefault();j.then(function(c){c.setUserId(a(d).attr("data-user-id"));c.setName(a(d).attr("data-name"));c.setContextId(a(d).attr("data-context-id"));c.setElement(d);c.show();b.stopImmediatePropagation()}).fail(c.exception)});d.define(b,[d.events.activate]);b.on(d.events.activate,function(){this.toggleDisableAllStatus()}.bind(this))};return j}); +define ("core_message/preferences_notifications_list_controller",["jquery","core/ajax","core/notification","core/custom_interaction_events","core_message/notification_preference","core_message/notification_processor_settings","core/modal_factory"],function(a,b,c,d,f,g,h){var i={DISABLE_NOTIFICATIONS:"[data-region=\"disable-notification-container\"] [data-disable-notifications]",DISABLE_NOTIFICATIONS_CONTAINER:"[data-region=\"disable-notification-container\"]",PREFERENCE:"[data-state]",PREFERENCE_ROW:"[data-region=\"preference-row\"]",PREFERENCE_INPUT:"[data-state] input",PROCESSOR_SETTING:"[data-processor-setting]"},j=function(b){this.root=a(b);this.userId=this.root.attr("data-user-id");this.registerEventListeners()};j.prototype.isDisabled=function(){return this.root.hasClass("disabled")};j.prototype.setDisabled=function(){this.root.addClass("disabled");this.root.find(i.PREFERENCE_INPUT).prop("disabled",!0)};j.prototype.setEnabled=function(){this.root.removeClass("disabled");this.root.find(i.PREFERENCE_INPUT).prop("disabled",!1)};j.prototype.toggleDisableAllStatus=function(){var d=a(i.DISABLE_NOTIFICATIONS),e=a(i.DISABLE_NOTIFICATIONS_CONTAINER),f=d.prop("checked");if(e.hasClass("loading")){return a.Deferred().resolve()}e.addClass("loading");var g={methodname:"core_user_update_user_preferences",args:{userid:this.userId,emailstop:f?1:0}};return b.call([g])[0].done(function(){if(f){this.setDisabled()}else{this.setEnabled()}}.bind(this)).always(function(){e.removeClass("loading")}).fail(c.exception)};j.prototype.registerEventListeners=function(){var b=a(i.DISABLE_NOTIFICATIONS);d.define(this.root,[d.events.activate]);this.root.on("change",function(b){if(!this.isDisabled()){var c=a(b.target).closest(i.PREFERENCE),d=a(b.target).closest(i.PREFERENCE_ROW),e=new f(d,this.userId);c.addClass("loading");e.save().always(function(){c.removeClass("loading")})}}.bind(this));var j=h.create({type:g.TYPE});this.root.on(d.events.activate,i.PROCESSOR_SETTING,function(b,d){var e=a(b.target).closest(i.PROCESSOR_SETTING);d.originalEvent.preventDefault();j.then(function(c){c.setUserId(a(e).attr("data-user-id"));c.setName(a(e).attr("data-name"));c.setContextId(a(e).attr("data-context-id"));c.setElement(e);c.show();b.stopImmediatePropagation()}).fail(c.exception)});d.define(b,[d.events.activate]);b.on(d.events.activate,function(){this.toggleDisableAllStatus()}.bind(this))};return j}); //# sourceMappingURL=preferences_notifications_list_controller.min.js.map diff --git a/message/amd/build/preferences_notifications_list_controller.min.js.map b/message/amd/build/preferences_notifications_list_controller.min.js.map index 700274e16e6d7..92b71f5e9a1e8 100644 --- a/message/amd/build/preferences_notifications_list_controller.min.js.map +++ b/message/amd/build/preferences_notifications_list_controller.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/preferences_notifications_list_controller.js"],"names":["define","$","Ajax","Notification","CustomEvents","NotificationPreference","NotificationProcessorSettings","ModalFactory","SELECTORS","DISABLE_NOTIFICATIONS","DISABLE_NOTIFICATIONS_CONTAINER","PREFERENCE","PREFERENCE_ROW","PREFERENCE_INPUT","PROCESSOR_SETTING","PreferencesController","element","root","userId","attr","registerEventListeners","prototype","isDisabled","hasClass","setDisabled","addClass","find","prop","setEnabled","removeClass","toggleDisableAllStatus","checkbox","container","ischecked","Deferred","resolve","request","methodname","args","userid","emailstop","call","done","bind","always","fail","exception","disabledNotificationsElement","events","activate","on","e","preferenceElement","target","closest","preferenceRow","preference","save","eventFormPromise","create","type","TYPE","preventDefault","then","modal","setUserId","setName","setContextId","setElement","show","stopImmediatePropagation"],"mappings":"AAuBAA,OAAM,0DAAC,CAAC,QAAD,CACC,WADD,CAEC,mBAFD,CAGC,gCAHD,CAIC,sCAJD,CAKC,8CALD,CAMC,oBAND,CAAD,CAQE,SACEC,CADF,CAEEC,CAFF,CAGEC,CAHF,CAIEC,CAJF,CAKEC,CALF,CAMEC,CANF,CAOEC,CAPF,CAQE,IAEFC,CAAAA,CAAS,CAAG,CACZC,qBAAqB,CAAE,+EADX,CAEZC,+BAA+B,CAAE,kDAFrB,CAGZC,UAAU,CAAE,cAHA,CAIZC,cAAc,CAAE,kCAJJ,CAKZC,gBAAgB,CAAE,oBALN,CAMZC,iBAAiB,CAAE,0BANP,CAFV,CAiBFC,CAAqB,CAAG,SAASC,CAAT,CAAkB,CAC1C,KAAKC,IAAL,CAAYhB,CAAC,CAACe,CAAD,CAAb,CACA,KAAKE,MAAL,CAAc,KAAKD,IAAL,CAAUE,IAAV,CAAe,cAAf,CAAd,CAEA,KAAKC,sBAAL,EACH,CAtBK,CA8BNL,CAAqB,CAACM,SAAtB,CAAgCC,UAAhC,CAA6C,UAAW,CACpD,MAAO,MAAKL,IAAL,CAAUM,QAAV,CAAmB,UAAnB,CACV,CAFD,CASAR,CAAqB,CAACM,SAAtB,CAAgCG,WAAhC,CAA8C,UAAW,CACrD,KAAKP,IAAL,CAAUQ,QAAV,CAAmB,UAAnB,EACA,KAAKR,IAAL,CAAUS,IAAV,CAAelB,CAAS,CAACK,gBAAzB,EAA2Cc,IAA3C,CAAgD,UAAhD,IACH,CAHD,CAUAZ,CAAqB,CAACM,SAAtB,CAAgCO,UAAhC,CAA6C,UAAW,CACpD,KAAKX,IAAL,CAAUY,WAAV,CAAsB,UAAtB,EACA,KAA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,CAAhB,EACA6C,CAAK,CAACE,OAAN,CAAcjE,CAAC,CAACe,CAAD,CAAD,CAAWG,IAAX,CAAgB,WAAhB,CAAd,EACA6C,CAAK,CAACG,YAAN,CAAmBlE,CAAC,CAACe,CAAD,CAAD,CAAWG,IAAX,CAAgB,iBAAhB,CAAnB,EACA6C,CAAK,CAACI,UAAN,CAAiBpD,CAAjB,EACAgD,CAAK,CAACK,IAAN,GAEAlB,CAAC,CAACmB,wBAAF,EAEH,CAVD,EAUGzB,IAVH,CAUQ1C,CAAY,CAAC2C,SAVrB,CAWH,CAfD,EAiBA1C,CAAY,CAACJ,MAAb,CAAoB+C,CAApB,CAAkD,CAC9C3C,CAAY,CAAC4C,MAAb,CAAoBC,QAD0B,CAAlD,EAIAF,CAA4B,CAACG,EAA7B,CAAgC9C,CAAY,CAAC4C,MAAb,CAAoBC,QAApD,CAA8D,UAAW,CACrE,KAAKnB,sBAAL,EACH,CAF6D,CAE5Da,IAF4D,CAEvD,IAFuD,CAA9D,CAGH,CAhDD,CAkDA,MAAO5B,CAAAA,CACV,CAtKK,CAAN","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 .\n\n/**\n * Controls the preferences for the list of notification types on the\n * message preference page\n *\n * @module core_message/preferences_notifications_list_controller\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery',\n 'core/ajax',\n 'core/notification',\n 'core/custom_interaction_events',\n 'core_message/notification_preference',\n 'core_message/notification_processor_settings',\n 'core/modal_factory',\n ],\n function(\n $,\n Ajax,\n Notification,\n CustomEvents,\n NotificationPreference,\n NotificationProcessorSettings,\n ModalFactory\n ) {\n\n var SELECTORS = {\n DISABLE_NOTIFICATIONS: '[data-region=\"disable-notification-container\"] [data-disable-notifications]',\n DISABLE_NOTIFICATIONS_CONTAINER: '[data-region=\"disable-notification-container\"]',\n PREFERENCE: '[data-state]',\n PREFERENCE_ROW: '[data-region=\"preference-row\"]',\n PREFERENCE_INPUT: '[data-state] input',\n PROCESSOR_SETTING: '[data-processor-setting]',\n };\n\n /**\n * Constructor for the PreferencesController.\n *\n * @class\n * @param {object} element jQuery object root element of the preference\n */\n var PreferencesController = function(element) {\n this.root = $(element);\n this.userId = this.root.attr('data-user-id');\n\n this.registerEventListeners();\n };\n\n /**\n * Check if the preferences are all disabled.\n *\n * @method isDisabled\n * @return {bool}\n */\n PreferencesController.prototype.isDisabled = function() {\n return this.root.hasClass('disabled');\n };\n\n /**\n * Disable all of the preferences.\n *\n * @method setDisabled\n */\n PreferencesController.prototype.setDisabled = function() {\n this.root.addClass('disabled');\n this.root.find(SELECTORS.PREFERENCE_INPUT).prop('disabled', true);\n };\n\n /**\n * Enable all of the preferences.\n *\n * @method setEnabled\n */\n PreferencesController.prototype.setEnabled = function() {\n this.root.removeClass('disabled');\n this.root.find(SELECTORS.PREFERENCE_INPUT).prop('disabled', false);\n };\n\n /**\n * Update the disable all notifications user property in the DOM and\n * send a request to update on the server.\n *\n * @method toggleDisableAllStatus\n * @return {Promise}\n */\n PreferencesController.prototype.toggleDisableAllStatus = function() {\n var checkbox = $(SELECTORS.DISABLE_NOTIFICATIONS);\n var container = $(SELECTORS.DISABLE_NOTIFICATIONS_CONTAINER);\n var ischecked = checkbox.prop('checked');\n\n if (container.hasClass('loading')) {\n return $.Deferred().resolve();\n }\n\n container.addClass('loading');\n\n var request = {\n methodname: 'core_user_update_user_preferences',\n args: {\n userid: this.userId,\n emailstop: ischecked ? 1 : 0,\n }\n };\n\n return Ajax.call([request])[0]\n .done(function() {\n if (ischecked) {\n this.setDisabled();\n } else {\n this.setEnabled();\n }\n }.bind(this))\n .always(function() {\n container.removeClass('loading');\n })\n .fail(Notification.exception);\n };\n\n /**\n * Set up all of the event listeners for the PreferencesController.\n *\n * @method registerEventListeners\n */\n PreferencesController.prototype.registerEventListeners = function() {\n var disabledNotificationsElement = $(SELECTORS.DISABLE_NOTIFICATIONS);\n\n CustomEvents.define(this.root, [\n CustomEvents.events.activate,\n ]);\n\n this.root.on('change', function(e) {\n if (!this.isDisabled()) {\n var preferenceElement = $(e.target).closest(SELECTORS.PREFERENCE);\n var preferenceRow = $(e.target).closest(SELECTORS.PREFERENCE_ROW);\n var preference = new NotificationPreference(preferenceRow, this.userId);\n\n preferenceElement.addClass('loading');\n preference.save().always(function() {\n preferenceElement.removeClass('loading');\n });\n }\n }.bind(this));\n\n var eventFormPromise = ModalFactory.create({\n type: NotificationProcessorSettings.TYPE,\n });\n\n this.root.on(CustomEvents.events.activate, SELECTORS.PROCESSOR_SETTING, function(e) {\n var element = $(e.target).closest(SELECTORS.PROCESSOR_SETTING);\n\n e.preventDefault();\n eventFormPromise.then(function(modal) {\n // Configure modal with element settings.\n modal.setUserId($(element).attr('data-user-id'));\n modal.setName($(element).attr('data-name'));\n modal.setContextId($(element).attr('data-context-id'));\n modal.setElement(element);\n modal.show();\n\n e.stopImmediatePropagation();\n return;\n }).fail(Notification.exception);\n });\n\n CustomEvents.define(disabledNotificationsElement, [\n CustomEvents.events.activate\n ]);\n\n disabledNotificationsElement.on(CustomEvents.events.activate, function() {\n this.toggleDisableAllStatus();\n }.bind(this));\n };\n\n return PreferencesController;\n});\n"],"file":"preferences_notifications_list_controller.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/preferences_notifications_list_controller.js"],"names":["define","$","Ajax","Notification","CustomEvents","NotificationPreference","NotificationProcessorSettings","ModalFactory","SELECTORS","DISABLE_NOTIFICATIONS","DISABLE_NOTIFICATIONS_CONTAINER","PREFERENCE","PREFERENCE_ROW","PREFERENCE_INPUT","PROCESSOR_SETTING","PreferencesController","element","root","userId","attr","registerEventListeners","prototype","isDisabled","hasClass","setDisabled","addClass","find","prop","setEnabled","removeClass","toggleDisableAllStatus","checkbox","container","ischecked","Deferred","resolve","request","methodname","args","userid","emailstop","call","done","bind","always","fail","exception","disabledNotificationsElement","events","activate","on","e","preferenceElement","target","closest","preferenceRow","preference","save","eventFormPromise","create","type","TYPE","data","originalEvent","preventDefault","then","modal","setUserId","setName","setContextId","setElement","show","stopImmediatePropagation"],"mappings":"AAuBAA,OAAM,0DAAC,CAAC,QAAD,CACC,WADD,CAEC,mBAFD,CAGC,gCAHD,CAIC,sCAJD,CAKC,8CALD,CAMC,oBAND,CAAD,CAQE,SACEC,CADF,CAEEC,CAFF,CAGEC,CAHF,CAIEC,CAJF,CAKEC,CALF,CAMEC,CANF,CAOEC,CAPF,CAQE,IAEFC,CAAAA,CAAS,CAAG,CACZC,qBAAqB,CAAE,+EADX,CAEZC,+BAA+B,CAAE,kDAFrB,CAGZC,UAAU,CAAE,cAHA,CAIZC,cAAc,CAAE,kCAJJ,CAKZC,gBAAgB,CAAE,oBALN,CAMZC,iBAAiB,CAAE,0BANP,CAFV,CAiBFC,CAAqB,CAAG,SAASC,CAAT,CAAkB,CAC1C,KAAKC,IAAL,CAAYhB,CAAC,CAACe,CAAD,CAAb,CACA,KAAKE,MAAL,CAAc,KAAKD,IAAL,CAAUE,IAAV,CAAe,cAAf,CAAd,CAEA,KAAKC,sBAAL,EACH,CAtBK,CA8BNL,CAAqB,CAACM,SAAtB,CAAgCC,UAAhC,CAA6C,UAAW,CACpD,MAAO,MAAKL,IAAL,CAAUM,QAAV,CAAmB,UAAnB,CACV,CAFD,CASAR,CAAqB,CAACM,SAAtB,CAAgCG,WAAhC,CAA8C,UAAW,CACrD,KAAKP,IAAL,CAAUQ,QAAV,CAAmB,UAAnB,EACA,KAAKR,IAAL,CAAUS,IAAV,CAAelB,CAAS,CAACK,gBAAzB,EAA2Cc,IAA3C,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AI,CAACC,aAAL,CAAmBC,cAAnB,GAEAN,CAAgB,CAACO,IAAjB,CAAsB,SAASC,CAAT,CAAgB,CAElCA,CAAK,CAACC,SAAN,CAAgBlE,CAAC,CAACe,CAAD,CAAD,CAAWG,IAAX,CAAgB,cAAhB,CAAhB,EACA+C,CAAK,CAACE,OAAN,CAAcnE,CAAC,CAACe,CAAD,CAAD,CAAWG,IAAX,CAAgB,WAAhB,CAAd,EACA+C,CAAK,CAACG,YAAN,CAAmBpE,CAAC,CAACe,CAAD,CAAD,CAAWG,IAAX,CAAgB,iBAAhB,CAAnB,EACA+C,CAAK,CAACI,UAAN,CAAiBtD,CAAjB,EACAkD,CAAK,CAACK,IAAN,GAEApB,CAAC,CAACqB,wBAAF,EAEH,CAVD,EAUG3B,IAVH,CAUQ1C,CAAY,CAAC2C,SAVrB,CAWH,CAhBD,EAkBA1C,CAAY,CAACJ,MAAb,CAAoB+C,CAApB,CAAkD,CAC9C3C,CAAY,CAAC4C,MAAb,CAAoBC,QAD0B,CAAlD,EAIAF,CAA4B,CAACG,EAA7B,CAAgC9C,CAAY,CAAC4C,MAAb,CAAoBC,QAApD,CAA8D,UAAW,CACrE,KAAKnB,sBAAL,EACH,CAF6D,CAE5Da,IAF4D,CAEvD,IAFuD,CAA9D,CAGH,CAjDD,CAmDA,MAAO5B,CAAAA,CACV,CAvKK,CAAN","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 .\n\n/**\n * Controls the preferences for the list of notification types on the\n * message preference page\n *\n * @module core_message/preferences_notifications_list_controller\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery',\n 'core/ajax',\n 'core/notification',\n 'core/custom_interaction_events',\n 'core_message/notification_preference',\n 'core_message/notification_processor_settings',\n 'core/modal_factory',\n ],\n function(\n $,\n Ajax,\n Notification,\n CustomEvents,\n NotificationPreference,\n NotificationProcessorSettings,\n ModalFactory\n ) {\n\n var SELECTORS = {\n DISABLE_NOTIFICATIONS: '[data-region=\"disable-notification-container\"] [data-disable-notifications]',\n DISABLE_NOTIFICATIONS_CONTAINER: '[data-region=\"disable-notification-container\"]',\n PREFERENCE: '[data-state]',\n PREFERENCE_ROW: '[data-region=\"preference-row\"]',\n PREFERENCE_INPUT: '[data-state] input',\n PROCESSOR_SETTING: '[data-processor-setting]',\n };\n\n /**\n * Constructor for the PreferencesController.\n *\n * @class\n * @param {object} element jQuery object root element of the preference\n */\n var PreferencesController = function(element) {\n this.root = $(element);\n this.userId = this.root.attr('data-user-id');\n\n this.registerEventListeners();\n };\n\n /**\n * Check if the preferences are all disabled.\n *\n * @method isDisabled\n * @return {bool}\n */\n PreferencesController.prototype.isDisabled = function() {\n return this.root.hasClass('disabled');\n };\n\n /**\n * Disable all of the preferences.\n *\n * @method setDisabled\n */\n PreferencesController.prototype.setDisabled = function() {\n this.root.addClass('disabled');\n this.root.find(SELECTORS.PREFERENCE_INPUT).prop('disabled', true);\n };\n\n /**\n * Enable all of the preferences.\n *\n * @method setEnabled\n */\n PreferencesController.prototype.setEnabled = function() {\n this.root.removeClass('disabled');\n this.root.find(SELECTORS.PREFERENCE_INPUT).prop('disabled', false);\n };\n\n /**\n * Update the disable all notifications user property in the DOM and\n * send a request to update on the server.\n *\n * @method toggleDisableAllStatus\n * @return {Promise}\n */\n PreferencesController.prototype.toggleDisableAllStatus = function() {\n var checkbox = $(SELECTORS.DISABLE_NOTIFICATIONS);\n var container = $(SELECTORS.DISABLE_NOTIFICATIONS_CONTAINER);\n var ischecked = checkbox.prop('checked');\n\n if (container.hasClass('loading')) {\n return $.Deferred().resolve();\n }\n\n container.addClass('loading');\n\n var request = {\n methodname: 'core_user_update_user_preferences',\n args: {\n userid: this.userId,\n emailstop: ischecked ? 1 : 0,\n }\n };\n\n return Ajax.call([request])[0]\n .done(function() {\n if (ischecked) {\n this.setDisabled();\n } else {\n this.setEnabled();\n }\n }.bind(this))\n .always(function() {\n container.removeClass('loading');\n })\n .fail(Notification.exception);\n };\n\n /**\n * Set up all of the event listeners for the PreferencesController.\n *\n * @method registerEventListeners\n */\n PreferencesController.prototype.registerEventListeners = function() {\n var disabledNotificationsElement = $(SELECTORS.DISABLE_NOTIFICATIONS);\n\n CustomEvents.define(this.root, [\n CustomEvents.events.activate,\n ]);\n\n this.root.on('change', function(e) {\n if (!this.isDisabled()) {\n var preferenceElement = $(e.target).closest(SELECTORS.PREFERENCE);\n var preferenceRow = $(e.target).closest(SELECTORS.PREFERENCE_ROW);\n var preference = new NotificationPreference(preferenceRow, this.userId);\n\n preferenceElement.addClass('loading');\n preference.save().always(function() {\n preferenceElement.removeClass('loading');\n });\n }\n }.bind(this));\n\n var eventFormPromise = ModalFactory.create({\n type: NotificationProcessorSettings.TYPE,\n });\n\n this.root.on(CustomEvents.events.activate, SELECTORS.PROCESSOR_SETTING, function(e, data) {\n var element = $(e.target).closest(SELECTORS.PROCESSOR_SETTING);\n\n data.originalEvent.preventDefault();\n\n eventFormPromise.then(function(modal) {\n // Configure modal with element settings.\n modal.setUserId($(element).attr('data-user-id'));\n modal.setName($(element).attr('data-name'));\n modal.setContextId($(element).attr('data-context-id'));\n modal.setElement(element);\n modal.show();\n\n e.stopImmediatePropagation();\n return;\n }).fail(Notification.exception);\n });\n\n CustomEvents.define(disabledNotificationsElement, [\n CustomEvents.events.activate\n ]);\n\n disabledNotificationsElement.on(CustomEvents.events.activate, function() {\n this.toggleDisableAllStatus();\n }.bind(this));\n };\n\n return PreferencesController;\n});\n"],"file":"preferences_notifications_list_controller.min.js"} \ No newline at end of file diff --git a/message/amd/src/preferences_notifications_list_controller.js b/message/amd/src/preferences_notifications_list_controller.js index daad95353d478..d80d02de40dfa 100644 --- a/message/amd/src/preferences_notifications_list_controller.js +++ b/message/amd/src/preferences_notifications_list_controller.js @@ -160,10 +160,11 @@ define(['jquery', type: NotificationProcessorSettings.TYPE, }); - this.root.on(CustomEvents.events.activate, SELECTORS.PROCESSOR_SETTING, function(e) { + this.root.on(CustomEvents.events.activate, SELECTORS.PROCESSOR_SETTING, function(e, data) { var element = $(e.target).closest(SELECTORS.PROCESSOR_SETTING); - e.preventDefault(); + data.originalEvent.preventDefault(); + eventFormPromise.then(function(modal) { // Configure modal with element settings. modal.setUserId($(element).attr('data-user-id'));