ru.coon 2.6.5 → 2.6.7

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/index.js +0 -1
  3. package/package.json +2 -2
  4. package/src/Function.js +1 -1
  5. package/src/common/component/characteristic/characteristicGroup/EditorOptionsWindow.js +150 -0
  6. package/src/common/component/characteristic/characteristicGroup/EditorOptionsWindowController.js +174 -0
  7. package/src/common/component/characteristic/characteristicGroup/EntityGroupCharacteristicEditor.js +23 -0
  8. package/src/common/component/characteristic/characteristicGroup/EntityGroupCharacteristicEditorController.js +38 -0
  9. package/src/common/component/editor/CharacteristicGridEditor.js +3 -0
  10. package/src/common/component/editor/TypedCharacteristicEditor.js +0 -5
  11. package/src/common/component/editor/creators/BaseEditorCreator.js +0 -3
  12. package/src/common/component/editor/creators/ByReportEditorCreator.js +0 -3
  13. package/src/common/component/editor/creators/CustomPanelEditorCreator.js +0 -3
  14. package/src/common/component/editor/creators/ForeignKeyEditorCreator.js +0 -3
  15. package/src/common/component/editor/creators/NoteEditorCreator.js +0 -3
  16. package/src/common/component/editor/creators/NumberEditorCreator.js +17 -4
  17. package/src/common/component/editor/creators/SimpleReportEditorCreator.js +0 -3
  18. package/src/common/component/editor/creators/TriggerFieldEditorCreator.js +0 -3
  19. package/src/common/component/formeditor/UiCFCard.js +86 -0
  20. package/src/common/component/formeditor/UiCFCardsGrid.js +69 -0
  21. package/src/common/component/formeditor/UiCFCell.js +12 -0
  22. package/src/common/component/formeditor/UiCFCellController.js +236 -0
  23. package/src/common/component/formeditor/UiCFCheckboxGroup.js +53 -0
  24. package/src/common/component/formeditor/UiCFContainer.js +15 -0
  25. package/src/common/component/formeditor/UiCFContainerController.js +217 -0
  26. package/src/common/component/formeditor/UiCFFieldsConfig.js +342 -0
  27. package/src/common/component/formeditor/UiCFRadioGrid.js +70 -0
  28. package/src/common/component/formeditor/UiCFRadioGroup.js +53 -0
  29. package/src/common/component/formeditor/UiCFReportField.js +48 -0
  30. package/src/common/component/formeditor/UiCFRow.js +13 -0
  31. package/src/common/component/formeditor/UiCFRowController.js +155 -0
  32. package/src/common/component/formeditor/UiCFSegmentedButton.js +62 -0
  33. package/src/common/component/formeditor/UiCFSegmentedButtonGrid.js +70 -0
  34. package/src/common/component/formeditor/UiCFSettingsWindow.js +62 -0
  35. package/src/common/component/formeditor/UiCFSpacer.js +8 -0
  36. package/src/common/component/formeditor/UiCFTab.js +51 -0
  37. package/src/common/component/formeditor/UiCustomForm.js +33 -0
  38. package/src/common/component/formeditor/UiCustomFormController.js +6 -0
  39. package/src/common/component/formeditor/UiCustomFormEditor.js +191 -0
  40. package/src/common/component/formeditor/UiCustomFormEditor.scss +13 -0
  41. package/src/common/component/formeditor/UiCustomFormEditorController.js +654 -0
  42. package/src/common/component/formeditor/UiCustomFormEditorView.js +7 -0
  43. package/src/report/component/settings/plugin/ReportFormPluginPanelController.js +1 -1
  44. package/src/report/plugin/grid/ReportColumnStatePlugin.js +18 -2
  45. package/src/uielement/component/SearchByPropCombo.js +53 -0
  46. package/src/uielement/plugin/UnifiedButtonToolbarPlugin.js +19 -2
  47. package/src/uielement/plugin/configPanel/MethodChainPluginConfigPanelFormEditor.js +10 -6
  48. package/src/uielement/plugin/configPanel/UnifiedButtonToolbarPluginConfigPanelFormEditor.js +34 -46
  49. package/src/version.js +1 -1
