PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/iic_db/808/Tpl/default/Public/Js/Form/SortSelect.js

http://iiccms.googlecode.com/
JavaScript | 314 lines | 204 code | 26 blank | 84 comment | 19 complexity | 8c0460ff44648fcf107a1511f5dd5cca MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. // +---------------------------------------------------------------------------+
  2. // | FCS -- Fast,Compatible & Simple OOP PHP Framework |
  3. // | FCS JS ??? |
  4. // +---------------------------------------------------------------------------+
  5. // | Copyright (c) 2005-2006 liu21st.com. All rights reserved. |
  6. // | Website: http://www.fcs.org.cn/ |
  7. // | Author : Liu21st ?? <liu21st@gmail.com> |
  8. // +---------------------------------------------------------------------------+
  9. // | This program is free software; you can redistribute it and/or modify it |
  10. // | under the terms of the GNU General Public License as published by the |
  11. // | Free Software Foundation; either version 2 of the License, or (at your |
  12. // | option) any later version. |
  13. // | |
  14. // | This program is distributed in the hope that it will be useful, but |
  15. // | WITHOUT ANY WARRANTY; without even the implied warranty of |
  16. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
  17. // | Public License for more details. |
  18. // +---------------------------------------------------------------------------+
  19. /**
  20. +------------------------------------------------------------------------------
  21. * ???????
  22. +------------------------------------------------------------------------------
  23. * @package Form
  24. * @link http://www.fcs.org.cn
  25. * @copyright Copyright (c) 2005-2006 liu21st.com. All rights reserved.
  26. * @author liu21st <liu21st@gmail.com>
  27. * @version $Id$
  28. +------------------------------------------------------------------------------
  29. */
  30. /*????
  31. +--------------------------------------------------------
  32. ??????????
  33. <script language="JavaScript" src="SortSelect.js"></script>
  34. <FORM METHOD=POST name = 'form1' ACTION="">
  35. <input name="search" type="text"><INPUT TYPE="button" onClick="sl.Search()" value="? ?" >
  36. <SELECT name="sort" size="12">
  37. <option value=1>1.name1</option>
  38. <option value=2>2.name2</option>
  39. <option value=3>3.name3</option>
  40. </SELECT>
  41. <INPUT TYPE="button" onClick="sl.fnFirst()" value="??" >
  42. <INPUT TYPE="button" onClick="sl.sortUp()" value="??" >
  43. <INPUT TYPE="button" onClick="sl.sortDown()" value="??" >
  44. <INPUT TYPE="button" onClick="sl.fnEnd()" value="??" >
  45. <INPUT TYPE="text" NAME="jumpNum" size="5">
  46. <INPUT TYPE="button" onClick="sl.jump()" value="??" >
  47. <INPUT TYPE="hidden" name="seqNoList">
  48. <INPUT TYPE="button" onClick="sl.ok()" value="??">
  49. </FORM>
  50. <SCRIPT LANGUAGE="JavaScript">
  51. <!--
  52. var sl = new SortList('form1','sort','search','jumpNum');
  53. //-->
  54. </SCRIPT>
  55. ???????????seqNoList?????
  56. ??:??,??:??
  57. +--------------------------------------------------------
  58. */
  59. function SortSelect(formName,sortPan,searchName,jumpNum){
  60. //????
  61. this.FormObj = document.getElementsByName(formName)[0];
  62. this.sortPan = document.getElementsByName(sortPan)[0];
  63. this.searchObj = document.getElementsByName(searchName)[0];
  64. this.jumpNum = document.getElementsByName(jumpNum)[0];
  65. //+--------------------------------------------------------
  66. //| ???????
  67. //+--------------------------------------------------------
  68. this.Search = function(){
  69. var length = this.sortPan.options.length;
  70. for (i =0 ;i<length; i++){
  71. if (this.sortPan.options[i].text.indexOf(this.searchObj.value)!=-1)
  72. {
  73. this.sortPan.item(i).selected = true;
  74. break;
  75. }
  76. }
  77. }
  78. //+--------------------------------------------------------
  79. //| ?????
  80. //+--------------------------------------------------------
  81. this.jump = function (){
  82. var n= this.jumpNum.value;
  83. var iIndex = this.sortPan.selectedIndex;
  84. var i= n-1;
  85. if( i == iIndex) return;
  86. if (i<iIndex)
  87. {
  88. for (k=0;k<iIndex-i;k++) this.sortUp();
  89. }
  90. else
  91. {
  92. for (k=0;k<i-iIndex;k++) this.sortDown();
  93. }
  94. }
  95. //+--------------------------------------------------------
  96. //| ???????
  97. //+--------------------------------------------------------
  98. this.sortUp = function ()
  99. {
  100. try
  101. {
  102. var iIndex = this.sortPan.selectedIndex;
  103. if(iIndex == 0)
  104. {
  105. return;
  106. }
  107. var curName = this.sortPan.item(iIndex).text;
  108. var ilength,iplace
  109. ilength=curName.length;
  110. iplace=curName.indexOf(".");
  111. var strNameState,strNameSpace
  112. strNameState=curName.substr(iplace+1,ilength)
  113. strNameSpace=curName.substr(0,iplace+1)
  114. var strNameStateMiddle
  115. strNameStateMiddle=strNameState
  116. var curName1 = this.sortPan.item(iIndex-1).text;
  117. var ilength1,iplace1
  118. ilength1=curName1.length;
  119. iplace1=curName1.indexOf(".");
  120. var strNameState1,strNameSpace1
  121. strNameState1=curName1.substr(iplace1+1,ilength1)
  122. strNameSpace1=curName1.substr(0,iplace1+1)
  123. strNameState=strNameState1
  124. strNameState1=strNameStateMiddle
  125. this.sortPan.item(iIndex).text =strNameSpace+strNameState
  126. this.sortPan.item(parseInt(iIndex) - 1).text=strNameSpace1+strNameState1
  127. var curValue = this.sortPan.item(iIndex).value;
  128. this.sortPan.item(iIndex).value = this.sortPan.item(parseInt(iIndex) - 1).value;
  129. this.sortPan.item(parseInt(iIndex)-1).value = curValue;
  130. this.sortPan.item(parseInt(iIndex)-1).selected = true;
  131. }
  132. catch(e)
  133. {
  134. return;
  135. }
  136. }
  137. //+--------------------------------------------------------
  138. //| ?????????
  139. //+--------------------------------------------------------
  140. this.fnFirst = function ()
  141. {
  142. try
  143. {
  144. var iIndex = this.sortPan.selectedIndex;
  145. if(iIndex == 0)
  146. {
  147. return;
  148. }
  149. while (iIndex>0)
  150. {
  151. var curName = this.sortPan.item(iIndex).text;
  152. var ilength,iplace
  153. ilength=curName.length;
  154. iplace=curName.indexOf(".");
  155. var strNameState,strNameSpace
  156. strNameState=curName.substr(iplace+1,ilength)
  157. strNameSpace=curName.substr(0,iplace+1)
  158. var strNameStateMiddle
  159. strNameStateMiddle=strNameState
  160. var curName1 = this.sortPan.item(iIndex-1).text;
  161. var ilength1,iplace1
  162. ilength1=curName1.length;
  163. iplace1=curName1.indexOf(".");
  164. var strNameState1,strNameSpace1
  165. strNameState1=curName1.substr(iplace1+1,ilength1)
  166. strNameSpace1=curName1.substr(0,iplace1+1)
  167. strNameState=strNameState1
  168. strNameState1=strNameStateMiddle
  169. this.sortPan.item(iIndex).text =strNameSpace+strNameState
  170. this.sortPan.item(parseInt(iIndex) - 1).text=strNameSpace1+strNameState1
  171. var curValue = this.sortPan.item(iIndex).value;
  172. this.sortPan.item(iIndex).value = this.sortPan.item(parseInt(iIndex) - 1).value;
  173. this.sortPan.item(parseInt(iIndex)-1).value = curValue;
  174. this.sortPan.item(parseInt(iIndex)-1).selected = true;
  175. iIndex=iIndex-1
  176. }
  177. }
  178. catch(e)
  179. {
  180. return;
  181. }
  182. }
  183. //+--------------------------------------------------------
  184. //| ???????
  185. //+--------------------------------------------------------
  186. this.sortDown = function ()
  187. {
  188. try
  189. {
  190. var iIndex = this.sortPan.selectedIndex;
  191. if(iIndex == this.sortPan.length - 1)
  192. {
  193. return;
  194. }
  195. var curName = this.sortPan.item(iIndex).text;
  196. var ilength,iplace
  197. ilength=curName.length;
  198. iplace=curName.indexOf(".");
  199. var strNameState,strNameSpace
  200. strNameState=curName.substr(iplace+1,ilength)
  201. strNameSpace=curName.substr(0,iplace+1)
  202. var strNameStateMiddle
  203. strNameStateMiddle=strNameState
  204. var curName1 = this.sortPan.item(iIndex+1).text;
  205. var ilength1,iplace1
  206. ilength1=curName1.length;
  207. iplace1=curName1.indexOf(".");
  208. var strNameState1,strNameSpace1
  209. strNameState1=curName1.substr(iplace1+1,ilength1)
  210. strNameSpace1=curName1.substr(0,iplace1+1)
  211. strNameState=strNameState1
  212. strNameState1=strNameStateMiddle
  213. this.sortPan.item(iIndex).text =strNameSpace+strNameState
  214. this.sortPan.item(parseInt(iIndex) + 1).text=strNameSpace1+strNameState1
  215. var curValue = this.sortPan.item(iIndex).value;
  216. this.sortPan.item(iIndex).value = this.sortPan.item(parseInt(iIndex) + 1).value;
  217. this.sortPan.item(parseInt(iIndex)+1).value = curValue;
  218. this.sortPan.item(parseInt(iIndex) + 1).selected = true;
  219. }
  220. catch(e)
  221. {
  222. return;
  223. }
  224. }
  225. //+--------------------------------------------------------
  226. //| ????????
  227. //+--------------------------------------------------------
  228. this.fnEnd = function ()
  229. {
  230. try
  231. {
  232. var iIndex = this.sortPan.selectedIndex;
  233. if(iIndex == this.sortPan.length - 1)
  234. {
  235. return;
  236. }
  237. while (iIndex<(this.sortPan.length - 1))
  238. {
  239. var curName = this.sortPan.item(iIndex).text;
  240. var ilength,iplace
  241. ilength=curName.length;
  242. iplace=curName.indexOf(".");
  243. var strNameState,strNameSpace
  244. strNameState=curName.substr(iplace+1,ilength)
  245. strNameSpace=curName.substr(0,iplace+1)
  246. var strNameStateMiddle
  247. strNameStateMiddle=strNameState
  248. var curName1 = this.sortPan.item(iIndex+1).text;
  249. var ilength1,iplace1
  250. ilength1=curName1.length;
  251. iplace1=curName1.indexOf(".");
  252. var strNameState1,strNameSpace1
  253. strNameState1=curName1.substr(iplace1+1,ilength1)
  254. strNameSpace1=curName1.substr(0,iplace1+1)
  255. strNameState=strNameState1
  256. strNameState1=strNameStateMiddle
  257. this.sortPan.item(iIndex).text =strNameSpace+strNameState
  258. this.sortPan.item(parseInt(iIndex) + 1).text=strNameSpace1+strNameState1
  259. var curValue = this.sortPan.item(iIndex).value;
  260. this.sortPan.item(iIndex).value = this.sortPan.item(parseInt(iIndex) + 1).value;
  261. this.sortPan.item(parseInt(iIndex)+1).value = curValue;
  262. this.sortPan.item(parseInt(iIndex) + 1).selected = true;
  263. iIndex=iIndex+1
  264. }
  265. }
  266. catch(e)
  267. {
  268. return;
  269. }
  270. }
  271. //+--------------------------------------------------------
  272. //| ???????
  273. //+--------------------------------------------------------
  274. this.ok = function ()
  275. {
  276. var str='';
  277. var iplace;
  278. for (i = 0; i <= this.sortPan.options.length-1; i++) {
  279. iplace = this.sortPan.options[i].text.indexOf(".");
  280. str += this.sortPan.options[i].value + ":" + this.sortPan.options[i].text.substr(0,iplace) + ",";
  281. }
  282. this.FormObj.seqNoList.value = str.substr(0,str.length-1);
  283. }
  284. //+--------------------------------------------------------
  285. //| ??
  286. //+--------------------------------------------------------
  287. }