Newer
Older
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
/**
* @module package/quiqqer/menu/bin/Controls/Independent/MenuPanel
* @author www.pcsg.de (Henning Leutz)
*/
define('package/quiqqer/menu/bin/Controls/Independent/MenuPanel', [
'qui/QUI',
'qui/controls/desktop/Panel',
'qui/controls/sitemap/Map',
'qui/controls/sitemap/Item',
'qui/controls/windows/Confirm',
'qui/controls/contextmenu/Menu',
'qui/controls/contextmenu/Item',
'Locale',
'package/quiqqer/menu/bin/classes/Independent/Handler',
'Mustache',
'text!package/quiqqer/menu/bin/Controls/Independent/MenuPanel.Create.html',
'css!package/quiqqer/menu/bin/Controls/Independent/MenuPanel.css'
], function (QUI, QUIPanel, QUIMap, QUIMapItem, QUIConfirm, QUIContextMenu, QUIContextMenuItem,
QUILocale, MenuHandler, Mustache, templateCreate) {
"use strict";
const lg = 'quiqqer/menu';
const Handler = new MenuHandler();
return new Class({
Extends: QUIPanel,
Type : 'package/quiqqer/menu/bin/Controls/Independent/MenuPanel',
Binds: [
'$onShow',
'$onCreate',
'$onInject',
'$openItem',
'$onContextMenu',
'addItem',
'save',
],
options: {
menuId: false
},
initialize: function (options) {
this.parent(options);
this.$ActiveItem = null;
this.$ActiveMapItem = null;
this.$Map = null;
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
this.addEvents({
onShow : this.$onShow,
onInject: this.$onInject,
onCreate: this.$onCreate
});
},
$onCreate: function () {
this.getContent().addClass('quiqqer-menu-menuPanel');
// buttons
this.addButton({
name : 'save',
text : QUILocale.get('quiqqer/quiqqer', 'save'),
events: {
click: this.save
}
});
this.addButton({
type: 'separator'
});
this.addButton({
name : 'add',
text : QUILocale.get('quiqqer/quiqqer', 'add'),
events: {
click: this.addItem
}
});
this.addButton({
name : 'add',
disabled: true,
text : QUILocale.get('quiqqer/quiqqer', 'remove'),
events : {
click: this.addItem
}
});
// content
this.$MapContainer = new Element('div', {
'class': 'quiqqer-menu-menuPanel-mapContainer'
}).inject(this.getContent());
this.$InnerContainer = new Element('div', {
'class': 'quiqqer-menu-menuPanel-innerContainer'
}).inject(this.getContent());
this.$Map = new QUIMap({}).inject(this.$MapContainer);
},
$onInject: function () {
this.Loader.show();
Handler.getMenu(this.getAttribute('menuId')).then((menuData) => {
this.setAttribute('title', menuData.title);
this.setAttribute('icon', 'fa fa-bars');
this.refresh();
// build sitemap
if (menuData.data !== null &&
typeof menuData.data.children !== 'undefined' &&
menuData.data.children.length
) {
const buildChildren = (Parent, children) => {
let i, len, data, title, Item;
const current = QUILocale.getCurrent();
for (i = 0, len = children.length; i < len; i++) {
data = children[i];
text : data.titleFrontend,
icon : data.typeIcon,
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
itemTitle: data.title,
itemType : data.type,
itemIcon : data.icon,
itemData : data.data,
events : {
click : this.$openItem,
contextMenu: this.$onContextMenu
}
});
Parent.appendChild(Item);
if (typeof data.children !== 'undefined' && data.children.length) {
buildChildren(Item, data.children);
}
}
};
buildChildren(this.$Map, menuData.data.children);
}
this.Loader.hide();
});
},
$onShow: function () {
},
save: function () {
this.Loader.show();
// map to array
const toArray = function (Item) {
let items = Item.getChildren();
if (Item.getType() === 'qui/controls/sitemap/Map') {
items = Item.$items;
}
let children = [];
for (let i = 0, len = items.length; i < len; i++) {
children.push(toArray(items[i]));
}
if (Item.getType() === 'qui/controls/sitemap/Map') {
return {
children: children
};
}
return {
title : Item.getAttribute('itemTitle'),
type : Item.getAttribute('itemType'),
data : Item.getAttribute('itemData'),
children: children
};
};
let result = toArray(this.$Map);
let title = null;
let workingTitle = null;
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
Handler.saveMenu(
this.getAttribute('menuId'),
title,
workingTitle,
result
).then(() => {
this.Loader.hide();
});
},
addItem: function (Parent, where) {
if (typeof where === 'undefined') {
where = 'bottom';
}
if (typeof Parent === 'undefined') {
const items = this.$Map.getSelectedChildren();
if (items.length) {
Parent = items[0];
}
}
new QUIConfirm({
title : QUILocale.get(lg, 'quiqqer.menu.independent.addItem.title'),
maxHeight: 400,
maxWidth : 500,
autoclose: false,
events : {
onOpen: (Win) => {
const Content = Win.getContent();
Win.Loader.show();
Content.set('html', Mustache.render(templateCreate, {
textTitle: QUILocale.get('quiqqer/quiqqer', 'title'),
textName : QUILocale.get('quiqqer/quiqqer', 'name'),
textType : QUILocale.get('quiqqer/quiqqer', 'type')
}));
Handler.getItemTypes().then((list) => {
const Types = Content.getElement('[name="itemType"]');
for (let i = 0, len = list.length; i < len; i++) {
new Element('option', {
html : list[i].title,
value : list[i].class,
'data-icon': list[i].icon
}).inject(Types);
}
Types.value = 'QUI\\Menu\\Independent\\Items\\Custom';
return QUI.parse(Win.getContent());
}).then(function () {
Win.Loader.hide();
});
},
onSubmit: (Win) => {
const Content = Win.getContent();
const Form = Content.getElement('form');
let current = QUILocale.getCurrent();
let title = Form.elements.itemTitle.value;
let type = Form.elements.itemType.value;
const Option = Form.elements.itemType.getElement(
'option[value="' + CSS.escape(type) + '"]'
);
try {
title = JSON.decode(title);
if (typeof title[current] !== 'undefined') {
title = title[current];
}
} catch (e) {
}
let itemAttributes = {
text : title,
icon : Option.get('data-icon'),
itemTitle: Form.elements.itemTitle.value,
itemType : Form.elements.itemType.value,
itemIcon : '',
events : {
click : this.$openItem,
contextMenu: this.$onContextMenu
}
};
if (where === 'bottom') {
Parent.appendChild(new QUIMapItem(itemAttributes));
Parent.open();
} else {
Parent.appendChild(new QUIMapItem(itemAttributes), where);
}
Win.close();
}
}
}).open();
},
/**
* opens the item - display the item data
*
* @param Item
*/
$openItem: function (Item) {
this.Loader.show();
this.$ActiveItem = null;
this.$ActiveMapItem = null;
Handler.getItemTypes().then((list) => {
let control = '';
let type = Item.getAttribute('itemType');
for (let i = 0, len = list.length; i < len; i++) {
if (list[i].class === type) {
control = list[i].jsControl;
break;
}
}
if (control === '') {
this.Loader.hide();
return;
}
require([control], (cls) => {
const SitemapItem = this.$getActiveSitemapItem();
this.$ActiveMapItem = this.$getActiveSitemapItem();
this.$ActiveItem = new cls({
title : SitemapItem.getAttribute('itemTitle'),
type : SitemapItem.getAttribute('itemType'),
icon : SitemapItem.getAttribute('itemIcon'),
data : SitemapItem.getAttribute('itemData'),
events: {
load: () => {
this.Loader.hide();
}
}
}).inject(this.$InnerContainer);
}, (err) => {
console.error(err);
this.Loader.hide();
});
});
},
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
$unloadCurrentItem: function () {
if (!this.$ActiveItem) {
return;
}
if (typeof this.$ActiveItem.save !== 'function') {
return;
}
const data = this.$ActiveItem.save();
if (!this.$ActiveMapItem) {
return;
}
this.$ActiveMapItem.setAttribute('itemTitle', data.title);
this.$ActiveMapItem.setAttribute('itemIcon', data.icon);
this.$ActiveMapItem.setAttribute('itemData', data.data);
},
$getActiveSitemapItem: function () {
const item = this.$Map.getSelectedChildren();
if (item.length) {
return item[0];
}
return null;
},
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/**
* Context menu für a sitemap item
*
* @param Item
* @param event
*/
$onContextMenu: function (Item, event) {
event.stop();
const pos = Item.getElm().getPosition();
const Menu = new QUIContextMenu({
events: {
onBlur: function (Instance) {
Instance.hide();
Instance.destroy();
}
}
});
// @todo locale
Menu.appendChild(new QUIContextMenuItem({
icon : 'fa fa-arrow-up',
text : 'Davor einfügen',
events: {
click: () => {
this.addItem(Item, 'before');
}
}
}));
Menu.appendChild(new QUIContextMenuItem({
icon : 'fa fa-arrow-down',
text : 'Danach einfügen',
events: {
click: () => {
this.addItem(Item, 'after');
}
}
}));
Menu.appendChild(new QUIContextMenuItem({
icon : 'fa fa-level-down',
text : 'Kind einfügen',
events: {
click: () => {
this.addItem(Item);
}
}
}));
Menu.appendChild(new QUIContextMenuItem({
icon : 'fa fa-trash',
text : 'Löschen',
events: {
click: () => {
Item.destroy();
}
}
}));
Menu.inject(document.body);
Menu.setPosition(pos.x, pos.y + 30);
Menu.setTitle(Item.getAttribute('text'));
Menu.show();
Menu.focus();
}
});
});