MDL-61575 message_notification: replace lp/dialogue with core/modal
[moodle.git] / message / amd / build / preferences_notifications_list_controller.min.js
CommitLineData
cd03a6fe 1define(["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,e,f,g){var h={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]"},i=function(b){this.root=a(b),this.userId=this.root.attr("data-user-id"),this.registerEventListeners()};return i.prototype.isDisabled=function(){return this.root.hasClass("disabled")},i.prototype.setDisabled=function(){this.root.addClass("disabled"),this.root.find(h.PREFERENCE_INPUT).prop("disabled",!0)},i.prototype.setEnabled=function(){this.root.removeClass("disabled"),this.root.find(h.PREFERENCE_INPUT).prop("disabled",!1)},i.prototype.toggleDisableAllStatus=function(){var d=a(h.DISABLE_NOTIFICATIONS),e=a(h.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(){f?this.setDisabled():this.setEnabled()}.bind(this)).always(function(){e.removeClass("loading")}).fail(c.exception)},i.prototype.registerEventListeners=function(){var b=a(h.DISABLE_NOTIFICATIONS);d.define(this.root,[d.events.activate]),this.root.on("change",function(b){if(!this.isDisabled()){var c=a(b.target).closest(h.PREFERENCE),d=a(b.target).closest(h.PREFERENCE_ROW),f=new e(d,this.userId);c.addClass("loading"),f.save().always(function(){c.removeClass("loading")})}}.bind(this));var i=g.create({type:f.TYPE});this.root.on(d.events.activate,h.PROCESSOR_SETTING,function(b){var d=a(b.target).closest(h.PROCESSOR_SETTING);b.preventDefault(),i.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))},i});