You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1 lines
3.0 KiB

define(["jquery","core/notification","core/str","core/pubsub","core/templates","core_message/message_repository","core/custom_interaction_events","core_message/message_drawer_events"],function(a,b,c,d,e,f,g,h){var i={CHECKBOX:'input[type="checkbox"]',SETTINGS:'[data-region="settings"]',PRIVACY_PREFERENCE:'[data-preference="blocknoncontacts"] input[type="radio"]',NOTIFICATIONS_PREFERENCE:'[data-preference="notifications"] input[type="checkbox"]',ENTER_TO_SEND_PREFERENCE:'[data-preference="entertosend"] input[type="checkbox"]',NOTIFICATION_PREFERENCES_CONTAINER:'[data-region="notification-preference-container"]',CONTENT_CONTAINER:'[data-region="content-container"]',PLACEHOLDER_CONTAINER:'[data-region="placeholder-container"]'},j={NOTIFICATION_PREFERENCES:"core_message/message_drawer_view_settings_body_content_notification_preferences"},k="message_provider_moodle_instantmessage",l=function(b,c){var d=b.find(i.PRIVACY_PREFERENCE);d.each(function(b,d){d=a(d),d.val()==c?d.prop("checked",!0):d.prop("checked",!1)})},m=function(a,b){var c=a.find(i.ENTER_TO_SEND_PREFERENCE);b?c.prop("checked",!0):c.prop("checked",!1)},n=function(a,c){return f.savePreferences(a,c).then(function(){d.publish(h.PREFERENCES_UPDATED,c)})["catch"](b.exception)},o=function(b,c){var d=b.find(i.SETTINGS);g.define(d,[g.events.activate]),d.on(g.events.activate,i.NOTIFICATIONS_PREFERENCE,function(b){var d=a(b.target).closest(i.NOTIFICATION_PREFERENCES_CONTAINER),e=d.find(i.CHECKBOX);if(e.length){var f=e.toArray().reduce(function(b,c){return c=a(c),c.prop("checked")&&b.push(c.attr("data-name")),b},[]),g=f.length?f.join(","):"none",h=[{type:"message_provider_moodle_instantmessage_loggedoff",value:g},{type:"message_provider_moodle_instantmessage_loggedin",value:g}];n(c,h)}}),d.on("change",i.PRIVACY_PREFERENCE,function(b){var d=a(b.target).val(),e=[{type:"message_blocknoncontacts",value:d}];n(c,e)}),d.on(g.events.activate,i.ENTER_TO_SEND_PREFERENCE,function(b){var d=a(b.target).prop("checked"),e=[{type:"message_entertosend",value:d}];n(c,e)})},p=function(a,c){f.getUserMessagePreferences(c).then(function(b){l(a,b.blocknoncontacts),m(a,b.entertosend);var c=[];b.preferences.components.length&&b.preferences.components.forEach(function(a){if(a.notifications.length){var b=a.notifications.filter(function(a){return a.preferencekey==k});if(b.length){var d=a.notifications[0];c=d.processors.map(function(a){var b=a.loggedin.checked||a.loggedoff.checked;return{displayname:a.displayname,name:a.name,checked:b,locked:a.locked,lockedmessage:a.lockedmessage||null}})}}});var d=a.find(i.NOTIFICATION_PREFERENCES_CONTAINER);return!c.length||(d.removeClass("hidden"),e.render(j.NOTIFICATION_PREFERENCES,{processors:c}).then(function(a){return d.append(a),a}))}).then(function(){a.find(i.CONTENT_CONTAINER).removeClass("hidden"),a.find(i.PLACEHOLDER_CONTAINER).addClass("hidden"),o(a,c)})["catch"](b.exception)},q=function(b,c,d,e,f){return d.attr("data-init")||(p(d,f),d.attr("data-init",!0)),a.Deferred().resolve().promise()},r=function(){return c.get_string("messagedrawerviewsettings","core_message")};return{show:q,description:r}});