# HG changeset patch # User Nicholas Jillings # Date 1464348737 -3600 # Node ID 02d5d22d70186cde995f66e7481365ed5b779e99 # Parent 3013cf94571676a4e8bf36258b227dfbbd04cf4f #79: Can re-order the survey Elements diff -r 3013cf945716 -r 02d5d22d7018 test_create/test_core.js --- a/test_create/test_core.js Fri May 27 12:16:42 2016 +0100 +++ b/test_create/test_core.js Fri May 27 12:32:17 2016 +0100 @@ -1969,8 +1969,46 @@ this.parent.specification.options.push(obj.specification); this.parent.childrenDOM.appendChild(obj.rootDOM); } - + this.parent.children.forEach(function(obj,index){ + obj.moveButtons.disable(index); + }); } + + this.moveButtons = { + root_up: document.createElement("button"), + root_down: document.createElement("button"), + parent: this, + handleEvent: function(event) { + var index = this.parent.parent.children.indexOf(this.parent); + if (event.currentTarget.getAttribute("direction") == "up") { + index = Math.max(index-1,0); + } else if (event.currentTarget.getAttribute("direction") == "down") { + index = Math.min(index+1,this.parent.parent.children.length-1); + } + this.parent.moveToPosition(index); + this.disable(index); + }, + disable: function(index) { + if (index == 0) { + this.root_up.disabled = true; + } else { + this.root_up.disabled = false; + } + if (index == this.parent.parent.children.length-1) { + this.root_down.disabled = true; + } else { + this.root_down.disabled = false; + } + } + } + this.moveButtons.root_up.setAttribute("direction","up"); + this.moveButtons.root_down.setAttribute("direction","down"); + this.moveButtons.root_up.addEventListener("click",this.moveButtons,false); + this.moveButtons.root_down.addEventListener("click",this.moveButtons,false); + this.moveButtons.root_up.textContent = "Move Up"; + this.moveButtons.root_down.textContent = "Move Down"; + this.buttonDOM.appendChild(this.moveButtons.root_up); + this.buttonDOM.appendChild(this.moveButtons.root_down); } this.addNode = { root: document.createElement("button"), @@ -1994,6 +2032,10 @@ this.children.push(newNode); this.childrenDOM.appendChild(newNode.rootDOM); } + + this.children.forEach(function(obj,index){ + obj.moveButtons.disable(index); + }); } this.pageNode = function(parent,rootObject)