ru.coon 2.6.8 → 2.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,896 @@
1
+ Ext.define('Coon.uielement.component.UiCPVisualEditor', {
2
+ extend: 'Ext.panel.Panel',
3
+ cls: 'UiCPVisualEditor',
4
+ alias: 'widget.UiCPVisualEditor',
5
+ xtype: 'UiCPVisualEditor',
6
+ header: false,
7
+ layout: 'border',
8
+ requires: [
9
+ 'Coon.uielement.component.UiCPVisualEditorConfigWindow'
10
+ ],
11
+ controller: {
12
+ defaultPixelsSize: 200,
13
+ bindingRegister: [],
14
+ plugins: [],
15
+ isTipOpened: false,
16
+ onTreeItemContextMenu: function(view, record, item, index, event, opt) {
17
+ this.onContextClick(event, item, {
18
+ 'cmp': this.getEditorPanel().down('[dataId=' + record.get('dataId') + ']'),
19
+ 'target': Ext.get(item.id).el,
20
+ });
21
+ return false;
22
+ },
23
+ deselectAllCmp: function() {
24
+ this.getEditorPanel().query('[dataId]').map((item) => {
25
+ if (item.el) {
26
+ item.el.dom.classList.remove('hover-item');
27
+ }
28
+ });
29
+ },
30
+ selectCmp: function(id) {
31
+ const cmp = this.getEditorPanel().down('[dataId=' + id + ']');
32
+ if (cmp && cmp.el) {
33
+ cmp.el.dom.classList.add('hover-item');
34
+ }
35
+ },
36
+ onTreeSelectionChange: function(tree, selection) {
37
+ this.deselectAllCmp();
38
+ if (selection.length) {
39
+ this.selectCmp(selection[0].get('dataId'));
40
+ }
41
+ },
42
+ getEditorPanel: function() {
43
+ return this.getView().down('[dataId=editorPanel]');
44
+ },
45
+ onRenderMainPanel: function() {
46
+ this.renderTemplate();
47
+ },
48
+ getFirstContainer: function(formData) {
49
+ return formData.find((item) => {
50
+ if (item.xtype === 'panel' || item.xtype === 'container') {
51
+ return item;
52
+ }
53
+ if (item.items && item.items.length) {
54
+ return this.getFirstContainer(item.items);
55
+ }
56
+ });
57
+ },
58
+ normaliseMainPluginsCfg: function(data) {
59
+ data.map((item) => {
60
+ if (item.cmpParams) {
61
+ if (item.cmpParams.mainPlugins && item.cmpParams.mainPlugins.length) {
62
+ this.plugins = item.cmpParams.mainPlugins;
63
+ delete item.cmpParams['mainPlugins'];
64
+ }
65
+ if (item.items && item.items.length) {
66
+ this.normaliseMainPluginsCfg(item.items);
67
+ }
68
+ }
69
+ });
70
+ },
71
+ renderTemplate: function(data) {
72
+ this.getEditorPanel().removeAll(true);
73
+ const formData = this.getTemplate(data);
74
+ const firstContainer = this.getFirstContainer(formData);
75
+ this.plugins = [];
76
+ this.normaliseMainPluginsCfg(formData);
77
+ if (this.plugins.length) {
78
+ firstContainer.plugins = this.plugins;
79
+ firstContainer.cmpParams.mainPlugins = this.plugins;
80
+ }
81
+ firstContainer['controller'] = {};
82
+ firstContainer['viewModel'] = {};
83
+ this.reloadTreeStore(formData);
84
+ try {
85
+ this.getEditorPanel().add(formData);
86
+ } catch (e) {
87
+ Ext.Msg.alert('Ошибка', e.message);
88
+ }
89
+ },
90
+ reloadTreeStore: function(formData) {
91
+ this.getView().down('[dataId=treeEditorPanel]').setRootNode(this.getNodeCfg(formData)[0]);
92
+ },
93
+ getNodeCfg: function(items) {
94
+ if (!items) {
95
+ return [];
96
+ }
97
+ return items.map((item) => {
98
+ const subItems = item.uiElementCd ? false : this.getNodeCfg(item.items);
99
+ let obj = {};
100
+ if (item.isContainer) {
101
+ obj = {leaf: false, children: []};
102
+ } else {
103
+ obj = {leaf: true};
104
+ }
105
+ const result = Ext.apply({
106
+ 'text': item.cmpParams.xtype,
107
+ 'dataId': item.cmpParams.dataId,
108
+ }, subItems && subItems.length ? {children: subItems, expanded: true} : obj);
109
+ return result;
110
+ });
111
+ },
112
+ getTemplate: function(data) {
113
+ if (!data) {
114
+ data = [this.getDefaultData()];
115
+ }
116
+ return data.map((item) => {
117
+ return this.getTemplateCmp(item);
118
+ });
119
+ },
120
+ getDefaultsByLayoutType: function(layout) {
121
+ switch (layout) {
122
+ case 'vbox':
123
+ return {width: '100%', flex: 1};
124
+ case 'hbox':
125
+ return {height: '100%', flex: 1};
126
+ }
127
+ },
128
+ modifyObject: function(obj) {
129
+ const newObject = {};
130
+ newObject.cmpParams = obj;
131
+ delete newObject.cmpParams['uiElementCd'];
132
+ // delete newObject.cmpParams['plugins'];
133
+ if (obj.xtype === 'ReportPanel') {
134
+ delete newObject.cmpParams['items'];
135
+ }
136
+ if (!obj.xtype) {
137
+ newObject.cmpParams.xtype = 'panel';
138
+ }
139
+
140
+ return newObject;
141
+ },
142
+ getTemplateCmp: function(cfg) {
143
+ const modifiedObject = typeof cfg.cmpParams !== 'undefined' ? cfg : this.modifyObject(cfg);
144
+ if (typeof modifiedObject.cmpParams.items !== 'undefined' && modifiedObject.cmpParams.items.length) {
145
+ modifiedObject.items = modifiedObject.cmpParams.items;
146
+ delete modifiedObject.cmpParams['items'];
147
+ }
148
+ if (!modifiedObject.cmpParams.dataId) {
149
+ modifiedObject.cmpParams.dataId = Ext.id() + '-interface-node';
150
+ }
151
+ const layout = typeof modifiedObject.cmpParams.layout === 'undefined' ? 'fit' :
152
+ modifiedObject.cmpParams.layout === 'object' ? modifiedObject.cmpParams.layout.type : modifiedObject.cmpParams.layout;
153
+ const newCmp = Ext.apply({
154
+ 'defaults': this.getDefaultsByLayoutType(layout),
155
+ 'cmpParams': modifiedObject.cmpParams,
156
+ }, modifiedObject.cmpParams);
157
+ if (modifiedObject.items && modifiedObject.items.length) {
158
+ newCmp.items = this.getTemplate(modifiedObject.items);
159
+ }
160
+ if (!newCmp.items || newCmp.items.length === 0) {
161
+ newCmp.cls = 'borders-default';
162
+ newCmp.listeners = {'render': this.onGetTemplateCmp.bind(this)};
163
+ }
164
+ return newCmp;
165
+ },
166
+ getCurrentPanelIndex: function(panel) {
167
+ let panelIndex = 0;
168
+ panel.up().items.items.map((item, index) => {
169
+ if (item.id === panel.id) {
170
+ panelIndex = index;
171
+ }
172
+ });
173
+ return panelIndex;
174
+ },
175
+ addCmp: function(cmp, side, inParent, xtype) {
176
+ if (inParent && cmp.up().xtype === cmp.xtype) {
177
+ cmp = cmp.up();
178
+ }
179
+ const parent = cmp.up();
180
+ if (!parent) {
181
+ return false;
182
+ }
183
+ const parentLayout = parent.layout.type || false;
184
+ const index = this.getCurrentPanelIndex(cmp);
185
+ let container = {};
186
+ let newIndex = index;
187
+ const needLayout = side === 'left' || side === 'right' ? 'hbox' : 'vbox';
188
+ if (side === 'down' || side === 'right') {
189
+ newIndex = Number(index) + 1;
190
+ }
191
+ if (parentLayout === needLayout) {
192
+ parent.insert(newIndex, this.getTemplateCmp(this.getDefaultCmp(xtype)));
193
+ } else {
194
+ container = {
195
+ xtype: xtype,
196
+ cmpParams: {
197
+ xtype: xtype,
198
+ layout: needLayout,
199
+ flex: cmp.flex || 1,
200
+ },
201
+ layout: needLayout,
202
+ flex: cmp.flex || 1,
203
+ items: [],
204
+ };
205
+ const currentTemplate = this.getTemplate(this.getData([cmp])).pop();
206
+ const defaultTemplate = this.getTemplateCmp(this.getDefaultCmp(xtype));
207
+ if (side === 'down' || side === 'right') {
208
+ container.items = [currentTemplate, defaultTemplate];
209
+ } else {
210
+ container.items = [defaultTemplate, currentTemplate];
211
+ }
212
+ parent.remove(cmp, true);
213
+ parent.insert(index, [container]);
214
+ }
215
+ this.renderTemplate(this.getData(this.getEditorPanel().items.items));
216
+ },
217
+ getData: function(items) {
218
+ if (!items) {
219
+ return [];
220
+ }
221
+ return items.map((item) => {
222
+ const subItems = !item.cmpParams ||
223
+ item.xtypesMap.grid ||
224
+ item.cmpParams.xtype === 'ReportPanel' ||
225
+ (!item.items ?
226
+ false :
227
+ this.getData(item.items.items)
228
+ );
229
+ const result = Ext.apply({
230
+ 'cmpParams': item.cmpParams,
231
+ }, subItems ? {items: subItems} : {});
232
+ return result;
233
+ });
234
+ },
235
+
236
+ onDeleteCmpClick: function(elem) {
237
+ const me = this;
238
+ Ext.Msg.show({
239
+ title: 'Внимание',
240
+ message: 'Вы действительно хотите удалить элемент рабочего стола?',
241
+ buttons: Ext.Msg.YESNO,
242
+ icon: Ext.Msg.QUESTION,
243
+ fn: function(btn) {
244
+ if (btn === 'yes') {
245
+ const branch = me.getDeletedBranch(elem);
246
+ const xtype = branch.xtype;
247
+ const parent = branch.up();
248
+ branch.destroy();
249
+ if (parent.xtype === xtype && parent.items.items.length === 1) {
250
+ parent.cmpParams = parent.items.items[0].cmpParams;
251
+ parent.cmpParams.items = me.getData(parent.items.items[0].items.items);
252
+ parent.removeAll(true);
253
+ }
254
+ me.reloadView();
255
+ }
256
+ },
257
+ });
258
+ },
259
+ getDeletedBranch: function(panel) {
260
+ if (panel.up().items.items.length > 1 || panel.xtype !== panel.up().xtype || panel.up().dataId === 'editorPanel') {
261
+ return panel;
262
+ }
263
+ return this.getDeletedBranch(panel.up());
264
+ },
265
+ clearBindRegister: function() {
266
+ this.bindingRegister.map((bind) => {
267
+ bind.destroy();
268
+ });
269
+ },
270
+ reloadView: function() {
271
+ this.clearBindRegister();
272
+ this.renderTemplate(this.getData(this.getEditorPanel().items.items));
273
+ },
274
+ onContextClick: function(event, dom, opt) {
275
+ const cmp = opt.cmp;
276
+ const target = !opt.target ? cmp : opt.target;
277
+ const contextMenu = new Ext.menu.Menu({
278
+ closeAction: 'destroy',
279
+ items: this.getMenuCfgByXtype(cmp.cmpParams.xtype, cmp),
280
+ listeners: {
281
+ hide: function() {
282
+ const me = this;
283
+ Ext.defer(() => me.destroy(), 2000);
284
+ },
285
+ },
286
+ });
287
+ contextMenu.showAt(target.getX(), target.getY());
288
+ event.preventDefault();
289
+ return false;
290
+ },
291
+ onGetTemplateCmp: function(elem) {
292
+ const cmp = Ext.get(elem.id);
293
+ cmp.on('mouseover', this.enableBorders.bind(this, cmp, true));
294
+ cmp.on('mouseout', this.enableBorders.bind(this, cmp, false));
295
+ cmp.on('contextmenu', this.onContextClick, this, {'cmp': elem});
296
+ /* elem.el.dom.addEventListener('mouseover', this.enableBorders.bind(this, true), this);
297
+ elem.el.dom.addEventListener('mouseout', this.enableBorders.bind(this, false), this);*/
298
+ },
299
+ enableBorders: function(elem, flag, event) {
300
+ if (flag) {
301
+ elem.dom.classList.add('hover-item');
302
+ } else {
303
+ elem.dom.classList.remove('hover-item');
304
+ }
305
+ // }
306
+ },
307
+ onClickButtonAddPanel: function(panel, event) {
308
+ this.addCmp(panel, event.target.getAttribute('data-side'), event.target.getAttribute('data-in-parent') === 'true', 'container');
309
+ },
310
+ renderMenu: function(panel, xtype, event) {
311
+ const me = this;
312
+ if (!me.isTipOpened) {
313
+ me.isTipOpened = true;
314
+ const tip = Ext.create('Ext.tip.Tip', {
315
+ autoShow: false,
316
+ target: event.target,
317
+ closeAction: 'destroy',
318
+ closable: true,
319
+ layout: 'fit',
320
+ cls: 'menu-tip',
321
+ listeners: {
322
+ 'beforeclose': function() {
323
+ me.isTipOpened = false;
324
+ },
325
+ },
326
+ items: [
327
+ {
328
+ xtype: 'treelist',
329
+ store: {
330
+ root: me.getMenuCfgByXtype(xtype),
331
+ },
332
+ listeners: {
333
+ 'itemclick': me.menuItemClick.bind(me, panel),
334
+ },
335
+ }
336
+ ],
337
+ });
338
+ tip.show();
339
+ // tip.setXY([event.clientX, event.clientY]);
340
+ }
341
+ },
342
+ getIndex: function(panel) {
343
+ let index = 0;
344
+ panel.up().items.keys.find((item, number) => {
345
+ if (panel.id === item) {
346
+ index = number;
347
+ return item;
348
+ }
349
+ });
350
+ return index;
351
+ },
352
+ getMenuCfgByXtype: function(xtype, panel) {
353
+ const me = this;
354
+ let buttons = [];
355
+ if (panel.isContainer) {
356
+ buttons = buttons.concat([{
357
+ iconCls: 'x-fa fa-file-invoice',
358
+ text: 'Добавить элемент',
359
+ handler: () => me.onAddCmpClick(panel),
360
+ },
361
+ {
362
+ iconCls: 'x-fa fa-file-invoice',
363
+ text: 'Импортировать существующую настраиваемую панель',
364
+ handler: () => me.onAddExistingPanelCmpClick(panel),
365
+ },
366
+ {iconCls: 'x-fa fa-copy', text: 'Копировать содержимое'},
367
+ {iconCls: 'x-fa fa-paste', text: 'Вставить содержимое'},
368
+ {iconCls: 'x-fa fa-pastafarianism', text: 'Заменить содержимое'}]
369
+ );
370
+ const firstContainer = this.getFirstContainer(this.getEditorPanel().items.items);
371
+ if (firstContainer.dataId !== panel.dataId) {
372
+ buttons = buttons.concat([
373
+ {
374
+ iconCls: 'x-fa fa-file-invoice',
375
+ text: 'Прикрепить отчет',
376
+ handler: () => me.onAddReportCmpClick(panel),
377
+ }
378
+ ]
379
+ );
380
+ }
381
+ }
382
+ if (panel.successUserEditingOptions && panel.successUserEditingOptions.length) {
383
+ buttons = buttons.concat([
384
+ {iconCls: 'x-fa fa-cog', text: 'Настройки', handler: () => me.onSettingsCmpClick(panel)}
385
+ ]);
386
+ }
387
+ if (panel.up().dataId !== 'editorPanel') {
388
+ buttons = buttons.concat([{
389
+ iconCls: 'x-fa fa-remove',
390
+ text: 'Удалить',
391
+ handler: () => me.onDeleteCmpClick(panel),
392
+ }]);
393
+ }
394
+ buttons = buttons.concat([{
395
+ iconCls: 'x-fa fa-save',
396
+ text: 'Сохранить',
397
+ handler: () => me.onSaveCmpClick(panel),
398
+ }]);
399
+
400
+ if (panel.up().layout.type !== 'border' && panel.up().isContainer && panel.up().items.length > 1) {
401
+ const curIndex = this.getIndex(panel);
402
+ if (curIndex === 0 || curIndex === panel.up().items.length - 1) {
403
+ if (curIndex === 0) {
404
+ buttons = buttons.concat([{
405
+ iconCls: 'x-fa fa-chevron-circle-down',
406
+ text: 'Переместить вниз',
407
+ handler: () => me.onMoveCmpClick(panel, curIndex + 1),
408
+ }]);
409
+ }
410
+ if (curIndex === panel.up().items.length - 1) {
411
+ buttons = buttons.concat([{
412
+ iconCls: 'x-fa fa-chevron-circle-up',
413
+ text: 'Переместить вверх',
414
+ handler: () => me.onMoveCmpClick(panel, curIndex - 1),
415
+ }]);
416
+ }
417
+ } else {
418
+ buttons = buttons.concat([{
419
+ iconCls: 'x-fa fa-chevron-circle-up',
420
+ text: 'Переместить вверх',
421
+ handler: () => me.onMoveCmpClick(panel, curIndex - 1),
422
+ }, {
423
+ iconCls: 'x-fa fa-chevron-circle-down',
424
+ text: 'Переместить вниз',
425
+ handler: () => me.onMoveCmpClick(panel, curIndex + 1),
426
+ }]);
427
+ }
428
+ }
429
+
430
+ switch (xtype) {
431
+ case 'container':
432
+ buttons = [
433
+ {
434
+ iconCls: 'x-fa fa-angle-left',
435
+ text: 'Добавить влево',
436
+ handler: () => me.addCmp(panel, 'left', false, xtype),
437
+ },
438
+ {
439
+ iconCls: 'x-fa fa-angle-right',
440
+ text: 'Добавить вправо',
441
+ handler: () => me.addCmp(panel, 'right', false, xtype),
442
+ },
443
+ {
444
+ iconCls: 'x-fa fa-angle-up',
445
+ text: 'Добавить панель вверх',
446
+ handler: () => me.addCmp(panel, 'up', false, xtype),
447
+ },
448
+ {
449
+ iconCls: 'x-fa fa-angle-down',
450
+ text: 'Добавить вниз',
451
+ handler: () => me.addCmp(panel, 'down', false, xtype),
452
+ },
453
+ {
454
+ iconCls: 'x-fa fa-angle-double-left',
455
+ text: 'Добавить в родителя влево',
456
+ handler: () => me.addCmp(panel, 'left', true, xtype),
457
+ },
458
+ {
459
+ iconCls: 'x-fa fa-angle-double-right',
460
+ text: 'Добавить в родителя вправо',
461
+ handler: () => me.addCmp(panel, 'right', true, xtype),
462
+ },
463
+ {
464
+ iconCls: 'x-fa fa-angle-double-up',
465
+ text: 'Добавить в родителя вверх',
466
+ handler: () => me.addCmp(panel, 'up', true, xtype),
467
+ },
468
+ {
469
+ iconCls: 'x-fa fa-angle-double-down',
470
+ text: 'Добавить в родителя вниз',
471
+ handler: () => me.addCmp(panel, 'down', true, xtype),
472
+ }
473
+ ].concat(buttons);
474
+ break;
475
+ }
476
+ return buttons;
477
+ },
478
+ menuItemClick: function(panel, list, opt) {
479
+ switch (opt.node.data.action) {
480
+ case 'add':
481
+ this.addCmp(panel, opt.node.data.side, opt.node.data.inParent, 'container');
482
+ break;
483
+ case 'addCmp':
484
+ this.onAddCmpClick(panel);
485
+ break;
486
+ case 'remove':
487
+ this.onDeleteCmpClick(panel);
488
+ break;
489
+ case 'save':
490
+ this.onSaveCmpClick(panel);
491
+ break;
492
+ }
493
+ list.up().close();
494
+ },
495
+ onMoveCmpClick: function(panel, needIndex) {
496
+ const parent = panel.up();
497
+ parent.remove(panel, false);
498
+ parent.insert(needIndex, panel);
499
+ this.reloadView();
500
+ },
501
+ onSaveCmpClick: function() {
502
+ JSON.stringify(this.getData(this.getEditorPanel().items.items));
503
+ },
504
+ enablePanelControls: function(div, flag) {
505
+ div.style.display = flag ? 'unset' : 'none';
506
+ },
507
+ onAddCmpClick: function(panel) {
508
+ const me = this;
509
+ let value = 'container';
510
+ let data = [
511
+ {'id': 'container', 'name': 'Контенер'},
512
+ {'id': 'panel', 'name': 'Панель'},
513
+ {'id': 'tabpanel', 'name': 'Таб панель'},
514
+ {'id': 'fieldset', 'name': 'fieldset'},
515
+ {'id': 'textfield', 'name': 'Текстовое поле'},
516
+ {'id': 'numberfield', 'name': 'Числовое поле'},
517
+ {'id': 'datefield', 'name': 'Дата'}
518
+ ];
519
+ if (panel.xtype === 'tabpanel') {
520
+ data = [{'id': 'panel', 'name': 'Панель'}];
521
+ value = 'panel';
522
+ }
523
+ Ext.create('Ext.window.Window', {
524
+ closable: true,
525
+ parentPanel: panel,
526
+ closeAction: 'destroy',
527
+ width: 400,
528
+ title: 'Добавлние элемента',
529
+ height: 170,
530
+ modal: true,
531
+ maximazible: false,
532
+ minimazible: false,
533
+ items: [
534
+ {
535
+ margin: '10px 5px',
536
+ fieldLabel: 'Тип элемента',
537
+ flex: 1,
538
+ width: '100%',
539
+ xtype: 'combo',
540
+ queryMode: 'local',
541
+ value: value,
542
+ displayField: 'name',
543
+ valueField: 'id',
544
+ store: {
545
+ fields: ['id', 'name'],
546
+ data: data,
547
+ },
548
+ }
549
+ ],
550
+ buttons: [
551
+ {
552
+ text: 'Применить',
553
+ handler: me.insertCmp.bind(me, panel),
554
+ },
555
+ {
556
+ text: 'Отмена',
557
+ handler: function() {
558
+ this.up('window').close();
559
+ },
560
+ }
561
+ ],
562
+ }).show();
563
+ },
564
+ insertCmp: function(panel, btn) {
565
+ const cmpXtype = btn.up('window').down('combo').getValue();
566
+ if (!panel.items.length) {
567
+ switch (cmpXtype) {
568
+ case 'textfield':
569
+ case 'numberfield':
570
+ case 'datefield':
571
+ panel.cmpParams.layout = 'anchor';
572
+ break;
573
+ case 'panel':
574
+ case 'tabpanel':
575
+ case 'fieldset':
576
+ case 'container':
577
+ panel.cmpParams.layout = 'fit';
578
+ break;
579
+ }
580
+ }
581
+ panel.add(this.getCfgCmpByXtype(cmpXtype));
582
+ this.reloadView();
583
+ btn.up('window').close();
584
+ },
585
+ getCfgCmpByXtype: function(xtype) {
586
+ switch (xtype) {
587
+ case 'panel':
588
+ return {
589
+ xtype: 'panel',
590
+ layout: 'fit',
591
+ cmpParams: {
592
+ xtype: 'panel',
593
+ layout: 'fit',
594
+ title: 'Новая панель',
595
+ },
596
+ title: 'Новая панель',
597
+ };
598
+ break;
599
+ case 'tabpanel':
600
+ return {
601
+ xtype: 'tabpanel',
602
+ layout: 'fit',
603
+ cmpParams: {
604
+ xtype: 'tabpanel',
605
+ layout: 'fit',
606
+ title: 'Новая панель',
607
+ },
608
+ title: 'Новая панель',
609
+ };
610
+ break;
611
+ case 'container':
612
+ return {
613
+ xtype: 'container',
614
+ cmpParams: {
615
+ xtype: 'container',
616
+ layout: 'fit',
617
+ },
618
+ layout: 'fit',
619
+ };
620
+ break;
621
+ case 'fieldset':
622
+ return {
623
+ xtype: 'fieldset',
624
+ cmpParams: {
625
+ xtype: 'fieldset',
626
+ layout: 'fit',
627
+ title: 'Филдсет',
628
+ },
629
+ };
630
+ break;
631
+ case 'textfield':
632
+ return {
633
+ xtype: 'textfield',
634
+ cmpParams: {
635
+ xtype: 'textfield',
636
+ anchor: '100%',
637
+ fieldLabel: 'Текствое поле',
638
+ },
639
+ };
640
+ break;
641
+ case 'numberfield':
642
+ return {
643
+ xtype: 'numberfield',
644
+ cmpParams: {
645
+ anchor: '100%',
646
+ xtype: 'numberfield',
647
+ fieldLabel: 'Числовое поле',
648
+ },
649
+ };
650
+ break;
651
+ case 'datefield':
652
+ return {
653
+ xtype: 'datefield',
654
+ cmpParams: {
655
+ anchor: '100%',
656
+ xtype: 'datefield',
657
+ fieldLabel: 'Дата поле',
658
+ },
659
+ };
660
+ break;
661
+ }
662
+ },
663
+
664
+ getDefaultData: function() {
665
+ return {
666
+ 'cmpParams': {'xtype': 'container', 'layout': 'fit', 'flex': 1, 'dataId': Ext.id() + '-interface-node'},
667
+
668
+ };
669
+ },
670
+ getDefaultCmp: function(xtype) {
671
+ return {
672
+ 'cmpParams': {
673
+ 'layout': 'fit',
674
+ 'flex': 1,
675
+ 'xtype': xtype || 'container',
676
+ },
677
+ };
678
+ },
679
+ onSettingsCmpClick(panel) {
680
+ const window = Ext.create('Coon.uielement.component.UiCPVisualEditorConfigWindow', {
681
+ 'parentPanel': panel,
682
+ 'parentController': this,
683
+ });
684
+ window.show();
685
+ },
686
+ getValueJson: function(str) {
687
+ try {
688
+ return JSON5.parse(str);
689
+ } catch (e) {
690
+ return str;
691
+ }
692
+ },
693
+ valueIsValidJson: function(str) {
694
+ try {
695
+ return JSON5.parse(str);
696
+ } catch (e) {
697
+ return false;
698
+ }
699
+ },
700
+ onAddReportCmpClick: function(panel) {
701
+ const me = this;
702
+ Ext.create('Ext.window.Window', {
703
+ height: '80%',
704
+ width: 700,
705
+ layout: 'fit',
706
+ closeAction: 'destroy',
707
+ modal: true,
708
+ resizable: false,
709
+ minimazible: false,
710
+ maximazible: false,
711
+
712
+ items: [
713
+ {
714
+ xtype: 'grid',
715
+ store: {
716
+ type: 'json',
717
+ pageSize: 0,
718
+ },
719
+ listeners: {
720
+ itemdblclick: function(element, record) {
721
+ const reportCfg = me.getDefaultCmp('ReportPanel');
722
+ reportCfg.cmpParams.reportId = record.get('CM_REPORT_CD');
723
+ panel.cmpParams = reportCfg.cmpParams;
724
+ me.reloadView();
725
+ element.up('window').close();
726
+ },
727
+ render: function(grid) {
728
+ Promise.all([
729
+ Ext.Ajax.request({
730
+ url: 'ReportFormData/get',
731
+ method: 'POST',
732
+ params: {
733
+ reportId: 'REPORTS',
734
+ parameterList: '[]',
735
+ },
736
+ })
737
+ ]).then(function(valArray) {
738
+ const panels = Ext.decode(valArray[0].responseText).list;
739
+ const data = panels.map((item) => {
740
+ return {
741
+ 'CM_REPORT_CD': item.CM_REPORT_CD,
742
+ 'DESCR': item.DESCR,
743
+ };
744
+ });
745
+ grid.getStore().loadData(data);
746
+ });
747
+ },
748
+ },
749
+ plugins: [
750
+ {ptype: 'gridfilterbar', clicksToEdit: 2}
751
+ ],
752
+ columns: [
753
+ {
754
+ dataIndex: 'CM_REPORT_CD', text: 'Наименование', flex: 1, filter: {type: 'string'},
755
+ },
756
+ {dataIndex: 'DESCR', text: 'Описание', flex: 2, filter: {type: 'string'}}
757
+
758
+ ],
759
+ }
760
+ ],
761
+ buttons: [{
762
+ text: 'Закрыть',
763
+ handler: (elem) => elem.up('window').close(),
764
+ }],
765
+ }).show();
766
+ },
767
+ getDataFromTemplateObj: function(template) {
768
+
769
+ },
770
+ onAddExistingPanelCmpClick: function(panel) {
771
+ const me = this;
772
+ Ext.create('Ext.window.Window', {
773
+ height: '80%',
774
+ width: 700,
775
+ layout: 'fit',
776
+ closeAction: 'destroy',
777
+ modal: true,
778
+ resizable: false,
779
+ minimazible: false,
780
+ maximazible: false,
781
+
782
+ items: [
783
+ {
784
+ xtype: 'grid',
785
+ store: {
786
+ type: 'json',
787
+ pageSize: 0,
788
+ },
789
+ listeners: {
790
+ itemdblclick: function(element, record) {
791
+ const command = Ext.create('command.GetUIElementCommand');
792
+ command.on('complete', function(UIElementBean) {
793
+ const value = me.valueIsValidJson(UIElementBean.propertyData);
794
+ if (!value) {
795
+ Ext.Msg.alert('Ошибка', 'Не корректный JSON объект');
796
+ return false;
797
+ }
798
+ try {
799
+ const check = Ext.create('Ext.panel.Panel', value);
800
+ check.destroy();
801
+ } catch (e) {
802
+ element.up('window').close();
803
+ Ext.Msg.alert('Ошибка', e.message);
804
+ return false;
805
+ }
806
+ panel.removeAll(true);
807
+ if (value && value.plugins && value.plugins.length) {
808
+ panel.cmpParams.mainPlugins = value.plugins;
809
+ delete value['plugins'];
810
+ }
811
+ const content = me.getTemplate([value]);
812
+ panel.add(content);
813
+ me.reloadView();
814
+ element.up('window').close();
815
+ /*
816
+ */
817
+ }, this);
818
+ command.execute(record.get('CM_REPORT_CD'));
819
+ },
820
+ render: function(grid) {
821
+ Promise.all([
822
+ Ext.Ajax.request({
823
+ url: 'ReportFormData/get',
824
+ method: 'POST',
825
+ params: {
826
+ reportId: 'UI_CUSTOM_PANELS_LIST',
827
+ parameterList: '[]',
828
+ },
829
+ })
830
+ ]).then(function(valArray) {
831
+ const panels = Ext.decode(valArray[0].responseText).list;
832
+ const data = panels.map((item) => {
833
+ return {
834
+ 'CM_REPORT_CD': item.UI_ELEMENT_CD,
835
+ 'DESCR': item.DESCR,
836
+ };
837
+ });
838
+ grid.getStore().loadData(data);
839
+ });
840
+ },
841
+ },
842
+ plugins: [
843
+ {ptype: 'gridfilterbar', clicksToEdit: 2}
844
+ ],
845
+ columns: [
846
+ {
847
+ dataIndex: 'CM_REPORT_CD', text: 'Наименование', flex: 1, filter: {type: 'string'},
848
+ },
849
+ {dataIndex: 'DESCR', text: 'Описание', flex: 2, filter: {type: 'string'}}
850
+
851
+ ],
852
+ }
853
+ ],
854
+ buttons: [{
855
+ text: 'Закрыть',
856
+ handler: (elem) => elem.up('window').close(),
857
+ }],
858
+ }).show();
859
+ },
860
+ },
861
+ items: [
862
+ {
863
+ xtype: 'panel',
864
+ region: 'center',
865
+ flex: 4,
866
+ layout: 'fit',
867
+ header: false,
868
+ dataId: 'editorPanel',
869
+ split: true,
870
+ },
871
+ {
872
+ xtype: 'treepanel',
873
+ store: {
874
+ type: 'tree',
875
+ rootVisible: false,
876
+ root: {
877
+ expanded: true,
878
+ children: [],
879
+ },
880
+ },
881
+ title: 'Структура',
882
+ cls: 'tree-container',
883
+ collapsible: true,
884
+ region: 'east',
885
+ flex: 1,
886
+ dataId: 'treeEditorPanel',
887
+ listeners: {
888
+ 'selectionchange': 'onTreeSelectionChange',
889
+ 'itemcontextmenu': 'onTreeItemContextMenu',
890
+ },
891
+ }
892
+ ],
893
+ listeners: {
894
+ render: 'onRenderMainPanel',
895
+ },
896
+ });