diff --git a/js/app/views/PlotComponents/PlotTree.js b/js/app/views/PlotComponents/PlotTree.js index 2013a81..dd86fbd 100644 --- a/js/app/views/PlotComponents/PlotTree.js +++ b/js/app/views/PlotComponents/PlotTree.js @@ -329,6 +329,104 @@ Ext.define('amdaPlotComp.PlotTree', { moveParam : function(record,targetNode,position) { + if (record.$className != 'amdaPlotObj.PlotParamTreeNode') + return false; + + var fromIndex = record.parentNode.indexOf(record); + var toIndex = targetNode.parentNode.indexOf(targetNode); + + var fromPanelObject = null; + if (!this.tabObject.get('tree-simplified-view')) + { + fromPanelObject = record.parentNode.parentNode.object; + } + else + fromPanelObject = record.parentNode.object; + if (fromPanelObject == null) + return false; + + switch (targetNode.$className) + { + case 'amdaPlotObj.PlotPanelTreeNode' : + case 'amdaPlotObj.PlotParamsTreeNode' : + var toPanelObject = targetNode.object; + if (toPanelObject.get('panel-plot-type') != fromPanelObject.get('panel-plot-type')) + return false; + if (toPanelObject == fromPanelObject) + { + //Move param on the same panel + fromPanelObject.params().data.removeAt(fromIndex); + toPanelObject.params().data.add(record.object); + this.buildPanelParamsNode(toPanelObject, record.object.get('id')); + } + else + { + //Move param on another panel + var clonedObject = record.object.copy(); + fromPanelObject.params().remove(record.object); + toPanelObject.set('last-param-id', toPanelObject.get('last-param-id')+1); + clonedObject.set('id', toPanelObject.get('last-param-id')); + toPanelObject.params().add(clonedObject); + this.buildPanelParamsNode(fromPanelObject); + this.buildPanelParamsNode(toPanelObject, clonedObject.get('id')); + } + return true; + case 'amdaPlotObj.PlotParamTreeNode' : + var toPanelObject = null; + if (!this.tabObject.get('tree-simplified-view')) + { + toPanelObject = targetNode.parentNode.parentNode.object; + } + else + toPanelObject = targetNode.parentNode.object; + targetNode.object; + if (toPanelObject.get('panel-plot-type') != fromPanelObject.get('panel-plot-type')) + return false; + + if (toPanelObject == fromPanelObject) + { + //Move param on the same panel + var insertIndex = -1; + switch (position) + { + case 'before' : + insertIndex = (fromIndex > toIndex) ? toIndex : toIndex - 1; + break; + case 'after' : + default : + insertIndex = (fromIndex > toIndex) ? toIndex + 1 : toIndex; + break; + } + fromPanelObject.params().data.removeAt(fromIndex); + toPanelObject.params().data.insert(insertIndex, record.object); + this.buildPanelParamsNode(toPanelObject, record.object.get('id')); + } + else + { + //move param on another panel + var insertIndex = -1; + switch (position) + { + case 'before' : + insertIndex = (toIndex == 0) ? 0: toIndex - 1; + break; + case 'after' : + default : + insertIndex = toIndex + 1; + break; + } + var clonedObject = record.object.copy(); + fromPanelObject.params().remove(record.object); + toPanelObject.set('last-param-id', toPanelObject.get('last-param-id')+1); + clonedObject.set('id', toPanelObject.get('last-param-id')); + toPanelObject.params().insert(insertIndex, clonedObject); + this.buildPanelParamsNode(fromPanelObject); + this.buildPanelParamsNode(toPanelObject, clonedObject.get('id')); + } + return true; + } + return false; + /*var fromIndex = targetNode.parentNode.indexOf(record); var toIndex = targetNode.parentNode.indexOf(targetNode); @@ -357,8 +455,6 @@ Ext.define('amdaPlotComp.PlotTree', { return false; }*/ - console.log('ToDo move param'); - return true; }, @@ -484,7 +580,35 @@ Ext.define('amdaPlotComp.PlotTree', { case 'amdaModel.MyDataParamNode' : return record.isLeaf(); case 'amdaPlotObj.PlotParamTreeNode' : - return true; + var fromPanelObject = null; + if (!this.tabObject.get('tree-simplified-view')) + { + fromPanelObject = record.parentNode.parentNode.object; + } + else + fromPanelObject = record.parentNode.object; + if (fromPanelObject == null) + return false; + + var toPanelObject = null; + switch (targetNode.$className) + { + case 'amdaPlotObj.PlotPanelTreeNode' : + case 'amdaPlotObj.PlotParamsTreeNode' : + toPanelObject = targetNode.object; + break; + case 'amdaPlotObj.PlotParamTreeNode' : + if (!this.tabObject.get('tree-simplified-view')) + { + toPanelObject = targetNode.parentNode.parentNode.object; + } + else + toPanelObject = targetNode.parentNode.object; + break; + } + if (toPanelObject == null) + return false; + return (fromPanelObject.get('panel-plot-type') == toPanelObject.get('panel-plot-type')); case 'amdaPlotObj.PlotPanelTreeNode' : switch (position) { -- libgit2 0.21.2