Merge branch 'master_MDL-37844' of git://github.com/danmarsden/moodle
[moodle.git] / message / module.js
blobdc4ee7a732425e67ca279ab1567f34c413c979f6
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);
11 setTimeout(delay_callback, delay);
14 M.core_message.combinedsearchgotfocus = function(e) {
15 if (e.target.get('value')==this.defaultsearchterm) {
16 e.target.select();
20 M.core_message.init_notification = function(Y, title, content, url) {
21 Y.use('overlay', function() {
22 var o = new Y.Overlay({
23 headerContent : title,
24 bodyContent : content
25 });
26 o.render(Y.one(document.body));
28 if (Y.UA.ie > 0 && Y.UA.ie < 7) {
29 // Adjust for IE 6 (can't handle fixed pos)
30 //align the bottom right corner of the overlay with the bottom right of the viewport
31 o.set("align", {
32 points:[Y.WidgetPositionAlign.BR, Y.WidgetPositionAlign.BR]
33 });
36 Y.one('#notificationyes').on('click', function(e) {
37 window.location.href = url;
38 }, o);
39 Y.one('#notificationno').on('click', function(e) {
40 o.hide();
41 e.preventDefault();
42 return false;
43 }, o);
44 });
47 M.core_message.init_defaultoutputs = function(Y) {
48 var defaultoutputs = {
50 init : function() {
51 Y.all('#defaultmessageoutputs select').each(function(node) {
52 // attach event listener
53 node.on('change', defaultoutputs.changeState);
54 // set initial layout
55 node.simulate("change");
56 }, this);
59 changeState : function(e) {
60 var value = e.target._node.options[e.target.get('selectedIndex')].value;
61 var parentnode = e.target.ancestor('td');
62 switch (value) {
63 case 'forced':
64 defaultoutputs.updateCheckboxes(parentnode, 1, 1);
65 break;
66 case 'disallowed':
67 defaultoutputs.updateCheckboxes(parentnode, 1, 0);
68 break;
69 case 'permitted':
70 defaultoutputs.updateCheckboxes(parentnode, 0, 0);
71 break;
75 updateCheckboxes : function(blocknode, disabled, checked) {
76 blocknode.all('input[type=checkbox]').each(function(node) {
77 node.removeAttribute('disabled');
78 if (disabled) {
79 node.setAttribute('disabled', 1)
80 node.removeAttribute('checked');
82 if (checked) {
83 node.setAttribute('checked', 1)
85 }, this);
89 defaultoutputs.init();
92 M.core_message.init_editsettings = function(Y) {
93 var editsettings = {
95 init : function() {
96 var disableall = Y.one(".disableallcheckbox");
97 disableall.on('change', editsettings.changeState);
98 disableall.simulate("change");
101 changeState : function(e) {
102 Y.all('.notificationpreference').each(function(node) {
103 var disabled = e.target.get('checked');
105 node.removeAttribute('disabled');
106 if (disabled) {
107 node.setAttribute('disabled', 1)
109 }, this);
113 editsettings.init();