Commit 13f28b15f9ba78eb63448d632f05fa25ae8202d7

Authored by Hacene SI HADJ MOHAND
1 parent edd2e650

rm_7054 in progress

Showing 1 changed file with 1010 additions and 1012 deletions   Show diff stats
js/app/views/CatalogUI.js
... ... @@ -8,1039 +8,1037 @@
8 8 */
9 9  
10 10 Ext.define('amdaUI.CatalogUI', {
11   - extend: 'Ext.container.Container',
12   - alias: 'widget.panelCatalog',
13   -
14   - requires: [
15   - 'Ext.ux.grid.menu.RangeMenu',
16   - 'Ext.ux.grid.FiltersFeature',
17   - 'Ext.ux.grid.filter.DateFilter',
18   - 'Ext.ux.grid.filter.NumericFilter',
19   - 'Ext.ux.grid.filter.StringFilter',
20   - 'Ext.grid.plugin.BufferedRenderer',
21   - 'amdaUI.StatisticalPlug'
22   - ],
23   -
24   - isCatalog : true,
25   - statics: {
26   - COL_TO_HIDE_DURATION : 'colToHideDuration'
27   - },
28   -
29   - constructor: function(config) {
30   - this.init(config);
31   - this.callParent(arguments);
32   - this.toReconfigure = true;
33   -
34   - if (this.object) {
35   - this.loadObject();
36   - }
37   - },
38   -
39   - setObject : function (object, toReconfigure) {
40   - if (toReconfigure)
41   - this.toReconfigure = true;
42   - // set object
43   - this.object = object;
44   - // load object into view
45   - this.loadObject();
46   - // show the default duration column
47   - this.TTGrid.headerCt.getGridColumns();
48   -
49   - Ext.Array.each(this.TTGrid.headerCt.getGridColumns(), function(item,index,all){
50   - // if item is the default duration column
51   - if ( item.id == amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'2' ) {
52   - // show this column
53   - item.show();
54   - }
55   - });
56   - // fire the refresh event (to statistical plugin)
57   - this.fireEvent("refresh");
58   - // global event
59   - myDesktopApp.EventManager.fireEvent("refresh");
60   - },
61   -
62   - /**
63   - * set params description into this.object
64   - */
65   - setParamInfo : function(parameters) {
66   - var params = [];
67   - Ext.Array.each(parameters, function(item, index) {
68   - params[index] = item;
69   - }, this);
70   -
71   - this.object.set('parameters', params);
72   - this.object.set('nbParameters', params.length);
73   - },
74   -
75   - /**
76   - * update this.object from form
77   - */
78   - updateObject : function(){
79   - // get the basic form
80   - var basicForm = this.formPanel.getForm();
81   - var updateStatus = true;
82   -
83   - var fieldsWithoutName = basicForm.getFields().items;
84   - Ext.Array.each(fieldsWithoutName, function(item, index,allItems){
85   - if(item !== this.fieldName) {
86   - if (!item.isValid()) {
87   - // set update isn't allowed
88   - updateStatus = false;
89   - }
90   - }
91   - }, this);
92   - // if the update is allowed
93   - if (updateStatus) {
94   - /// real object update
95   - // update TimeTable object with the content of form
96   - basicForm.updateRecord(this.object);
97   - }
98   - // return the update status
99   - return updateStatus;
100   - },
101   -
102   - addInterval : function(start, stop) {
103   - var row = this.TTGrid.getStore().getTotalCount();
104   - var me = this;
105   - this.TTGrid.getSelectionModel().deselectAll();
106   - AmdaAction.addCacheInterval({'start' : start, 'stop' : stop, 'index' : row, 'isCatalog' : true},function (result, e) {
107   - this.status = result.status;
108   - if (!this.TTGrid.getStore().loading) {
109   - this.TTGrid.getStore().reload({
110   - callback : function(records, options, success) {
111   - me.TTGrid.getView().bufferedRenderer.scrollTo(row, false, function() {
112   - me.TTGrid.getView().select(row);
113   - }, me);
114   - }
115   - });
  11 + extend: 'Ext.container.Container',
  12 + alias: 'widget.panelCatalog',
  13 +
  14 + requires: [
  15 + 'Ext.ux.grid.menu.RangeMenu',
  16 + 'Ext.ux.grid.FiltersFeature',
  17 + 'Ext.ux.grid.filter.DateFilter',
  18 + 'Ext.ux.grid.filter.NumericFilter',
  19 + 'Ext.ux.grid.filter.StringFilter',
  20 + 'Ext.grid.plugin.BufferedRenderer',
  21 + 'amdaUI.StatisticalPlug'
  22 + ],
  23 +
  24 + isCatalog: true,
  25 + statics: {
  26 + COL_TO_HIDE_DURATION: 'colToHideDuration'
  27 + },
  28 +
  29 + constructor: function (config) {
  30 + this.init(config);
  31 + this.callParent(arguments);
  32 + this.toReconfigure = true;
  33 +
  34 + if (this.object) {
  35 + this.loadObject();
  36 + }
  37 + },
  38 +
  39 + setObject: function (object, toReconfigure) {
  40 + if (toReconfigure)
  41 + this.toReconfigure = true;
  42 + // set object
  43 + this.object = object;
  44 + // load object into view
  45 + this.loadObject();
  46 + // show the default duration column
  47 + this.TTGrid.headerCt.getGridColumns();
  48 +
  49 + Ext.Array.each(this.TTGrid.headerCt.getGridColumns(), function (item, index, all) {
  50 + // if item is the default duration column
  51 + if (item.id == amdaUI.CatalogUI.COL_TO_HIDE_DURATION + '2') {
  52 + // show this column
  53 + item.show();
  54 + }
  55 + });
  56 + // fire the refresh event (to statistical plugin)
  57 + this.fireEvent("refresh");
  58 + // global event
  59 + myDesktopApp.EventManager.fireEvent("refresh");
  60 + },
  61 +
  62 + /**
  63 + * set params description into this.object
  64 + */
  65 + setParamInfo: function (parameters) {
  66 + var params = [];
  67 + Ext.Array.each(parameters, function (item, index) {
  68 + params[index] = item;
  69 + }, this);
  70 +
  71 + this.object.set('parameters', params);
  72 + this.object.set('nbParameters', params.length);
  73 + },
  74 +
  75 + /**
  76 + * update this.object from form
  77 + */
  78 + updateObject: function () {
  79 + // get the basic form
  80 + var basicForm = this.formPanel.getForm();
  81 + var updateStatus = true;
  82 +
  83 + var fieldsWithoutName = basicForm.getFields().items;
  84 + Ext.Array.each(fieldsWithoutName, function (item, index, allItems) {
  85 + if (item !== this.fieldName) {
  86 + if (!item.isValid()) {
  87 + // set update isn't allowed
  88 + updateStatus = false;
116 89 }
117   - }, this);
118   - },
119   -
120   - updateCount : function() {
121   - this.object.set('nbIntervals',this.TTGrid.getStore().getTotalCount());
122   - this.formPanel.getForm().findField('nbIntervals').setValue(this.object.get('nbIntervals'));
123   - },
124   - generateTT : function(){
125   - if(this.fclose()){
126   - Ext.Msg.confirm('Generate TT', 'Current Catalog has been modified.\nDo you want to save it to include these changes in the generated Time Table ?' ,
127   - function (btn, text){
128   - if (btn == 'yes'){
129   - // mark this.closed as true before the call to close() as that will fire the beforeclose event again
130   - if(this.object.get('id') ==""){
131   - // case of creation of catalog
132   - this.saveCatalog(true,true);
133   - }else{
134   - // casse existing catalog
135   - this.saveProcess(false,true,true);
136   - }
137   - return;
138   - }
139   - }, this);
140   -
141   - }else{
142   - this.createTT(this.object.get('id'));
143   - return;
144 90 }
  91 + }, this);
  92 + // if the update is allowed
  93 + if (updateStatus) {
  94 + /// real object update
  95 + // update TimeTable object with the content of form
  96 + basicForm.updateRecord(this.object);
  97 + }
  98 + // return the update status
  99 + return updateStatus;
  100 + },
  101 +
  102 + addInterval: function (start, stop) {
  103 + var row = this.TTGrid.getStore().getTotalCount();
  104 + var me = this;
  105 + this.TTGrid.getSelectionModel().deselectAll();
  106 + AmdaAction.addCacheInterval({'start': start, 'stop': stop, 'index': row, 'isCatalog': true}, function (result, e) {
  107 + this.status = result.status;
  108 + if (!this.TTGrid.getStore().loading) {
  109 + this.TTGrid.getStore().reload({
  110 + callback: function (records, options, success) {
  111 + me.TTGrid.getView().bufferedRenderer.scrollTo(row, false, function () {
  112 + me.TTGrid.getView().select(row);
  113 + }, me);
  114 + }
  115 + });
  116 + }
  117 + }, this);
  118 + },
  119 +
  120 + updateCount: function () {
  121 + this.object.set('nbIntervals', this.TTGrid.getStore().getTotalCount());
  122 + this.formPanel.getForm().findField('nbIntervals').setValue(this.object.get('nbIntervals'));
  123 + },
  124 + generateTT: function () {
  125 + if (this.fclose()) {
  126 + Ext.Msg.confirm('Generate TT', 'Current Catalog has been modified.\nDo you want to save it to include these changes in the generated Time Table ?',
  127 + function (btn, text) {
  128 + if (btn == 'yes') {
  129 + // mark this.closed as true before the call to close() as that will fire the beforeclose event again
  130 + if (this.object.get('id') == "") {
  131 + // case of creation of catalog
  132 + this.saveCatalog(true, true);
  133 + } else {
  134 + // casse existing catalog
  135 + this.saveProcess(false, true, true);
  136 + }
  137 + return;
  138 + }
  139 + }, this);
  140 +
  141 + } else {
  142 + this.createTT(this.object.get('id'));
  143 + return;
  144 + }
  145 + },
  146 + createTT: function (catId) {
  147 + var ttObj = Ext.create('amdaModel.TimeTable');
  148 + var timeTabNode = Ext.create('amdaModel.TimeTableNode', {leaf: true});
  149 + ttObj.set('relatedCatalogId', catId)
  150 + creatDate = new Date(this.object.get('created'));
  151 + date = Ext.Date.format(creatDate, 'Y-m-d\\TH:i:s');
  152 + descr = 'Generated by CDPP/Amda Catalog Module \n' + 'From Catalog: ' + this.object.get('name') + '\nOn: ' + date + '\n';
  153 + ttObj.set('description', descr + this.object.get('description'));
  154 + timeTabNode.set('object', ttObj);
  155 + var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
  156 + var ttRootNode = explorerTree.getRootNode().findChild('id', 'timeTable-treeRootNode', true);
  157 + amdaModel.InteractiveNode.preloadNodes(ttRootNode.getRootNode(),
  158 + function ()
  159 + {
  160 + // edit newNode into Parameter Module with node as contextNode
  161 + timeTabNode.editInModule();
  162 + });
  163 + },
  164 + onAfterInit: function (result, e)
  165 + {
  166 + var me = this;
  167 + if (!result) {
  168 + myDesktopApp.errorMsg(e.message);
  169 + Ext.defer(function () {
  170 + Ext.Msg.toFront()
  171 + }, 10);
  172 +
  173 + return;
  174 + } else if (!result.success)
  175 + {
  176 + if (result.message)
  177 + myDesktopApp.errorMsg(result.message);
  178 + else
  179 + myDesktopApp.errorMsg('Unknown error during catalog cache initialisation');
  180 +
  181 + Ext.defer(function () {
  182 + Ext.Msg.toFront()
  183 + }, 10);
  184 + return;
  185 + }
  186 +
  187 + if (me.toReconfigure)
  188 + {
  189 + // clear filters
  190 + if (me.TTGrid.filters) {
  191 + me.TTGrid.getStore().clearFilter(true);
  192 + me.TTGrid.filters.clearFilters();
  193 + me.TTGrid.filters.destroy();
  194 + }
  195 +
  196 + var fieldsConfig = [
  197 + {
  198 + name: 'start',
  199 + type: 'date',
  200 + dateFormat: 'Y-m-d\\TH:i:s',
  201 + convert: function (value, rec) {
  202 + if (!Ext.isDate(value)) {
  203 + var valueString = new String(value);
  204 + return new Date(valueString.replace(/\-/g, '\/').replace(/[T|Z]/g, ' '));
  205 + }
  206 + return value;
  207 + }
  208 + },
  209 + {
  210 + name: 'stop',
  211 + type: 'date',
  212 + dateFormat: 'Y-m-d\\TH:i:s',
  213 + convert: function (value, rec) {
  214 + if (!Ext.isDate(value)) {
  215 + var valueString = new String(value);
  216 + return new Date(valueString.replace(/\-/g, '\/').replace(/[T|Z]/g, ' '));
  217 + }
  218 + return value;
  219 + }
  220 + },
  221 + {
  222 + name: 'durationHour',
  223 + type: 'float',
  224 + convert: function (value, rec) {
  225 + if (rec.get('stop') && rec.get('start') && (rec.get('stop') - rec.get('start')) >= 0) {
  226 + return (rec.get('stop') - rec.get('start')) / 3600000.0;
  227 + }
145 228 },
146   - createTT : function(catId){
147   - var ttObj = Ext.create('amdaModel.TimeTable');
148   - var timeTabNode = Ext.create('amdaModel.TimeTableNode',{leaf : true});
149   - ttObj.set('relatedCatalogId', catId)
150   - creatDate=new Date(this.object.get('created'));
151   - date=Ext.Date.format(creatDate,'Y-m-d\\TH:i:s');
152   - descr='Generated by CDPP/Amda Catalog Module \n'+ 'From Catalog: '+this.object.get('name')+'\nOn: '+date+'\n';
153   - ttObj.set('description', descr+this.object.get('description'));
154   - timeTabNode.set('object',ttObj);
155   - var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
156   - var ttRootNode = explorerTree.getRootNode().findChild('id', 'timeTable-treeRootNode', true);
157   - amdaModel.InteractiveNode.preloadNodes(ttRootNode.getRootNode(),
158   - function()
159   - {
160   - // edit newNode into Parameter Module with node as contextNode
161   - timeTabNode.editInModule();
162   - });
  229 + persist: false
  230 + },
  231 + {
  232 + name: 'durationMin',
  233 + type: 'float',
  234 + convert: function (value, rec) {
  235 + if (rec.get('stop') && rec.get('start') && (rec.get('stop') - rec.get('start')) >= 0) {
  236 + return (rec.get('stop') - rec.get('start')) / 60000.0;
  237 + }
163 238 },
164   - onAfterInit: function(result, e)
165   - {
166   - var me = this;
167   - if (!result) {
168   - myDesktopApp.errorMsg(e.message);
169   - Ext.defer(function(){Ext.Msg.toFront()},10);
170   -
171   - return;
172   - }
173   - else if (!result.success)
174   - {
175   - if (result.message)
176   - myDesktopApp.errorMsg(result.message);
177   - else
178   - myDesktopApp.errorMsg('Unknown error during catalog cache initialisation');
179   -
180   - Ext.defer(function(){Ext.Msg.toFront()},10);
181   - return;
182   - }
183   -
184   - if (me.toReconfigure)
185   - {
186   - // clear filters
187   - if (me.TTGrid.filters) {
188   - me.TTGrid.getStore().clearFilter(true);
189   - me.TTGrid.filters.clearFilters();
190   - me.TTGrid.filters.destroy();
191   - }
192   -
193   - var fieldsConfig = [
194   - {
195   - name : 'start',
196   - type : 'date',
197   - dateFormat: 'Y-m-d\\TH:i:s',
198   - convert: function(value,rec) {
199   - if (!Ext.isDate(value)){
200   - var valueString = new String(value);
201   - return new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
202   - }
203   - return value;
204   - }
205   - },
206   - {
207   - name : 'stop',
208   - type : 'date',
209   - dateFormat: 'Y-m-d\\TH:i:s',
210   - convert: function(value,rec) {
211   - if (!Ext.isDate(value)){
212   - var valueString = new String(value);
213   - return new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
214   - }
215   - return value;
216   - }
217   - },
218   - {
219   - name:'durationHour',
220   - type: 'float',
221   - convert: function(value, rec){
222   - if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) {
223   - return (rec.get('stop') - rec.get('start'))/3600000.0;
224   - }
225   - },
226   - persist: false
227   - },
228   - {
229   - name: 'durationMin',
230   - type: 'float',
231   - convert: function(value, rec){
232   - if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) {
233   - return (rec.get('stop') - rec.get('start'))/60000.0;
234   - }
235   - },
236   - persist: false
237   - },
238   - {
239   - name: 'durationSec',
240   - type: 'float',
241   - convert: function(value, rec){
242   - if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) {
243   - return (rec.get('stop') - rec.get('start'))/1000.0;
244   - }
245   - },
246   - persist: false
247   - },
248   - { name: 'cacheId', type : 'int'},
249   - { name: 'isNew', type : 'boolean', defaultValue: false },
250   - { name: 'isModified', type : 'boolean', defaultValue: false}
251   - ];
252   -
253   - var updateDurationColumnsVisibility = function(columns, visibleId) {
254   - Ext.Array.each(columns, function(item,index){
255   - // if item is a column to hide automatically
256   - if ( Ext.util.Format.substr(item.id, 0, amdaUI.CatalogUI.COL_TO_HIDE_DURATION.length) == amdaUI.CatalogUI.COL_TO_HIDE_DURATION ) {
257   - // if item isn't the column which is being declared and is not hidden
258   - if ( item.id != visibleId && !item.isHidden() ){
259   - // hide this column
260   - item.hide();
261   - }
262   - }
263   - });
264   - };
265   -
266   - var columnsConfig = [
267   - {
268   - xtype: 'rownumberer',
269   - width: 50,
270   - renderer: function(value, metaData, record){
271   - var msg = record.index + 1;
272   - if (record.get('isNew') || record.get('isModified')) {
273   - msg += ' *';
274   - metaData.style = 'font-weight: bold'
275   - }
276   - return msg;
277   - }
278   - },
279   - {
280   - xtype: 'datecolumn',
281   - text: 'Start Time',
282   - format: 'Y-m-d\\TH:i:s',
283   - sortable : true,
284   - dataIndex: 'start',
285   - width : 120,
286   - menuDisabled: false,
287   - editor : {
288   - xtype:'datefield',
289   - allowBlank:false,
290   - hideTrigger: true,
291   - format : 'Y-m-d\\TH:i:s'
292   - },
293   - filter: { type: 'date', dateFormat: 'Y-m-d' }
294   - },
295   - {
296   - xtype: 'datecolumn',
297   - text: 'Stop Time',
298   - format: 'Y-m-d\\TH:i:s',
299   - sortable : true,
300   - dataIndex: 'stop',
301   - width : 120,
302   - menuDisabled: false,
303   - editor : {
304   - xtype:'datefield',
305   - allowBlank:false,
306   - hideTrigger: true,
307   - format : 'Y-m-d\\TH:i:s'
308   - },
309   - filter: { type: 'date', dateFormat: 'Y-m-d' }
310   - },
311   - {
312   - xtype: 'gridcolumn',
313   - text: 'Duration (hour)',
314   - sortable : true,
315   - dataIndex: 'durationHour',
316   - width : 120,
317   - menuDisabled: false,
318   - hidden:true,
319   - id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'1',
320   - renderer: function(value) {
321   - return Ext.util.Format.number(value,'0.00');
322   - },
323   - listeners: {
324   - beforeshow : function(){
325   - updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'1');
326   - }
327   - },
328   - filter: { type: 'numeric'}
329   - },
330   - {
331   - xtype: 'gridcolumn',
332   - text: 'Duration (Min)',
333   - sortable : true,
334   - dataIndex: 'durationMin',
335   - width : 120,
336   - menuDisabled: false,
337   - hidden:false,
338   - id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'2',
339   - renderer: function(value) {
340   - return Ext.util.Format.number(value,'0.00');
341   - },
342   - listeners: {
343   - beforeshow : function(){
344   - updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'2');
345   - }
346   - },
347   - filter: { type: 'numeric'}
348   - },
349   - {
350   - xtype: 'gridcolumn',
351   - text: 'Duration (Sec)',
352   - sortable : true,
353   - dataIndex: 'durationSec',
354   - width : 120,
355   - menuDisabled: false,
356   - hidden:true,
357   - id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'3',
358   - renderer: function(value) {
359   - return Ext.util.Format.number(value,'0.00');
360   - },
361   - listeners: {
362   - beforeshow : function(){
363   - updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'3');
364   - }
365   - },
366   - filter: { type: 'numeric'}
367   - }
368   - ];
369   - var pramColumnWidth =120*(1-0.7*(1-1/result.parameters.length));
370   - Ext.Array.each(result.parameters, function(obj, index) {
371   - var field = {
372   - name: obj.id
373   - };
374   - var column = {
375   - text: obj.name,
376   - sortable : true,
377   - dataIndex: obj.id,
378   - menuDisabled: false
379   - };
380   - switch (obj.type) {
381   - case 0: //double
382   - field = Ext.apply({}, field, {
383   - type: 'string'
384   - });
385   - column = Ext.apply({}, column, {
386   - xtype: 'gridcolumn',
387   - width : pramColumnWidth * parseInt(obj.size),
388   - editor: 'textfield',
389   - filter: { type: 'numeric'}
390   - });
391   - break;
392   - case 1: //dateTime
393   - field = Ext.apply({}, field, {
394   - type : 'date',
  239 + persist: false
  240 + },
  241 + {
  242 + name: 'durationSec',
  243 + type: 'float',
  244 + convert: function (value, rec) {
  245 + if (rec.get('stop') && rec.get('start') && (rec.get('stop') - rec.get('start')) >= 0) {
  246 + return (rec.get('stop') - rec.get('start')) / 1000.0;
  247 + }
  248 + },
  249 + persist: false
  250 + },
  251 + {name: 'cacheId', type: 'int'},
  252 + {name: 'isNew', type: 'boolean', defaultValue: false},
  253 + {name: 'isModified', type: 'boolean', defaultValue: false}
  254 + ];
  255 +
  256 + var updateDurationColumnsVisibility = function (columns, visibleId) {
  257 + Ext.Array.each(columns, function (item, index) {
  258 + // if item is a column to hide automatically
  259 + if (Ext.util.Format.substr(item.id, 0, amdaUI.CatalogUI.COL_TO_HIDE_DURATION.length) == amdaUI.CatalogUI.COL_TO_HIDE_DURATION) {
  260 + // if item isn't the column which is being declared and is not hidden
  261 + if (item.id != visibleId && !item.isHidden()) {
  262 + // hide this column
  263 + item.hide();
  264 + }
  265 + }
  266 + });
  267 + };
  268 +
  269 + var columnsConfig = [
  270 + {
  271 + xtype: 'rownumberer',
  272 + width: 50,
  273 + renderer: function (value, metaData, record) {
  274 + var msg = record.index + 1;
  275 + if (record.get('isNew') || record.get('isModified')) {
  276 + msg += ' *';
  277 + metaData.style = 'font-weight: bold'
  278 + }
  279 + return msg;
  280 + }
  281 + },
  282 + {
  283 + xtype: 'datecolumn',
  284 + text: 'Start Time',
  285 + format: 'Y-m-d\\TH:i:s',
  286 + sortable: true,
  287 + dataIndex: 'start',
  288 + width: 120,
  289 + menuDisabled: false,
  290 + editor: {
  291 + xtype: 'datefield',
  292 + allowBlank: false,
  293 + hideTrigger: true,
  294 + format: 'Y-m-d\\TH:i:s'
  295 + },
  296 + filter: {type: 'date', dateFormat: 'Y-m-d'}
  297 + },
  298 + {
  299 + xtype: 'datecolumn',
  300 + text: 'Stop Time',
  301 + format: 'Y-m-d\\TH:i:s',
  302 + sortable: true,
  303 + dataIndex: 'stop',
  304 + width: 120,
  305 + menuDisabled: false,
  306 + editor: {
  307 + xtype: 'datefield',
  308 + allowBlank: false,
  309 + hideTrigger: true,
  310 + format: 'Y-m-d\\TH:i:s'
  311 + },
  312 + filter: {type: 'date', dateFormat: 'Y-m-d'}
  313 + },
  314 + {
  315 + xtype: 'gridcolumn',
  316 + text: 'Duration (hour)',
  317 + sortable: true,
  318 + dataIndex: 'durationHour',
  319 + width: 120,
  320 + menuDisabled: false,
  321 + hidden: true,
  322 + id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION + '1',
  323 + renderer: function (value) {
  324 + return Ext.util.Format.number(value, '0.00');
  325 + },
  326 + listeners: {
  327 + beforeshow: function () {
  328 + updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION + '1');
  329 + }
  330 + },
  331 + filter: {type: 'numeric'}
  332 + },
  333 + {
  334 + xtype: 'gridcolumn',
  335 + text: 'Duration (Min)',
  336 + sortable: true,
  337 + dataIndex: 'durationMin',
  338 + width: 120,
  339 + menuDisabled: false,
  340 + hidden: false,
  341 + id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION + '2',
  342 + renderer: function (value) {
  343 + return Ext.util.Format.number(value, '0.00');
  344 + },
  345 + listeners: {
  346 + beforeshow: function () {
  347 + updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION + '2');
  348 + }
  349 + },
  350 + filter: {type: 'numeric'}
  351 + },
  352 + {
  353 + xtype: 'gridcolumn',
  354 + text: 'Duration (Sec)',
  355 + sortable: true,
  356 + dataIndex: 'durationSec',
  357 + width: 120,
  358 + menuDisabled: false,
  359 + hidden: true,
  360 + id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION + '3',
  361 + renderer: function (value) {
  362 + return Ext.util.Format.number(value, '0.00');
  363 + },
  364 + listeners: {
  365 + beforeshow: function () {
  366 + updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION + '3');
  367 + }
  368 + },
  369 + filter: {type: 'numeric'}
  370 + }
  371 + ];
  372 + var pramColumnWidth = 120 * (1 - 0.7 * (1 - 1 / result.parameters.length));
  373 + Ext.Array.each(result.parameters, function (obj, index) {
  374 + var field = {
  375 + name: obj.id
  376 + };
  377 + var column = {
  378 + text: obj.name,
  379 + sortable: true,
  380 + dataIndex: obj.id,
  381 + menuDisabled: false
  382 + };
  383 + switch (obj.type) {
  384 + case 0: //double
  385 + field = Ext.apply({}, field, {
  386 + type: 'string'
  387 + });
  388 + column = Ext.apply({}, column, {
  389 + xtype: 'gridcolumn',
  390 + width: pramColumnWidth * parseInt(obj.size),
  391 + editor: 'textfield',
  392 + filter: {type: 'numeric'}
  393 + });
  394 + break;
  395 + case 1: //dateTime
  396 + field = Ext.apply({}, field, {
  397 + type: 'date',
395 398 dateFormat: 'Y-m-d\\TH:i:s',
396   - convert: function(value,rec) {
397   - if (!Ext.isDate(value)){
398   - var valueString = new String(value);
399   - return new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
400   - }
401   - return value;
  399 + convert: function (value, rec) {
  400 + if (!Ext.isDate(value)) {
  401 + var valueString = new String(value);
  402 + return new Date(valueString.replace(/\-/g, '\/').replace(/[T|Z]/g, ' '));
  403 + }
  404 + return value;
402 405 }
403 406  
404   - });
405   - column = Ext.apply({}, column, {
  407 + });
  408 + column = Ext.apply({}, column, {
406 409 xtype: 'datecolumn',
407   - width : 120,
408   - editor : {
409   - xtype:'datefield',
410   - allowBlank:false,
411   - hideTrigger: true,
412   - format : 'Y-m-d\\TH:i:s'
  410 + width: 120,
  411 + editor: {
  412 + xtype: 'datefield',
  413 + allowBlank: false,
  414 + hideTrigger: true,
  415 + format: 'Y-m-d\\TH:i:s'
413 416 },
414   - filter: { type: 'date', dateFormat: 'Y-m-d' }
415   - });
416   - break;
417   - case 2: //string
418   - field = Ext.apply({}, field, {
419   - type: 'string'
420   - });
421   - column = Ext.apply({}, column, {
422   - xtype: 'gridcolumn',
423   - width : pramColumnWidth * parseInt(obj.size),
424   - editor: 'textfield',
425   - filter: { type: 'string'}
426   - });
427   - break;
428   - case 3: //int
429   - field = Ext.apply({}, field, {
430   - type: 'string'
  417 + filter: {type: 'date', dateFormat: 'Y-m-d'}
  418 + });
  419 + break;
  420 + case 2: //string
  421 + field = Ext.apply({}, field, {
  422 + type: 'string'
  423 + });
  424 + column = Ext.apply({}, column, {
  425 + xtype: 'gridcolumn',
  426 + width: pramColumnWidth * parseInt(obj.size),
  427 + editor: 'textfield',
  428 + filter: {type: 'string'}
  429 + });
  430 + break;
  431 + case 3: //int
  432 + field = Ext.apply({}, field, {
  433 + type: 'string'
  434 + });
  435 + column = Ext.apply({}, column, {
  436 + xtype: 'gridcolumn',
  437 + width: pramColumnWidth * parseInt(obj.size),
  438 + editor: 'textfield',
  439 + filter: {type: 'numeric'}
  440 + });
  441 + break;
  442 + default:
  443 + field = Ext.apply({}, field, {
  444 + type: 'string'
  445 + });
  446 + column = Ext.apply({}, column, {
  447 + xtype: 'gridcolumn',
  448 + width: pramColumnWidth * parseInt(obj.size),
  449 + editor: 'textfield',
  450 + filter: {type: 'string'}
  451 + });
  452 + }
  453 + fieldsConfig.push(field);
  454 + columnsConfig.push(column);
431 455 });
432   - column = Ext.apply({}, column, {
433   - xtype: 'gridcolumn',
434   - width : pramColumnWidth * parseInt(obj.size),
435   - editor: 'textfield',
436   - filter: { type: 'numeric'}
  456 +
  457 + var store = Ext.create('Ext.data.Store', {
  458 + fields: fieldsConfig,
  459 + autoDestroy: false,
  460 + pageSize: 200,
  461 + buffered: true,
  462 + purgePageCount: 0,
  463 + remoteSort: true,
  464 + proxy: {
  465 + type: 'direct',
  466 + api: {read: AmdaAction.readCacheIntervals},
  467 + // remplir automatiquement tt, sharedtt , catalog, shared catalog
  468 + extraParams: {'typeTT': 'catalog'},
  469 + reader:
  470 + {
  471 + type: 'json',
  472 + root: 'intervals',
  473 + totalProperty: 'totalCount'
  474 + }
  475 + },
  476 + listeners: {
  477 + scope: me,
  478 + load: function (store, records) {
  479 + // myDesktopApp.EventManager.fireEvent('refresh');
  480 + me.TTGrid.getView().refresh();
  481 + me.TTGrid.getSelectionModel().refresh();
  482 + me.updateCount();
  483 + //Statistical plugin
  484 + this.fireEvent("refresh");
  485 + }
  486 + }
437 487 });
438   - break;
439   - default:
440   - field = Ext.apply({}, field, {
441   - type: 'string'
442   - });
443   - column = Ext.apply({}, column, {
444   - xtype: 'gridcolumn',
445   - width : pramColumnWidth * parseInt(obj.size),
446   - editor: 'textfield',
447   -filter: { type: 'string'}
  488 +
  489 + me.TTGrid.reconfigure(store, columnsConfig);
  490 + if (me.TTGrid.filters) {
  491 + me.TTGrid.filters.bindStore(store);
  492 + }
  493 + }
  494 + me.TTGrid.getSelectionModel().deselectAll();
  495 + //
  496 + // // clear filters
  497 + // me.TTGrid.getStore().clearFilter(true);
  498 + //
  499 + // clear sort
  500 + me.TTGrid.getStore().sorters.clear();
  501 + //me.TTGrid.getStore().sorters = new Ext.util.MixedCollection();
  502 +
  503 + //set cache token to the Catalog object
  504 + me.object.set('cacheToken', result.token);
  505 + me.setParamInfo(result.parameters);
  506 + me.TTGrid.getStore().load();
  507 +
  508 + me.status = result.status;
  509 + //Statistical plugin
  510 + me.fireEvent("refresh");
  511 + },
  512 +
  513 + /**
  514 + * load object catalog into this view
  515 + */
  516 + loadObject: function () {
  517 + // load object into form
  518 + this.formPanel.getForm().loadRecord(this.object);
  519 +
  520 + this.status = null;
  521 +
  522 + if (this.object.get('fromPlugin') && (this.object.get('objName') != '')) {
  523 + if (this.object.get('objFormat') && this.object.get('objFormat') != '') {
  524 + //From uploaded file
  525 + AmdaAction.initObjectCacheFromUploadedFile(this.object.get('objName'), this.object.get('objFormat'), this.isCatalog, this.onAfterInit, this);
  526 + } else {
  527 + //From tmp object (ie Statistics result)
  528 + AmdaAction.initObjectCacheFromTmpObject(this.object.get('folderId'), this.object.get('objName'), this.isCatalog, this.onAfterInit, this);
  529 + }
  530 + } else {
  531 + var typeTT = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id).linkedNode.data.nodeType;
  532 +
  533 + if (this.object.get('id') == '' && this.object.get('relatedTimeTableId') == '') {
  534 + // creating new catalog
  535 + AmdaAction.initObjectCache(this.isCatalog, this.object.get('nbParameters'), this.onAfterInit, this);
  536 + } else if (this.object.get('relatedTimeTableId') != '') {
  537 + // Generate Catalog from Time Table
  538 + AmdaAction.initObjectCacheFromTimeTable(this.object.get('relatedTimeTableId'), typeTT, this.object.get('nbParameters'), this.onAfterInit, this);
  539 + } else {
  540 + //From existing TT file
  541 + AmdaAction.initObjectCacheFromObject(this.object.get('id'), typeTT, this.onAfterInit, this);
  542 + }
  543 + }
  544 + //Statistical plugin
  545 + this.fireEvent("refresh");
  546 + },
  547 +
  548 + checkIntervalsStatusForSave: function (onStatusOk) {
  549 + onStatusOk();
  550 + },
  551 +
  552 + /*
  553 + * save method called by Save button
  554 + */
  555 + saveProcess: function (toRename, onAfterSave, notDisplayMsg)
  556 + {
  557 + var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
  558 + // store / columns are the same - not needed to reconfigure grid
  559 + this.toReconfigure = false;
  560 +
  561 + // if save shared catalog
  562 + if (module.contextNode && (module.contextNode.get('id') == 'sharedcatalog-treeRootNode'))
  563 + {
  564 + module.linkedNode = null;
  565 + module.createLinkedNode();
  566 + module.createObject(this.object.getJsonValues());
  567 + var obj = module.linkedNode.get('object');
  568 + // synchronisation of objects
  569 + this.object = obj;
  570 + module.linkedNode.create({notDisplayMsg: notDisplayMsg, callback: function () {
  571 + if (onAfterSave)
  572 + this.createTT(this.object.get('id'));
  573 + }, scope: this});
  574 + }
  575 + // if the name has been modified this is a creation
  576 + else if (this.fclose()) {
  577 + if (this.object.isModified('name') || this.object.get('fromPlugin')) {
  578 + // if object already has an id : it's a 'rename' of an existing
  579 + if (this.object.get('id')) {
  580 + // the context Node is the parent node of current edited one
  581 + var contextNode = module.linkedNode.parentNode;
  582 + // link a new node to the TimeTableModule
  583 + module.createLinkedNode();
  584 + // set the contextNode
  585 + module.linkedNode.set('contextNode', contextNode);
  586 + // create a new object linked
  587 + module.createObject(this.object.getJsonValues());
  588 +
  589 + var obj = module.linkedNode.get('object');
  590 + // synchronisation of objects
  591 + this.object = obj;
  592 + if (toRename)
  593 + module.linkedNode.toRename = true;
  594 + }
  595 + module.linkedNode.create({callback: function () {
  596 + module.linkedNode.update({notDisplayMsg: notDisplayMsg, callback: function () {
  597 + if (onAfterSave)
  598 + this.createTT(this.object.get('id'));
  599 + }, scope: this}, "", notDisplayMsg);
  600 + }, scope: this});
  601 + } else {
  602 + //update
  603 + module.linkedNode.update({notDisplayMsg: notDisplayMsg, callback: function () {
  604 + if (onAfterSave)
  605 + this.createTT(this.object.get('id'));
  606 + }, scope: this});
  607 + }
  608 + }
  609 + },
  610 + saveCatalog: function (onAfterSave, notDisplayMsg) {
  611 + if (this.updateObject())
  612 + {
  613 + var basicForm = this.formPanel.getForm();
  614 + // if there's at least one record in the store of TTGrid
  615 + if (this.TTGrid.getStore().getTotalCount() > 0)
  616 + {
  617 + // update TimeTable object which the content of form
  618 + basicForm.updateRecord(this.object);
  619 +
  620 + var me = this;
  621 + this.checkIntervalsStatusForSave(function () {
  622 + //Name validation
  623 + var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
  624 +
  625 + if (!module)
  626 + return;
  627 + module.linkedNode.isValidName(me.fieldName.getValue(), function (res)
  628 + {
  629 + if (!res) {
  630 + me.fieldName.validFlag = 'Error during object validation';
  631 + myDesktopApp.errorMsg(me.fieldName.validFlag);
  632 + me.fieldName.validate();
  633 + return;
  634 + }
  635 +
  636 + if (!res.valid) {
  637 + if (res.error) {
  638 + if (res.error.search('subtree') != -1) {
  639 + Ext.MessageBox.show({title: 'Warning',
  640 + msg: res.error + '<br/>Do you want to overwrite it?',
  641 + width: 300,
  642 + buttons: Ext.MessageBox.OKCANCEL,
  643 + fn: me.overwriteProcess,
  644 + icon: Ext.MessageBox.WARNING,
  645 + scope: me
  646 + });
  647 + me.fieldName.validFlag = true;
  648 + } else
  649 + me.fieldName.validFlag = res.error;
  650 + } else {
  651 + me.fieldName.validFlag = 'Invalid object name';
  652 + myDesktopApp.errorMsg(me.fieldName.validFlag);
  653 + }
  654 + me.fieldName.validate();
  655 + return;
  656 + }
  657 +
  658 + me.fieldName.validFlag = true;
  659 + me.fieldName.validate();
  660 + me.saveProcess(false, onAfterSave, notDisplayMsg);
  661 + });
448 662 });
449   -}
450   -fieldsConfig.push(field);
451   -columnsConfig.push(column);
452   -});
  663 + } else {
  664 + Ext.Msg.alert('No intervals', 'Your catalog is invalid, <br>you must have at least one interval');
  665 + }
  666 + }
  667 + },
  668 +
  669 + /**
  670 + * overwrite metod called by Save button
  671 + */
  672 + overwriteProcess: function (btn) {
  673 + if (btn == 'cancel')
  674 + return;
  675 +
  676 + this.fieldName.clearInvalid();
  677 + this.saveProcess(true);
  678 + },
  679 +
  680 + /**
  681 + * Check if changes were made before closing window
  682 + * @return true if changes
  683 + */
  684 + fclose: function () {
  685 + if (this.status == null)
  686 + return false;
  687 +
  688 + var isDirty = this.formPanel.getForm().isDirty() || (this.status.isModified) || (this.status.nbModified > 0) || (this.status.nbNew > 0);
  689 + return isDirty;
  690 + },
  691 +
  692 + init: function (config)
  693 + {
  694 + this.object = config.object;
  695 +
  696 + this.fieldName = new Ext.form.field.Text({
  697 + fieldLabel: 'Name',
  698 + allowBlank: false,
  699 + stripCharsRe: /(^\s+|\s+$)/g,
  700 + emptyText: 'Please no spaces!',
  701 + name: 'name',
  702 + validateOnChange: false,
  703 + validateOnBlur: false,
  704 + validFlag: false,
  705 + validator: function () {
  706 + return this.validFlag;
  707 + }
  708 + });
453 709  
454   - var store = Ext.create('Ext.data.Store', {
455   - fields: fieldsConfig,
456   - autoDestroy: false,
457   - pageSize : 200,
458   - buffered : true,
459   - purgePageCount: 0,
460   - remoteSort: true,
461   - proxy: {
462   - type: 'direct',
463   - api : { read : AmdaAction.readCacheIntervals },
464   - // remplir automatiquement tt, sharedtt , catalog, shared catalog
465   - extraParams : {'typeTT' : 'catalog'},
466   - reader:
467   - {
468   - type: 'json',
469   - root: 'intervals',
470   - totalProperty : 'totalCount'
471   - }
472   - },
473   - listeners: {
474   - scope : me,
475   - load: function(store,records) {
476   - // myDesktopApp.EventManager.fireEvent('refresh');
477   - me.TTGrid.getView().refresh();
478   - me.TTGrid.getSelectionModel().refresh();
479   - me.updateCount();
480   - //Statistical plugin
481   - this.fireEvent("refresh");
482   - }
483   - }
484   - });
485   -
486   - me.TTGrid.reconfigure(store, columnsConfig);
487   - if (me.TTGrid.filters) {
488   - me.TTGrid.filters.bindStore(store);
489   - }
490   - }
491   - me.TTGrid.getSelectionModel().deselectAll();
492   - //
493   - // // clear filters
494   - // me.TTGrid.getStore().clearFilter(true);
495   - //
496   - // clear sort
497   - me.TTGrid.getStore().sorters.clear();
498   - //me.TTGrid.getStore().sorters = new Ext.util.MixedCollection();
499   -
500   - //set cache token to the Catalog object
501   - me.object.set('cacheToken', result.token);
502   - me.setParamInfo(result.parameters);
503   - me.TTGrid.getStore().load();
504   -
505   - me.status = result.status;
506   - //Statistical plugin
507   - me.fireEvent("refresh");
508   - },
509   -
510   - /**
511   - * load object catalog into this view
512   - */
513   - loadObject : function(){
514   - // load object into form
515   - this.formPanel.getForm().loadRecord(this.object);
516   -
517   - this.status = null;
518   -
519   - if (this.object.get('fromPlugin') && (this.object.get('objName') != '')){
520   - if (this.object.get('objFormat') && this.object.get('objFormat') != ''){
521   - //From uploaded file
522   - AmdaAction.initObjectCacheFromUploadedFile(this.object.get('objName'), this.object.get('objFormat'), this.isCatalog, this.onAfterInit, this);
523   - }
524   - else {
525   - //From tmp object (ie Statistics result)
526   - AmdaAction.initObjectCacheFromTmpObject(this.object.get('folderId'), this.object.get('objName'), this.isCatalog, this.onAfterInit, this);
527   - }
528   - }
529   - else {
530   - var typeTT = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id).linkedNode.data.nodeType;
531   -
532   - if (this.object.get('id') == '' && this.object.get('relatedTimeTableId') == '') {
533   - // creating new catalog
534   - AmdaAction.initObjectCache(this.isCatalog, this.object.get('nbParameters'), this.onAfterInit,this);
535   - }
536   - else if(this.object.get('relatedTimeTableId') != ''){
537   - // Generate Catalog from Time Table
538   - AmdaAction.initObjectCacheFromTimeTable(this.object.get('relatedTimeTableId'), typeTT, this.object.get('nbParameters'),this.onAfterInit, this);
539   - }
540   - else {
541   - //From existing TT file
542   - AmdaAction.initObjectCacheFromObject(this.object.get('id'), typeTT, this.onAfterInit, this);
543   - }
544   - }
545   - //Statistical plugin
546   - this.fireEvent("refresh");
547   - },
548   -
549   - checkIntervalsStatusForSave : function(onStatusOk) {
550   - onStatusOk();
551   - },
552   -
553   - /*
554   - * save method called by Save button
555   - */
556   - saveProcess : function(toRename, onAfterSave, notDisplayMsg)
557   - {
558   - var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
559   - // store / columns are the same - not needed to reconfigure grid
560   - this.toReconfigure = false;
561   -
562   - // if save shared catalog
563   - if (module.contextNode && (module.contextNode.get('id') == 'sharedcatalog-treeRootNode'))
564   - {
565   - module.linkedNode = null;
566   - module.createLinkedNode();
567   - module.createObject(this.object.getJsonValues());
568   - var obj = module.linkedNode.get('object');
569   - // synchronisation of objects
570   - this.object = obj;
571   - module.linkedNode.create({notDisplayMsg:notDisplayMsg, callback : function() {if (onAfterSave) this.createTT(this.object.get('id'));}, scope : this});
572   - }
573   - // if the name has been modified this is a creation
574   - else if (this.fclose()) {
575   - if (this.object.isModified('name') || this.object.get('fromPlugin')) {
576   - // if object already has an id : it's a 'rename' of an existing
577   - if (this.object.get('id')){
578   - // the context Node is the parent node of current edited one
579   - var contextNode = module.linkedNode.parentNode;
580   - // link a new node to the TimeTableModule
581   - module.createLinkedNode();
582   - // set the contextNode
583   - module.linkedNode.set('contextNode',contextNode);
584   - // create a new object linked
585   - module.createObject(this.object.getJsonValues());
586   -
587   - var obj = module.linkedNode.get('object');
588   - // synchronisation of objects
589   - this.object = obj;
590   - if (toRename) module.linkedNode.toRename = true;
591   - }
592   - module.linkedNode.create({callback : function() {module.linkedNode.update({notDisplayMsg:notDisplayMsg, callback : function() {if (onAfterSave) this.createTT(this.object.get('id'));}, scope : this},"",notDisplayMsg);}, scope : this});
593   - } else {
594   - //update
595   - module.linkedNode.update({notDisplayMsg:notDisplayMsg,callback : function() {if (onAfterSave) this.createTT(this.object.get('id'));}, scope : this});
596   - }
597   - }
598   - },
599   - saveCatalog : function (onAfterSave,notDisplayMsg){
600   - if (this.updateObject())
601   - {
602   - var basicForm = this.formPanel.getForm();
603   - // if there's at least one record in the store of TTGrid
604   - if (this.TTGrid.getStore().getTotalCount() > 0)
605   - {
606   - // update TimeTable object which the content of form
607   - basicForm.updateRecord(this.object);
  710 + var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
  711 +// clicksToEdit: 2,
  712 + onEditComplete: function (ed, value, startValue) {
  713 + var me = this,
  714 + activeColumn = me.getActiveColumn(),
  715 + context = me.context,
  716 + record;
  717 +
  718 + if (activeColumn) {
  719 + record = context.record;
  720 +
  721 + me.setActiveEditor(null);
  722 + me.setActiveColumn(null);
  723 + me.setActiveRecord(null);
  724 +
  725 + context.value = value;
  726 + if (!me.validateEdit()) {
  727 + me.editing = false;
  728 + return;
  729 + }
  730 +
  731 + // Only update the record if the new value is different than the
  732 + // startValue. When the view refreshes its el will gain focus
  733 + if (!record.isEqual(value, startValue)) {
  734 + var obj = {
  735 + 'cacheId': record.get('cacheId'),
  736 + 'isCatalog': true,
  737 + 'data': {}
  738 + };
  739 + obj['data'][activeColumn.dataIndex] = value;
  740 +
  741 + //Interval is modified on the server side
  742 + me.editing = true;
  743 +
  744 + AmdaAction.modifyCacheInterval(obj, function (result, e) {
  745 + var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
  746 + if (module)
  747 + module.getUiContent().status = result.status;
  748 + if (!context.store.loading) {
  749 + context.grid.getSelectionModel().deselectAll();
  750 + context.store.reload({
  751 + callback: function (records, options, success) {
  752 + context.view.bufferedRenderer.scrollTo(context.rowIdx, true, function () {
  753 + me.fireEvent('edit', me, context);
  754 + me.editing = false;
  755 + }, me);
  756 + }
  757 + });
  758 + } else {
  759 + me.editing = false;
  760 + }
  761 + }, this);
  762 + } else
  763 + me.editing = false;
  764 + }
  765 + }
  766 + });
  767 +
  768 + var filters = {
  769 + ftype: 'filters',
  770 + encode: true, // json encode the filter query
  771 + local: false,
  772 + filters: [
  773 +
  774 + ]
  775 + };
  776 +
  777 + this.TTGrid = Ext.create('Ext.grid.Panel', {
  778 + height: 530,
  779 + features: [filters],
  780 + columns: [],
  781 + frame: true,
  782 + columnLines: true,
  783 + selModel: {pruneRemoved: false},
  784 + // selType: 'cellmodel',
  785 + plugins: [cellEditing, {ptype: 'bufferedrenderer'}],
  786 + dockedItems: [{
  787 + xtype: 'toolbar',
  788 + items: [{
  789 + iconCls: 'icon-add',
  790 + scope: this,
  791 + handler: function () {
  792 + cellEditing.cancelEdit();
  793 + var store = this.TTGrid.getStore();
  794 +
  795 + var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
  796 + var row = 0;
  797 + if (selection)
  798 + row = store.indexOf(selection) + 1;
  799 + this.TTGrid.getSelectionModel().deselectAll();
608 800  
609 801 var me = this;
610   - this.checkIntervalsStatusForSave(function () {
611   - //Name validation
  802 + AmdaAction.addCacheInterval({'index': row, 'isCatalog': true}, function (result, e) {
  803 + this.status = result.status;
  804 + if (!this.TTGrid.getStore().loading) {
  805 + this.TTGrid.getStore().reload({
  806 + callback: function (records, options, success) {
  807 + me.TTGrid.getView().bufferedRenderer.scrollTo(row, false, function () {
  808 + me.TTGrid.getView().select(row);
  809 + cellEditing.startEditByPosition({row: row, column: 1});
  810 + }, me);
  811 + }
  812 + });
  813 + }
  814 + }, this);
  815 + }
  816 + }, {
  817 + iconCls: 'icon-delete',
  818 + disabled: true,
  819 + itemId: 'delete',
  820 + scope: this,
  821 + handler: function () {
  822 + var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
  823 + if (selection)
  824 + {
  825 + var rowId = selection.get('cacheId');
  826 + this.TTGrid.getSelectionModel().deselectAll();
  827 + AmdaAction.removeTTCacheIntervalFromId(rowId, this.isCatalog, function (result, e) {
  828 + this.status = result.status;
  829 + if (!this.TTGrid.getStore().loading) {
  830 + this.TTGrid.getStore().reload();
  831 + }
  832 + }, this);
  833 + }
  834 + }
  835 + }, '->',
  836 + {
  837 + text: 'Clear Filters',
  838 + scope: this,
  839 + handler: function () {
  840 + this.TTGrid.getStore().clearFilter(true);
  841 + this.TTGrid.filters.clearFilters();
  842 + }
  843 + }]
  844 + }]
  845 + });
  846 +
  847 + this.formPanel = Ext.create('Ext.form.Panel', {
  848 + region: 'center',
  849 + layout: 'hbox',
  850 + model: 'amdaModel.Catalog',
  851 + trackResetOnLoad: true, // reset to the last loaded record
  852 + bodyStyle: {background: '#dfe8f6'},
  853 + defaults: {border: false, align: 'stretch', bodyStyle: {background: '#dfe8f6'}, padding: '3'},
  854 + fieldDefaults: {labelWidth: 80, labelAlign: 'top'},
  855 + items: [{
  856 + xtype: 'form',
  857 + flex: 1,
  858 + buttonAlign: 'left',
  859 + // title : 'Information',
  860 + layout: {type: 'vbox', pack: 'start', align: 'stretch'},
  861 + items: [
  862 + this.fieldName,
  863 + {
  864 + xtype: 'fieldcontainer',
  865 + layout: 'hbox',
  866 + items: [{
  867 + xtype: 'datefield', fieldLabel: 'Creation date',
  868 + name: 'created', disabled: true,
  869 + hideTrigger: true, format: 'Y/m/d H:i:s'
  870 + },
  871 + {xtype: 'splitter'},
  872 + {xtype: 'textfield', fieldLabel: 'Intervals', name: 'nbIntervals', disabled: true}
  873 + ]
  874 + },
  875 + {
  876 + xtype: 'textarea',
  877 + name: 'description',
  878 + fieldLabel: 'Description',
  879 + height: 200
  880 + },
  881 + {
  882 + xtype: 'component',
  883 + height: 90
  884 + }],
  885 + dockedItems: [
  886 + {
  887 + xtype: 'toolbar',
  888 + dock: 'bottom',
  889 + ui: 'footer',
  890 + height: 140,
  891 +
  892 + items: [
  893 + {
  894 + type: 'button',
  895 + text: 'Save',
  896 + width: 50,
  897 + scope: this,
  898 + handler: function ()
  899 + {
  900 + this.saveCatalog();
  901 + }
  902 + }, {
  903 + type: 'button',
  904 + text: 'Reset',
  905 + width: 50,
  906 + scope: this,
  907 + handler: function () {
  908 + var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
  909 + // module.createLinkedNode();
  910 + // module.createObject();
  911 + this.setObject(module.getLinkedNode().get('object'), true);
  912 + }
  913 + },
  914 + {
  915 + type: 'button',
  916 + text: 'Create New Catalog',
  917 + width: 120,
  918 + scope: this,
  919 + handler: function ()
  920 + {
612 921 var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
613 922  
614   - if (!module) return;
615   - module.linkedNode.isValidName(me.fieldName.getValue(), function (res)
616   - {
617   - if (!res) {
618   - me.fieldName.validFlag = 'Error during object validation';
619   - myDesktopApp.errorMsg(me.fieldName.validFlag);
620   - me.fieldName.validate();
621   - return;
622   - }
  923 + if (!module)
  924 + return;
  925 +
  926 + module.createLinkedNode();
  927 + module.createObject();
  928 +
  929 + var obj = module.linkedNode.get('object');
  930 +
  931 + var me = this;
623 932  
624   - if (!res.valid) {
625   - if (res.error) {
626   - if (res.error.search('subtree') != -1) {
627   - Ext.MessageBox.show({title:'Warning',
628   - msg: res.error+'<br/>Do you want to overwrite it?',
629   - width: 300,
630   - buttons: Ext.MessageBox.OKCANCEL,
631   - fn : me.overwriteProcess,
632   - icon: Ext.MessageBox.WARNING,
633   - scope : me
634   - });
635   - me.fieldName.validFlag = true;
636   - }
637   - else
638   - me.fieldName.validFlag = res.error;
639   - }
640   - else {
641   - me.fieldName.validFlag = 'Invalid object name';
642   - myDesktopApp.errorMsg(me.fieldName.validFlag);
643   - }
644   - me.fieldName.validate();
645   - return;
  933 + Ext.Msg.prompt('Create catalog', 'Enter the number of columns:', function (btn, text) {
  934 + if (btn == 'ok') {
  935 + module.createLinkedNode();
  936 + module.createObject();
  937 + var obj = module.linkedNode.get('object');
  938 +
  939 + var nbParam = parseInt(text);
  940 + if ((nbParam <= 0) || (nbParam > 100)) {
  941 + nbParam = 1;
646 942 }
647 943  
648   - me.fieldName.validFlag = true;
649   - me.fieldName.validate();
650   - me.saveProcess(false, onAfterSave,notDisplayMsg);
  944 + obj.set('nbParameters', nbParam);
  945 + me.setObject(obj, true);
  946 + }
  947 + }, this);
  948 +
  949 + }
  950 + }]
  951 + },
  952 +
  953 +
  954 + //statistical info
  955 + {
  956 + xtype: 'toolbar',
  957 + dock: 'bottom',
  958 + ui: 'footer',
  959 + items: [{
  960 + xtype: 'button',
  961 + text: 'Statistical info',
  962 + scope: this,
  963 + //dock: 'bottom',
  964 + //ui: 'footer',
  965 + handler: function () {
  966 + this.fireEvent('info', 'catalogUI');
  967 + }
  968 + },
  969 + {
  970 + type: 'button',
  971 + text: 'Visualize',
  972 + scope: this,
  973 + handler: function () {
  974 + var me = this;
  975 + myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.visu.id, true, function (module) {
  976 + //temporary linked node - as Visu module is 'pseudo' interactive - no 'save', no 'execute'
  977 + var temporaryNode = Ext.create('amdaModel.CatalogNode', {leaf: true});
  978 + if (temporaryNode)
  979 + temporaryNode.set('object', me.object);
  980 + module.setLinkedNode(temporaryNode);
  981 +
  982 + module.createWindow();
651 983 });
652   - });
653   - }
654   - else {
655   - Ext.Msg.alert('No intervals', 'Your catalog is invalid, <br>you must have at least one interval');
656   - }
  984 + }
  985 + }
  986 + ]
  987 + },
  988 + {
  989 + xtype: 'toolbar',
  990 + dock: 'bottom',
  991 + ui: 'footer',
  992 + items: [{
  993 + xtype: 'button',
  994 + text: 'Generate Time Table',
  995 + scope: this,
  996 + //dock: 'bottom',
  997 + //ui: 'footer',
  998 + handler: function () {
  999 + this.generateTT(this.object.get('id'));
  1000 + }
  1001 + }]},
  1002 + ],
  1003 +
  1004 + },
  1005 + {
  1006 + xtype: 'form',
  1007 + bodyStyle: {background: '#dfe8f6'},
  1008 + //padding: '3',
  1009 + flex: 2,
  1010 + items: [this.TTGrid]
  1011 + }]
  1012 + });
  1013 +
  1014 + this.TTGrid.getSelectionModel().on('selectionchange', function (selModel, selections) {
  1015 + this.TTGrid.down('#delete').setDisabled(selections.length === 0);
  1016 + }, this);
  1017 +
  1018 + var myConf = {
  1019 + layout: 'border',
  1020 + items: [
  1021 + this.formPanel,
  1022 + {
  1023 + xtype: 'panel',
  1024 + region: 'south',
  1025 + title: 'Information',
  1026 + collapsible: true,
  1027 + collapseMode: 'header',
  1028 + height: 100,
  1029 + autoHide: false,
  1030 + bodyStyle: 'padding:5px',
  1031 + iconCls: 'icon-information',
  1032 + loader:
  1033 + {
  1034 + autoLoad: true,
  1035 + url: helpDir + 'catalogHOWTO'
  1036 + }
657 1037 }
658   - },
659   -
660   - /**
661   - * overwrite metod called by Save button
662   - */
663   - overwriteProcess : function(btn) {
664   - if (btn == 'cancel') return;
665   -
666   - this.fieldName.clearInvalid();
667   - this.saveProcess(true);
668   - },
669   -
670   - /**
671   - * Check if changes were made before closing window
672   - * @return true if changes
673   - */
674   - fclose : function() {
675   - if (this.status == null)
676   - return false;
677   -
678   - var isDirty = this.formPanel.getForm().isDirty() || (this.status.isModified) || (this.status.nbModified > 0) || (this.status.nbNew > 0);
679   - return isDirty;
680   - },
681   -
682   - init : function (config)
683   - {
684   - this.object = config.object;
685   -
686   - this.fieldName = new Ext.form.field.Text({
687   - fieldLabel: 'Name',
688   - allowBlank : false,
689   - stripCharsRe: /(^\s+|\s+$)/g,
690   - emptyText: 'Please no spaces!',
691   - name: 'name',
692   - validateOnChange: false,
693   - validateOnBlur: false,
694   - validFlag: false,
695   - validator : function() {
696   - return this.validFlag;
697   - }
698   - });
699   -
700   - var cellEditing = Ext.create('Ext.grid.plugin.CellEditing',{
701   -// clicksToEdit: 2,
702   - onEditComplete : function(ed, value, startValue) {
703   - var me = this,
704   - activeColumn = me.getActiveColumn(),
705   - context = me.context,
706   - record;
707   -
708   - if (activeColumn) {
709   - record = context.record;
710   -
711   - me.setActiveEditor(null);
712   - me.setActiveColumn(null);
713   - me.setActiveRecord(null);
714   -
715   - context.value = value;
716   - if (!me.validateEdit()) {
717   - me.editing = false;
718   - return;
719   - }
720   -
721   - // Only update the record if the new value is different than the
722   - // startValue. When the view refreshes its el will gain focus
723   - if (!record.isEqual(value, startValue)) {
724   - var obj = {
725   - 'cacheId' : record.get('cacheId'),
726   - 'isCatalog' : true,
727   - 'data' : {}
728   - };
729   - obj['data'][activeColumn.dataIndex] = value;
730   -
731   - //Interval is modified on the server side
732   - me.editing = true;
733   -
734   - AmdaAction.modifyCacheInterval(obj, function (result, e) {
735   - var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
736   - if (module)
737   - module.getUiContent().status = result.status;
738   - if (!context.store.loading) {
739   - context.grid.getSelectionModel().deselectAll();
740   - context.store.reload({
741   - callback : function(records, options, success) {
742   - context.view.bufferedRenderer.scrollTo(context.rowIdx, true, function() {
743   - me.fireEvent('edit', me, context);
744   - me.editing = false;
745   - }, me);
746   - }
747   - });
748   - }
749   - else {
750   - me.editing = false;
751   - }
752   - }, this);
753   - }
754   - else
755   - me.editing = false;
756   - }
757   - }
758   - });
759   -
760   - var filters = {
761   - ftype: 'filters',
762   - encode: true, // json encode the filter query
763   - local: false,
764   - filters: [
765   -
766   - ]
767   - };
768   -
769   - this.TTGrid = Ext.create('Ext.grid.Panel', {
770   - height: 530,
771   - features: [filters],
772   - columns: [ ],
773   - frame: true,
774   - columnLines: true,
775   - selModel: {pruneRemoved: false},
776   - // selType: 'cellmodel',
777   - plugins: [ cellEditing, { ptype : 'bufferedrenderer'} ],
778   - dockedItems: [{
779   - xtype: 'toolbar',
780   - items: [{
781   - iconCls: 'icon-add',
782   - scope: this,
783   - handler: function(){
784   - cellEditing.cancelEdit();
785   - var store = this.TTGrid.getStore();
786   -
787   - var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
788   - var row = 0;
789   - if (selection)
790   - row = store.indexOf(selection) + 1;
791   - this.TTGrid.getSelectionModel().deselectAll();
792   -
793   - var me = this;
794   - AmdaAction.addCacheInterval({'index' : row, 'isCatalog' : true}, function (result, e) {
795   - this.status = result.status;
796   - if (!this.TTGrid.getStore().loading) {
797   - this.TTGrid.getStore().reload({
798   - callback : function(records, options, success) {
799   - me.TTGrid.getView().bufferedRenderer.scrollTo(row, false, function() {
800   - me.TTGrid.getView().select(row);
801   - cellEditing.startEditByPosition({row: row, column: 1});
802   - }, me);
803   - }
804   - });
805   - }
806   - }, this);
807   - }
808   - },{
809   - iconCls: 'icon-delete',
810   - disabled: true,
811   - itemId: 'delete',
812   - scope: this,
813   - handler: function(){
814   - var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
815   - if (selection)
816   - {
817   - var rowId = selection.get('cacheId');
818   - this.TTGrid.getSelectionModel().deselectAll();
819   - AmdaAction.removeTTCacheIntervalFromId(rowId, this.isCatalog, function (result, e) {
820   - this.status = result.status;
821   - if (!this.TTGrid.getStore().loading) {
822   - this.TTGrid.getStore().reload();
823   - }
824   - }, this);
825   - }
826   - }
827   - },'->',
828   - {
829   - text: 'Clear Filters',
830   - scope: this,
831   - handler: function () {
832   - this.TTGrid.getStore().clearFilter(true);
833   - this.TTGrid.filters.clearFilters();
834   - }
835   - }]
836   - }]
837   - });
838   -
839   - this.formPanel = Ext.create('Ext.form.Panel', {
840   - region : 'center',
841   - layout: 'hbox',
842   - model : 'amdaModel.Catalog',
843   - trackResetOnLoad : true, // reset to the last loaded record
844   - bodyStyle: {background : '#dfe8f6'},
845   - defaults: { border : false, align: 'stretch', bodyStyle: {background : '#dfe8f6'}, padding: '3'},
846   - fieldDefaults: { labelWidth: 80, labelAlign : 'top' },
847   - items: [{
848   - xtype: 'form',
849   - flex: 1,
850   - buttonAlign: 'left',
851   - // title : 'Information',
852   - layout: {type: 'vbox', pack: 'start', align: 'stretch'},
853   - items : [
854   - this.fieldName,
855   - {
856   - xtype: 'fieldcontainer',
857   - layout: 'hbox',
858   - items: [{
859   - xtype:'datefield', fieldLabel:'Creation date',
860   - name: 'created', disabled: true,
861   - hideTrigger: true, format: 'Y/m/d H:i:s'
862   - },
863   - { xtype: 'splitter' },
864   - { xtype:'textfield', fieldLabel: 'Intervals', name: 'nbIntervals', disabled: true }
865   - ]
866   - },
867   - {
868   - xtype: 'textarea',
869   - name: 'description',
870   - fieldLabel: 'Description',
871   - height: 200
872   - },
873   - {
874   - xtype: 'component',
875   - height: 90
876   - }],
877   - dockedItems:[{
878   - xtype: 'toolbar',
879   - dock: 'bottom',
880   - ui: 'footer',
881   - items: [{
882   - type: 'button',
883   - text: 'Create New Catalog',
884   - scope : this,
885   - handler: function ()
886   - {
887   - var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
888   -
889   - if (!module) return;
890   -
891   - module.createLinkedNode();
892   - module.createObject();
893   -
894   - var obj = module.linkedNode.get('object');
895   -
896   - var me = this;
897   -
898   - Ext.Msg.prompt('Create catalog', 'Enter the number of columns:', function(btn, text){
899   - if (btn == 'ok'){
900   - module.createLinkedNode();
901   - module.createObject();
902   - var obj = module.linkedNode.get('object');
903   -
904   - var nbParam = parseInt(text);
905   - if ((nbParam <= 0) || (nbParam > 100)) {
906   - nbParam = 1;
907   - }
908   -
909   - obj.set('nbParameters', nbParam);
910   - me.setObject(obj,true);
911   - }
912   - }, this);
913   -
914   - }
915   - }]
916   - },
917   -
918   - {
919   - xtype: 'toolbar',
920   - dock: 'bottom',
921   - ui: 'footer',
922   - items: [
923   - {
924   - type: 'button',
925   - text: 'Save',
926   - scope : this,
927   - handler: function ()
928   - {
929   - this.saveCatalog();
930   -
931   - }
932   - },{
933   - type: 'button',
934   - text: 'Reset',
935   - scope : this,
936   - handler: function() {
937   - var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
938   -// module.createLinkedNode();
939   -// module.createObject();
940   - this.setObject(module.getLinkedNode().get('object'), true);
941   - }
942   - },
943   -// {
944   -// type: 'button',
945   -// text: 'Share',
946   -// scope : this,
947   -// handler: function() {
948   -// var me = this;
949   -// myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id, true, function (module) {
950   -// var catalog = module.getLinkedNode().get('object');
951   -// module.shareCatalog({'name' : catalog.get('text'), 'id' : catalog.get('id')});
952   -// });
953   -// }
954   -// },
955   -
956   - ]
957   - },
958   - //statistical info
959   - {
960   - xtype: 'toolbar',
961   - dock: 'bottom',
962   - ui: 'footer',
963   - items:[{
964   - xtype: 'button',
965   - text: 'Statistical info',
966   - scope: this,
967   - //dock: 'bottom',
968   - //ui: 'footer',
969   - handler: function() {
970   - this.fireEvent('info','catalogUI');
971   - }
972   - },
973   - {
974   - type: 'button',
975   - text: 'Visualize',
976   - scope: this,
977   - handler: function() {
978   - var me = this;
979   - myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.visu.id, true, function (module) {
980   - //temporary linked node - as Visu module is 'pseudo' interactive - no 'save', no 'execute'
981   - var temporaryNode = Ext.create('amdaModel.CatalogNode', { leaf : true });
982   - if (temporaryNode) temporaryNode.set('object',me.object);
983   - module.setLinkedNode(temporaryNode);
984   -
985   - module.createWindow();
986   - });
987   - }
988   - }
989   - ]
990   - },
991   - {
992   - xtype: 'toolbar',
993   - dock: 'bottom',
994   - ui: 'footer',
995   - items:[{
996   - xtype: 'button',
997   - text: 'Generate Time Table',
998   - scope: this,
999   - //dock: 'bottom',
1000   - //ui: 'footer',
1001   - handler: function() {
1002   - this.generateTT(this.object.get('id'));
1003   - }
1004   - }]},
1005   - ]
1006   - },
1007   - {
1008   - xtype: 'form',
1009   - bodyStyle: {background : '#dfe8f6'},
1010   - //padding: '3',
1011   - flex: 2,
1012   - items : [ this.TTGrid ]
1013   - }]
1014   - });
1015   -
1016   - this.TTGrid.getSelectionModel().on('selectionchange', function(selModel,selections) {
1017   - this.TTGrid.down('#delete').setDisabled(selections.length === 0);
1018   - }, this);
1019   -
1020   - var myConf = {
1021   - layout: 'border',
1022   - items: [
1023   - this.formPanel,
1024   - {
1025   - xtype: 'panel',
1026   - region: 'south',
1027   - title: 'Information',
1028   - collapsible: true,
1029   - collapseMode: 'header',
1030   - height: 100,
1031   - autoHide: false,
1032   - bodyStyle: 'padding:5px',
1033   - iconCls: 'icon-information',
1034   - loader:
1035   - {
1036   - autoLoad: true,
1037   - url: helpDir+'catalogHOWTO'
1038   - }
1039   - }
1040   - ] ,
1041   - plugins: [ {ptype: 'statisticalPlugin'} ]
1042   - };
1043   - Ext.apply (this, Ext.apply(arguments, myConf));
1044   - }
  1038 + ],
  1039 + plugins: [{ptype: 'statisticalPlugin'}]
  1040 + };
  1041 + Ext.apply(this, Ext.apply(arguments, myConf));
  1042 + }
1045 1043  
1046 1044 });
... ...