diff --git a/js/app/models/InteractiveNode.js b/js/app/models/InteractiveNode.js index 67e09e7..d4ec76c 100644 --- a/js/app/models/InteractiveNode.js +++ b/js/app/models/InteractiveNode.js @@ -190,7 +190,7 @@ Ext.define('amdaModel.InteractiveNode', { var scope = opt.scope ? opt.scope : this; if (opt.callback) - opt.callback.call(scope,'update'); + opt.callback.call(scope,'update',res); if(opt.notDisplayMsg || opt.callback ){ //do nothing }else{ @@ -337,7 +337,7 @@ Ext.define('amdaModel.InteractiveNode', { if (opt) { var scope = opt.scope ? opt.scope : this; if (opt.callback) - opt.callback.call(scope,'create'); + opt.callback.call(scope,'create',res); } }, this); } diff --git a/js/app/views/CatalogUI.js b/js/app/views/CatalogUI.js index 6a98e91..8196c46 100644 --- a/js/app/views/CatalogUI.js +++ b/js/app/views/CatalogUI.js @@ -149,62 +149,18 @@ Ext.define('amdaUI.CatalogUI', { return; } }, - updateSurveyDates : function(ttObj){ - var starts = []; - var stops= []; + updateSurveyDates : function(res){ if (this.TTGrid.getStore().getTotalCount() <= 0) return; - reqObj = { - 'typeTT': 'catalog', - } - AmdaAction.readCacheIntervals(reqObj, function(result, e) - { - if (!result) { - myDesktopApp.errorMsg(e.message); - Ext.defer(function () { - Ext.Msg.toFront() - }, 10); - - return; - } else if (!result.success) - { - if (result.message) - myDesktopApp.errorMsg(result.message); - else - myDesktopApp.errorMsg('Unknown error during catalog survey dates update'); - - Ext.defer(function () { - Ext.Msg.toFront() - }, 10); - - return; - } - Ext.Array.each(result.intervals, function (item, index) { - starts[index] = new Date(item.start); - stops[index] = new Date(item.stop); - }); - if(starts.length !== 0 || stops.length !== 0) { - - starts.sort(function(a,b){return a.getTime() - b.getTime()}); - stops.sort(function(a,b){return a.getTime() - b.getTime()}); - - s = starts[0]; - e = stops[stops.length - 1]; - - s = Ext.Date.format(s, 'Y-m-d\\TH:i:s.u'); - e = Ext.Date.format(e, 'Y-m-d\\TH:i:s.u'); - - if(! ttObj.get('surveyStart') ){ - ttObj.set('surveyStart', s); - this.status.isModified = true; - } - if(! ttObj.get('surveyStop') ){ - ttObj.set('surveyStop', e); - this.status.isModified = true; - } - } - }); + if(! this.object.get('surveyStart') ){ + this.object.set('surveyStart', res['minStart']); + this.status.isModified = true; + } + if(! this.object.get('surveyStop') ){ + this.object.set('surveyStop', res['maxStop']); + this.status.isModified = true; + } }, createTT: function (catId) { @@ -216,7 +172,6 @@ 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')); - //this.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); @@ -689,6 +644,40 @@ Ext.define('amdaUI.CatalogUI', { }, checkIntervalsStatusForSave: function (onStatusOk) { + if (this.status == null) + return; + + if (this.status.nbValid <= 0) + { + myDesktopApp.errorMsg('Your catalog is invalid, <br>you must have at least one valid interval'); + return; + } + + var msg = ''; + if (this.status.nbInvalid > 0) + msg += 'There are some invalid intervals. Only valid intervals will be saved!<br/>'; + if (this.status.nbFiltered > 0) + msg += 'There are some filtered intervals. Filtered intervals will not be saved!<br/>'; + if (msg != '') + { + msg += 'Do you want to continue?'; + Ext.Msg.show({ + title: 'Warning!', + msg: msg, + buttons: Ext.Msg.OKCANCEL, + fn: function (btnId) { + if (btnId === 'cancel') { + // cancel the save action + } else { + onStatusOk(); + } + }, + scope: this, + icon: Ext.Msg.WARNING + }); + return; + } + onStatusOk(); }, @@ -700,7 +689,6 @@ Ext.define('amdaUI.CatalogUI', { var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id); // store / columns are the same - not needed to reconfigure grid this.toReconfigure = false; - this.updateSurveyDates(this.object); // if save shared catalog if (module.contextNode && (module.contextNode.get('id') == 'sharedcatalog-treeRootNode')) @@ -711,13 +699,14 @@ Ext.define('amdaUI.CatalogUI', { var obj = module.linkedNode.get('object'); // synchronisation of objects this.object = obj; - module.linkedNode.create({notDisplayMsg: notDisplayMsg, callback: function () { - if (onAfterSave) + module.linkedNode.create({notDisplayMsg: notDisplayMsg, callback: function (type,res) { + this.updateSurveyDates(res); + if (onAfterSave) onAfterSave(); }, scope: this}); } // if the name has been modified this is a creation - else if (this.fclose() || this.status && (this.status.nbFiltered > 0)) { + else if (this.fclose() || this.status) { if (this.object.isModified('name') || this.object.get('fromPlugin')) { // if object already has an id : it's a 'rename' of an existing if (this.object.get('id')) { @@ -737,16 +726,18 @@ Ext.define('amdaUI.CatalogUI', { module.linkedNode.toRename = true; } module.linkedNode.create({callback: function () { - module.linkedNode.update({notDisplayMsg: notDisplayMsg, callback: function () { - if (onAfterSave) - onAfterSave(); + module.linkedNode.update({notDisplayMsg: notDisplayMsg, callback: function (type,res) { + this.updateSurveyDates(res); + if (onAfterSave) + onAfterSave(); }, scope: this}, "", notDisplayMsg); }, scope: this}); } else { //update - module.linkedNode.update({notDisplayMsg: notDisplayMsg, callback: function () { - if (onAfterSave) - onAfterSave(); + module.linkedNode.update({notDisplayMsg: notDisplayMsg, callback: function (type,res) { + this.updateSurveyDates(res); + if (onAfterSave) + onAfterSave(); }, scope: this}); } } @@ -755,58 +746,52 @@ Ext.define('amdaUI.CatalogUI', { if (this.updateObject()) { var basicForm = this.formPanel.getForm(); - // if there's at least one record in the store of TTGrid - if (this.TTGrid.getStore().getTotalCount() > 0) - { // update TimeTable object which the content of form - basicForm.updateRecord(this.object); - var me = this; - this.checkIntervalsStatusForSave(function () { - //Name validation - var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id); - - if (!module) + basicForm.updateRecord(this.object); + var me = this; + this.checkIntervalsStatusForSave(function () { + //Name validation + var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id); + + if (!module) + return; + module.linkedNode.isValidName(me.fieldName.getValue(), function (res) + { + if (!res) { + me.fieldName.validFlag = 'Error during object validation'; + myDesktopApp.errorMsg(me.fieldName.validFlag); + me.fieldName.validate(); return; - module.linkedNode.isValidName(me.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 + '<br/>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; + if (!res.valid) { + if (res.error) { + if (res.error.search('subtree') != -1) { + Ext.MessageBox.show({title: 'Warning', + msg: res.error + '<br/>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.validFlag = true; me.fieldName.validate(); - me.saveProcess(false, onAfterSave, notDisplayMsg); - }); + return; + } + + me.fieldName.validFlag = true; + me.fieldName.validate(); + me.saveProcess(false, onAfterSave, notDisplayMsg); }); - } else { - Ext.Msg.alert('No intervals', 'Your catalog is invalid, <br>you must have at least one interval'); - } + }); } }, diff --git a/php/classes/CatalogMgr.php b/php/classes/CatalogMgr.php index f0054a4..d63cd44 100644 --- a/php/classes/CatalogMgr.php +++ b/php/classes/CatalogMgr.php @@ -92,6 +92,8 @@ class CatalogMgr extends TimeTableMgr else return array('error' => 'Unknown error during intervals save'); } + $result['minStart'] = TimeUtils::stamp2iso($resultSaveInt['minStart']); + $result['maxStop'] = TimeUtils::stamp2iso($resultSaveInt['maxStop']); } return $result; } diff --git a/php/classes/TimeTableMgr.php b/php/classes/TimeTableMgr.php index 2f81d86..1db316c 100644 --- a/php/classes/TimeTableMgr.php +++ b/php/classes/TimeTableMgr.php @@ -148,7 +148,7 @@ class TimeTableMgr extends AmdaObjectMgr if ($tmpFileExist) { unlink($ttFilePath . ".tmp"); } - return ['id' => $p->id, 'info' => $result['info']]; + return $result; } catch (Exception $exception) { //Restore TT file if ($tmpFileExist) { @@ -524,9 +524,19 @@ class TimeTableMgr extends AmdaObjectMgr $objToGet->removeChild($toRemove); unset($toRemove); } + $minStart =0; + $maxStop=0; //add new intervals foreach ($intervals as $interval) { + $startTime = TimeUtils::iso2stamp($interval['start']); + $stopTime = TimeUtils::iso2stamp($interval['stop']); + if ($minStart == 0) + $minStart = $startTime; + elseif ($startTime < $minStart ) + $minStart = $startTime; + if ($stopTime > $maxStop ) + $maxStop = $stopTime; $newInterval = $this->createIntervalElement($interval, $options); $this->objectDom->documentElement->appendChild($newInterval); } @@ -538,7 +548,8 @@ class TimeTableMgr extends AmdaObjectMgr unset($this->objectDom); - return ['success' => true, 'action' => $action, 'nbIntervals' => count($intervals)]; + return ['success' => true, 'action' => $action, 'nbIntervals' => count($intervals), + 'minStart' => $minStart, 'maxStop' => $maxStop]; } /** -- libgit2 0.21.2