forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.js
114 lines (98 loc) · 3.4 KB
/
module.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
M.core_message = M.core_message || {};
M.core_message.init_focus = function(Y, eid) {
document.getElementById(eid).focus();
};
M.core_message.init_refresh_page = function(Y, delay, url) {
var delay_callback = function() {
document.location.replace(url);
};
setTimeout(delay_callback, delay);
};
M.core_message.combinedsearchgotfocus = function(e) {
if (e.target.get('value')==this.defaultsearchterm) {
e.target.select();
}
};
M.core_message.init_notification = function(Y, title, content, url) {
Y.use('overlay', function() {
var o = new Y.Overlay({
headerContent : title,
bodyContent : content
});
o.render(Y.one(document.body));
if (Y.UA.ie > 0 && Y.UA.ie < 7) {
// Adjust for IE 6 (can't handle fixed pos)
//align the bottom right corner of the overlay with the bottom right of the viewport
o.set("align", {
points:[Y.WidgetPositionAlign.BR, Y.WidgetPositionAlign.BR]
});
}
Y.one('#notificationyes').on('click', function(e) {
window.location.href = url;
}, o);
Y.one('#notificationno').on('click', function(e) {
o.hide();
e.preventDefault();
return false;
}, o);
});
};
M.core_message.init_defaultoutputs = function(Y) {
var defaultoutputs = {
init : function() {
Y.all('#defaultmessageoutputs select').each(function(node) {
// attach event listener
node.on('change', defaultoutputs.changeState);
// set initial layout
node.simulate("change");
}, this);
},
changeState : function(e) {
var value = e.target._node.options[e.target.get('selectedIndex')].value;
var parentnode = e.target.ancestor('td');
switch (value) {
case 'forced':
defaultoutputs.updateCheckboxes(parentnode, 1, 1);
break;
case 'disallowed':
defaultoutputs.updateCheckboxes(parentnode, 1, 0);
break;
case 'permitted':
defaultoutputs.updateCheckboxes(parentnode, 0, 0);
break;
}
},
updateCheckboxes : function(blocknode, disabled, checked) {
blocknode.all('input[type=checkbox]').each(function(node) {
node.removeAttribute('disabled');
if (disabled) {
node.setAttribute('disabled', 1)
node.removeAttribute('checked');
}
if (checked) {
node.setAttribute('checked', 1)
}
}, this);
}
}
defaultoutputs.init();
}
M.core_message.init_editsettings = function(Y) {
var editsettings = {
init : function() {
var disableall = Y.one(".disableallcheckbox");
disableall.on('change', editsettings.changeState);
disableall.simulate("change");
},
changeState : function(e) {
Y.all('.notificationpreference').each(function(node) {
var disabled = e.target.get('checked');
node.removeAttribute('disabled');
if (disabled) {
node.setAttribute('disabled', 1)
}
}, this);
}
}
editsettings.init();
}