Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
4.9 KiB

  1. <% ' General depository for frequently used javascript functions for our "list control" ******* %>
  2. <!--#include file="iijsls.str"-->
  3. <%
  4. ' Main listFunction object, to allow other frames to access global functions,
  5. ' and to serve as a data cache. This will be instantiated in the list script.
  6. %>
  7. function listFuncs(sortby, specSort, mainframe){
  8. //general
  9. this.sel = -1;
  10. this.lastSel = 0;
  11. this.bHasList = true;
  12. this.noupdate = false;
  13. this.sortAsc = true;
  14. //functions
  15. this.addItem=addItem;
  16. this.delItem=delItem;
  17. this.moveItem=moveItem;
  18. this.sortList = sortList;
  19. this.reSort = reSort;
  20. this.writeList=buildListForm;
  21. this.SetListVals=SetListVals;
  22. this.writeCol = writeCol;
  23. this.loadList = loadList;
  24. //specifics
  25. this.sortby = sortby;
  26. this.specSort =specSort;
  27. this.mainframe = mainframe;
  28. }
  29. <% ' ******* Sets the current selection ******* %>
  30. function setLastSel(id)
  31. {
  32. for (var i=0; i < cachedList.length; i++)
  33. {
  34. if (cachedList[i].id == id)
  35. {
  36. listFunc.sel = i;
  37. return;
  38. }
  39. }
  40. }
  41. <% ' ******* Used throughout the list "controls" to write out a table cell. ******* %>
  42. <% ' ******* a, the align parameter, is optional ******* %>
  43. function writeCol(colspan,w,str,a)
  44. {
  45. var writestr = "<TD";
  46. if (colspan != "")
  47. {
  48. writestr += " COLSPAN = " + colspan
  49. }
  50. if (w != "")
  51. {
  52. writestr += " WIDTH = " + w;
  53. }
  54. if (a != "")
  55. {
  56. writestr += " ALIGN = " + a;
  57. }
  58. writestr += "><%= sFont("","","",True) %>" + str + "</FONT></TD>";
  59. return writestr;
  60. }
  61. <% '***** This is the sortOrder function that allows heading to be sorted by string values, rather than numerically... **** %>
  62. function sortOrder(a,b)
  63. {
  64. <%
  65. ' a and b are automatically passed in by the JScript array sort function
  66. ' In this case, they are array items which contain custom objects. The
  67. ' listFunc.sortby is set in the call to sortList, which is executed when
  68. ' the user clicks a heading. The entry points are in the files labled ii*hd.asp
  69. ' (ie, iiacsshd.asp, etc.) The sortby property will contain the name of the
  70. ' property on the object to sort by, for example filename or date...
  71. 'listFunc is required in order for this to work properly...
  72. %>
  73. if (listFunc != null)
  74. {
  75. if (listFunc.specSort != "")
  76. {
  77. astr = a[listFunc.specSort] + a[listFunc.sortby];
  78. bstr = b[listFunc.specSort] + b[listFunc.sortby];
  79. }
  80. else
  81. {
  82. astr = a[listFunc.sortby];
  83. bstr = b[listFunc.sortby];
  84. }
  85. if (!isNaN(astr))
  86. {
  87. astr = astr.toString();
  88. bstr = bstr.toString();
  89. }
  90. lcastr = astr.toLowerCase();
  91. lcbstr = bstr.toLowerCase();
  92. if (lcastr < lcbstr)
  93. {
  94. retval = -1;
  95. }
  96. else
  97. {
  98. if (lcastr > lcbstr)
  99. {
  100. retval = 1;
  101. }
  102. else
  103. {
  104. retval = 0;
  105. }
  106. }
  107. if (!listFunc.sortAsc)
  108. {
  109. retval = retval * -1;
  110. }
  111. return retval;
  112. }
  113. }
  114. <% '***** Sort routine called by headings ***** %>
  115. <% '***** This requires the sortOrder function ***** %>
  116. function sortList(sortby)
  117. {
  118. if (listFunc != null)
  119. {
  120. i= listFunc.sel;
  121. if (i != -1)
  122. {
  123. lastsel = cachedList[i].id
  124. }
  125. if (sortby != listFunc.sortby)
  126. {
  127. listFunc.sortby = sortby;
  128. listFunc.sortAsc = true;
  129. }
  130. else
  131. {
  132. listFunc.sortAsc = !listFunc.sortAsc;
  133. }
  134. var num = parseFloat(cachedList[sortby]);
  135. if (isNaN(num))
  136. {
  137. cachedList.sort(sortOrder);
  138. }
  139. else
  140. {
  141. cachedList.sort(numOrder);
  142. }
  143. if (i != -1)
  144. {
  145. setLastSel(lastsel);
  146. }
  147. loadList();
  148. }
  149. }
  150. <% '**** List Resorting function *** %>
  151. function reSort()
  152. {
  153. //set our sortAsc so we aren't just reversing the list...
  154. listFunc.sortAsc = !listFunc.sortAsc;
  155. sortList(listFunc.sortby);
  156. }
  157. <% '**** List Delete function *** %>
  158. function delItem(){
  159. if (listFunc.sel >= 0)
  160. {
  161. listFunc.noupdate = true;
  162. i=eval(listFunc.sel);
  163. cachedList[i].deleted=true;
  164. cachedList[i].updated=true;
  165. i=i-1;
  166. <% 'run through the list to find the Next non-deleted item %>
  167. for (var j=i; j >=0; j--) {
  168. if (cachedList[j].deleted){
  169. }
  170. else{
  171. break
  172. }
  173. }
  174. listFunc.sel=j;
  175. loadList();
  176. }
  177. else{
  178. alert("<%= L_SELECTITEM_TEXT %>");
  179. }
  180. }
  181. <% '**** List Delete function *** %>
  182. function initParam(paramVal,defaultVal)
  183. {
  184. if (paramVal == null)
  185. {
  186. return defaultVal;
  187. }
  188. return paramVal;
  189. }
  190. function addItem()
  191. {
  192. var i=cachedList.length;
  193. listFunc.noupdate = true;
  194. cachedList[i]=new listObj(i);
  195. cachedList[i].newitem=true;
  196. cachedList[i].updated=true;
  197. listFunc.sel=i;
  198. loadList();
  199. }
  200. function moveItem(dir){
  201. sel = eval(listFunc.sel);
  202. if (sel > -1){
  203. if (!cachedList[sel].deleted){
  204. if ((sel + dir >= 0) && (sel + dir < (cachedList.length))){
  205. cachedList[sel].id += dir;
  206. cachedList[sel].updated = true;
  207. sel += dir;
  208. cachedList[sel].id -= dir;
  209. listFunc.sel = sel;
  210. cachedList.sort(sortOrder);
  211. loadList();
  212. }
  213. }
  214. }
  215. }