@@ -0,0 +1,86 @@
1
+ /* global Ext */
2
+ Ext.define('Coon.common.component.formeditor.UiCFCard', {
3
+ extend: 'Ext.panel.Panel',
4
+ xtype: 'UiCFCard',
5
+ layout: 'card',
6
+ bind: {
7
+ activeItem: '{activeItem}',
8
+ },
9
+ viewModel: {
10
+ data: {
11
+ activeItem: 0,
12
+ },
13
+ },
14
+ controller: {
15
+ init(view) {
16
+ if (view.initialConfig && !view.initialConfig.checkOptions) {
17
+ if (view.initialConfig && view.initialConfig.countCards) {
18
+ view.initialConfig.countCards.forEach((setting, index) => {
19
+ let item = view.items.getAt(view.items.findIndex('itemId', setting.itemId));
20
+ if (!item) {
21
+ item = view.add({
22
+ xtype: 'panel',
23
+ layout: 'fit',
24
+ itemId: setting.itemId,
25
+ items: [{xtype: 'UiCFContainer'}],
26
+ });
27
+ }
28
+ if (setting.title) {
29
+ item.setTitle(setting.title);
30
+ }
31
+ });
32
+ if (view.initialConfig.countCards.length < view.items.getCount()) {
33
+ const ids = view.initialConfig.countCards.map((item) => item.itemId);
34
+ view.items.items.forEach((item) => {
35
+ if (ids.indexOf(item.itemId) < 0) {
36
+ view.remove(item);
37
+ }
38
+ });
39
+ }
40
+ } else {
41
+ const itemId = 'UiCFCard_' + Ext.id().replace('-', '_');
42
+ view.value = view.countCards = [
43
+ {
44
+ 'title': '',
45
+ 'itemId': itemId,
46
+ }
47
+ ],
48
+ view.add({
49
+ xtype: 'panel',
50
+ layout: 'fit',
51
+ itemId: itemId,
52
+ items: [{xtype: 'UiCFContainer'}],
53
+ });
54
+ }
55
+ const vm = this.getViewModel();
56
+ vm.bind('{activeItem}', (activeItem) => {
57
+ this.lookup('backButton').setVisible(view.items.getCount() > 1 && Number(activeItem) > 0);
58
+ this.lookup('forwardButton').setVisible(view.items.getCount() > 1 && Number(activeItem) < view.items.items.length - 1);
59
+ }, this);
60
+ }
61
+ },
62
+ back() {
63
+ const vm = this.getViewModel();
64
+ this.getViewModel().set('activeItem', Number(vm.get('activeItem'))-1);
65
+ },
66
+ forward() {
67
+ const vm = this.getViewModel();
68
+ if (Coon.Function.validateAllFieldsOnForm(this.getView().items.getAt(Number(vm.get('activeItem'))))) {
69
+ this.getViewModel().set('activeItem', Number(vm.get('activeItem'))+1);
70
+ } else {
71
+ Ext.Msg.show({
72
+ title: 'Ошибка',
73
+ message: 'Проверьте корректность заполнения полей формы',
74
+ icon: Ext.Msg.ERROR,
75
+ buttons: Ext.Msg.OK,
76
+ });
77
+ }
78
+ },
79
+ },
80
+ minHeight: 100,
81
+ buttons: [
82
+ {text: 'Назад', reference: 'backButton', handler: 'back'},
83
+ {text: 'Вперед', reference: 'forwardButton', handler: 'forward'}
84
+ ],
85
+ items: [],
86
+ });
@@ -0,0 +1,69 @@
1
+ /* global Ext */
2
+ Ext.define('Coon.common.component.formeditor.UiCFCardsGrid', {
3
+ extend: 'Ext.grid.Panel',
4
+ xtype: 'UiCFCardsGrid',
5
+ flex: 1,
6
+ title: 'Элементы компонента',
7
+ minHeight: 100,
8
+ controller: {
9
+ init(view) {
10
+ const vm = this.getViewModel();
11
+ vm.getStore('cardsStore').on('datachanged', (store) => {
12
+ vm.set('dataCount', store.data.length);
13
+ }, this);
14
+ if (view.initialConfig && view.initialConfig.value) {
15
+ vm.getStore('cardsStore').loadData(view.initialConfig.value);
16
+ }
17
+ this.getView().getFormData = this.getFormData.bind(this);
18
+ },
19
+ getFormData() {
20
+ return this.getViewModel().getStore('cardsStore').getRange().map((rec) => {
21
+ return {title: rec.get('title'), itemId: rec.get('itemId')};
22
+ });
23
+ },
24
+ addRow() {
25
+ this.getViewModel().getStore('cardsStore').add({itemId: 'UiCFCard_' + Ext.id().replace('-', '_')});
26
+ },
27
+ deleteRow() {
28
+ this.getViewModel().getStore('cardsStore').remove(this.getViewModel().get('selection'));
29
+ },
30
+ },
31
+ viewModel: {
32
+ data: {
33
+ selection: null,
34
+ dataCount: 1,
35
+ },
36
+ stores: {
37
+ cardsStore: {
38
+ type: 'json',
39
+ fields: ['title', 'itemId'],
40
+ data: [
41
+ ],
42
+ },
43
+ },
44
+ },
45
+ tbar: [
46
+ {
47
+ text: 'Добавить',
48
+ handler: 'addRow',
49
+ },
50
+ {
51
+ text: 'Удалить',
52
+ handler: 'deleteRow',
53
+ bind: {
54
+ disabled: '{!selection || dataCount < 2}',
55
+ },
56
+ }
57
+ ],
58
+ bind: {
59
+ store: '{cardsStore}',
60
+ selection: '{selection}',
61
+ },
62
+ columns: [
63
+ {xtype: 'rownumberer'},
64
+ {dataIndex: 'title', text: 'Заголовок', flex: 1, editor: {xtype: 'textfield'}}
65
+ ],
66
+ plugins: [
67
+ {ptype: 'cellediting'}
68
+ ],
69
+ });
@@ -0,0 +1,12 @@
1
+ /* global Ext */
2
+ Ext.define('Coon.common.component.formeditor.UiCFCell', {
3
+ extend: 'Ext.container.Container',
4
+ controller: 'UiCFCellController',
5
+ xtype: 'UiCFCell',
6
+ flex: 200,
7
+ collapsible: true,
8
+ margin: 5,
9
+ layout: 'fit',
10
+ items: [
11
+ ],
12
+ });
@@ -0,0 +1,236 @@
1
+ Ext.define('Coon.common.component.formeditor.UiCFCellController', {
2
+ extend: 'Ext.app.ViewController',
3
+ alias: 'controller.UiCFCellController',
4
+ menuItems: {},
5
+ oldWidth: 0,
6
+ minCellWidth: 150,
7
+ readOnly: false,
8
+ init: function() {
9
+ this.setDefaultMenuItems();
10
+ this.initMouseEvents();
11
+ },
12
+ setDefaultMenuItems() {
13
+ const rowCnt = this.getUiCFRowController();
14
+ this.menuItems = {
15
+ left: {
16
+ text: 'влево', iconCls: 'fa fa-arrow-left',
17
+ handler: this.moveCellLeft.bind(this),
18
+ },
19
+ right: {
20
+ text: 'вправо', iconCls: 'fa fa-arrow-right',
21
+ handler: this.moveCellRight.bind(this),
22
+ },
23
+ copy: {
24
+ text: 'копировать', iconCls: 'fa fa-copy',
25
+ handler: this.copyCell.bind(this),
26
+ },
27
+ cut: {
28
+ text: 'вырезать', iconCls: 'fa fa-cut',
29
+ handler: this.cutCell.bind(this),
30
+ },
31
+ paste: {
32
+ text: 'вставить', iconCls: 'fa fa-paste',
33
+ handler: this.pasteCell.bind(this),
34
+ },
35
+ remove: {
36
+ text: 'удалить', iconCls: 'fa fa-trash',
37
+ handler: this.removeCell.bind(this),
38
+ },
39
+ layout: {
40
+ text: 'выравнивание', iconCls: 'fa fa-bars',
41
+ menu: [
42
+ {text: 'выравнять текущую строку', handler: rowCnt.layoutCellsInRow.bind(rowCnt)},
43
+ {text: 'выравнять по шаблону', handler: rowCnt.layoutByTemplate.bind(rowCnt)}
44
+ ],
45
+ },
46
+ flexLayout: {
47
+ text: 'задать относительный размер', iconCls: 'fa fa-arrows-alt-v',
48
+ handler: rowCnt.setFlex.bind(rowCnt),
49
+ },
50
+ };
51
+ },
52
+
53
+ setResizer() {
54
+ this.oldWidth = this.getView().getWidth();
55
+ const uiCFEditorController = this.getUiCFEditorController();
56
+ if (uiCFEditorController && uiCFEditorController.activeResizer) {
57
+ uiCFEditorController.activeResizer.destroy();
58
+ uiCFEditorController.activeResizer = null;
59
+ }
60
+ const rowController = this.getUiCFRowController();
61
+ const row = this.getView().up('UiCFRow');
62
+ const countCells = rowController.getCountCells();
63
+ const cellIndex = rowController.getCellIndexInRow(this.getView());
64
+ if (cellIndex !== countCells - 1) {
65
+ const currentItem = this.getView();
66
+ const nextItem = row.items.getAt(cellIndex + 1);
67
+ this.oldWidth = currentItem.getWidth();
68
+ if (uiCFEditorController) {
69
+ uiCFEditorController.activeResizer = Ext.create('Ext.resizer.Resizer', {
70
+ target: currentItem.getEl(),
71
+ handles: 'e',
72
+ minWidth: this.minCellWidth,
73
+ pinned: true,
74
+ listeners: {
75
+ resize: (cmp, width) => {
76
+ const dif = width - this.oldWidth;
77
+ const module = Math.abs(dif);
78
+ const percent = Ext.Number.parseInt(Ext.Number.toFixed(module/this.oldWidth, 2)*100);
79
+ const difFlex = Ext.Number.parseInt(currentItem.flex * percent / 100);
80
+ const minFlex = Ext.Number.parseInt(this.minCellWidth * nextItem.flex / nextItem.getWidth());
81
+ let nextSum = nextItem.flex - difFlex;
82
+ let curSum = currentItem.flex + difFlex;
83
+ if (dif > 0 && nextItem.flex - difFlex < minFlex) {
84
+ curSum -= minFlex - nextSum;
85
+ nextSum = minFlex;
86
+ }
87
+ nextItem.setFlex(dif > 0 ? nextSum : nextItem.flex + difFlex);
88
+ currentItem.setFlex(dif > 0 ? curSum : currentItem.flex - difFlex);
89
+ row.updateLayout();
90
+ this.oldWidth = currentItem.getWidth();
91
+ },
92
+ },
93
+ });
94
+ }
95
+ }
96
+ },
97
+ moveCellLeft() {
98
+ const rowController = this.getUiCFRowController();
99
+ rowController.moveCell(this.getView(), 'left');
100
+ this.setResizer();
101
+ },
102
+
103
+ moveCellRight() {
104
+ const rowController = this.getUiCFRowController();
105
+ rowController.moveCell(this.getView(), 'right');
106
+ this.setResizer();
107
+ },
108
+
109
+ copyCell() {
110
+ const cnt = this.getUiCFEditorController();
111
+ cnt.copyCell = this;
112
+ if (cnt.cutCell) {
113
+ cnt.cutCell.getView().removeCls('cutCell');
114
+ cnt.cutCell = null;
115
+ }
116
+ },
117
+
118
+ pasteCell() {
119
+ const cnt = this.getUiCFEditorController();
120
+ const cell = cnt.copyCell || cnt.cutCell;
121
+ if (cell) {
122
+ const cfg = cnt.getCfg(cell.getView());
123
+ if (cnt.copyCell) {
124
+ this.getUiCFRowController().addCell(this.getUiCFContainerController().generateNewNames(cfg), this.getView());
125
+ } else {
126
+ cell.getUiCFRowController().removeCell(cell.getView());
127
+ cnt.cutCell = null;
128
+ this.getUiCFRowController().addCell(cfg, this.getView());
129
+ }
130
+ }
131
+ },
132
+
133
+ cutCell() {
134
+ const cnt = this.getUiCFEditorController();
135
+ this.getView().addCls('cutCell');
136
+ cnt.cutCell = this;
137
+ cnt.copyCell = null;
138
+ },
139
+
140
+ getUiCFEditorController() {
141
+ return this.getView().up('UiCustomFormEditor').getController();
142
+ },
143
+
144
+ removeCell() {
145
+ const rowController = this.getUiCFRowController();
146
+ rowController.removeCell(this.getView());
147
+ },
148
+
149
+ getField() {
150
+ return this.getView().items.find((el) => el.itemId === 'field');
151
+ },
152
+
153
+ initMouseEvents() {
154
+ if (!this.getUiCFContainerController() || this.readOnly) {
155
+ return;
156
+ }
157
+ this.getView().on('render', (cmp) => {
158
+ const listeners = {
159
+ contextmenu: 'onMouseEvent',
160
+ scope: this,
161
+ destroyable: true,
162
+ priority: 1,
163
+ stopPropagation: true,
164
+ };
165
+ cmp.getEl().on(listeners);
166
+ }, this);
167
+ },
168
+ onMouseEvent(event) {
169
+ if (this.readOnly) {
170
+ return;
171
+ }
172
+ const contextMenu = new Ext.menu.Menu({
173
+ closeAction: 'destroy',
174
+ items: this.getMenuItems(),
175
+ listeners: {
176
+ hide: function() {
177
+ const me = this;
178
+ Ext.defer(() => me.destroy(), 2000);
179
+ },
180
+ },
181
+ });
182
+ contextMenu.showAt(event.pageX, event.pageY);
183
+ event.preventDefault();
184
+ return false;
185
+ },
186
+ getCellIndexInRow() {
187
+ return this.getUiCFRowController().getCellIndexInRow(this.getView());
188
+ },
189
+ getCountCellsInRow() {
190
+ return this.getUiCFRowController().getCountCells();
191
+ },
192
+ getMenuItems() {
193
+ const count = this.getCountCellsInRow();
194
+ const mainC = this.getUiCFContainerController();
195
+ const rowC = this.getUiCFRowController();
196
+ let menuItems = [];
197
+ menuItems = menuItems.concat(mainC.getMenuItems(this.getRow()));
198
+ menuItems = menuItems.concat(rowC.getMenuItems(this.getView()));
199
+ if (count > 1) {
200
+ const index = this.getCellIndexInRow() + 1;
201
+ if (count > index) {
202
+ menuItems.push(this.menuItems.right);
203
+ }
204
+ if (index > 1) {
205
+ menuItems.push(this.menuItems.left);
206
+ }
207
+ }
208
+ const cnt = this.getUiCFEditorController();
209
+ const cell = cnt.copyCell || cnt.cutCell;
210
+ menuItems.push(this.menuItems.copy);
211
+ menuItems.push(this.menuItems.cut);
212
+ if (cell && cell.getView() && cell.getView().id !== this.getView().id) {
213
+ menuItems.push(this.menuItems.paste);
214
+ }
215
+ if (rowC.getCountCells() > 1) {
216
+ menuItems.push(this.menuItems.layout);
217
+ }
218
+ if (this.menuItems.flexLayout) {
219
+ const tmp = this.menuItems.flexLayout;
220
+ tmp.text = 'задать относительный размер' + (rowC.getView().flex > 0 ? ' (' + rowC.getView().flex + ')' : '');
221
+ menuItems.push(tmp);
222
+ }
223
+
224
+ menuItems.push(this.menuItems.remove);
225
+ return menuItems;
226
+ },
227
+ getUiCFContainerController() {
228
+ return this.getView().up('UiCFContainer') ? this.getView().up('UiCFContainer').getController() : null;
229
+ },
230
+ getRow() {
231
+ return this.getView().up('UiCFRow');
232
+ },
233
+ getUiCFRowController() {
234
+ return this.getRow().getController();
235
+ },
236
+ });
@@ -0,0 +1,53 @@
1
+ /* global Ext */
2
+ Ext.define('Coon.common.component.formeditor.UiCFCheckboxGroup', {
3
+ extend: 'Ext.form.CheckboxGroup',
4
+ xtype: 'UiCFCheckboxGroup',
5
+ controller: {
6
+ init(view) {
7
+ let i = 1;
8
+ if (view.initialConfig && !view.initialConfig.checkOptions) {
9
+ if (view.initialConfig && view.initialConfig.countCards) {
10
+ view.initialConfig.countCards.forEach((setting, index) => {
11
+ let item = view.items.getAt(view.items.findIndex('itemId', setting.itemId));
12
+ if (!item) {
13
+ item = view.add({
14
+ itemId: setting.itemId,
15
+ inputValue: setting.inputValue,
16
+ });
17
+ }
18
+ if (setting.boxLabel) {
19
+ item.setBoxLabel(setting.boxLabel);
20
+ }
21
+ if (setting.inputValue) {
22
+ item.inputValue = setting.inputValue;
23
+ } else {
24
+ item.inputValue = i++;
25
+ }
26
+ });
27
+ if (view.initialConfig.countCards.length < view.items.getCount()) {
28
+ const ids = view.initialConfig.countCards.map((item) => item.itemId);
29
+ view.items.items.forEach((item) => {
30
+ if (ids.indexOf(item.itemId) < 0) {
31
+ view.remove(item);
32
+ }
33
+ });
34
+ }
35
+ } else {
36
+ const itemId = 'UiCFRadio_' + Ext.id().replace('-', '_');
37
+ view.countCards = [
38
+ {
39
+ 'itemId': itemId,
40
+ 'inputValue': i,
41
+ }
42
+ ],
43
+ view.add({
44
+ 'itemId': itemId,
45
+ 'inputValue': i,
46
+ });
47
+ i++;
48
+ }
49
+ }
50
+ },
51
+ },
52
+ items: [],
53
+ });
@@ -0,0 +1,15 @@
1
+ /* global Ext */
2
+ Ext.define('Coon.common.component.formeditor.UiCFContainer', {
3
+ extend: 'Ext.panel.Panel',
4
+ controller: 'UiCFContainerController',
5
+ xtype: 'UiCFContainer',
6
+ cls: 'UiCFContainer',
7
+ layout: {
8
+ type: 'vbox',
9
+ align: 'stretch',
10
+ },
11
+ minHeight: 30,
12
+ items: [
13
+
14
+ ],
15
+ });
@@ -0,0 +1,217 @@
1
+ Ext.define('Coon.common.component.formeditor.UiCFContainerController', {
2
+ extend: 'Ext.app.ViewController',
3
+ alias: 'controller.UiCFContainerController',
4
+ readOnly: false,
5
+ init: function(view) {
6
+ this.initMouseEvents();
7
+ },
8
+ getCountElemsByXtype(xtype) {
9
+ return Ext.ComponentQuery.query('[xtype='+xtype+']', this.getUiCFEditorController().getView()).length;
10
+ },
11
+ initMouseEvents() {
12
+ if (this.readOnly) {
13
+ return;
14
+ }
15
+ this.getView().on('render', (cmp) => {
16
+ cmp.getEl().on({
17
+ contextmenu: 'onMouseContextEvent',
18
+ scope: this,
19
+ destroyable: true,
20
+ priority: 2,
21
+ stopPropagation: true,
22
+ });
23
+
24
+ cmp.getEl().on({
25
+ click: 'onMouseClickEvent',
26
+ scope: this,
27
+ destroyable: true,
28
+ stopPropagation: true,
29
+ });
30
+ }, this);
31
+ },
32
+ onMouseClickEvent(event) {
33
+ if (this.readOnly) {
34
+ return;
35
+ }
36
+ const el = this.getFieldByEl(event.target);
37
+ if (!el) {
38
+ return false;
39
+ }
40
+ const cmp = Ext.getCmp(el.id);
41
+ if (cmp) {
42
+ const vm = this.getViewModel();
43
+ const currentField = vm.get('focusedField');
44
+ if (currentField && currentField.el && currentField.el.dom) {
45
+ currentField.removeCls('selectedField');
46
+ }
47
+ vm.set('focusedField', cmp);
48
+ cmp.addCls('selectedField');
49
+ }
50
+ },
51
+
52
+ getFieldByEl(el) {
53
+ const checkClass = (el) => {
54
+ return el && el.classList ? el.classList.contains('componentTarget') : false;
55
+ };
56
+ const isUiCFContainer = (el) => {
57
+ return el && el.classList ? el.classList.contains('UiCustomFormEditor') : false;
58
+ };
59
+ if (checkClass(el)) {
60
+ return Ext.getCmp(el.id);
61
+ } else {
62
+ if (isUiCFContainer(el.parentNode)) {
63
+ return null;
64
+ }
65
+ return this.getFieldByEl(el.parentNode);
66
+ }
67
+ },
68
+
69
+ onMouseContextEvent(event) {
70
+ if (this.readOnly) {
71
+ return;
72
+ }
73
+ const menu = this.getMenuItems();
74
+ const contextMenu = new Ext.menu.Menu({
75
+ closeAction: 'destroy',
76
+ items: menu[0]['menu'],
77
+ listeners: {
78
+ hide: function() {
79
+ const me = this;
80
+ Ext.defer(() => me.destroy(), 2000);
81
+ },
82
+ },
83
+ });
84
+ contextMenu.showAt(event.pageX, event.pageY);
85
+ event.preventDefault();
86
+ return false;
87
+ },
88
+ moveRow(row, direction) {
89
+ const rowIndex = this.getRowIndex(row);
90
+ const view = this.getView();
91
+ const countRows = this.getCountRows();
92
+ if (countRows > 1) {
93
+ if (direction === 'up') {
94
+ view.moveBefore(row, view.items.getAt(rowIndex - 1));
95
+ } else {
96
+ view.moveAfter(row, view.items.getAt(rowIndex + 1));
97
+ }
98
+ }
99
+ },
100
+ getCountRows() {
101
+ return this.getView().items.length;
102
+ },
103
+
104
+ getRows() {
105
+ return this.getView().items.getRange();
106
+ },
107
+
108
+ getRowIndex(row) {
109
+ return this.getView().items.indexOfKey(row.id);
110
+ },
111
+
112
+ removeRow(row) {
113
+ this.getView().remove(this.getRowIndex(row));
114
+ },
115
+
116
+ addRow(type) {
117
+ let cfg = null;
118
+ if (!Ext.isObject(type)) {
119
+ cfg = {
120
+ xtype: 'UiCFRow',
121
+ items: [{
122
+ xtype: 'UiCFCell',
123
+ items: [Ext.apply({
124
+ xtype: type,
125
+ name: type + '-' + (this.getCountElemsByXtype(type) + 1),
126
+ cls: 'componentTarget',
127
+ }, Coon.UiCFFieldsConfig.getFieldCfg(type))],
128
+ }],
129
+ };
130
+ } else {
131
+ cfg ={
132
+ xtype: 'UiCFRow',
133
+ items: [type],
134
+ };
135
+ }
136
+ this.getView().add(cfg);
137
+ },
138
+ pasteCell() {
139
+ const cnt = this.getUiCFEditorController();
140
+ const cell = cnt.copyCell || cnt.cutCell;
141
+ if (cell) {
142
+ const cfg = cnt.getCfg(cell.getView());
143
+ if (cnt.copyCell) {
144
+ const mod = this.generateNewNames(cfg);
145
+ this.addRow(mod);
146
+ } else {
147
+ cell.getUiCFRowController().removeCell(cell.getView());
148
+ cnt.cutCell = null;
149
+ this.addRow(cfg);
150
+ }
151
+ }
152
+ },
153
+ generateNewNames(cfg) {
154
+ const arr = ['UiCFSegmentedButton'];
155
+ if (cfg.items && cfg.items.length) {
156
+ cfg.items = cfg.items.map((item) => {
157
+ return this.generateNewNames(item);
158
+ });
159
+ }
160
+ if (arr.indexOf(cfg.xtype) >= 0) {
161
+ cfg = this.changeItemIds(cfg);
162
+ }
163
+ if (cfg.name) {
164
+ cfg.name = cfg.xtype + '-' + (this.getCountElemsByXtype(cfg.xtype) + 1);
165
+ }
166
+ return cfg;
167
+ },
168
+
169
+ changeItemIds(cfg) {
170
+ if (cfg && cfg.countCards && cfg.countCards.length) {
171
+ cfg.countCards.forEach((cadrd, indexCard) => {
172
+ cfg.items.forEach((item, index) => {
173
+ if (cadrd['itemId'] === item['itemId']) {
174
+ const newId = cadrd['itemId'] + '_' + Ext.id().replace('-', '_');
175
+ cfg.countCards[indexCard]['itemId'] = newId;
176
+ cfg.items[index]['itemId'] = newId;
177
+ return;
178
+ }
179
+ });
180
+ });
181
+ }
182
+ return cfg;
183
+ },
184
+
185
+ getUiCFEditorController() {
186
+ return this.getView().up('UiCustomFormEditor').getController();
187
+ },
188
+
189
+ getMenuItems(activeRow) {
190
+ const me = this;
191
+ const menuItems = [
192
+ {
193
+ text: 'добавить', iconCls: 'fa fa-plus',
194
+ menu: Coon.UiCFFieldsConfig.getFieldsTypes().map((item) => {
195
+ return {
196
+ text: item.description,
197
+ iconCls: '',
198
+ handler: () => {
199
+ me.addRow(item.type, activeRow);
200
+ },
201
+ };
202
+ }),
203
+ }
204
+ ];
205
+ const cnt = this.getUiCFEditorController();
206
+ const cell = cnt.copyCell || cnt.cutCell;
207
+ if (cell && cell.getView() && cell.getView().id !== this.getView().id) {
208
+ menuItems[0].menu.push({
209
+ text: 'вставить', iconCls: 'fa fa-paste',
210
+ handler: this.pasteCell.bind(this),
211
+ });
212
+ }
213
+ return menuItems;
214
+ },
215
+
216
+
217
+ });