req_array.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. //-- $I.: Img, $L: Label, $C: Control, $M: more control, $V: enable checkbox,
  17. // $$: parentId placeholder - to be replaced by the real one
  18. function show_hide(obj)
  19. {
  20. if (obj.style.display == 'block') {
  21. obj.style.display='none';
  22. return ">>";
  23. } else {
  24. obj.style.display='block';
  25. return "<<";
  26. }
  27. }
  28. function show_hide_inline(obj)
  29. {
  30. if (obj.style.display == 'inline') {
  31. obj.style.display='none';
  32. } else {
  33. obj.style.display='inline';
  34. }
  35. }
  36. function onClickDest(chked, ctrlObj)
  37. {
  38. if (!chked) {
  39. ctrlObj.style.display='none';
  40. } else {
  41. ctrlObj.style.display='inline';
  42. ctrlObj.value = document.forms[0].action;
  43. }
  44. }
  45. function enableButton(tableId)
  46. {
  47. var table = document.getElementById(tableId);
  48. var b = document.getElementById(tableId+"_RvBtn");
  49. b.disabled = (table.rows.length==0);
  50. //alert("btn id="+tableId+"_Remove" + " disabled "+ (table.rows.length==0));
  51. }
  52. function removeRow(tableId)
  53. {
  54. var table = document.getElementById(tableId);
  55. table.deleteRow(-1);
  56. enableButton(tableId);
  57. document.getElementById(tableId+'_ItemCt').value = table.rows.length;
  58. }
  59. function appendRow(tableId, itemName, htmlContentFunc)
  60. {
  61. var table = document.getElementById(tableId);
  62. var x = table.insertRow(-1);
  63. var idx = x.rowIndex;
  64. var oldContent = htmlContentFunc(tableId,itemName);
  65. // replace $$ with tableId
  66. var regex1 = new RegExp('\\$\\$', 'g');
  67. var newId = tableId+'.'+idx;
  68. var ctrlId = newId;
  69. if (newId.indexOf('$$.')==0)
  70. newId = newId.substring(4);
  71. newContent = oldContent.replace(regex1, newId);
  72. if (idx>0)
  73. {
  74. var regex = new RegExp(tableId+'\\.0\\.', 'g');
  75. newContent = newContent.replace(regex, ctrlId+'.');
  76. }
  77. {
  78. var r1=x.insertCell(0);
  79. r1.innerHTML = "<img src='/esp/files/img/form_minus.gif' alt='-' id='$I." + ctrlId + "' onclick='hideIt(\""+ ctrlId + "\")'/>";
  80. // + "<input type='checkbox' checked='1' onClick='enableInput(this,\"" + ctrlId + "\")' id='$V." + ctrlId + "'/>";
  81. var r2=x.insertCell(1);
  82. r2.innerHTML = "<span id='$M." + ctrlId + "' style='display:none'><img src='/esp/files/img/form_more.gif' alt='more' onclick='onMore(\"" + ctrlId + "\")'/></span>"
  83. + "<span id='$L." + ctrlId + "'><b>" + itemName + "[" + (idx + 1) + "]:</b></span>";
  84. var r3=x.insertCell(2);
  85. r3.innerHTML = newContent;
  86. }
  87. enableButton(tableId);
  88. document.getElementById(tableId+'_ItemCt').value = table.rows.length;
  89. }
  90. function hideIt(idCtrl) {
  91. var ctrl = document.getElementById('$C.'+idCtrl);
  92. if (!ctrl) {
  93. return;
  94. }
  95. var moreCtrl = document.getElementById('$M.'+idCtrl);
  96. if (ctrl.style.display != "none") {
  97. document.getElementById('$I.'+idCtrl).src = "/esp/files/img/form_plus.gif";
  98. ctrl.style.display = "none";
  99. if (moreCtrl) moreCtrl.style.display = "block";
  100. } else {
  101. document.getElementById('$I.'+idCtrl).src = "/esp/files/img/form_minus.gif";
  102. ctrl.style.display = "block";
  103. if (moreCtrl) moreCtrl.style.display = "none";
  104. }
  105. }
  106. function onMore(idCtrl) {
  107. var ctrl = document.getElementById('$C.'+idCtrl);
  108. if (!ctrl) return;
  109. document.getElementById('$I.'+idCtrl).src = "/esp/files/img/form_minus.gif";
  110. ctrl.style.display = "block";
  111. ctrl = document.getElementById('$L.'+idCtrl);
  112. if (!ctrl) return;
  113. ctrl.style.display = "block";
  114. ctrl = document.getElementById('$M.'+idCtrl);
  115. if (!ctrl) return;
  116. ctrl.style.display = "none";
  117. }
  118. function enableSubInputs(toDisable,parentId) {
  119. var ctrls = document.forms['esp_form'].elements;
  120. for (var idx=0; idx<ctrls.length; idx++) {
  121. var c = ctrls[idx];
  122. if (c.id!='' && c.type == 'checkbox'){
  123. if ( (c.id.substr(0,3) == '$V.') && (c.id.substr(3,parentId.length+1)==(parentId+'.')) ) {
  124. if ( (c.checked && toDisable) || (!c.checked && !toDisable) )
  125. c.click();
  126. }
  127. }
  128. }
  129. }
  130. function disableBoolInput(ctrl,disable) {
  131. var hCtrl = document.getElementById('$D.'+ctrl.id);
  132. if (ctrl) {
  133. if (!disable) {
  134. if(ctrl.disabled) {
  135. hCtrl.disabled = false;
  136. ctrl.disabled = false;
  137. }
  138. }else{
  139. if (!ctrl.disabled) {
  140. hCtrl.disabled = true;
  141. ctrl.disabled = true;
  142. }
  143. }
  144. }
  145. }
  146. function disableIEControl(ctrl,disable){
  147. if (ctrl.type=='checkbox') {
  148. ctrl.disabled = disable;
  149. } else {
  150. if (disable) {
  151. ctrl.disabled = true;
  152. ctrl.className = 'disabled';
  153. } else {
  154. ctrl.disabled = false;
  155. ctrl.className = '';
  156. }
  157. }
  158. }
  159. function disableInputControl(ctrl,disable) {
  160. if (ctrl.type=='checkbox')
  161. disableBoolInput(ctrl,disable);
  162. else if (isIE)
  163. disableIEControl(ctrl,disable);
  164. else
  165. ctrl.disabled = disable;
  166. }
  167. function disableInputLabel(label,disable) {
  168. if (label)
  169. label.style.color = disable ? 'gray': 'black';
  170. }
  171. function enableInput(checkbox,idCtrl) {
  172. var ctrl = document.getElementById(idCtrl);
  173. var disable = !checkbox.checked;
  174. // label
  175. var label = document.getElementById('$L.'+idCtrl);
  176. disableInputLabel(label,disable);
  177. // input
  178. if (!ctrl)
  179. enableSubInputs(disable,idCtrl);
  180. else
  181. disableInputControl(ctrl,disable);
  182. }
  183. function onBoolChange(checkbox) {
  184. var hiddenCtrl = document.getElementById('$D.'+checkbox.id);
  185. if (hiddenCtrl)
  186. hiddenCtrl.value = checkbox.checked ? "1" : "0";
  187. }
  188. function onTriButtonKeyPress(obj)
  189. {
  190. if (event.keyCode == 32) //space
  191. {
  192. onClickTriButton(obj, 1);
  193. return false;
  194. }
  195. return true;
  196. }
  197. function onClickTriButton(btn, clicks)
  198. {
  199. while (clicks--)
  200. {
  201. if (btn.value=='default')
  202. {
  203. btn.value='true';
  204. btn.style.color='green';
  205. btn.name=btn.id;
  206. }
  207. else if (btn.value=='true')
  208. {
  209. btn.value='false';
  210. btn.style.color='red';
  211. btn.name=btn.id;
  212. }
  213. else
  214. {
  215. btn.value='default';
  216. btn.style.color='gray';
  217. btn.name='';
  218. }
  219. }
  220. }