-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewHandlers_add.js
225 lines (185 loc) · 7.9 KB
/
viewHandlers_add.js
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
requirejs('Scripts/AddonMenu/addonMenu')
nodeHandlers.addonMenuTreeRoot = inheritNodeHandler('addonMenuTreeRoot', 'Base', {
getChildren: function (node) {
return new Promise(function (resolve, reject) {
if(!node.datasource){
resolve();
}
node.dataSource.actions.forEach(itm => {
if(itm.type == "group"){
node.addChild(itm,'addonGroupNode')
} else{
node.addChild(itm,'addonMenuNode')
}
})
resolve();
});
},
drop: function (dataSource, e, index) {
let srcObjectNode = dnd.getDragObject(e);
// datatype of the element that was dropped
let datatype = dnd.getDropDataType(e);
if (srcObjectNode && (datatype == 'addonGroupNode' || datatype == 'addonMenuNode')) {
// the details of the datasource will change after it has been
// moved, save the current details for later
let ctrl = e.dataTransfer.getSourceControl();
let srcObjectParent;
if(srcObjectNode.group == "root"){
srcObjectParent = ctrl.controlClass.dataSource.root;
} else {
srcObjectParent = ctrl.controlClass.dataSource.root.findChild(`addonGroupNode:${srcObjectNode.group}`);
}
let targetParent = ctrl.controlClass.dataSource.root;
if(datatype == 'addonMenuNode'){
addons.addonMenu.moveAction(srcObjectNode,dataSource);
ctrl.controlClass.dataSource.notifyChanged();
if(targetParent.persistentID != srcObjectParent.persistentID){
// parent has changed, also update source node
nodeUtils.refreshNodeChildren(srcObjectParent);
}
} else {
addons.addonMenu.moveGroup(srcObjectNode,dataSource);
}
ctrl.controlClass.dataSource.notifyChanged();
nodeUtils.refreshNodeChildren(ctrl.controlClass.root);
}
},
});
nodeHandlers.addonGroupNode = inheritNodeHandler('addonGroupNode', 'Base', {
hideCheckbox: function (node) {
return true;
},
title: function (node) {
return node.dataSource.title;
},
hasChildren: function(node){
return (node.dataSource.hasOwnProperty('actions') && node.dataSource.actions.length > 0);
},
getChildren: function (node) {
return new Promise(function (resolve, reject) {
if(nodeHandlers[node.handlerID].hasChildren(node)){
node.dataSource.actions.forEach(itm => {
node.addChild(itm,'addonMenuNode')
});
}
resolve();
});
},
canDrop: node => true,
canEdit: node => true,
canDelete: node => true,
setTitle: function (node, newTitle) {
node.dataSource.title = newTitle;
nodeUtils.refreshNodeChildren(node.parent);
},
drop: function (dataSource, e, index) {
let srcObjectNode = dnd.getDragObject(e);
// datatype of the element that was dropped
let datatype = dnd.getDropDataType(e);
if (srcObjectNode && (datatype == 'addonGroupNode' || datatype == 'addonMenuNode')) {
if (srcObjectNode.id == dataSource.id){
// we cannot drop to itself
return
}
// the details of the datasource will change after it has been
// moved, save the current details for later
let ctrl = e.dataTransfer.getSourceControl();
let srcObjectParent;
if(srcObjectNode.group == "root"){
srcObjectParent = ctrl.controlClass.dataSource.root;
} else {
srcObjectParent = ctrl.controlClass.dataSource.root.findChild(`addonGroupNode:${srcObjectNode.group}`);
}
let targetParent = e._dropNode.parent;
if(datatype == "addonMenuNode"){
// if the dropped element was an action it will be moved
// to the item it has been dropped on
targetParent = e._dropNode;
}
if(datatype == 'addonMenuNode'){
addons.addonMenu.moveAction(srcObjectNode,dataSource);
} else {
addons.addonMenu.moveGroup(srcObjectNode,dataSource);
}
ctrl.controlClass.dataSource.notifyChanged();
nodeUtils.refreshNodeChildren(ctrl.controlClass.root);
if(datatype == 'addonMenuNode'){
nodeUtils.refreshNodeChildren(targetParent);
if(targetParent.persistentID != srcObjectParent.persistentID){
// parent has changed, also update source node
nodeUtils.refreshNodeChildren(srcObjectParent);
}
}
}
},
deleteItems: function (node) {
addons.addonMenu.removeGroup(node.dataSource);
nodeUtils.refreshNodeChildren(node.parent);
},
});
nodeHandlers.addonMenuNode = inheritNodeHandler('addonMenuNode', 'Base', {
hideCheckbox: function (node) {
return false;
},
title: function (node) {
// var nodeTitle = node.dataSource.hasOwnProperty('title') ? node.dataSource.title : actions[node.dataSource.action].title();
return window.uitools.getPureTitle(actions[node.dataSource.action].title());
},
hasChildren: function(node){
return (node.dataSource.hasOwnProperty('actions') && node.dataSource.actions.length > 0);
},
getChildren: function (node) {
return new Promise(function (resolve, reject) {
if(nodeHandlers[node.handlerID].hasChildren(node)){
node.dataSource.actions.forEach(itm => {
node.addChild(itm,'addonMenuNode')
});
}
resolve();
});
},
canDrop: node => true,
canDelete: node => false,
drop: function (dataSource, e, index) {
let srcObjectNode = dnd.getDragObject(e);
// datatype of the element that was dropped
let datatype = dnd.getDropDataType(e);
if (srcObjectNode && (datatype == 'addonGroupNode' || datatype == 'addonMenuNode')) {
if (srcObjectNode.id == dataSource.id){
// we cannot drop to itself
return
}
// the details of the datasource will change after it has been
// moved, save the current details for later
let ctrl = e.dataTransfer.getSourceControl();
let srcObjectParent;
if(srcObjectNode.group == "root"){
srcObjectParent = ctrl.controlClass.dataSource.root;
} else {
srcObjectParent = ctrl.controlClass.dataSource.root.findChild(`addonGroupNode:${srcObjectNode.group}`);
}
let targetParent;
if(dataSource.type == "action" ){
targetParent = e._dropNode.parent;
} else {
alert('how can this even happen?')
// element was dropped on a group or root, use the target node as parent
targetParent = e._dropNode;
}
if(datatype == 'addonMenuNode'){
addons.addonMenu.moveAction(srcObjectNode,dataSource);
} else {
addons.addonMenu.moveGroup(srcObjectNode,dataSource);
}
ctrl.controlClass.dataSource.notifyChanged();
nodeUtils.refreshNodeChildren(ctrl.controlClass.root);
if(datatype == 'addonMenuNode'){
nodeUtils.refreshNodeChildren(targetParent);
if(targetParent.persistentID != srcObjectParent.persistentID){
// parent has changed, also update source node
nodeUtils.refreshNodeChildren(srcObjectParent);
}
}
}
},
});