module.js 4.6 KB

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