Commit 6e2fdb1f74fa7214afbef0ed8e0848b590c82a67

Authored by Benjamin Renard
1 parent 7c762483

Implments save current tab

js/app/views/PlotComponents/PlotTabPanel.js
... ... @@ -103,16 +103,21 @@ Ext.define('amdaPlotComp.PlotTabPanel', {
103 103 var i = 0;
104 104 for (i = 0; i < this.items.getCount(); ++i)
105 105 {
106   - var tabObj = this.object.tabs().getAt(i);
  106 + var tabItem = this.items.getAt(i);
  107 + var tabContent = tabItem.items.getAt(0);
  108 + var tabObj = this.object.tabs().getById(tabContent.tabId);
  109 + if (!tabObj) {
  110 + continue;
  111 + }
107 112 if (!haveSelectedTab) {
108 113 //Set first tab as the selected one
109   - this.setActiveTab(this.items.getAt(i));
  114 + this.setActiveTab(tabItem);
110 115 this.object.set('active-tab-id', tabObj.get('id'));
111 116 haveSelectedTab = true;
112 117 }
113 118 var tabNumber = i+1;
114   - this.items.getAt(i).setTitle((tabObj.get('tab-name') != '') ? tabObj.get('tab-name') : 'Plot '+tabNumber);
115   - this.items.getAt(i).items.getAt(0).setTabObject(this.object.tabs().getAt(i));
  119 + tabItem.setTitle((tabObj.get('tab-name') != '') ? tabObj.get('tab-name') : 'Plot '+tabNumber);
  120 + tabContent.setTabObject(tabObj);
116 121 }
117 122 },
118 123  
... ...
js/app/views/PlotUI.js
... ... @@ -195,16 +195,82 @@ Ext.define(&#39;amdaUI.PlotUI&#39;, {
195 195 this.timeSelector.setVisible(isLinkedToMultiPlotMode);
196 196 },
197 197  
  198 + keepOnlySelectedTabInObject: function(showWarning, onSuccess) {
  199 + if (this.object.tabs().count() == 1) {
  200 + if (onSuccess) {
  201 + onSuccess();
  202 + }
  203 + return;
  204 + }
  205 +
  206 + var me = this;
  207 + var removeFunc = function() {
  208 + var tabsToRemove = [];
  209 + var selectedTabFound = false;
  210 + me.object.tabs().each(function(tab) {
  211 + if (tab.get('id') != me.object.get('active-tab-id')) {
  212 + tabsToRemove.push(tab);
  213 + }
  214 + else {
  215 + selectedTabFound = true;
  216 + }
  217 + });
  218 + if (!selectedTabFound) {
  219 + myDesktopApp.errorMsg('Cannot retrieve selected tab');
  220 + return false;
  221 + }
  222 + if (tabsToRemove.length > 0) {
  223 + me.object.tabs().remove(tabsToRemove);
  224 + }
  225 + return true;
  226 + };
  227 +
  228 + if (!showWarning) {
  229 + if (removeFunc()) {
  230 + if (onSuccess) {
  231 + onSuccess();
  232 + }
  233 + }
  234 + return;
  235 + }
  236 +
  237 +
  238 + Ext.Msg.show( { title : 'Warning',
  239 + msg: 'Active plot will be saved, but other ones will be lost.<br/>Do you want to continue?',
  240 + width: 300,
  241 + buttons: Ext.Msg.OKCANCEL,
  242 + fn: function(btn) {
  243 + if (btn == 'cancel') return;
  244 +
  245 + if (removeFunc()) {
  246 + if (onSuccess) {
  247 + onSuccess();
  248 + }
  249 + }
  250 + return;
  251 + },
  252 + scope: me
  253 + });
  254 + },
  255 +
198 256 savePlotRequest : function(allTabs = false) {
199 257 var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
200 258 if (!plotModule)
201 259 return;
202 260 this.updateObject();
203 261 this.object.set('active-tab-id', this.plotTabs.getSelectedTabId());
  262 + var me = this;
204 263  
205 264 if ((this.object.get('id') != '') && (plotModule.linkedNode.get('text') == this.object.get('name'))) {
206 265 //update existing request
207   - plotModule.linkedNode.update();
  266 + if (!allTabs) {
  267 + this.keepOnlySelectedTabInObject(true, function() {
  268 + plotModule.linkedNode.update();
  269 + });
  270 + }
  271 + else {
  272 + plotModule.linkedNode.update();
  273 + }
208 274 return;
209 275 }
210 276  
... ... @@ -236,7 +302,15 @@ Ext.define(&#39;amdaUI.PlotUI&#39;, {
236 302 }
237 303 return;
238 304 }
239   - me.saveProcess(false);
  305 + if (!allTabs) {
  306 + me.keepOnlySelectedTabInObject((me.object.get('id') == ''), function() {
  307 + me.saveProcess(false);
  308 + me.setObject(me.object);
  309 + });
  310 + }
  311 + else {
  312 + me.saveProcess(false);
  313 + }
240 314 });
241 315 },
242 316  
... ...