/** * Project  : AMDA-NG * Name : OperationsTT.js * @class amdaUI.OperationsTT * @extends Ext.form.FieldSet * @brief Operations in Time Table Module UI (View) * @author Myriam * @version $Id: OperationsTT.js 1855 2013-11-19 13:23:55Z elena $ ******************************************************************************** * FT Id : Date : Name - Description ******************************************************************************* * 08/06/2011: Myriam - Migration extjs4 */ Ext.define('amdaUI.OperationsTT', { extend: 'Ext.form.FieldSet', alias: 'widget.operationsTT', // Translate Extend or Shift in seconds TranslateSec: function(valueForm, valueUnit) { if (valueForm == "") var value = 0; else switch (valueUnit) { case "sec": var value = valueForm; break; case "min": var value = valueForm * 60; break; case "hour": var value = valueForm * 3600; break; case "day": var value = valueForm * 86400; break; default: break; } return value; }, // Extend and shift intervals ExtendTT: function(dir){ var extendForm = this.formExtend.getForm().findField('extend').getValue(); var extendUnit = this.formExtend.getForm().findField('extendUnit').getValue(); var shiftForm = this.formExtend.getForm().findField('shift').getValue(); var shiftUnit = this.formExtend.getForm().findField('shiftUnit').getValue(); if ((extendForm == null) && (shiftForm == null))return; // Translate Extend and Shift in milliseconds var extend = dir * this.TranslateSec(extendForm, extendUnit); var shift = dir * this.TranslateSec(shiftForm, shiftUnit); this.cntApply += dir; if (this.cntApply < 0) { this.cntApply = 0; alert("Nothing to Undo"); return; } var me = this; me.parent.TTGrid.getSelectionModel().deselectAll(); AmdaAction.operationTTCacheIntervals(extend,shift, function () { me.parent.TTGrid.getStore().reload(); // Update historic field var history = me.parent.formPanel.getForm().findField('history').getValue(); if (extend != 0) { history += " \n Extended by "+ dir*extendForm + " " + extendUnit; } if (shift != 0) { history += " \n Shifted by "+ dir*shiftForm + " " + shiftUnit; } me.parent.formPanel.getForm().findField('history').setValue(history); }); }, // Merge intervals MergeTT: function(){ var me = this; AmdaAction.mergeTTCacheIntervals(function () { me.parent.TTGrid.getStore().reload({ callback : function(records, options, success) { me.parent.updateCount(); }, scope : me }); }); }, initComponent : function (){ this.cntApply = 0; this.formExtend = new Ext.form.Panel({ xtype: 'form', frame: true, buttonAlign: 'center', height: 75, trackResetOnLoad : true, // reset to the last loaded record fieldDefaults: { labelWidth: 40, labelSeparator: '' }, items: [ { xtype: 'fieldcontainer', layout: 'hbox', fieldLabel:'Extend', items: [ {xtype:'numberfield', name: 'extend', hideTrigger: true, width: 60}, {xtype: 'splitter', width: 5}, { xtype:'combo', name: 'extendUnit', store:['sec', 'min', 'hour', 'day'], editable: false, width: 60, value: 'min', triggerAction: 'all' }, {xtype: 'splitter', width: 20}, {xtype:'displayfield', value: 'Shift', width: 30}, {xtype:'numberfield', name: 'shift', hideTrigger: true, width: 60}, {xtype: 'splitter', width: 5}, { xtype:'combo', name: 'shiftUnit', store:['sec', 'min', 'hour', 'day'], editable: false, width: 60, value: 'min', triggerAction: 'all' } ] } ], fbar: [{ text: 'Apply', scope: this, handler: function () { this.ExtendTT(1); this.parent.fireEvent('refresh'); } },{ text: 'Undo', scope: this, handler: function () { this.ExtendTT(-1); this.parent.fireEvent('refresh'); } }] }); var config = { title:'Operations on Intervals', style: { borderWidth: '2px' }, items: [ {xtype: 'splitter', width: 5}, this.formExtend, { xtype: 'form', frame: true, border: 1, height: 60, layout: { type: 'hbox', pack: 'center', align: 'middle' }, items: [ { xtype: 'button', text: 'Merge intervals', minWidth: 105, scope : this, handler: function () { this.MergeTT(); this.parent.fireEvent('refresh'); } }, { xtype: 'container', width: 5 }, { xtype: 'button', text: 'Statistical info', minWidth: 105, scope: this, handler: function() { this.parent.fireEvent('info','timeTableUi'); } } ] } ] }; Ext.apply (this , Ext.apply (this.initialConfig, config)); this.callParent(arguments); } });