privileges.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: ps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2011
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  9. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  10. function select(p, v) {
  11. for (var i=0;i<document.pform.elements.length;i++)
  12. {
  13. var e = document.pform.elements[i];
  14. if (e.name.substring(0, p.length)==p)
  15. {
  16. e.checked = v;
  17. }
  18. }
  19. event_onclick();
  20. }
  21. function event_onclick(chkPrefix, hidPrefix)
  22. {
  23. var newpv = "";
  24. var newmv = "";
  25. // scan all checkboxes using a well known prefix
  26. for (i=0; i<document.pform.elements.length; i++)
  27. {
  28. var e = document.pform.elements[i];
  29. if (e.name.substring(0, chkPrefix.length) == chkPrefix)
  30. {
  31. if (e.checked)
  32. {
  33. // get its hidden input equivalent
  34. p = document.pform.elements[hidPrefix + e.name.substring(chkPrefix.length)];
  35. pv = p.value;
  36. if (newpv == "")
  37. {
  38. // first state
  39. newpv = pv;
  40. }
  41. else if (newpv != pv)
  42. {
  43. // mixed state
  44. for (j = 0; j < newpv.length; j++)
  45. {
  46. permission = newpv.substr(j, 1);
  47. if ((-1 == pv.indexOf(permission)) && (-1 == newmv.indexOf(permission)))
  48. newmv += permission;
  49. }
  50. for (j=0; j<pv.length; j++)
  51. {
  52. permission = pv.substr(j, 1);
  53. if ((-1 == newpv.indexOf(permission)) && (-1 == newmv.indexOf(permission)))
  54. newmv += permission;
  55. }
  56. }
  57. }
  58. }
  59. }
  60. // for each 'permission' in 'mixed' if 'pattern' has it, remove it from 'pattern'
  61. for (i = 0; i < newmv.length; i++)
  62. {
  63. permission = newmv.substr(i, 1);
  64. newpv = newpv.replace(new RegExp(permission,""), "");
  65. }
  66. // set the values
  67. document.pform.elements['privileges_pattern'].value = newpv;
  68. document.pform.elements['privileges_mixed'].value = newmv;
  69. // update all checkboxes images
  70. all = "rRwWxXpPtT";
  71. for (i=0; i<all.length; i++)
  72. {
  73. permission = all.substr(i, 1);
  74. if (newmv.indexOf(permission) != -1)
  75. state = 2;
  76. else
  77. state = (newpv.indexOf(permission) != -1) ? 1 : 0;
  78. setImage(permission, state);
  79. }
  80. }
  81. function checkboxKeyHandler(rwxp)
  82. {
  83. var Key;
  84. Key = window.event.keyCode;
  85. if (Key==32) //space bar
  86. {
  87. document.pform.uncommitted_permissions.value='1';
  88. check(rwxp);
  89. }
  90. }
  91. function check(permission)
  92. {
  93. otherPermission = (permission == permission.toLowerCase()) ? permission.toUpperCase() : permission.toLowerCase();
  94. p = document.pform.elements['privileges_pattern'];
  95. m = document.pform.elements['privileges_mixed'];
  96. pv = p.value; // get values for pattern and mixed
  97. mv = m.value;
  98. ppos = pv.indexOf(permission);
  99. if (-1 == ppos) // is it unchecked or third state?
  100. {
  101. // add 'permission' to 'pv', remove 'otherPermission' from 'pv' and
  102. // remove both ('permission' and 'otherPermission') from 'mv'
  103. pv += permission;
  104. re = RegExp(otherPermission,"");
  105. pv = pv.replace(re, "");
  106. mv = mv.replace(re, "");
  107. mv = mv.replace(new RegExp(permission,""), "");
  108. state = 1; // checked
  109. }
  110. else
  111. {
  112. // just remove 'permission' from 'pv'
  113. pv = pv.replace(new RegExp(permission,""), "");
  114. state = 0; // unchecked
  115. }
  116. setImage(permission, state); // new checkbox state
  117. setImage(otherPermission, 0); // reset other to unchecked
  118. p.value = pv; // reassign values
  119. m.value = mv;
  120. if (window.on_uncommitted_permissions_changed)
  121. {
  122. on_uncommitted_permissions_changed();
  123. }
  124. return;
  125. }
  126. function setImage(permission, state)
  127. {
  128. obj = document.images[permission];
  129. if (obj)
  130. {
  131. img = obj.src;
  132. ipos = img.lastIndexOf('checkbox_');
  133. path = img.substr(0, ipos);
  134. switch (state)
  135. {
  136. case 1:
  137. gif = "checked";
  138. obj.alt=checkbox_checked_message;
  139. break;
  140. case 2:
  141. gif = "mixed";
  142. obj.alt=checkbox_mixed_message;
  143. break;
  144. default:
  145. gif = "unchecked";
  146. obj.alt=checkbox_unchecked_message;
  147. break;
  148. }
  149. obj.src = path + 'checkbox_' + gif + '.gif';
  150. }
  151. }