From 6e2fdb1f74fa7214afbef0ed8e0848b590c82a67 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Tue, 7 May 2019 17:58:44 +0200 Subject: [PATCH] Implments save current tab --- js/app/views/PlotComponents/PlotTabPanel.js | 13 +++++++++---- js/app/views/PlotUI.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 6 deletions(-) diff --git a/js/app/views/PlotComponents/PlotTabPanel.js b/js/app/views/PlotComponents/PlotTabPanel.js index 595efd0..5fa631b 100644 --- a/js/app/views/PlotComponents/PlotTabPanel.js +++ b/js/app/views/PlotComponents/PlotTabPanel.js @@ -103,16 +103,21 @@ Ext.define('amdaPlotComp.PlotTabPanel', { var i = 0; for (i = 0; i < this.items.getCount(); ++i) { - var tabObj = this.object.tabs().getAt(i); + var tabItem = this.items.getAt(i); + var tabContent = tabItem.items.getAt(0); + var tabObj = this.object.tabs().getById(tabContent.tabId); + if (!tabObj) { + continue; + } if (!haveSelectedTab) { //Set first tab as the selected one - this.setActiveTab(this.items.getAt(i)); + this.setActiveTab(tabItem); this.object.set('active-tab-id', tabObj.get('id')); haveSelectedTab = true; } var tabNumber = i+1; - this.items.getAt(i).setTitle((tabObj.get('tab-name') != '') ? tabObj.get('tab-name') : 'Plot '+tabNumber); - this.items.getAt(i).items.getAt(0).setTabObject(this.object.tabs().getAt(i)); + tabItem.setTitle((tabObj.get('tab-name') != '') ? tabObj.get('tab-name') : 'Plot '+tabNumber); + tabContent.setTabObject(tabObj); } }, diff --git a/js/app/views/PlotUI.js b/js/app/views/PlotUI.js index e21531c..398fd1b 100644 --- a/js/app/views/PlotUI.js +++ b/js/app/views/PlotUI.js @@ -195,16 +195,82 @@ Ext.define('amdaUI.PlotUI', { this.timeSelector.setVisible(isLinkedToMultiPlotMode); }, + keepOnlySelectedTabInObject: function(showWarning, onSuccess) { + if (this.object.tabs().count() == 1) { + if (onSuccess) { + onSuccess(); + } + return; + } + + var me = this; + var removeFunc = function() { + var tabsToRemove = []; + var selectedTabFound = false; + me.object.tabs().each(function(tab) { + if (tab.get('id') != me.object.get('active-tab-id')) { + tabsToRemove.push(tab); + } + else { + selectedTabFound = true; + } + }); + if (!selectedTabFound) { + myDesktopApp.errorMsg('Cannot retrieve selected tab'); + return false; + } + if (tabsToRemove.length > 0) { + me.object.tabs().remove(tabsToRemove); + } + return true; + }; + + if (!showWarning) { + if (removeFunc()) { + if (onSuccess) { + onSuccess(); + } + } + return; + } + + + Ext.Msg.show( { title : 'Warning', + msg: 'Active plot will be saved, but other ones will be lost.
Do you want to continue?', + width: 300, + buttons: Ext.Msg.OKCANCEL, + fn: function(btn) { + if (btn == 'cancel') return; + + if (removeFunc()) { + if (onSuccess) { + onSuccess(); + } + } + return; + }, + scope: me + }); + }, + savePlotRequest : function(allTabs = false) { var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id); if (!plotModule) return; this.updateObject(); this.object.set('active-tab-id', this.plotTabs.getSelectedTabId()); + var me = this; if ((this.object.get('id') != '') && (plotModule.linkedNode.get('text') == this.object.get('name'))) { //update existing request - plotModule.linkedNode.update(); + if (!allTabs) { + this.keepOnlySelectedTabInObject(true, function() { + plotModule.linkedNode.update(); + }); + } + else { + plotModule.linkedNode.update(); + } return; } @@ -236,7 +302,15 @@ Ext.define('amdaUI.PlotUI', { } return; } - me.saveProcess(false); + if (!allTabs) { + me.keepOnlySelectedTabInObject((me.object.get('id') == ''), function() { + me.saveProcess(false); + me.setObject(me.object); + }); + } + else { + me.saveProcess(false); + } }); }, -- libgit2 0.21.2