/** * Project  : AMDA-NG * Name : ParamArgumentsPlug.js * @plugin amdaUI.ParamArgumentsPlug * @extends Ext.util.Observable * @ptype paramArgumentsPlugin * @brief Plugin to select arguments of a parameter * @author Benjamin * @version $Id: ParamArgumentsPlug.js ******************************************************************************** * FT Id : Date : Name - Description ******************************************************************************* * : */ Ext.define('amdaUI.ParamArgumentsPlug', { extend: 'Ext.util.Observable', alias: 'plugin.paramArgumentsPlugin', win : null, form : null, paramObject: null, paramArgs: null, onApply: null, requires: [ 'amdaUI.ParamArgumentsUI' ], constructor: function(config) { Ext.apply(this, config); this.callParent(arguments); }, onDestroy : function() { this.win = null; }, init: function(cmp) { this.hostCmp = cmp; }, computeHeight: function() { if (!this.paramArgs) return 0; var maxPos = 0; this.paramArgs.items.each(function(item) { if (!item.isVisible()) return; var crtPos = item.getPosition(true); if (maxPos < crtPos[1] + item.getHeight()) maxPos = crtPos[1] + item.getHeight(); }); return maxPos + 75; }, /** * creation of the window */ show : function(prefixId, paramRequestObject) { var me = this; if (!this.win) { this.win = new Ext.Window({ id: prefixId + '-param-arg-win', width: 280, height: 150, x: 0, y: 0, baseCls:'x-panel', title: '', layout: 'fit', constrain: true, collapsible: true, resizable: false, ghost: false, renderTo: this.hostCmp.ownerCt.body, items: this.getFormConfig(), closeAction: 'hide', listeners: { scope: this, beforeclose: function() { //this.hostCmp.setDisabled(false); Ext.PluginManager.unregister(this); } , show: function() { me.win.setHeight(me.computeHeight()); } }, getConstrainVector: function(constrainTo){ var me = this; if (me.constrain || me.constrainHeader) { constrainTo = constrainTo || (me.floatParent && me.floatParent.getTargetEl()) || me.container || me.el.getScopeParent(); return (me.constrainHeader ? me.header.el : me.el).getConstrainVector(constrainTo); } } }); this.win.on('destroy', this.onDestroy, this); Ext.PluginManager.register(this); } this.win.setTitle('Arguments for ' + paramRequestObject.get('paramid')); //Work with a clone of the request para object. this.paramObject = paramRequestObject; var workingParamObject = this.paramObject.copy(); this.paramArgs.editParameter(workingParamObject, this.hostCmp, function() { me.win.setHeight(me.computeHeight()); }); //this.hostCmp.setDisabled(true); this.win.show(); }, close : function() { if (this.win == null) return; this.win.close(); }, onModifyHeight : function(pluginOwner) { if (pluginOwner && pluginOwner.win) pluginOwner.win.setHeight(pluginOwner.computeHeight()); }, /** * Main form */ getFormConfig: function(){ this.paramArgs = Ext.create('amdaUI.ParamArgumentsUI', { }); this.paramArgs.onModifyHeight = this.onModifyHeight; this.paramArgs.pluginOwner = this; var me = this; this.form = new Ext.form.FormPanel( { frame: true, width: 230, height: 120, layout: { type: 'vbox', pack: 'start', align: 'stretch' }, fieldDefaults: { labelWidth: 60 }, items: [ me.paramArgs ], buttons: [ { text: 'Apply', scope : this, handler: function(bt,event) { //Set modification if (me.paramObject) me.paramObject.data = me.paramArgs.paramRequestObject.data; if (me.onApply) me.onApply(me.hostCmp, me.paramArgs.paramRequestObject); me.close(); } }, { text: 'Reset', scope : this, handler: function(bt,event) { if (me.paramArgs) me.paramArgs.resetValues(); } } ] }); return this.form; } });