MDL-55393 message: New WS get_user_notification_preferences
[moodle.git] / message / module.js
blob4c5bd67dd6a551f9fd233496581ff4f8a4e405d6
1 M.core_message = M.core_message || {};
3 M.core_message.init_focus = function(Y, eid) {
4     document.getElementById(eid).focus();
5 };
7 M.core_message.init_refresh_page = function(Y, delay, url) {
8     var delay_callback = function() {
9         document.location.replace(url);
10     };
11     setTimeout(delay_callback, delay);
14 M.core_message.combinedsearchgotfocus = function(e) {
15     if (e.target.get('value')==this.defaultsearchterm) {
16         e.target.select();
17     }
20 M.core_message.init_defaultoutputs = function(Y) {
21     var defaultoutputs = {
23         init : function() {
24             Y.all('#defaultmessageoutputs select').each(function(node) {
25                 // attach event listener
26                 node.on('change', defaultoutputs.changeState);
27                 // set initial layout
28                 node.simulate("change");
29             }, this);
31             Y.all('#defaultmessageoutputs input.messagedisable').each(function(node) {
32                 // Attach event listener
33                 node.on('change', defaultoutputs.changeProviderState);
34                 node.simulate("change");
35             }, this);
36         },
38         changeState : function(e) {
39             var value = e.target._node.options[e.target.get('selectedIndex')].value;
40             var parentnode = e.target.ancestor('td');
41             switch (value) {
42             case 'forced':
43                 defaultoutputs.updateCheckboxes(parentnode, 1, 1);
44                 break;
45             case 'disallowed':
46                 defaultoutputs.updateCheckboxes(parentnode, 1, 0);
47                 break;
48             case 'permitted':
49                 defaultoutputs.updateCheckboxes(parentnode, 0, 0);
50                 break;
51             }
52         },
54         updateCheckboxes : function(blocknode, disabled, checked) {
55             blocknode.all('input[type=checkbox]').each(function(node) {
56                 node.removeAttribute('disabled');
57                 if (disabled) {
58                     node.setAttribute('disabled', 1)
59                     node.removeAttribute('checked');
60                 }
61                 if (checked) {
62                     node.setAttribute('checked', 1)
63                 }
64             }, this);
65         },
67         changeProviderState : function(e) {
68             var isenabled = e.target.get('checked') || undefined;
69             var parentnode = e.target.ancestor('tr');
70             if (!isenabled) {
71                 parentnode.all('select').each(function(node) {
72                     node.set('value', 'disallowed');
73                     node.setAttribute('disabled', 1);
74                     defaultoutputs.updateCheckboxes(node.ancestor('td'), 1, 0);
75                 }, this);
76                 parentnode.addClass('dimmed_text');
77             } else {
78                 parentnode.all('select[disabled]').each(function(node) {
79                     node.removeAttribute('disabled');
80                     node.set('value', 'permitted');
81                     defaultoutputs.updateCheckboxes(node.ancestor('td'), 0, 0);
82                 }, this);
83                 parentnode.removeClass('dimmed_text');
84             }
85         }
86     }
88     defaultoutputs.init();
91 M.core_message.init_editsettings = function(Y) {
92     var editsettings = {
94         init : function() {
95             var disableall = Y.one(".disableallcheckbox");
96             disableall.on('change', editsettings.changeState);
97             disableall.simulate("change");
98         },
100         changeState : function(e) {
101             Y.all('.notificationpreference').each(function(node) {
102                 var disabled = e.target.get('checked');
104                 node.removeAttribute('disabled');
105                 if (disabled) {
106                     node.setAttribute('disabled', 1)
107                 }
108             }, this);
109         }
110     }
112     editsettings.init();