swapbox.js
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:7k
源码类别:

电子政务应用

开发平台:

Java

  1. // This is the form name on the HTML page
  2. var formName = "faqform";
  3. // The select box on the left side
  4. var fromSelect = "selectFrom";
  5. // The select box on the right side
  6. var toSelect = "selectInto";
  7. // The name fo the text box where the article 'trail' is displayed
  8. var textTrail = "displayTrail";
  9. function addCategory(catIndex,sb1)
  10. {
  11. if(categoryArray[catIndex][1] != -1)
  12. {
  13. addCategory(categoryArray[catIndex][1],sb1);
  14. }
  15. if(sb1 == fromSelect)
  16. {
  17. if(categoryArray[catIndex][3] == 0)
  18. {
  19. document.forms[formName].elements[sb1].options[document.forms[formName].elements[sb1].options.length] = new Option(getCategoryDepth(catIndex) + categoryArray[catIndex][0],"",false,false);
  20. document.forms[formName].elements[sb1].options[document.forms[formName].elements[sb1].options.length - 1].style.backgroundColor = "#cccccc";
  21. categoryArray[catIndex][3] = 1;
  22. }
  23. }
  24. else
  25. {
  26. if(categoryArray[catIndex][2] == 0)
  27. {
  28. document.forms[formName].elements[sb1].options[document.forms[formName].elements[sb1].options.length] = new Option(getCategoryDepth(catIndex) + categoryArray[catIndex][0],"",false,false);
  29. document.forms[formName].elements[sb1].options[document.forms[formName].elements[sb1].options.length - 1].style.backgroundColor = "#cccccc";
  30. categoryArray[catIndex][2] = 1;
  31. }
  32. }
  33. }
  34. function addArticle(artIndex)
  35. {
  36. document.forms[formName].elements[articleArray[artIndex][3]].options[document.forms[formName].elements[articleArray[artIndex][3]].options.length] = new Option(getArticleDepth(artIndex) + articleArray[artIndex][0],articleArray[artIndex][1],false,false);
  37. document.forms[formName].elements[articleArray[artIndex][3]].options[document.forms[formName].elements[articleArray[artIndex][3]].options.length - 1].style.backgroundColor = "#cccfff";
  38. }
  39. function shiftArticle(fromSelectName, toSelectName)
  40. {
  41. var tempSelected = document.forms[formName].elements[fromSelectName].selectedIndex;
  42. if(document.forms[formName].elements[fromSelectName].selectedIndex == -1)
  43. {
  44. alert('You must select an article to move!');
  45. return false;
  46. }
  47. else if(document.forms[formName].elements[fromSelectName].options[tempSelected].value == "")
  48. {
  49. alert('You must select an article to move!');
  50. return false;
  51. }
  52. else
  53. {
  54. var tempValue = document.forms[formName].elements[fromSelectName].options[tempSelected].value;
  55. var tempIDStart = tempValue.indexOf(";");
  56. var tempIDEnd = tempValue.lastIndexOf(";");
  57. var tempIndex = tempValue.substring(tempIDStart + 1, tempIDEnd);
  58. if(document.all == null)
  59. {
  60. document.forms[formName].elements[fromSelectName].options[tempSelected] = null;
  61. }
  62. else
  63. {
  64. document.forms[formName].elements[fromSelectName].options.remove(tempSelected);
  65. }
  66. articleArray[tempIndex][3] = toSelectName;
  67. clearSelectBox(toSelectName);
  68. fillSelectBox(-1,toSelectName);
  69. }
  70. if(document.forms[formName].elements[fromSelectName].selectedIndex != -1)
  71. {
  72. shiftArticle(fromSelectName, toSelectName);
  73. }
  74. else
  75. {
  76. clearSelectBox(fromSelectName);
  77. fillSelectBox(-1,fromSelectName);
  78. document.forms[formName].elements[textTrail].value = "";
  79. }
  80. }
  81. function fillSelectBox(catIndex,selectBox)
  82. {
  83. for(var i = 0; i < categoryArray.length; i++)
  84. {
  85. if(categoryArray[i][1] == catIndex)
  86. {
  87. addCategory(i,fromSelect);
  88. fillSelectBox(i,selectBox);
  89. for(j = 0; j < articleArray.length; j++)
  90. {
  91. if(articleArray[j][2] == i && (articleArray[j][3] == selectBox || selectBox == ""))
  92. {
  93. if(selectBox == "")
  94. {
  95. addCategory(i,articleArray[j][3]);
  96. }
  97. else
  98. {
  99. addCategory(i,selectBox);
  100. }
  101. addArticle(j);
  102. }
  103. }
  104. }
  105. }
  106. if(catIndex == -1)
  107. {
  108. for(x = 0; x < articleArray.length; x++)
  109. {
  110. if(articleArray[x][2] == catIndex && (articleArray[x][3] == selectBox || selectBox == ""))
  111. {
  112. addArticle(x);
  113. }
  114. }
  115. }
  116. }
  117. function getCategoryDepth(catIndex)
  118. {
  119. if(categoryArray[catIndex][1] == -1)
  120. {
  121. return "";
  122. }
  123. else
  124. {
  125. return document.forms[formName].whitespace.value + getCategoryDepth(categoryArray[catIndex][1]);
  126. }
  127. }
  128. function getArticleDepth(artIndex)
  129. {
  130. if(articleArray[artIndex][2] == -1)
  131. {
  132. return "";
  133. }
  134. else
  135. {
  136. return getCategoryDepth(articleArray[artIndex][2]) + "- ";
  137. }
  138. }
  139. function clearSelectBox(selectBox)
  140. {
  141. for(j = document.forms[formName].elements[selectBox].options.length; j >= 0; j--)
  142. {
  143. if(document.all == null)
  144. {
  145. document.forms[formName].elements[selectBox].options[j] = null;
  146. }
  147. else
  148. {
  149. document.forms[formName].elements[selectBox].options.remove(j);
  150. }
  151. }
  152. for(i = 0; i < categoryArray.length; i++)
  153. {
  154. if(selectBox == toSelect)
  155. {
  156. categoryArray[i][2] = 0;
  157. }
  158. else
  159. {
  160. categoryArray[i][3] = 0;
  161. }
  162. }
  163. }
  164. function selectBoxToString(selectBox, hiddenInput)
  165. {
  166. var tempString = "";
  167. for(j = 0; j < document.forms[formName].elements[selectBox].options.length; j++)
  168. {
  169. if(document.forms[formName].elements[selectBox].options[j].value == "")
  170. {
  171. // Skip it
  172. }
  173. else
  174. {
  175. var tempValue = document.forms[formName].elements[selectBox].options[j].value;
  176. var tempIDStart = tempValue.indexOf(";");
  177. tempString = tempString + tempValue.substring(0, tempIDStart) + ";";
  178. }
  179. }
  180. document.forms[formName].elements[hiddenInput].value = tempString;
  181. }
  182. function getCategoryTrail(catIndex)
  183. {
  184. if(categoryArray[catIndex][1] == -1)
  185. {
  186. return categoryArray[catIndex][0];
  187. }
  188. else
  189. {
  190. return getCategoryTrail(categoryArray[catIndex][1]) + " >> " + categoryArray[catIndex][0];
  191. }
  192. }
  193. function getArticleTrail(selectIndex,selectBox)
  194. {
  195. var tempValue = document.forms[formName].elements[selectBox].options[selectIndex].value;
  196. if(tempValue == "")
  197. {
  198. return "";
  199. }
  200. var tempIDStart = tempValue.indexOf(";");
  201. artIndex = tempValue.substring(tempIDStart + 1, tempValue.length - 1);
  202. if(articleArray[artIndex][2] == -1)
  203. {
  204. return articleArray[artIndex][0];
  205. }
  206. else
  207. {
  208. return getCategoryTrail(articleArray[artIndex][2]) + " >> " + articleArray[artIndex][0];
  209. }
  210. }
  211. function moveSelectDown(sb1)
  212. {
  213. var tempIndex = document.forms[formName].elements[sb1].options.selectedIndex;
  214. if(tempIndex != -1)
  215. {
  216. if(tempIndex != document.forms[formName].elements[sb1].options.length - 1)
  217. {
  218. document.forms[formName].elements[sb1].options[tempIndex].selected = false;
  219. document.forms[formName].elements[sb1].options[tempIndex + 1].selected = true;
  220. return true;
  221. }
  222. }
  223. return false;
  224. }
  225. function moveSelectUp(sb1)
  226. {
  227. var tempIndex = document.forms[formName].elements[sb1].options.selectedIndex;
  228. if(tempIndex != -1)
  229. {
  230. if(tempIndex != 0)
  231. {
  232. document.forms[formName].elements[sb1].options[tempIndex].selected = false;
  233. document.forms[formName].elements[sb1].options[tempIndex - 1].selected = true;
  234. return true;
  235. }
  236. }
  237. return false;
  238. }