rb-document-form-constructor 0.8.55 → 0.8.57

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.
@@ -1,254 +1,254 @@
1
- <template>
2
- <div class="rb-doc-template-constructor d-flex">
3
- <doc-template-facet-list @fieldMoveEnd="onFieldMoveEnd" :facets="facets"></doc-template-facet-list>
4
-
5
- <div class="rb-form-constructor flex-fill">
6
- <div class="rb-constructor-toolbar d-flex flex-row">
7
- <h4>Добавить секцию: </h4>
8
- <div class="rb-layout-buttons">
9
- <b-button pill variant="outline-gray" @click="addSection(1)">
10
- <rb-text>Секция с 1 колонкой</rb-text>
11
- <rb-icon :icon="iconAdd"></rb-icon>
12
- </b-button>
13
- <b-button pill variant="outline-gray" @click="addSection(2)">
14
- <rb-text>Секция с 2 колонками</rb-text>
15
- <rb-icon :icon="iconAdd"></rb-icon>
16
- </b-button>
17
- <b-button pill variant="outline-gray" @click="addSection(3)">
18
- <rb-text>Секция с 3 колонками</rb-text>
19
- <rb-icon :icon="iconAdd"></rb-icon>
20
- </b-button>
21
- </div>
22
- </div>
23
-
24
- <div class="rb-constructor-body">
25
- <draggable v-model="formConfig.section"
26
- :animation="200"
27
- group="section"
28
- ghost-class="rb-form-card-moving"
29
- handle=".rb-row-drag-handle">
30
- <b-card v-for="(section, index) in formConfig.sections" :key="section.labelRu"
31
- class="rb-form-card" :data-hash="hash">
32
- <template #header>
33
- <rb-icon :icon="iconDrag"
34
- class="cursor-pointer rb-row-drag-handle"></rb-icon>
35
- <rb-text class="flex-fill" @click="editSection(section)">
36
- {{ section.labelRu }}
37
- </rb-text>
38
- <span class="rb-actions">
39
- <rb-icon :icon="iconEdit" class="cursor-pointer"
40
- @click="editSection(section)"></rb-icon>
41
- <rb-icon :icon="iconDelete" class="cursor-pointer"
42
- @click="removeSection(section, index)"></rb-icon>
43
- </span>
44
- </template>
45
-
46
- <div class="d-flex flex-row">
47
- <draggable tag="b-form"
48
- class="rb-form-column"
49
- v-for="column in section.columns"
50
- :key="column.index"
51
- :class="{'rb-single-column': section.columnCount === 1}"
52
- v-model="column.fields"
53
- @add="onFieldAddedToColumn($event, column, section)"
54
- :animation="200"
55
- group="fields"
56
- ghost-class="rb-moving-item"
57
- handle=".rb-field-drag-handle">
58
- <b-form-row v-for="field in column.fields" :key="field.name"
59
- class="cursor-pointer" @click="showProperties(field, $event)">
60
- <b-col lg="12">
61
- <b-form-group :label="field.labelRu">
62
- <template #label>
63
- <rb-icon :icon="iconDrag" class="rb-field-drag-handle"></rb-icon>
64
- <rb-text>{{ field.labelRu }}</rb-text>
65
- <rb-icon :icon="iconDelete" class="rb-remove-field"
66
- @click.prevent="onRemoveField($event, field, column)">
67
- </rb-icon>
68
- </template>
69
- <component v-bind:is="field.input.type"
70
- :id="field.name"
71
- v-if="field.input"
72
- v-bind="getFieldExtendedPropsData(field)"
73
- disabled
74
- class="cursor-pointer">
75
- </component>
76
- </b-form-group>
77
- </b-col>
78
- </b-form-row>
79
- </draggable>
80
- </div>
81
- </b-card>
82
- </draggable>
83
- </div>
84
-
85
- <doc-template-field-sidebar v-model="sidebarField"
86
- :visible="sidebarVisible"
87
- :form-config="formConfig"
88
- @hide="sidebarVisible=false">
89
- </doc-template-field-sidebar>
90
-
91
- <doc-template-section-modal :mode="sectionModalCfg.mode"
92
- :section="sectionModalCfg.section"
93
- :on-after-ok="sectionModalCfg.onAfterOk">
94
- </doc-template-section-modal>
95
- </div>
96
- </div>
97
- </template>
98
-
99
- <script>
100
- import DocTemplateFacetList from "@/components/DocTemplateFacetList";
101
- import DocTemplateFieldSidebar from "@/components/DocTemplateFieldSidebar";
102
- import DocTemplateSectionModal from "@/components/DocTemplateSectionModal";
103
- import draggable from 'vuedraggable';
104
- import {UtFormConfig} from "../utils/UtFormConfig";
105
- import {UtFormConstructor} from "../utils/UtFormConstructor";
106
-
107
- export default {
108
- name: 'DocTemplateConstructor',
109
- components: {DocTemplateFacetList, DocTemplateFieldSidebar, DocTemplateSectionModal, draggable},
110
- props: {
111
- formConfig: {
112
- type: Object, default: () => {
113
- return {sections: []}
114
- }
115
- },
116
- facets: {type: Array, default: () => []}
117
- },
118
- data() {
119
- return {
120
- sidebarVisible: false,
121
- sidebarField: null,
122
- columnTo: false,
123
- hash: '',
124
- sectionModalCfg: {
125
- id: 'rb-doc-template-section-modal',
126
- mode: 'ins',
127
- section: null,
128
- onAfterOk() {
129
- }
130
- }
131
- }
132
- },
133
- computed: {
134
- iconAdd() {
135
- return UtFormConstructor.config.icons.iconAdd;
136
- },
137
- iconEdit() {
138
- return UtFormConstructor.config.icons.iconEdit;
139
- },
140
- iconDelete() {
141
- return UtFormConstructor.config.icons.iconDelete;
142
- },
143
- iconDrag() {
144
- return UtFormConstructor.config.icons.iconDrag;
145
- }
146
- },
147
- methods: {
148
- showProperties(field, event) {
149
- if (event.target.classList
150
- && event.target.classList.contains('rb-remove-field')) {
151
- return;
152
- }
153
-
154
- this.sidebarVisible = true;
155
- this.sidebarField = field;
156
- },
157
- addSection(columnCount) {
158
- let section = {labelRu: null, columnCount: columnCount};
159
- this.sectionModalCfg.mode = 'ins';
160
- this.sectionModalCfg.section = section;
161
- this.sectionModalCfg.onAfterOk = () => {
162
- section.columns = [];
163
- for (let i = 0; i < columnCount; i++) {
164
- section.columns.push({
165
- index: i,
166
- fields: []
167
- });
168
- }
169
-
170
- this.formConfig.sections.push(section)
171
- }
172
- this.$bvModal.show(this.sectionModalCfg.id);
173
- },
174
- editSection(section) {
175
- this.sectionModalCfg.mode = 'update';
176
- this.sectionModalCfg.section = section;
177
- this.sectionModalCfg.onAfterOk = () => {
178
- }
179
- this.$bvModal.show(this.sectionModalCfg.id);
180
- },
181
- removeSection(section, index) {
182
- this.formConfig.sections.splice(index, 1);
183
- /*UtModal.showYesNoDialog('Вы действительно хотите удалить секцию?', {
184
- onOk: (event, modal) => {
185
- this.formConfig.sections.splice(index, 1);
186
- UtModal.closeModal(modal);
187
- }
188
- });*/
189
- },
190
- multipleFieldAreOnFormConfig(field) {
191
- let count = 0;
192
- this.formConfig.sections.forEach(s => {
193
- s.columns.forEach(c => {
194
- c.fields.forEach(f => {
195
- if (f.name === field.name) {
196
- count++;
197
- }
198
- })
199
- })
200
- });
201
- return count > 1;
202
- },
203
- removeFieldFromColumn(field, column, newIndex) {
204
- let index = newIndex != null ? newIndex : -1;
205
-
206
- if (index < 0) {
207
- index = column.fields.findIndex(f => field.name === f.name);
208
- }
209
-
210
- if (index >= 0) {
211
- column.fields.splice(index, 1);
212
- }
213
- },
214
- onRemoveField(event, field, column) {
215
- event.preventDefault();
216
- this.removeFieldFromColumn(field, column)
217
- },
218
- onFieldAddedToColumn(event, column, section) {
219
- this.columnTo = column;
220
- },
221
- onFieldMoveEnd(event) {
222
- const {newIndex} = event;
223
- let field = event.item._underlying_vm_;
224
-
225
- if (!field.hasOwnProperty('defaultValue')) {
226
- this.$set(field, 'defaultValue', undefined);
227
- }
228
-
229
- let found = this.multipleFieldAreOnFormConfig(field);
230
- if (found) {
231
- this.removeFieldFromColumn(field, this.columnTo, newIndex);
232
- this.resetDragVariables();
233
- this.$bvModal.msgBoxOk('На форме уже есть это поле', {
234
- title: 'Ошибка',
235
- headerClass: 'rb-error-msg-box__header',
236
- bodyClass: 'rb-error-msg-box__body',
237
- footerClass: 'rb-error-msg-box__footer',
238
- centered: true,
239
- noCloseOnBackdrop: true,
240
- noCloseOnEsc: true
241
- });
242
- }
243
- this.resetDragVariables();
244
- this.hash = (Math.random() + 1).toString(36).substring(7);
245
- },
246
- getFieldExtendedPropsData(field) {
247
- return {...field.input.propsData, placeholder: field.tag, disabled: true};
248
- },
249
- resetDragVariables() {
250
- this.columnTo = null;
251
- },
252
- },
253
- }
254
- </script>
1
+ <template>
2
+ <div class="rb-doc-template-constructor d-flex">
3
+ <doc-template-facet-list @fieldMoveEnd="onFieldMoveEnd" :facets="facets"></doc-template-facet-list>
4
+
5
+ <div class="rb-form-constructor flex-fill">
6
+ <div class="rb-constructor-toolbar d-flex flex-row">
7
+ <h4>Добавить секцию: </h4>
8
+ <div class="rb-layout-buttons">
9
+ <b-button pill variant="outline-gray" @click="addSection(1)">
10
+ <rb-text>Секция с 1 колонкой</rb-text>
11
+ <rb-icon :icon="iconAdd"></rb-icon>
12
+ </b-button>
13
+ <b-button pill variant="outline-gray" @click="addSection(2)">
14
+ <rb-text>Секция с 2 колонками</rb-text>
15
+ <rb-icon :icon="iconAdd"></rb-icon>
16
+ </b-button>
17
+ <b-button pill variant="outline-gray" @click="addSection(3)">
18
+ <rb-text>Секция с 3 колонками</rb-text>
19
+ <rb-icon :icon="iconAdd"></rb-icon>
20
+ </b-button>
21
+ </div>
22
+ </div>
23
+
24
+ <div class="rb-constructor-body">
25
+ <draggable v-model="formConfig.section"
26
+ :animation="200"
27
+ group="section"
28
+ ghost-class="rb-form-card-moving"
29
+ handle=".rb-row-drag-handle">
30
+ <b-card v-for="(section, index) in formConfig.sections" :key="section.labelRu"
31
+ class="rb-form-card" :data-hash="hash">
32
+ <template #header>
33
+ <rb-icon :icon="iconDrag"
34
+ class="cursor-pointer rb-row-drag-handle"></rb-icon>
35
+ <rb-text class="flex-fill" @click="editSection(section)">
36
+ {{ section.labelRu }}
37
+ </rb-text>
38
+ <span class="rb-actions">
39
+ <rb-icon :icon="iconEdit" class="cursor-pointer"
40
+ @click="editSection(section)"></rb-icon>
41
+ <rb-icon :icon="iconDelete" class="cursor-pointer"
42
+ @click="removeSection(section, index)"></rb-icon>
43
+ </span>
44
+ </template>
45
+
46
+ <div class="d-flex flex-row">
47
+ <draggable tag="b-form"
48
+ class="rb-form-column"
49
+ v-for="column in section.columns"
50
+ :key="column.index"
51
+ :class="{'rb-single-column': section.columnCount === 1}"
52
+ v-model="column.fields"
53
+ @add="onFieldAddedToColumn($event, column, section)"
54
+ :animation="200"
55
+ group="fields"
56
+ ghost-class="rb-moving-item"
57
+ handle=".rb-field-drag-handle">
58
+ <b-form-row v-for="field in column.fields" :key="field.name"
59
+ class="cursor-pointer" @click="showProperties(field, $event)">
60
+ <b-col lg="12">
61
+ <b-form-group :label="field.labelRu">
62
+ <template #label>
63
+ <rb-icon :icon="iconDrag" class="rb-field-drag-handle"></rb-icon>
64
+ <rb-text>{{ field.labelRu }}</rb-text>
65
+ <rb-icon :icon="iconDelete" class="rb-remove-field"
66
+ @click.prevent="onRemoveField($event, field, column)">
67
+ </rb-icon>
68
+ </template>
69
+ <component v-bind:is="field.input.type"
70
+ :id="field.name"
71
+ v-if="field.input"
72
+ v-bind="getFieldExtendedPropsData(field)"
73
+ disabled
74
+ class="cursor-pointer">
75
+ </component>
76
+ </b-form-group>
77
+ </b-col>
78
+ </b-form-row>
79
+ </draggable>
80
+ </div>
81
+ </b-card>
82
+ </draggable>
83
+ </div>
84
+
85
+ <doc-template-field-sidebar v-model="sidebarField"
86
+ :visible="sidebarVisible"
87
+ :form-config="formConfig"
88
+ @hide="sidebarVisible=false">
89
+ </doc-template-field-sidebar>
90
+
91
+ <doc-template-section-modal :mode="sectionModalCfg.mode"
92
+ :section="sectionModalCfg.section"
93
+ :on-after-ok="sectionModalCfg.onAfterOk">
94
+ </doc-template-section-modal>
95
+ </div>
96
+ </div>
97
+ </template>
98
+
99
+ <script>
100
+ import DocTemplateFacetList from "@/components/DocTemplateFacetList";
101
+ import DocTemplateFieldSidebar from "@/components/DocTemplateFieldSidebar";
102
+ import DocTemplateSectionModal from "@/components/DocTemplateSectionModal";
103
+ import draggable from 'vuedraggable';
104
+ import {UtFormConfig} from "../utils/UtFormConfig";
105
+ import {UtFormConstructor} from "../utils/UtFormConstructor";
106
+
107
+ export default {
108
+ name: 'DocTemplateConstructor',
109
+ components: {DocTemplateFacetList, DocTemplateFieldSidebar, DocTemplateSectionModal, draggable},
110
+ props: {
111
+ formConfig: {
112
+ type: Object, default: () => {
113
+ return {sections: []}
114
+ }
115
+ },
116
+ facets: {type: Array, default: () => []}
117
+ },
118
+ data() {
119
+ return {
120
+ sidebarVisible: false,
121
+ sidebarField: null,
122
+ columnTo: false,
123
+ hash: '',
124
+ sectionModalCfg: {
125
+ id: 'rb-doc-template-section-modal',
126
+ mode: 'ins',
127
+ section: null,
128
+ onAfterOk() {
129
+ }
130
+ }
131
+ }
132
+ },
133
+ computed: {
134
+ iconAdd() {
135
+ return UtFormConstructor.config.icons.iconAdd;
136
+ },
137
+ iconEdit() {
138
+ return UtFormConstructor.config.icons.iconEdit;
139
+ },
140
+ iconDelete() {
141
+ return UtFormConstructor.config.icons.iconDelete;
142
+ },
143
+ iconDrag() {
144
+ return UtFormConstructor.config.icons.iconDrag;
145
+ }
146
+ },
147
+ methods: {
148
+ showProperties(field, event) {
149
+ if (event.target.classList
150
+ && event.target.classList.contains('rb-remove-field')) {
151
+ return;
152
+ }
153
+
154
+ this.sidebarVisible = true;
155
+ this.sidebarField = field;
156
+ },
157
+ addSection(columnCount) {
158
+ let section = {labelRu: null, columnCount: columnCount};
159
+ this.sectionModalCfg.mode = 'ins';
160
+ this.sectionModalCfg.section = section;
161
+ this.sectionModalCfg.onAfterOk = () => {
162
+ section.columns = [];
163
+ for (let i = 0; i < columnCount; i++) {
164
+ section.columns.push({
165
+ index: i,
166
+ fields: []
167
+ });
168
+ }
169
+
170
+ this.formConfig.sections.push(section)
171
+ }
172
+ this.$bvModal.show(this.sectionModalCfg.id);
173
+ },
174
+ editSection(section) {
175
+ this.sectionModalCfg.mode = 'update';
176
+ this.sectionModalCfg.section = section;
177
+ this.sectionModalCfg.onAfterOk = () => {
178
+ }
179
+ this.$bvModal.show(this.sectionModalCfg.id);
180
+ },
181
+ removeSection(section, index) {
182
+ this.formConfig.sections.splice(index, 1);
183
+ /*UtModal.showYesNoDialog('Вы действительно хотите удалить секцию?', {
184
+ onOk: (event, modal) => {
185
+ this.formConfig.sections.splice(index, 1);
186
+ UtModal.closeModal(modal);
187
+ }
188
+ });*/
189
+ },
190
+ multipleFieldAreOnFormConfig(field) {
191
+ let count = 0;
192
+ this.formConfig.sections.forEach(s => {
193
+ s.columns.forEach(c => {
194
+ c.fields.forEach(f => {
195
+ if (f.name === field.name) {
196
+ count++;
197
+ }
198
+ })
199
+ })
200
+ });
201
+ return count > 1;
202
+ },
203
+ removeFieldFromColumn(field, column, newIndex) {
204
+ let index = newIndex != null ? newIndex : -1;
205
+
206
+ if (index < 0) {
207
+ index = column.fields.findIndex(f => field.name === f.name);
208
+ }
209
+
210
+ if (index >= 0) {
211
+ column.fields.splice(index, 1);
212
+ }
213
+ },
214
+ onRemoveField(event, field, column) {
215
+ event.preventDefault();
216
+ this.removeFieldFromColumn(field, column)
217
+ },
218
+ onFieldAddedToColumn(event, column, section) {
219
+ this.columnTo = column;
220
+ },
221
+ onFieldMoveEnd(event) {
222
+ const {newIndex} = event;
223
+ let field = event.item._underlying_vm_;
224
+
225
+ if (!field.hasOwnProperty('defaultValue')) {
226
+ this.$set(field, 'defaultValue', undefined);
227
+ }
228
+
229
+ let found = this.multipleFieldAreOnFormConfig(field);
230
+ if (found) {
231
+ this.removeFieldFromColumn(field, this.columnTo, newIndex);
232
+ this.resetDragVariables();
233
+ this.$bvModal.msgBoxOk('На форме уже есть это поле', {
234
+ title: 'Ошибка',
235
+ headerClass: 'rb-error-msg-box__header',
236
+ bodyClass: 'rb-error-msg-box__body',
237
+ footerClass: 'rb-error-msg-box__footer',
238
+ centered: true,
239
+ noCloseOnBackdrop: true,
240
+ noCloseOnEsc: true
241
+ });
242
+ }
243
+ this.resetDragVariables();
244
+ this.hash = (Math.random() + 1).toString(36).substring(7);
245
+ },
246
+ getFieldExtendedPropsData(field) {
247
+ return {...field.input.propsData, placeholder: field.tag, disabled: true};
248
+ },
249
+ resetDragVariables() {
250
+ this.columnTo = null;
251
+ },
252
+ },
253
+ }
254
+ </script>