/** * Project : AMDA-NG4 * Name : InteractiveModule.js * @class amdaDesktop.InteractiveModule * @extends amdaDesktop.AmdaModule * @brief Generic Interactive Module controller definition * @author CDA * @version $Id: InteractiveModule.js 2109 2014-02-19 17:47:37Z elena $ ******************************************************************************* * FT Id : Date : Name - Description ******************************************************************************* * : :08/06/2011: CDA - Migration extjs4 * : :09/06/2011: elena - generic Interactive modules methods: init(), createWindow(), * createLinkedNode(), createObject() now are defined here */ Ext.define('amdaDesktop.InteractiveModule', { extend: 'amdaDesktop.AmdaModule', /** * @cfg {amdaModel.InteractiveNode} the explorer node linked to this module */ linkedNode : null, nodeDataModel: ' ', width : 700, height: 510, uiType : ' ', // helpTitle : 'help on the module', /** * Module link in Start Menu */ init : function() { this.launcher = { text : this.title, iconCls : this.icon, handler : this.createWindow, scope : this }; }, /** * Window Creation method of the Module */ createWindow : function () { if (this.linkedNode === null){ this.createLinkedNode(); } this.createObject(); var desktop = this.app.getDesktop(); var win = desktop.getWindow(this.id); var me = this; if (!win) { win = desktop.createWindow({ id : this.id, title : this.title, width : this.width, minWidth : this.width, height : this.height, minHeight: this.height, iconCls : this.icon, border : false, //constrainHeader : true, layout : 'fit', stateful : true, stateId : this.id, stateEvents: ['move','show','resize'], tools: [ { type:'help', qtip: this.helpTitle, scope:this, handler: function(event, toolEl, panel){ myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function(module) { module.createWindow(me.helpFile, me.helpTitle); }); } } ], items : [ { xtype : this.uiType, object : this.linkedNode.get('object'), id : this.contentId } ] }); this.closed = false; win.on({ scope: this, // on window activation event activate: function(){ // order to pin this Module with WsExplorer this.pin(); }, // on window closing event beforeclose: function (win, eOpts) { this.saveState(); var isDirty = this.getUiContent().fclose(); if (!this.closed && isDirty) { Ext.Msg.confirm('Close', 'Current window has been modified.\nDo you want to close the window ?' , function (btn, text){ if (btn == 'yes'){ // mark this.closed as true before the call to close() as that will fire the beforeclose event again this.closed = true; win.close(); } },this); } else if (!isDirty) { this.closed = true; } if (this.closed) { //remove object from linkedNode in order to minimize used memory this.linkedNode.set('object',''); // unlink Node this.setLinkedNode(null); // order to unpin this Module from WsExplorer this.unpin(); } // Don't automatically close if the form is dirty, let the call to this.close() within the confirm box close the window. return this.closed; }, minimize: function (win, eOpts) { // Save form if (this.getUiContent().formPanel) this.getUiContent().formPanel.getForm().updateRecord(this.linkedNode.get('object')); else this.getUiContent().items.getAt(0).getForm().updateRecord(this.linkedNode.get('object')); // Save grids this.getUiContent().updateObject(); } }); } else { this.getUiContent().setObject(this.linkedNode.get('object')); } win.show(); }, /** * Mechanism to attach a Module to the Workspace Explorer to enable interactions * @param moduleName the module to attach */ pin : function() { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id).pinMechanism(this.id); }, /** * Mechanism to detach a Module to the Workspace Explorer to enable interactions * @param moduleName the module to detach */ unpin : function() { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id).setPinedModule(null); }, /** * Getter of linkedNode * @return {amdaModel.InteractiveNode} linkedNode */ getLinkedNode : function (){ return this.linkedNode; }, /** * link the current node in the current module * @param {amdaModel.InteractiveNode} myLinkedNode */ setLinkedNode : function (myLinkedNode){ if (this.linkedNode) { this.linkedNode.set('object',''); } this.linkedNode = myLinkedNode; }, /** * * create Node of Appropriate Type if it doesn't exist */ createLinkedNode : function (){ var newNode = Ext.create(this.nodeDataModel, { leaf : true, contextNode : this.contextNode }); this.setLinkedNode(newNode); }, /** * * */ createObject : function (obj){ var object; if (this.linkedNode.get('object')){ object = this.linkedNode.get('object'); } else { if (!obj) { obj = this.getState(); } object = Ext.create(this.linkedNode.get('objectDataModel'), obj); this.linkedNode.set('object',object); } }, /** * Setter of contextNode * @param {amdaModel.InteractiveNode} contextNode * the node from which the Module was called */ setContextNode : function (myContextNode){ this.contextNode = myContextNode; }, /** * Color mechanism of Header of this intarctive module */ colorHeaderModule : function() { myDesktopApp.desktop.getWindow(this.id).getEl().addCls('window-active'); }, /** * UnColor mechanism of Header of this intarctive module */ uncolorHeaderModule : function() { myDesktopApp.desktop.getWindow(this.id).getEl().removeCls('window-active'); }, /** * Receiption method of a parameter sent from explorer (by drop) * @param {String} objectName The name of sent object * @param {String} isLeaf boolean true if it's a leaf parameter */ addParam : function(objectName, isLeaf, isScatter, needsArgs) { var uiContent = this.getUiContent(); uiContent.addParam(objectName, isLeaf, isScatter, needsArgs); }, saveState : Ext.emptyFn, getState : function() { return null; } });