Commit d794a307c8262ffd1f8518b96d328e484e55bfa9
1 parent
b9c5d84e
Exists in
master
and in
95 other branches
Fix bug when a plot rquest is overwriten
Showing
3 changed files
with
73 additions
and
13 deletions
Show diff stats
js/app/models/PlotObjects/MultiplotRequestObject.js
... | ... | @@ -67,6 +67,25 @@ Ext.define('amdaPlotObj.MultiplotRequestObject', { |
67 | 67 | return newPlotNode; |
68 | 68 | }, |
69 | 69 | |
70 | + overwritePlot: function(plotNode, targetPlotNode) { | |
71 | + var targetIndex = -1; | |
72 | + this.plots().each(function(node, index) { | |
73 | + if (node == targetPlotNode) { | |
74 | + targetIndex = index; | |
75 | + } | |
76 | + }); | |
77 | + if (targetIndex < 0) { | |
78 | + //Target not exists in multiplot node => add it | |
79 | + this.plots().add(targetPlotNode); | |
80 | + targetIndex = this.plots().count() - 1; | |
81 | + } | |
82 | + var data = plotNode.get('object').getJsonValues(); | |
83 | + data.id = targetPlotNode.get('id'); | |
84 | + targetPlotNode.set('object', Ext.create('amdaPlotObj.PlotRequestObject', data)); | |
85 | + plotNode.get('object').reject(); | |
86 | + return targetPlotNode; | |
87 | + }, | |
88 | + | |
70 | 89 | createNewPlotFromObject: function(plotObject) { |
71 | 90 | var plotNode = Ext.create('amdaModel.PlotNode', { |
72 | 91 | leaf : true |
... | ... |
js/app/views/PlotComponents/PlotTabContent.js
... | ... | @@ -112,27 +112,40 @@ Ext.define('amdaPlotComp.PlotTabContent', { |
112 | 112 | }); |
113 | 113 | }, |
114 | 114 | |
115 | - saveProcess : function(toRename) { | |
115 | + saveProcess : function(overwriteExistingNode) { | |
116 | + var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id); | |
117 | + if (!plotModule) | |
118 | + return; | |
119 | + | |
116 | 120 | var me = this; |
117 | - if (toRename) { | |
121 | + if (overwriteExistingNode) { | |
118 | 122 | this.updateTimeObject(); |
119 | - this.plotNode.update({plot: true, callback: function() { | |
120 | - me.setPlotNode(me.plotNode); //to update initial request data | |
121 | - me.plotTabPanel.updatePlotTabs(); | |
122 | - }}); | |
123 | + amdaModel.InteractiveNode.preloadNodes(this.plotNode.getRootNode(), function () { | |
124 | + var targetPlotNode = me.plotNode.getRootNode().findChild('text', me.plotNode.get('object').get('name'), true); | |
125 | + if (!targetPlotNode) { | |
126 | + myDesktopApp.errorMsg('Cannot retrieve request node'); | |
127 | + return; | |
128 | + } | |
129 | + targetPlotNode = plotModule.linkedNode.get('object').overwritePlot(me.plotNode, targetPlotNode); | |
130 | + if (targetPlotNode) { | |
131 | + //Reject modifications in old plot node | |
132 | + me.resetModif(); | |
133 | + targetPlotNode.update({plot: true, callback: function() { | |
134 | + me.setPlotNode(targetPlotNode); | |
135 | + me.plotTabPanel.updatePlotTabs(); | |
136 | + me.updateUI(); | |
137 | + }}); | |
138 | + } | |
139 | + }); | |
123 | 140 | } |
124 | 141 | else { |
125 | 142 | if (this.plotNode.get('object').get('id') != '') { |
126 | 143 | //Duplicate request |
127 | - var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id); | |
128 | - if (!plotModule) | |
129 | - return; | |
130 | - var newPlotNode = plotModule.linkedNode.get('object').duplicatePlot(this.plotNode); | |
144 | + var newPlotNode = this.plotTabPanel.duplicatePlotNode(this.plotNode); | |
131 | 145 | if (newPlotNode) { |
132 | 146 | //Reject modifications in old plot node |
133 | - this.plotNode.reject(); | |
134 | - this.plotNode.set('object', Ext.create('amdaPlotObj.PlotRequestObject', this.initialObjectData)); | |
135 | - //Set new plot node | |
147 | + this.resetModif(); | |
148 | + //Set new plot node to the current tab | |
136 | 149 | this.setPlotNode(newPlotNode); |
137 | 150 | } |
138 | 151 | } |
... | ... | @@ -146,6 +159,10 @@ Ext.define('amdaPlotComp.PlotTabContent', { |
146 | 159 | } |
147 | 160 | }, |
148 | 161 | |
162 | + resetModif : function() { | |
163 | + this.plotNode.set('object', Ext.create('amdaPlotObj.PlotRequestObject', this.initialObjectData)); | |
164 | + }, | |
165 | + | |
149 | 166 | getDataProcess : function() { |
150 | 167 | var downObject = amdaModel.DownloadNode.decodeObject(this.plotNode.get('object')); |
151 | 168 | amdaModel.DownloadNode.set('object',Ext.create('amdaModel.Download',downObject)); |
... | ... |
js/app/views/PlotComponents/PlotTabPanel.js
... | ... | @@ -88,10 +88,14 @@ Ext.define('amdaPlotComp.PlotTabPanel', { |
88 | 88 | }, |
89 | 89 | close: function( tab, eOpts ) { |
90 | 90 | if (tab.items.getAt(0).plotNode) { |
91 | + tab.items.getAt(0).resetModif(); | |
91 | 92 | this.multiplot_object.removePlotByInternalId(tab.items.getAt(0).plotNode.internalId); |
92 | 93 | } |
93 | 94 | }, |
94 | 95 | destroy: function(tab, eOpts) { |
96 | + if (tab.items.getAt(0) && tab.items.getAt(0).plotNode) { | |
97 | + tab.items.getAt(0).resetModif(); | |
98 | + } | |
95 | 99 | if (!this.tabbar_destroy) |
96 | 100 | this.updatePlotTabs(); |
97 | 101 | } |
... | ... | @@ -103,6 +107,14 @@ Ext.define('amdaPlotComp.PlotTabPanel', { |
103 | 107 | |
104 | 108 | return tabContent; |
105 | 109 | }, |
110 | + | |
111 | + duplicatePlotNode: function(plotNode) | |
112 | + { | |
113 | + var newPlotNode = this.multiplot_object.duplicatePlot(plotNode); | |
114 | + if (!newPlotNode) | |
115 | + return null; | |
116 | + return newPlotNode; | |
117 | + }, | |
106 | 118 | |
107 | 119 | updatePlotTabs: function() |
108 | 120 | { |
... | ... | @@ -119,6 +131,18 @@ Ext.define('amdaPlotComp.PlotTabPanel', { |
119 | 131 | } |
120 | 132 | }, |
121 | 133 | |
134 | + closePlotTabIfOpened: function(plotNodeToClose) { | |
135 | + for (i = 0; i < this.items.getCount(); ++i) | |
136 | + { | |
137 | + var tabItem = this.items.getAt(i); | |
138 | + var tabContent = tabItem.items.getAt(0); | |
139 | + var plotNode = tabContent.plotNode; | |
140 | + if (plotNode == renamedNode) { | |
141 | + this.remove(tabItem.getId()); | |
142 | + } | |
143 | + } | |
144 | + }, | |
145 | + | |
122 | 146 | updateRequestName: function(renamedNode) |
123 | 147 | { |
124 | 148 | for (i = 0; i < this.items.getCount(); ++i) |
... | ... |