# HG changeset patch # User Nicholas Jillings # Date 1464344962 -3600 # Node ID fe81bbb074ad3638abf728b9b4bbfd7c86c36af8 # Parent 36934565bf6e8a082a3aab3b7ae0e5c13cd5cf5c #79: Each surveyEntryNode has a moveTo(index) function which will move the entry to the new position diff -r 36934565bf6e -r fe81bbb074ad test_create/test_core.js --- a/test_create/test_core.js Fri May 27 11:07:07 2016 +0100 +++ b/test_create/test_core.js Fri May 27 11:29:22 2016 +0100 @@ -1947,19 +1947,29 @@ this.deleteNode.root.addEventListener("click",this.deleteNode,false); this.buttonDOM.appendChild(this.deleteNode.root); - this.getSurveyPosition = function() { - return this.parent.specification.options.findIndex(function(element){ - if (element == this) {return true;} - else {return false;} - },this.specification); - } - - this.swapOrder = function(other) { - // Enables two nodes to swap their respective positions - var other_pos = other.getSurveyPosition(); - var my_pos = this.getSurveyPosition(); - this.parent.specification.options[other_pos] = this.specification; - this.parent.specification.options[my_pos] = other.specification; + this.moveToPosition = function(new_index){ + new_index = Math.min(new_index,this.parent.children.length); + var curr_index = this.parent.children.findIndex(function(elem){ + if (elem == this) {return true;} else {return false;} + },this); + // Split at the current location to remove the node and shift all the children up + var tail = this.parent.children.splice(curr_index+1); + this.parent.children.pop(); + this.parent.children = this.parent.children.concat(tail); + + //Split at the new location and insert the node + tail = this.parent.children.splice(new_index); + this.parent.children.push(this); + this.parent.children = this.parent.children.concat(tail); + + // Re-build the specification + this.parent.specification.options = []; + this.parent.childrenDOM.innerHTML = ""; + for (var obj of this.parent.children) { + this.parent.specification.options.push(obj.specification); + this.parent.childrenDOM.appendChild(obj.rootDOM); + } + } } this.addNode = {