/** * Project  : AMDA-NG * Name : ParameterUI.js * @class amdaUI.ParameterUI * @extends Ext.container.Container * @brief Parameter Module UI definition (View) * @author * @version $Id: ParameterUI.js 2257 2014-04-02 12:21:27Z elena $ ******************************************************************************** * FT Id : Date : Name - Description ******************************************************************************* * */ Ext.define('amdaUI.ParameterUI', { extend: 'Ext.container.Container', alias: 'widget.panelParam', requires: [ 'amdaUI.AliasUI', 'amdaUI.CalculatorUI', 'extensions.SelectableTextArea', 'amdaUI.SearchParamEditorPlugin' ], constructor: function(config) { this.init(config); this.callParent(arguments); // load object into form this.formPanel.getForm().loadRecord(this.object); }, addParam : function(newParamName,isLeaf) { if (isLeaf){ var selection = this.constructionField.getSelection(); this.constructionField.setValue(selection.beforeText + newParamName + selection.afterText); this.constructionField.focus(); this.constructionField.setCaretPosition(this.constructionField.getValue().length); } }, setObject : function (object) { this.object = object; // load object into form this.formPanel.getForm().loadRecord(this.object); }, /** * update this.object from form */ updateObject : function(){ // get the basic form var basicForm = this.formPanel.getForm(); var updateStatus = true; var fieldsWithoutName = basicForm.getFields().items; Ext.Array.each(fieldsWithoutName, function(item, index,allItems){ if(item !== this.fieldName) { if (!item.isValid()) { // set update isn't allowed updateStatus = false; } } }, this); // if the update is allowed if (updateStatus) { /// real object update // update TimeTable object with the content of form basicForm.updateRecord(this.object); } // return the update status return updateStatus; }, updateConstruct : function(oldval,newval) { // update constructionField (Construct parameter) in window parameter var expression = this.constructionField.value; oldval = oldval.replace(/[(]/g,"\\("); oldval = oldval.replace(/[)]/g,"\\)"); var reg=new RegExp(oldval, "g"); expression = expression.replace(reg, newval); this.constructionField.setValue(expression); }, /** * Parameter compilation */ compilParam : function($action) { var obj = { paramId : 'ws_'+this.object.get('name') }; AmdaAction.compilParam(obj, function (result, e) { if (!result || !result.success) { if (result.message) myDesktopApp.warningMsg(result.message); else myDesktopApp.warningMsg('Unknown error during parameter compilation'); return; } }); }, /** * save method called by Save button */ saveProcess : function(toRename){ if(this.object.dirty) { // Parameter Module var paramModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id); // if the name has been modified this is a creation if (this.object.isModified('name')){ // if object already has an id : it's a 'rename' of an existing TimeTable if (this.object.get('id')){ // the context Node is the parent node of current edited one var contextNode = paramModule.linkedNode.parentNode; // link a new node to the TimeTableModule paramModule.createLinkedNode(); // set the contextNode paramModule.linkedNode.set('contextNode',contextNode); // create a new object linked paramModule.createObject(this.object.getJsonValues()); var paramobj = paramModule.linkedNode.get('object'); //synchronize objects this.object = paramobj; if (toRename) paramModule.linkedNode.toRename = true; } paramModule.linkedNode.create({scope : this, callback : this.compilParam}); paramModule.linkedNode.set('iconCls', 'icon-scalar'); paramModule.linkedNode.set('isParameter', true); // fire creation event // this.object.fireEvent('create'); } else { paramModule.linkedNode.set('contextNode',paramModule.contextNode); paramModule.linkedNode.update({scope : this, callback : this.compilParam}); // this.object.fireEvent('modify'); } } }, /** * overwrite metod called by Save button */ overwriteProcess : function(btn){ if (btn == 'cancel') return; this.fieldName.clearInvalid(); this.saveProcess(true); }, /** * Check if brackets are balanced */ isBalanced : function(str){ str = (""+str).replace(/[^()\[\]{}]/g, ""); var bracket = { "]": "[", "}": "{", ")": "(" }, openBrackets = [], isClean = true, i = 0, len = str.length; for(; isClean && i 1) { nameToSent += "(0)"; myDesktopApp.warningMsg("parameter "+name+" is array of size: " +size+"
Please put index"); } break; default : return false; } var paramModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id); if (data.records[0].get('needsArgs')) { paramModule.getUiContent().fireEvent('openParamEditor',nameToSent); } else { paramModule.addParam(nameToSent,true); } return true; } }); } } //TODO: ?validator on formula structure? // listener : { // valid : function(field) { // // } // } }); this.formPanel = new Ext.form.Panel({ id: 'vbox-paramForm', bodyStyle: {background : '#dfe8f6'}, border: false, buttonAlign: 'left', region: 'center', trackResetOnLoad: true, //reset to the last loaded record layout: { type: 'vbox', defaultMargins: {top: 10, left:10, bottom:5, right:5}, align: 'stretch' }, defaults: { border: false }, items: [ { flex: 1, xtype: 'container', border: false, layout: { type: 'table', columns: 3 }, defaultType: 'textfield', defaults: { labelAlign: 'top' }, items: [ this.fieldName, { xtype:'component', width: 20 },{ itemId: 'formParamTimeStep', fieldLabel: 'Time Step (sec)*', labelAlign: 'top', allowBlank : false, blankText : 'Time Step is required', name : 'timestep', regex : new RegExp('^[0-9]+$'), regexText : 'Time Step has to be a numeric value', width: 150, validateOnChange: false, validateOnBlur: false },{ xtype: 'textfield', itemId: 'formParamUnit', fieldLabel: 'Units', name : 'units', width: 150 },{ xtype:'component', width: 20 },{ xtype: 'textfield', itemId: 'formParamYTitle', fieldLabel: 'Y Title for Plot', name : 'ytitle', width: 150 },{ xtype: 'textfield', itemId: 'formParamDescription', name: 'description', xtype: 'textarea', fieldLabel:'Description', width: 320, height: 75, colspan: 3 }] }, this.constructionField ], fbar: [ { text: 'Save', scope : this, handler: function(){ if (this.updateObject()){ var paramModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id); if (!paramModule) return; var me = this; paramModule.linkedNode.isValidName(this.fieldName.getValue(), function (res) { if (!res) { me.fieldName.validFlag = 'Error during object validation'; myDesktopApp.errorMsg(me.fieldName.validFlag); me.fieldName.validate(); return; } if (!res.valid) { if (res.error) { if (res.error.search('subtree') != -1) { Ext.MessageBox.show({title:'Warning', msg: res.error+'
Do you want to overwrite it?', width: 300, buttons: Ext.MessageBox.OKCANCEL, fn : me.overwriteProcess, icon: Ext.MessageBox.WARNING, scope : me }); me.fieldName.validFlag = true; } else me.fieldName.validFlag = res.error; } else { me.fieldName.validFlag = 'Invalid object name'; myDesktopApp.errorMsg(me.fieldName.validFlag); } me.fieldName.validate(); return; } me.fieldName.validFlag = true; me.fieldName.validate(); me.saveProcess(false); }); } } }, { text: 'Reset', scope: this, handler: function(){ var paramModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id); paramModule.createLinkedNode(); paramModule.createObject(); this.setObject(paramModule.getLinkedNode().get('object')); /* reset with keeping old object this.formPanel.getForm().reset(); */ } } ] }); var myConf = { layout: 'border', border: false, defaults: { layout: 'fit', border: false }, items: [ this.formPanel, { xtype: 'panel', region: 'south', title: 'Information', collapsible: true, height: 100, autoHide: false, iconCls: 'icon-information', bodyStyle: 'padding:5px', loader: { autoLoad: true, url: helpDir+'myParameterHOWTO' } } ], plugins: [ {ptype: 'calculator', myBtns:[], context: 'Parameter' }, {ptype: 'searchParamEditorPlugin'}] }; Ext.apply(this, Ext.apply(arguments, myConf)); } });