MDL-54708 message: notification popover respects message preferences
[moodle.git] / message / module.js
CommitLineData
8a811c56 1M.core_message = M.core_message || {};
5f3bf83f 2
e44bc5a1 3M.core_message.init_focus = function(Y, eid) {
5f3bf83f 4 document.getElementById(eid).focus();
1d236fef 5};
5f3bf83f 6
5f3bf83f 7M.core_message.init_refresh_page = function(Y, delay, url) {
e5e50970
DP
8 var delay_callback = function() {
9 document.location.replace(url);
10 };
11 setTimeout(delay_callback, delay);
1d236fef 12};
c8621a02 13
c8621a02
AD
14M.core_message.combinedsearchgotfocus = function(e) {
15 if (e.target.get('value')==this.defaultsearchterm) {
16 e.target.select();
17 }
1d236fef 18};
b32778c4 19
1d72e9d4
RK
20M.core_message.init_defaultoutputs = function(Y) {
21 var defaultoutputs = {
22
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);
fd0f7ac5
RT
30
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);
1d72e9d4
RK
36 },
37
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 },
53
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);
fd0f7ac5
RT
65 },
66
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 {
0802d98a 78 parentnode.all('select[disabled]').each(function(node) {
fd0f7ac5
RT
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 }
1d72e9d4
RK
85 }
86 }
87
88 defaultoutputs.init();
bb3546f3
AD
89}
90
91M.core_message.init_editsettings = function(Y) {
92 var editsettings = {
93
94 init : function() {
95 var disableall = Y.one(".disableallcheckbox");
96 disableall.on('change', editsettings.changeState);
97 disableall.simulate("change");
98 },
99
100 changeState : function(e) {
101 Y.all('.notificationpreference').each(function(node) {
102 var disabled = e.target.get('checked');
103
104 node.removeAttribute('disabled');
105 if (disabled) {
106 node.setAttribute('disabled', 1)
107 }
108 }, this);
109 }
110 }
111
112 editsettings.init();
e5e50970 113}