InsertToTTCatlog.js
7.13 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
Ext.define('amdaPlotComp.intervalSelection.InsertToTTCatlog', {
extend: 'Ext.form.FieldSet',
collapsible: false,
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: 'textfield',
fieldLabel: 'Name',
name: self.fieldTypeName,
itemId: self.fieldTypeName,
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'));
return true;
}
});
}
}
},
{
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.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 start = this.parent.getField1Value();
const stop = this.parent.getField2Value();
const TTCatType = this._getFieldTypeTTCat().getValue();
const isCatalog = (TTCatType == 'catalog');
myDesktopApp.getLoadedModule(isCatalog ? this.catModuleId : this.ttModuleId, true, function (module) {
var targetModuleUI = module.getUiContent();
if (targetModuleUI)
targetModuleUI.addInterval(start, stop);
});
}
});