Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cfsetting enablecfoutputonly="true">
- <cfparam name="attributes.listOfIDs" default="">
- <cfif thisTag.ExecutionMode eq "start">
- <cfset variables.arPos = ArrayNew(1)>
- <cfloop from="1" to="#attributes.rowTotal#" index="variables.i">
- <cfset arrayAppend(variables.arPos,variables.i)>
- </cfloop>
- <cfset request._rowSorterOrder = 0>
- <cfset request._rowSorterPosSpan = "">
- <cfsavecontent variable="variables.forHead">
- <cfoutput><script language="JavaScript" type="text/javascript">
- jQuery(
- function() {
- <cfset count = 1>
- <cfloop list="#attributes.listOfIds#" delimiters="," index="id">
- addIDtoArPos('#id#');
- </cfloop>
- }
- );
- function addIDtoArPos(newID) {
- /* I insert a newID into the arPos and return the new ID */
- var addOn = new Number(0);
- //addDebug(' New');
- for (var i in arPos) {
- if (arPos.hasOwnProperty(i)) {
- var rootID = arPos[i].substr(0,32);
- //addDebug(rootID + ' : rootID: <br>' + newID + ' newID: ' );
- if (rootID == newID) {
- addOn += 1;
- }
- }
- }
- console.log(newID);
- console.log(addOn);
- var addID = newID + '-' + addOn;
- arPos[arPos.length] = addID;
- document.getElementById('rowSorterIDs').value = arPos.toString();
- return addID;
- }
- arPos = [];
- function getArrayPos(ITEM) {
- var ret = -1;
- for (var i in arPos) {
- if (arPos[i] == ITEM){
- ret = new Number(i);
- break;
- }
- }
- return ret;
- }
- function existsInArPos(ID) {
- for (var i in arPos) {
- if (arPos.hasOwnProperty(i)) {
- var rootID = arPos[i].substr(0,32);
- if (rootID == ID) {
- return true;
- }
- }
- }
- return false;
- }
- function move(mainMover,direction) {
- topRowSorterDiv = document.getElementById('rowSorterDiv');
- currentPos = getArrayPos(mainMover);
- if ((direction == "up" && currentPos == 0) ||
- (direction == "down" && currentPos == (arPos.lenght-1))) {
- //clicking on an invisible up or down arrow in top or bottom position...just return
- return;
- }
- if (currentPos >= 0){
- //lets find the position of the secondary mover
- if (direction == "up") {
- var secPos = currentPos-1; //want the previous item in the array
- } else {
- var secPos = currentPos+1; //want the next item in the array
- }
- secMover = arPos[secPos]; //secondary mover
- /*var currentMainDoc = document.getElementById('rowHasID_'+mainMover).value;
- var currentSecDoc = document.getElementById('rowHasID_'+secMover).value;
- //alert('mainMover: ' + mainMover + ' ' + currentMainDoc + '\n' + 'secMover: ' + secMover + ' ' + currentSecDoc);
- //now set them
- document.getElementById('rowHasID_'+mainMover).value = currentSecDoc;
- document.getElementById('rowHasID_'+secMover).value = currentMainDoc;*/
- node1 = document.getElementById(mainMover);
- node2 = document.getElementById(secMover);
- //switch them around
- if (direction == "up") {
- //then we want node 1 before node 2
- topRowSorterDiv.insertBefore(node1, node2);
- var upModuleID = node1.id;
- var downModuleID = node2.id;
- } else {
- topRowSorterDiv.insertBefore(node2, node1);
- var upModuleID = node2.id;
- var downModuleID = node1.id;
- }
- //opacity(mainMover,60,100,500)
- setBG('Orange',mainMover);
- setTimeout("setBG('##fff','"+mainMover+"')",500);
- //set array to new positions
- arPos[secPos] = mainMover;
- arPos[currentPos] = secMover;
- //update display counter and form fields
- var mainOrder = getArrayPos(mainMover)+1;
- var secOrder = getArrayPos(secMover)+1;
- document.getElementById('pos'+mainMover).innerHTML = mainOrder;
- document.getElementById('pos'+secMover).innerHTML = secOrder;
- document.getElementById('orderForID_'+mainMover).value = mainOrder;
- document.getElementById('orderForID_'+secMover).value = secOrder;
- navCleanUp();
- }
- }
- function remove(divID) {
- var d = document.getElementById('rowSorterDiv');
- var olddiv = document.getElementById(divID);
- d.removeChild(olddiv);
- //now remove it from the array
- var newPos = new Array();
- var count = 0;
- for (var i in arPos) {
- if (arPos.hasOwnProperty(i)) {
- if (arPos[i] != divID) {
- newPos[count] = arPos[i];
- count++;
- }
- }
- }
- arPos = newPos;
- document.getElementById('rowSorterIDs').value = arPos.toString();
- navCleanUp();
- sumPages(); setPositionRules(); <!--- TODO: Uncouple this --->
- setOrder();
- }
- function setOrder() {
- var d = document.getElementById('rowSorterDiv');
- var chLen =d.childNodes.length;
- var counter = new Number(0);
- for (var i = 0; i < chLen; i++) {
- if (d.childNodes[i].id && d.childNodes[i].className){
- counter += 1;
- document.getElementById('pos'+d.childNodes[i].id).innerHTML = counter;
- document.getElementById('orderForID_'+d.childNodes[i].id).value = counter;
- }
- }
- }
- function setBG(BG,ID) {
- document.getElementById(ID).style.backgroundColor = BG;
- }
- function setMessage(BG,TEXT) {
- //document.getElementById('message').style.backgroundColor = BG;
- //document.getElementById('message').innerHTML = TEXT;
- }
- function navCleanUp() {
- <!--- hide display for the top mod up button and bottom mod down button --->
- //ColdFusion.Log.dump(arPos);
- if (arPos.length == 1) {
- document.getElementById(arPos[0]+'-up').innerHTML = '<img src="images/dot_white.jpg" width="20" height="20">';
- document.getElementById(arPos[arPos.length-1] + '-down').innerHTML = '<img src="images/dot_white.jpg" width="20" height="20">';
- } else if (arPos.length > 1) {
- document.getElementById(arPos[0]+'-up').innerHTML = '<img src="images/dot_white.jpg" width="20" height="20">';
- document.getElementById(arPos[1]+'-up').innerHTML = ' ';
- if (arPos.length == 1) {
- <!--- then the top position (0) has to show a down arrow --->
- document.getElementById(arPos[0] + '-down').innerHTML = ' ';
- } else {
- ColdFusion.Log.info(arPos.length);
- document.getElementById(arPos[arPos.length-1] + '-down').innerHTML = '<img src="images/dot_white.jpg" width="20" height="20">';
- document.getElementById(arPos[arPos.length-2] + '-down').innerHTML = ' ';
- }
- }
- }
- </script>
- </cfoutput>
- </cfsavecontent>
- <cfhtmlhead text="#variables.forHead#">
- <cfoutput>
- <input type="hidden" name="rowSorterIDs" id="rowSorterIDs" value="#attributes.listOfIDs#">
- <div id="rowSorterDiv">
- </cfoutput>
- <cfelse>
- <cfoutput></div>
- <span id="rowSorterPosSpan">#request._rowSorterPosSpan#</span>
- <script type="text/javascript">navCleanUp()</script>
- </cfoutput>
- <cfset structDelete(request,"_rowSorterOrder")>
- <cfset structDelete(request,"_rowSorterPosSpan")>
- </cfif>
Add Comment
Please, Sign In to add comment