diff --git a/js/app/models/TimeTable.js b/js/app/models/TimeTable.js index a6b6963..1303137 100644 --- a/js/app/models/TimeTable.js +++ b/js/app/models/TimeTable.js @@ -134,7 +134,7 @@ Ext.define('amdaModel.TimeTable', { {name: 'fromPlugin', type: 'boolean', defaultValue: false}, {name: 'created', type: 'date'}, {name: 'description', type: 'string'}, - {name: 'contact', type: 'string'}, + {name: 'contact', type: 'string', defaultValue:sessionID}, {name: 'surveyStart', type: 'date'}, {name: 'surveyStop', type: 'date'}, {name: 'history', type: 'string'}, @@ -181,7 +181,7 @@ Ext.define('amdaModel.TimeTable', { } values.objName = this.get('objName'); values.objFormat = this.get('objFormat'); - values.folderId = this.get('folderId'); + values.folderId = this.get('folderId'); values.nbIntervals = this.get('nbIntervals'); values.cacheToken = this.get('cacheToken'); diff --git a/js/app/views/CatalogUI.js b/js/app/views/CatalogUI.js index b0b1f52..4390dd6 100644 --- a/js/app/views/CatalogUI.js +++ b/js/app/views/CatalogUI.js @@ -22,6 +22,7 @@ Ext.define('amdaUI.CatalogUI', { ], isCatalog: true, + activeField : null, statics: { COL_TO_HIDE_DURATION: 'colToHideDuration' }, @@ -148,6 +149,30 @@ Ext.define('amdaUI.CatalogUI', { return; } }, + updateSurveyDates : function(ttObj){ + var starts = []; + var stops= []; + Ext.Array.each(this.TTGrid.getStore().data.first.value, function (item, index) { + starts[index] = (item.raw.start); + stops[index] = (item.raw.stop); + }); + if(starts.length !== 0 || stops.length !== 0) { + + starts.sort(); + stops.sort(); + s = new Date(starts[0]); + e = new Date(stops[stops.length - 1]); + if(! ttObj.get('surveyStart') ){ + ttObj.set('surveyStart', this.convertUTCDateToLocalDate(s)); + this.status.isModified = true; + } + if(! ttObj.get('surveyStop') ){ + ttObj.set('surveyStop', this.convertUTCDateToLocalDate(e)); + this.status.isModified = true; + } + } + }, + createTT: function (catId) { var ttObj = Ext.create('amdaModel.TimeTable'); var timeTabNode = Ext.create('amdaModel.TimeTableNode', {leaf: true}); @@ -157,8 +182,7 @@ Ext.define('amdaUI.CatalogUI', { descr = 'Generated by CDPP/Amda Catalog Module \n' + 'From Catalog: ' + this.object.get('name') + '\nOn: ' + date + '\n'; ttObj.set('description', descr + this.object.get('description')); ttObj.set('contact', this.object.get('contact')); - ttObj.set('surveyStart', this.object.get('surveyStart')); - ttObj.set('surveyStop', this.object.get('surveyStop')); + updateSurveyDates(ttObj); timeTabNode.set('object', ttObj); var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID); var ttRootNode = explorerTree.getRootNode().findChild('id', 'timeTable-treeRootNode', true); @@ -594,6 +618,7 @@ Ext.define('amdaUI.CatalogUI', { loadObject: function () { // load object into form this.object.set('created', this.convertUTCDateToLocalDate(this.object.get('created'))); + this.updateSurveyDates(this.object); this.formPanel.getForm().loadRecord(this.object); this.status = null; @@ -645,6 +670,7 @@ Ext.define('amdaUI.CatalogUI', { module.createObject(this.object.getJsonValues()); var obj = module.linkedNode.get('object'); // synchronisation of objects + this.updateSurveyDates(obj); this.object = obj; module.linkedNode.create({notDisplayMsg: notDisplayMsg, callback: function () { if (onAfterSave) @@ -694,8 +720,8 @@ Ext.define('amdaUI.CatalogUI', { if (this.TTGrid.getStore().getTotalCount() > 0) { // update TimeTable object which the content of form + this.updateSurveyDates(this.object); basicForm.updateRecord(this.object); - var me = this; this.checkIntervalsStatusForSave(function () { //Name validation @@ -767,7 +793,30 @@ Ext.define('amdaUI.CatalogUI', { var isDirty = this.formPanel.getForm().isDirty() || (this.status.isModified) || (this.status.nbModified > 0) || (this.status.nbNew > 0); return isDirty; }, - + onChangeStartField: function(field, newValue, oldValue) + { + if (field.isValid() && this.activeField =='surveyStart' ) { + // launch the update of duration fields + var form = this.findParentByType('form').getForm(); + var start = form.findField('surveyStart').getValue(); + var stop =form.findField('surveyStop').getValue(); + if ( stop <= start ) { + field.markInvalid('Start Time must be before Stop Time'); + } + } + }, + onChangeStopField: function(field, newValue, oldValue) + { + if (field.isValid() && this.activeField =='surveyStop' ) { + // launch the update of duration fields + var form = this.findParentByType('form').getForm(); + var start = form.findField('surveyStart').getValue(); + var stop =form.findField('surveyStop').getValue(); + if ( stop <= start ) { + field.markInvalid('Stop Time must be after Start Time'); + } + } + }, init: function (config) { this.object = config.object; @@ -967,22 +1016,34 @@ Ext.define('amdaUI.CatalogUI', { items :[{ fieldLabel: 'Start Time', name: 'surveyStart', - emptyText: 'YYYY/MM/DDThh:mm:ss', + emptyText: 'YYYY/MM/DDThh:mm:ss', format: 'Y-m-d\\TH:i:s', - enforceMaxLength: true, + enforceMaxLength: true, maxLength: 19, labelWidth: 60, - labelAlign: 'left' + labelAlign: 'left', + listeners: { + change: this.onChangeStartField, + focus: function(field) { + this.activeField = 'surveyStart'; + }, + } }, { fieldLabel: 'Stop Time', name: 'surveyStop', - emptyText: 'YYYY/MM/DDThh:mm:ss', + emptyText: 'YYYY/MM/DDThh:mm:ss', format: 'Y-m-d\\TH:i:s', labelAlign: 'left', enforceMaxLength: true, maxLength: 19, labelWidth: 60, - align: 'left' + align: 'left', + listeners: { + change: this.onChangeStopField, + focus: function(field) { + this.activeField = 'surveyStop'; + }, + } }] }, { -- libgit2 0.21.2