InsertToTTCatlog.js
16.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
Ext.define('amdaPlotComp.intervalSelection.InsertToTTCatlog', {
extend: 'Ext.form.FieldSet',
collapsible: true,
layout: LAYOUT_STYLE,
title: 'Add in Time Table or Catalog',
name: 'tt-insertion-fieldset',
fieldTypeTTCat: 'ttcat-type',
fieldTypeName: 'ttcat-name',
ttModuleId: 'timetab-win',
catModuleId: 'catalog-win',
linkedTTCatNode: null,
parent: null,
initComponent: function () {
const self = this;
const insertTypeStore = Ext.create('Ext.data.Store', {
fields: ['key', 'name'],
data: [
{ "key": "timeTable", "name": "TimeTable" },
{ "key": "catalog", "name": "Catalog" }
]
});
Ext.apply(self, {
items: [{
xtype: 'combo',
fieldLabel: 'Insert In',
store: insertTypeStore,
queryMode: 'local',
displayField: 'name',
valueField: 'key',
editable: false,
value: 'timeTable',
name: self.fieldTypeTTCat,
itemId: self.fieldTypeTTCat,
},
{
xtype: 'combo',
fieldLabel: 'Name',
editable: true,
hideTrigger: true,
store: Ext.create('Ext.data.Store', {
fields: ['text']
}),
name: self.fieldTypeName,
itemId: self.fieldTypeName,
queryMode: 'local',
displayField: 'text',
valueField: 'text',
listeners: {
render: function (o, op) {
var field = this;
var el = this.el;
Ext.create('Ext.dd.DropTarget', el, {
ddGroup: 'explorerTree',
notifyOver: function (ddSource, e, data) {
var TTCatType = self._getFieldTypeTTCat().getValue();
if (data.records[0].data.leaf && (data.records[0].data.nodeType == TTCatType)) {
this.valid = true;
return this.dropAllowed;
}
this.valid = false;
return this.dropNotAllowed;
},
notifyDrop: function (ddSource, e, data) {
if (!this.valid)
return false;
field.setValue(data.records[0].get('text'));
var store = field.getStore();
store.loadData([{ text: data.records[0].get('text') }], false);
field.setValue(data.records[0].get('text'));
field.fireEvent('select', field, [field.getStore().findRecord('text', data.records[0].get('text'))]);
return true;
}
});
},
change: function (field, newValue) {
// change event to handle the case when the user types a name
var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
var ttCatRootNode = explorerTree.getRootNode().findChild('id', 'catalog-treeRootNode', true);
var matchingNodes = [];
var store = field.getStore();
amdaModel.InteractiveNode.preloadNodes(ttCatRootNode, function () {
matchingNodes = []; // Clear previous matches
ttCatRootNode.eachChild(function (node) {
if (newValue && node.get('text').toLowerCase().includes(newValue.toLowerCase())) {
matchingNodes.push({ text: node.get('text') });
}
});
if ((self._getFieldTypeTTCat().getValue() == 'catalog') && (matchingNodes.length > 0)) {
store.removeAll();
store.loadData(matchingNodes);
field.expand();
} else {
store.removeAll();
if (newValue) {
store.add({ text: newValue });
field.setValue(newValue);
field.fireEvent('select', field, [store.findRecord('text', newValue)]);
field.expand();
} else {
store.removeAll();
var parametersGrid = self.down('#parametersGrid');
parametersGrid.getStore().removeAll();
field.collapse();
}
}
self._getFieldTypeTTCat().on('change', function () {
field.setValue('');
store.removeAll();
var parametersGrid = self.down('#parametersGrid');
parametersGrid.getStore().removeAll();
});
field.focus(false, 100);
});
},
select: function (combo) {
// select event to handle the case when the user selects a name from the dropdown
if(self._getFieldTypeTTCat().getValue() == 'catalog'){
var selectedName = combo.getRawValue();
var panel = combo.up('fieldset').down('panel');
var store = panel.down('#parametersGrid').getStore();
var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
var ttCatRootNode = explorerTree.getRootNode().findChild('id', 'catalog-treeRootNode', true);
var nodeWithSameName = ttCatRootNode.findChild('text', selectedName, true);
if (nodeWithSameName) {
var opt = {
'typeTT': 'catalog',
'id': nodeWithSameName.data.id,
'name': selectedName
};
// Get parameters for the selected catalog
AmdaAction.readIntervalsForChart(opt, function (result, e) {
if (result && result.success) {
store.removeAll();
Ext.Array.each(result.parameters, function (param) {
if (param.size > 1 || param.id.includes('COMPONENT'))
return; // Skip parameters with size > 1
store.add({
name: param.name,
id : param.id,
value: ''
});
});
}
});
} else {
store.removeAll();
}
}
self.selectUsed = true; // flag to indicate that the select event was triggered by the user
},
blur: function (field) {
// blur event to handle the case when the user types a name and then clicks outside the field
if (!self.selectUsed) {
var value = field.getRawValue();
field.fireEvent('select', field);
}
self.selectUsed = false;
}
}
},
{
// Panel for parameters
xtype: 'panel',
layout: 'fit',
title: 'Parameters',
collapsible: true,
hidden: true,
// tbar: [
// {
// xtype: 'tbtext',
// text: 'Parameters'
// },
// '->',
// {
// iconCls: 'icon-add',
// text: 'Add Parameter',
// handler: function () {
// var grid = this.up('panel').down('#parametersGrid');
// var store = grid.getStore();
// store.add({ name: '', value: '' });
// }
// }
// ],
items: [
{
xtype: 'grid',
store: Ext.create('Ext.data.Store', {
fields: ['name', 'value']
}),
columns: [
{ text: 'Name', dataIndex: 'name', editor: 'textfield', flex: 1 },
{ text: 'Value', dataIndex: 'value', editor: 'textfield', flex: 1 }
],
selType: 'cellmodel',
plugins: {
ptype: 'cellediting',
clicksToEdit: 1
},
height: 200,
width: 400,
itemId: 'parametersGrid',
}
],
listeners: {
beforerender: function () {
var TTCatType = self._getFieldTypeTTCat().getValue();
this.setVisible(TTCatType == 'catalog');
},
render: function (o, op) {
self._getFieldTypeTTCat().on('change', function (field, newValue) {
this.setVisible(newValue == 'catalog');
}, this);
}
}
},
{
xtype: 'button',
width: width,
text: 'Insert Interval',
scope: this,
handler: function () {
var me = this;
var TTCatType = self._getFieldTypeTTCat().getValue();
var TTCatName = self._getFieldNameTTCat().getValue();
var isCatalog = (TTCatType == 'catalog');
myDesktopApp.getLoadedModule(isCatalog ? this.catModuleId : this.ttModuleId, true, function (module) {
var targetModuleUI = module.getUiContent();
if (me.linkedTTCatNode && (me.linkedTTCatNode.get('text') == TTCatName) && (me.linkedTTCatNode.get('nodeType') == TTCatType)) {
if (targetModuleUI)
me.insertInterval();
else {
me.linkedTTCatNode.editLeaf(function () {
me.insertInterval();
});
}
}
else {
var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
var ttCatRootNode = explorerTree.getRootNode().findChild('id', isCatalog ? 'catalog-treeRootNode' : 'timeTable-treeRootNode', true);
amdaModel.InteractiveNode.preloadNodes(ttCatRootNode, function () {
var nodeWithSameName = null;
if (TTCatName != ''){
nodeWithSameName = ttCatRootNode.findChild('text', TTCatName, true);
}
if (nodeWithSameName !== null){
me.linkedTTCatNode = nodeWithSameName;}
else {
module.createLinkedNode();
module.getLinkedNode().set('text', TTCatName);
me.linkedTTCatNode = module.getLinkedNode();
var obj = {
name: TTCatName,
fromPlugin: true
};
if (isCatalog) {
Ext.Msg.prompt('Define Parameters', 'Please enter parameters number for the new catalog:', function (btn, text) {
if (btn == 'ok') {
obj.nbParameters = parseInt(text, 10);
if (isNaN(obj.nbParameters)) {
obj.nbParameters = 1;
}
module.name = 'color';
module.createObject(obj);
me.linkedTTCatNode.editLeaf(function () {
me.insertInterval();
});
}
});
return;
}
else {
module.createObject(obj);
}
}
me.linkedTTCatNode.editLeaf(function () {
me.insertInterval();
});
});
}
});
}
}
]
});
self.callParent(arguments);
},
_getFieldTypeTTCat: function () {
return this.down('#' + this.fieldTypeTTCat);
},
_getFieldNameTTCat: function () {
return this.down('#' + this.fieldTypeName);
},
/**
* add Interval to Time table or Catalog
*/
insertInterval: function () {
const self = this;
const start = self.parent.getField1Value();
const stop = self.parent.getField2Value();
const TTCatType = self._getFieldTypeTTCat().getValue();
const isCatalog = (TTCatType == 'catalog');
myDesktopApp.getLoadedModule(isCatalog ? self.catModuleId : self.ttModuleId, true, function (module) {
var targetModuleUI = module.getUiContent();
var parametersGrid = self.down('#parametersGrid');
var parametersStore = parametersGrid.getStore();
var parametersData = {};
var index = targetModuleUI.object.data.nbIntervals;
// Add parameters and values to the interval
parametersStore.each(function(record) {
parametersData[record.get('id')] = record.get('value');
});
if (targetModuleUI)
targetModuleUI.addInterval(start, stop, index, parametersData);
});
},
// getCatalogParameters: function(catalogId) {
// const self = this;
// AmdaAction.readIntervalsForChart({
// 'typeTT': 'catalog',
// 'id': catalogId,
// 'name': this.linkedTTCatNode.get('name')
// }, function(result, e) {
// if (result && result.success) {
// const parametersGrid = self.down('#parametersGrid');
// const store = parametersGrid.getStore();
// store.removeAll();
// Ext.Array.each(result.parameters, function(param) {
// store.add({
// name: param.id,
// value: ''
// });
// });
// }
// });
// }
});