Guest User

Untitled

a guest
Jan 23rd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. <cfsetting enablecfoutputonly="true">
  2. <cfparam name="attributes.listOfIDs" default="">
  3. <cfif thisTag.ExecutionMode eq "start">
  4. <cfset variables.arPos = ArrayNew(1)>
  5. <cfloop from="1" to="#attributes.rowTotal#" index="variables.i">
  6. <cfset arrayAppend(variables.arPos,variables.i)>
  7. </cfloop>
  8. <cfset request._rowSorterOrder = 0>
  9. <cfset request._rowSorterPosSpan = "">
  10. <cfsavecontent variable="variables.forHead">
  11. <cfoutput><script language="JavaScript" type="text/javascript">
  12. jQuery(
  13. function() {
  14. <cfset count = 1>
  15. <cfloop list="#attributes.listOfIds#" delimiters="," index="id">
  16. addIDtoArPos('#id#');
  17. </cfloop>
  18.  
  19. }
  20. );
  21. function addIDtoArPos(newID) {
  22. /* I insert a newID into the arPos and return the new ID */
  23. var addOn = new Number(0);
  24. //addDebug(' New');
  25. for (var i in arPos) {
  26. if (arPos.hasOwnProperty(i)) {
  27. var rootID = arPos[i].substr(0,32);
  28. //addDebug(rootID + ' : rootID: <br>' + newID + ' newID: ' );
  29. if (rootID == newID) {
  30. addOn += 1;
  31. }
  32. }
  33. }
  34. console.log(newID);
  35. console.log(addOn);
  36. var addID = newID + '-' + addOn;
  37. arPos[arPos.length] = addID;
  38. document.getElementById('rowSorterIDs').value = arPos.toString();
  39. return addID;
  40. }
  41.  
  42. arPos = [];
  43.  
  44.  
  45. function getArrayPos(ITEM) {
  46. var ret = -1;
  47. for (var i in arPos) {
  48. if (arPos[i] == ITEM){
  49. ret = new Number(i);
  50. break;
  51. }
  52. }
  53. return ret;
  54. }
  55. function existsInArPos(ID) {
  56. for (var i in arPos) {
  57. if (arPos.hasOwnProperty(i)) {
  58. var rootID = arPos[i].substr(0,32);
  59. if (rootID == ID) {
  60. return true;
  61. }
  62. }
  63. }
  64. return false;
  65. }
  66.  
  67. function move(mainMover,direction) {
  68. topRowSorterDiv = document.getElementById('rowSorterDiv');
  69. currentPos = getArrayPos(mainMover);
  70. if ((direction == "up" && currentPos == 0) ||
  71. (direction == "down" && currentPos == (arPos.lenght-1))) {
  72. //clicking on an invisible up or down arrow in top or bottom position...just return
  73. return;
  74. }
  75. if (currentPos >= 0){
  76. //lets find the position of the secondary mover
  77. if (direction == "up") {
  78. var secPos = currentPos-1; //want the previous item in the array
  79. } else {
  80. var secPos = currentPos+1; //want the next item in the array
  81. }
  82. secMover = arPos[secPos]; //secondary mover
  83.  
  84. /*var currentMainDoc = document.getElementById('rowHasID_'+mainMover).value;
  85. var currentSecDoc = document.getElementById('rowHasID_'+secMover).value;
  86. //alert('mainMover: ' + mainMover + ' ' + currentMainDoc + '\n' + 'secMover: ' + secMover + ' ' + currentSecDoc);
  87. //now set them
  88. document.getElementById('rowHasID_'+mainMover).value = currentSecDoc;
  89. document.getElementById('rowHasID_'+secMover).value = currentMainDoc;*/
  90.  
  91. node1 = document.getElementById(mainMover);
  92. node2 = document.getElementById(secMover);
  93. //switch them around
  94. if (direction == "up") {
  95. //then we want node 1 before node 2
  96. topRowSorterDiv.insertBefore(node1, node2);
  97. var upModuleID = node1.id;
  98. var downModuleID = node2.id;
  99. } else {
  100. topRowSorterDiv.insertBefore(node2, node1);
  101. var upModuleID = node2.id;
  102. var downModuleID = node1.id;
  103. }
  104. //opacity(mainMover,60,100,500)
  105. setBG('Orange',mainMover);
  106. setTimeout("setBG('##fff','"+mainMover+"')",500);
  107. //set array to new positions
  108. arPos[secPos] = mainMover;
  109. arPos[currentPos] = secMover;
  110. //update display counter and form fields
  111. var mainOrder = getArrayPos(mainMover)+1;
  112. var secOrder = getArrayPos(secMover)+1;
  113. document.getElementById('pos'+mainMover).innerHTML = mainOrder;
  114. document.getElementById('pos'+secMover).innerHTML = secOrder;
  115. document.getElementById('orderForID_'+mainMover).value = mainOrder;
  116. document.getElementById('orderForID_'+secMover).value = secOrder;
  117. navCleanUp();
  118. }
  119. }
  120. function remove(divID) {
  121. var d = document.getElementById('rowSorterDiv');
  122. var olddiv = document.getElementById(divID);
  123. d.removeChild(olddiv);
  124. //now remove it from the array
  125. var newPos = new Array();
  126. var count = 0;
  127. for (var i in arPos) {
  128. if (arPos.hasOwnProperty(i)) {
  129. if (arPos[i] != divID) {
  130. newPos[count] = arPos[i];
  131. count++;
  132. }
  133. }
  134. }
  135. arPos = newPos;
  136. document.getElementById('rowSorterIDs').value = arPos.toString();
  137. navCleanUp();
  138. sumPages(); setPositionRules(); <!--- TODO: Uncouple this --->
  139. setOrder();
  140. }
  141. function setOrder() {
  142. var d = document.getElementById('rowSorterDiv');
  143. var chLen =d.childNodes.length;
  144. var counter = new Number(0);
  145. for (var i = 0; i < chLen; i++) {
  146. if (d.childNodes[i].id && d.childNodes[i].className){
  147. counter += 1;
  148. document.getElementById('pos'+d.childNodes[i].id).innerHTML = counter;
  149. document.getElementById('orderForID_'+d.childNodes[i].id).value = counter;
  150. }
  151. }
  152. }
  153. function setBG(BG,ID) {
  154. document.getElementById(ID).style.backgroundColor = BG;
  155. }
  156. function setMessage(BG,TEXT) {
  157. //document.getElementById('message').style.backgroundColor = BG;
  158. //document.getElementById('message').innerHTML = TEXT;
  159. }
  160. function navCleanUp() {
  161. <!--- hide display for the top mod up button and bottom mod down button --->
  162. //ColdFusion.Log.dump(arPos);
  163. if (arPos.length == 1) {
  164. document.getElementById(arPos[0]+'-up').innerHTML = '<img src="images/dot_white.jpg" width="20" height="20">';
  165. document.getElementById(arPos[arPos.length-1] + '-down').innerHTML = '<img src="images/dot_white.jpg" width="20" height="20">';
  166. } else if (arPos.length > 1) {
  167. document.getElementById(arPos[0]+'-up').innerHTML = '<img src="images/dot_white.jpg" width="20" height="20">';
  168. document.getElementById(arPos[1]+'-up').innerHTML = '&nbsp;';
  169. if (arPos.length == 1) {
  170. <!--- then the top position (0) has to show a down arrow --->
  171. document.getElementById(arPos[0] + '-down').innerHTML = '&nbsp;';
  172. } else {
  173. ColdFusion.Log.info(arPos.length);
  174. document.getElementById(arPos[arPos.length-1] + '-down').innerHTML = '<img src="images/dot_white.jpg" width="20" height="20">';
  175. document.getElementById(arPos[arPos.length-2] + '-down').innerHTML = '&nbsp;';
  176. }
  177. }
  178. }
  179. </script>
  180. </cfoutput>
  181. </cfsavecontent>
  182. <cfhtmlhead text="#variables.forHead#">
  183. <cfoutput>
  184. <input type="hidden" name="rowSorterIDs" id="rowSorterIDs" value="#attributes.listOfIDs#">
  185. <div id="rowSorterDiv">
  186. </cfoutput>
  187. <cfelse>
  188. <cfoutput></div>
  189. <span id="rowSorterPosSpan">#request._rowSorterPosSpan#</span>
  190. <script type="text/javascript">navCleanUp()</script>
  191. </cfoutput>
  192. <cfset structDelete(request,"_rowSorterOrder")>
  193. <cfset structDelete(request,"_rowSorterPosSpan")>
  194. </cfif>
Add Comment
Please, Sign In to add comment