/** * Project : AMDA-NG4 * Name : PlotTabNode.js * @class amdaModel.PlotTabNode * @extends amdaModel.ExecutableNode * @brief Basic Model of Node corresponding to a tab of a plot request * @author Benjamin Renard */ Ext.define('amdaModel.PlotTabNode', { extend: 'amdaModel.ExecutableNode', fields : [ {name : 'tabid', type:'string', defaultValue:'', persist: false} ], statics: { nodeType: 'plottab' }, constructor : function(config){ this.callParent(arguments); this.set('moduleId',myDesktopApp.dynamicModules.plot.id); //this.set('objectDataModel','amdaPlotObj.PlotRequestObject'); this.set('nodeType',this.self.nodeType); this.set('leaf',true); this.set('iconCls','icon-plot-page'); }, allMenuItems : function() { var menuItems = [ { fnId : 'ptab-openTab', text : 'Open in new Plot Request' }, { fnId : 'ptab-insertTab', text : 'Insert in current Plot Request' }, { fnId : 'ptab-renameTab', text : 'Rename Plot Tab' }]; return menuItems; }, allMenuMultiItems : function() { var menuMulti = [ ]; return menuMulti; }, getAllContextMenuItems: function(){ return this.allMenuItems(); }, getMultiContextMenuItems: function(){ return this.allMenuMultiItems(); }, onMenuItemClick : function(menu,item,event) { var fnId = Ext.util.Format.substr(item.fnId, 5, item.fnId.length); switch (fnId) { case 'openTab': this.insertPlotTabRequest(true); break; case 'insertTab': this.insertPlotTabRequest(false); break; case 'renameTab': this.renameTab(); break; default: break; } }, insertPlotTabRequest : function(inNewRequest) { var me = this; amdaModel.InteractiveNode.preloadNodes(this.parentNode.getRootNode(), function() { AmdaAction.getObject(me.parentNode.get('id'), me.parentNode.get('nodeType'), function (result,remoteEvent) { var paramObj = Ext.create(me.parentNode.get('objectDataModel'), result); var tabData = null; paramObj.tabs().each(function(tab) { if (tab.get('id') == me.get('tabid')) { tabData = tab.getJsonValues(); } }); if (tabData != null) { if (inNewRequest) { tabData['id'] = 1; paramObj.set('id',''); paramObj.set('name', ''); paramObj.set('folderId', ''); paramObj.set('active-tab-id', 1); paramObj.set('last-tab-id', 1); paramObj.set('last-plotted-tab', 1); paramObj.loadTabs([tabData]); myDesktopApp.getLoadedModule(me.get('moduleId'), true, function (module) { module.setContextNode(me.parentNode.getRootNode()); module.createWindow(function () { var uiContent = module.getUiContent(); if (uiContent != null) { uiContent.resetProcess(paramObj.getJsonValues()); } }); }); } else { myDesktopApp.getLoadedModule(me.get('moduleId'), true, function (module) { module.createWindow(function () { var uiContent = module.getUiContent(); if (uiContent != null) { var tabObj = new amdaPlotObj.PlotTabObject(tabData); uiContent.insertPlotTab(tabData); } }); }); } } }, me); }); }, editPlotTab : function() { var me = this; this.parentNode.editLeaf(function () { myDesktopApp.getLoadedModule(me.get('moduleId'), true, function (module) { var uiContent = module.getUiContent(); if (uiContent != null) { uiContent.forceActiveTab(me.get('tabid')); } }); }); }, renameTab: function() { if (this.myGetOwnerTree()) { var item = this.myGetOwnerTree().getSelectionModel().selected.items[0]; this.myGetOwnerTree().fireEvent('edition', this.myGetOwnerTree().view, item); } }, rename: function(value,callBackFn) { var me = this; var dataToSend = {id : this.get('tabid'), old_name: this.modified.text, name: value, parent : this.data.parentId, leaf: this.isLeaf(), nodeType: this.get('nodeType')}; AmdaAction.renameObject(dataToSend, function (result) { callBackFn(result); myDesktopApp.getLoadedModule(me.get('moduleId'), true, function (module) { var uiContent = module.getUiContent(); if (uiContent != null) { if ((module.linkedNode != null) && (module.linkedNode.get('id') == dataToSend.parent)) { uiContent.updatePlotTabName(dataToSend.id, dataToSend.name); } } }); }); }, });