/
var
/
www
/
html
/
cdhu
/
message
/
amd
/
build
/
Upload File
HOME
define(["jquery","core/ajax","core/notification","core/custom_interaction_events","core_message/notification_preference","core_message/notification_processor_settings"],function(a,b,c,d,e,f){var g={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]"},h=function(b){this.root=a(b),this.userId=this.root.attr("data-user-id"),this.registerEventListeners()};return h.prototype.isDisabled=function(){return this.root.hasClass("disabled")},h.prototype.setDisabled=function(){this.root.addClass("disabled"),this.root.find(g.PREFERENCE_INPUT).prop("disabled",!0)},h.prototype.setEnabled=function(){this.root.removeClass("disabled"),this.root.find(g.PREFERENCE_INPUT).prop("disabled",!1)},h.prototype.toggleDisableAllStatus=function(){var d=a(g.DISABLE_NOTIFICATIONS),e=a(g.DISABLE_NOTIFICATIONS_CONTAINER),f=d.prop("checked");if(e.hasClass("loading"))return a.Deferred().resolve();e.addClass("loading");var h={methodname:"core_user_update_user_preferences",args:{userid:this.userId,emailstop:f?1:0}};return b.call([h])[0].done(function(){f?this.setDisabled():this.setEnabled()}.bind(this)).always(function(){e.removeClass("loading")}).fail(c.exception)},h.prototype.registerEventListeners=function(){var b=a(g.DISABLE_NOTIFICATIONS);d.define(this.root,[d.events.activate]),this.root.on("change",function(b){if(!this.isDisabled()){var c=a(b.target).closest(g.PREFERENCE),d=a(b.target).closest(g.PREFERENCE_ROW),f=new e(d,this.userId);c.addClass("loading"),f.save().always(function(){c.removeClass("loading")})}}.bind(this)),this.root.on(d.events.activate,g.PROCESSOR_SETTING,function(b,c){var d=a(b.target).closest(g.PROCESSOR_SETTING),e=new f(d);e.show(),c.originalEvent.preventDefault()}),d.define(b,[d.events.activate]),b.on(d.events.activate,function(){this.toggleDisableAllStatus()}.bind(this))},h});