rb-document-form-constructor 0.1.3 → 0.1.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.
@@ -1,13 +1,98 @@
1
+ import crypto from 'crypto';
2
+
3
+ const UtFormConfig = {
4
+ findField(fieldName, formConfig) {
5
+ if (!formConfig || !formConfig.sections) {
6
+ return null;
7
+ }
8
+
9
+ let found = null;
10
+ formConfig.sections.every(r => {
11
+ if (r.columns) {
12
+ r.columns.every(c => {
13
+ c.fields.forEach(f => {
14
+ if (f.name === fieldName) {
15
+ found = f;
16
+ }
17
+ });
18
+
19
+ if (found) {
20
+ return false;
21
+ }
22
+ });
23
+ }
24
+
25
+ if (found) {
26
+ return false;
27
+ }
28
+ });
29
+ return found;
30
+ },
31
+
32
+ findRule(ruleId, formConfig) {
33
+ if (!formConfig || !formConfig.sections) {
34
+ return null;
35
+ }
36
+
37
+ let found = null;
38
+ formConfig.sections.every(s => {
39
+ if (s.columns) {
40
+ s.columns.every(c => {
41
+ c.fields.every(f => {
42
+ if (f.rules) {
43
+ f.rules.forEach(r => {
44
+ if (r.id === ruleId) {
45
+ found = r;
46
+ }
47
+ });
48
+ }
49
+
50
+ if (found) {
51
+ return false;
52
+ }
53
+ });
54
+
55
+ if (found) {
56
+ return false;
57
+ }
58
+ });
59
+ }
60
+
61
+ if (found) {
62
+ return false;
63
+ }
64
+ });
65
+ return found;
66
+ },
67
+
68
+ getFields(formConfig) {
69
+ let fields = [];
70
+ formConfig.sections.forEach(s => {
71
+ if (s.columns) {
72
+ s.columns.forEach(c => {
73
+ if (c.fields) {
74
+ c.fields.forEach(f => {
75
+ fields.push(f);
76
+ });
77
+ }
78
+ });
79
+ }
80
+ });
81
+ return fields;
82
+ }
83
+
84
+ };
85
+
1
86
  let __clone = function (data) {
2
87
  return JSON.parse(JSON.stringify(data));
3
88
  };
4
89
 
5
90
  let __assign = function () {
6
91
  __assign = Object.assign || function __assign(t) {
7
- for (var s, i = 1, n = arguments.length; i < n; i++) {
92
+ for (let s, i = 1, n = arguments.length; i < n; i++) {
8
93
  s = arguments[i];
9
94
 
10
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
95
+ for (let p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
11
96
  }
12
97
 
13
98
  return t;
@@ -16,6 +101,50 @@ let __assign = function () {
16
101
  return __assign.apply(this, arguments);
17
102
  };
18
103
 
104
+ let __mergeInputInMapOfArrays = function (inputs, formConfigInputs) {
105
+ for (let dataType in formConfigInputs) {
106
+ let foundInputs = inputs[dataType];
107
+
108
+ if (foundInputs) {
109
+ __mergeInputsInArray(foundInputs, formConfigInputs[dataType]);
110
+ } else {
111
+ inputs[dataType] = formConfigInputs[dataType];
112
+ }
113
+ }
114
+ };
115
+
116
+ let __mergeInputsInMap = function (inputs, formConfigInputs) {
117
+ for (let name in formConfigInputs) {
118
+ inputs[name] = __assign(inputs[name] ? inputs[name] : {}, formConfigInputs[name] ? formConfigInputs[name] : {});
119
+ }
120
+ };
121
+
122
+ let __mergeInputsInArray = function (inputs, formConfigInputs) {
123
+ formConfigInputs.forEach(input => {
124
+ let index = inputs.findIndex(item => item.name === input.name);
125
+
126
+ if (index >= 0) {
127
+ inputs[index] = input;
128
+ } else {
129
+ inputs.push(input);
130
+ }
131
+ });
132
+ };
133
+
134
+ let __applyDefaultProps = function (input) {
135
+ for (let propName in input.props) {
136
+ input.propsData[propName] = input.props[propName].default;
137
+ }
138
+ };
139
+
140
+ let __applyRefProps = function (input, refConfig) {
141
+ if (refConfig !== null && refConfig !== void 0 && refConfig.propsData) {
142
+ for (let propName in refConfig.propsData) {
143
+ input.propsData[propName] = refConfig.propsData[propName];
144
+ }
145
+ }
146
+ };
147
+
19
148
  let fcInputs = {
20
149
  text: {
21
150
  text: 'Текст',
@@ -113,6 +242,7 @@ let baseConfig = {
113
242
  dictInputs: __clone(fcDictInputs),
114
243
  refInputs: __clone(fcRefInputs),
115
244
  refInputConfigs: __clone(fcRefInputConfigs),
245
+ rules: [],
116
246
  icons: {
117
247
  iconExpandFacet: 'icon-chevron-up',
118
248
  iconCollapseFacet: 'icon-chevron-down',
@@ -122,9 +252,10 @@ let baseConfig = {
122
252
  iconEdit: 'icon-edit',
123
253
  iconDelete: 'icon-delete',
124
254
  iconDrag: 'icon-reorder'
125
- }
255
+ },
256
+ ruleContext: {}
126
257
  };
127
- const UtFormConfig = {
258
+ const UtFormConstructor = {
128
259
  config: {},
129
260
 
130
261
  init(formConfig) {
@@ -132,19 +263,19 @@ const UtFormConfig = {
132
263
 
133
264
  if (formConfig) {
134
265
  if (formConfig.inputs) {
135
- this.mergeInputsInMap(this.config.inputs, formConfig.inputs);
266
+ __mergeInputsInMap(this.config.inputs, formConfig.inputs);
136
267
  }
137
268
 
138
269
  if (formConfig.primitiveInputs) {
139
- this.mergeInputInMapOfArrays(this.config.primitiveInputs, formConfig.primitiveInputs);
270
+ __mergeInputInMapOfArrays(this.config.primitiveInputs, formConfig.primitiveInputs);
140
271
  }
141
272
 
142
273
  if (formConfig.dictInputs) {
143
- this.mergeInputsInArray(this.config.dictInputs, formConfig.dictInputs);
274
+ __mergeInputsInArray(this.config.dictInputs, formConfig.dictInputs);
144
275
  }
145
276
 
146
277
  if (formConfig.refInputs) {
147
- this.mergeInputInMapOfArrays(this.config.refInputs, formConfig.refInputs);
278
+ __mergeInputInMapOfArrays(this.config.refInputs, formConfig.refInputs);
148
279
  }
149
280
 
150
281
  if (formConfig.refInputConfigs) {
@@ -154,45 +285,15 @@ const UtFormConfig = {
154
285
  if (formConfig.icons) {
155
286
  this.config.icons = __assign(this.config.icons, formConfig.icons);
156
287
  }
157
- }
158
- },
159
288
 
160
- mergeInputInMapOfArrays(inputs, formConfigInputs) {
161
- for (let dataType in formConfigInputs) {
162
- let foundInputs = inputs[dataType];
163
-
164
- if (foundInputs) {
165
- this.mergeInputsInArray(foundInputs, formConfigInputs[dataType]);
166
- } else {
167
- inputs[dataType] = formConfigInputs[dataType];
289
+ if (formConfig.rules) {
290
+ this.config.rules = formConfig.rules;
168
291
  }
169
- }
170
- },
171
292
 
172
- mergeInputsInMap(inputs, formConfigInputs) {
173
- for (let name in formConfigInputs) {
174
- inputs[name] = __assign(inputs[name] ? inputs[name] : {}, formConfigInputs[name] ? formConfigInputs[name] : {});
175
- }
176
- },
177
-
178
- mergeInputsInArray(inputs, formConfigInputs) {
179
- formConfigInputs.forEach(input => {
180
- let index = inputs.findIndex(item => item.name === input.name);
181
-
182
- if (index >= 0) {
183
- inputs[index] = input;
184
- } else {
185
- inputs.push(input);
293
+ if (formConfig.ruleContext) {
294
+ this.config.ruleContext = formConfig.ruleContext;
186
295
  }
187
- });
188
- },
189
-
190
- getAllInputTypes() {
191
- return this.config.inputs;
192
- },
193
-
194
- getAllDictInputs() {
195
- return this.config.dictInputs;
296
+ }
196
297
  },
197
298
 
198
299
  getInputTypes(field) {
@@ -216,18 +317,21 @@ const UtFormConfig = {
216
317
 
217
318
  if (field.ref && this.config.refInputs[field.ref]) {
218
319
  input = __clone(this.config.refInputs[field.ref][0]);
219
- this.applyDefaultProps(input);
320
+
321
+ __applyDefaultProps(input);
220
322
 
221
323
  if (this.config.refInputConfigs[field.ref] && this.config.refInputConfigs[field.ref][input.name]) {
222
- this.applyRefProps(input, this.config.refInputConfigs[field.ref][input.name]);
324
+ __applyRefProps(input, this.config.refInputConfigs[field.ref][input.name]);
223
325
  }
224
326
  } else if (field.dict) {
225
327
  input = __clone(this.config.dictInputs[0]);
226
328
  input.props.dict.default = field.ref;
227
- this.applyDefaultProps(input);
329
+
330
+ __applyDefaultProps(input);
228
331
  } else {
229
332
  input = __clone(this.config.primitiveInputs[field.type][0]);
230
- this.applyDefaultProps(input);
333
+
334
+ __applyDefaultProps(input);
231
335
  }
232
336
 
233
337
  return input;
@@ -236,48 +340,48 @@ const UtFormConfig = {
236
340
  getInputTypeByName(name, field) {
237
341
  let input = JSON.parse(JSON.stringify(this.config.inputs[name]));
238
342
 
239
- if (field.ref && this.config.refInputConfigs[field.ref]) {
240
- this.applyDefaultProps(input);
343
+ if (field.ref && this.config.refInputs[field.ref]) {
344
+ __applyDefaultProps(input);
241
345
 
242
346
  if (this.config.refInputConfigs[field.ref] && this.config.refInputConfigs[field.ref][input.name]) {
243
- this.applyRefProps(input, this.config.refInputConfigs[field.ref][input.name]);
347
+ __applyRefProps(input, this.config.refInputConfigs[field.ref][input.name]);
244
348
  }
245
349
  } else if (field.dict) {
246
350
  input.props.dict.default = field.ref;
247
- this.applyDefaultProps(input);
351
+
352
+ __applyDefaultProps(input);
248
353
  } else {
249
- this.applyDefaultProps(input);
354
+ __applyDefaultProps(input);
250
355
  }
251
356
 
357
+ input.propsData['ref'] = field.name;
252
358
  return input;
253
359
  },
254
360
 
255
- applyDefaultProps(input) {
256
- for (let propName in input.props) {
257
- input.propsData[propName] = input.props[propName].default;
258
- }
361
+ getAvailableFieldRules(field) {
362
+ return this.config.rules.filter(rule => {
363
+ return !rule.fields || rule.fields.length === 0 || rule.fields.indexOf(field.name) >= 0;
364
+ });
259
365
  },
260
366
 
261
- applyRefProps(input, refConfig) {
262
- if (refConfig !== null && refConfig !== void 0 && refConfig.propsData) {
263
- for (let propName in refConfig.propsData) {
264
- input.propsData[propName] = refConfig.propsData[propName];
265
- }
266
- }
367
+ getRuleContext() {
368
+ return this.config.ruleContext;
267
369
  },
268
370
 
269
- parseFacets(formConfig) {
270
- let facets = [];
271
- formConfig.sections.every(section => {
272
- section.columns.every(c => {
273
- c.fields.forEach(f => {
274
- if (!(facets.indexOf(f.facet) >= 0)) {
275
- facets.push(f.facet);
276
- }
277
- });
278
- });
279
- });
280
- return facets;
371
+ runRule(context, script) {
372
+ let appendScript = `
373
+ var doc = this.form.doc;
374
+ var form = this.form;
375
+ var event = this.event;
376
+ var eventName = this.eventName;
377
+
378
+ `;
379
+
380
+ let func = function (script) {
381
+ return eval(script);
382
+ };
383
+
384
+ func.call(context, appendScript + script);
281
385
  }
282
386
 
283
387
  };
@@ -301,7 +405,7 @@ const UtFormConfig = {
301
405
  //
302
406
  //
303
407
  //
304
- var script$4 = {
408
+ var script$5 = {
305
409
  name: 'DocTemplateSectionModal',
306
410
  props: {
307
411
  section: Object,
@@ -435,10 +539,10 @@ function normalizeComponent(template, style, script, scopeId, isFunctionalTempla
435
539
  }
436
540
 
437
541
  /* script */
438
- const __vue_script__$4 = script$4;
542
+ const __vue_script__$5 = script$5;
439
543
  /* template */
440
544
 
441
- var __vue_render__$4 = function () {
545
+ var __vue_render__$5 = function () {
442
546
  var _vm = this;
443
547
 
444
548
  var _h = _vm.$createElement;
@@ -486,19 +590,19 @@ var __vue_render__$4 = function () {
486
590
  })], 1)], 1)], 1)], 1)], 1);
487
591
  };
488
592
 
489
- var __vue_staticRenderFns__$4 = [];
593
+ var __vue_staticRenderFns__$5 = [];
490
594
  /* style */
491
595
 
492
- const __vue_inject_styles__$4 = undefined;
596
+ const __vue_inject_styles__$5 = undefined;
493
597
  /* scoped */
494
598
 
495
- const __vue_scope_id__$4 = undefined;
599
+ const __vue_scope_id__$5 = undefined;
496
600
  /* module identifier */
497
601
 
498
- const __vue_module_identifier__$4 = undefined;
602
+ const __vue_module_identifier__$5 = undefined;
499
603
  /* functional template */
500
604
 
501
- const __vue_is_functional_template__$4 = false;
605
+ const __vue_is_functional_template__$5 = false;
502
606
  /* style inject */
503
607
 
504
608
  /* style inject SSR */
@@ -506,9 +610,9 @@ const __vue_is_functional_template__$4 = false;
506
610
  /* style inject shadow dom */
507
611
 
508
612
  const __vue_component__$6 = /*#__PURE__*/normalizeComponent({
509
- render: __vue_render__$4,
510
- staticRenderFns: __vue_staticRenderFns__$4
511
- }, __vue_inject_styles__$4, __vue_script__$4, __vue_scope_id__$4, __vue_is_functional_template__$4, __vue_module_identifier__$4, false, undefined, undefined, undefined);
613
+ render: __vue_render__$5,
614
+ staticRenderFns: __vue_staticRenderFns__$5
615
+ }, __vue_inject_styles__$5, __vue_script__$5, __vue_scope_id__$5, __vue_is_functional_template__$5, __vue_module_identifier__$5, false, undefined, undefined, undefined);
512
616
 
513
617
  var DocTemplateSectionModal = __vue_component__$6;
514
618
 
@@ -5901,7 +6005,7 @@ if (typeof window !== "undefined" && "Vue" in window) {
5901
6005
  });
5902
6006
 
5903
6007
  //
5904
- var script$3 = {
6008
+ var script$4 = {
5905
6009
  name: 'DocTemplateFacetList',
5906
6010
  components: {
5907
6011
  draggable: vuedraggable_umd
@@ -5923,11 +6027,11 @@ var script$3 = {
5923
6027
 
5924
6028
  computed: {
5925
6029
  iconExpandFacet() {
5926
- return UtFormConfig.config.icons.iconExpandFacet;
6030
+ return UtFormConstructor.config.icons.iconExpandFacet;
5927
6031
  },
5928
6032
 
5929
6033
  iconCollapseFacet() {
5930
- return UtFormConfig.config.icons.iconCollapseFacet;
6034
+ return UtFormConstructor.config.icons.iconCollapseFacet;
5931
6035
  }
5932
6036
 
5933
6037
  },
@@ -5944,7 +6048,7 @@ var script$3 = {
5944
6048
  methods: {
5945
6049
  onFieldCloned(cloneField) {
5946
6050
  let field = JSON.parse(JSON.stringify(cloneField));
5947
- field.input = UtFormConfig.getDefaultInput(field);
6051
+ field.input = UtFormConstructor.getDefaultInput(field);
5948
6052
  return field;
5949
6053
  },
5950
6054
 
@@ -5993,10 +6097,10 @@ var script$3 = {
5993
6097
  };
5994
6098
 
5995
6099
  /* script */
5996
- const __vue_script__$3 = script$3;
6100
+ const __vue_script__$4 = script$4;
5997
6101
  /* template */
5998
6102
 
5999
- var __vue_render__$3 = function () {
6103
+ var __vue_render__$4 = function () {
6000
6104
  var _vm = this;
6001
6105
 
6002
6106
  var _h = _vm.$createElement;
@@ -6027,18 +6131,17 @@ var __vue_render__$3 = function () {
6027
6131
  key: facet.name,
6028
6132
  staticClass: "rb-facet"
6029
6133
  }, [_c('h6', {
6030
- staticClass: "rb-facet-label d-flex"
6134
+ staticClass: "rb-facet-label d-flex cursor-pointer",
6135
+ on: {
6136
+ "click": function ($event) {
6137
+ facet.expanded = !facet.expanded;
6138
+ }
6139
+ }
6031
6140
  }, [_c('rb-text', {
6032
6141
  staticClass: "flex-fill"
6033
6142
  }, [_vm._v(_vm._s(facet.labelRu))]), _vm._v(" "), _c('rb-icon', {
6034
- staticClass: "cursor-pointer",
6035
6143
  attrs: {
6036
6144
  "icon": facet.expanded ? _vm.iconCollapseFacet : _vm.iconExpandFacet
6037
- },
6038
- on: {
6039
- "click": function ($event) {
6040
- facet.expanded = !facet.expanded;
6041
- }
6042
6145
  }
6043
6146
  })], 1), _vm._v(" "), facet.expanded ? _c('b-list-group', [_c('draggable', {
6044
6147
  attrs: {
@@ -6072,19 +6175,19 @@ var __vue_render__$3 = function () {
6072
6175
  }), 0)], 1);
6073
6176
  };
6074
6177
 
6075
- var __vue_staticRenderFns__$3 = [];
6178
+ var __vue_staticRenderFns__$4 = [];
6076
6179
  /* style */
6077
6180
 
6078
- const __vue_inject_styles__$3 = undefined;
6181
+ const __vue_inject_styles__$4 = undefined;
6079
6182
  /* scoped */
6080
6183
 
6081
- const __vue_scope_id__$3 = undefined;
6184
+ const __vue_scope_id__$4 = undefined;
6082
6185
  /* module identifier */
6083
6186
 
6084
- const __vue_module_identifier__$3 = undefined;
6187
+ const __vue_module_identifier__$4 = undefined;
6085
6188
  /* functional template */
6086
6189
 
6087
- const __vue_is_functional_template__$3 = false;
6190
+ const __vue_is_functional_template__$4 = false;
6088
6191
  /* style inject */
6089
6192
 
6090
6193
  /* style inject SSR */
@@ -6092,109 +6195,663 @@ const __vue_is_functional_template__$3 = false;
6092
6195
  /* style inject shadow dom */
6093
6196
 
6094
6197
  const __vue_component__$5 = /*#__PURE__*/normalizeComponent({
6095
- render: __vue_render__$3,
6096
- staticRenderFns: __vue_staticRenderFns__$3
6097
- }, __vue_inject_styles__$3, __vue_script__$3, __vue_scope_id__$3, __vue_is_functional_template__$3, __vue_module_identifier__$3, false, undefined, undefined, undefined);
6198
+ render: __vue_render__$4,
6199
+ staticRenderFns: __vue_staticRenderFns__$4
6200
+ }, __vue_inject_styles__$4, __vue_script__$4, __vue_scope_id__$4, __vue_is_functional_template__$4, __vue_module_identifier__$4, false, undefined, undefined, undefined);
6098
6201
 
6099
6202
  var DocTemplateFacetList = __vue_component__$5;
6100
6203
 
6204
+ const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
6205
+
6206
+ let poolPtr = rnds8Pool.length;
6207
+ function rng() {
6208
+ if (poolPtr > rnds8Pool.length - 16) {
6209
+ crypto.randomFillSync(rnds8Pool);
6210
+ poolPtr = 0;
6211
+ }
6212
+
6213
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
6214
+ }
6215
+
6216
+ var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
6217
+
6218
+ function validate(uuid) {
6219
+ return typeof uuid === 'string' && REGEX.test(uuid);
6220
+ }
6221
+
6222
+ /**
6223
+ * Convert array of 16 byte values to UUID string format of the form:
6224
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
6225
+ */
6226
+
6227
+ const byteToHex = [];
6228
+
6229
+ for (let i = 0; i < 256; ++i) {
6230
+ byteToHex.push((i + 0x100).toString(16).substr(1));
6231
+ }
6232
+
6233
+ function stringify(arr, offset = 0) {
6234
+ // Note: Be careful editing this code! It's been tuned for performance
6235
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
6236
+ const uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
6237
+ // of the following:
6238
+ // - One or more input array values don't map to a hex octet (leading to
6239
+ // "undefined" in the uuid)
6240
+ // - Invalid input values for the RFC `version` or `variant` fields
6241
+
6242
+ if (!validate(uuid)) {
6243
+ throw TypeError('Stringified UUID is invalid');
6244
+ }
6245
+
6246
+ return uuid;
6247
+ }
6248
+
6249
+ function v4(options, buf, offset) {
6250
+ options = options || {};
6251
+ const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
6252
+
6253
+ rnds[6] = rnds[6] & 0x0f | 0x40;
6254
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
6255
+
6256
+ if (buf) {
6257
+ offset = offset || 0;
6258
+
6259
+ for (let i = 0; i < 16; ++i) {
6260
+ buf[offset + i] = rnds[i];
6261
+ }
6262
+
6263
+ return buf;
6264
+ }
6265
+
6266
+ return stringify(rnds);
6267
+ }
6268
+
6101
6269
  //
6102
- var script$2 = {
6103
- name: 'DocTemplateFieldSidebar',
6270
+ var script$3 = {
6271
+ name: 'FieldRuleFormModal',
6272
+ components: {
6273
+ DocForm
6274
+ },
6104
6275
  props: {
6105
- value: {
6106
- type: Object,
6107
- default: null
6276
+ field: Object,
6277
+ rule: Object,
6278
+ formConfig: Object,
6279
+ mode: {
6280
+ type: String,
6281
+ default: 'ins'
6108
6282
  },
6109
- visible: {
6110
- type: Boolean,
6111
- default: null
6112
- }
6283
+ onAfterOk: Function
6113
6284
  },
6114
6285
 
6115
6286
  data() {
6116
6287
  return {
6117
- innerVisible: null,
6118
- field: null,
6119
- currentInputName: null
6288
+ id: 'rb-field-rule-form-modal',
6289
+ state: this.getDefaultState(),
6290
+ innerFormConfig: null,
6291
+ innerRule: null
6120
6292
  };
6121
6293
  },
6122
6294
 
6123
6295
  computed: {
6124
- inputOptions() {
6125
- return this.field ? UtFormConfig.getInputTypes(this.field) : [];
6296
+ title() {
6297
+ return this.mode === 'ins' ? 'Добавление правила' : 'Редактирование правила';
6126
6298
  },
6127
6299
 
6128
- iconCloseSidebar() {
6129
- return UtFormConfig.config.icons.iconCloseFieldSidebar;
6300
+ fields() {
6301
+ return UtFormConfig.getFields(this.formConfig);
6130
6302
  },
6131
6303
 
6132
- iconOpenSidebar() {
6133
- return UtFormConfig.config.icons.iconOpenFieldSidebar;
6304
+ rulePresets() {
6305
+ return UtFormConstructor.getAvailableFieldRules(this.field);
6134
6306
  }
6135
6307
 
6136
6308
  },
6137
6309
  watch: {
6138
- visible() {
6139
- this.innerVisible = this.visible;
6310
+ formConfig() {
6311
+ this.copyToInnerFormConfig();
6140
6312
  },
6141
6313
 
6142
- value() {
6143
- this.field = this.value;
6144
-
6145
- if (this.field && this.field.input) {
6146
- this.currentInputName = this.field.input.name;
6314
+ rule() {
6315
+ if (this.rule) {
6316
+ this.innerRule = this.rule;
6317
+ } else {
6318
+ this.innerRule = this.getDefaultRule();
6147
6319
  }
6148
- },
6149
-
6150
- field() {
6151
- this.$emit('input', this.field);
6152
- this.$emit('change', this.field);
6153
- },
6154
-
6155
- currentInputName() {
6156
- this.field.input = UtFormConfig.getInputTypeByName(this.currentInputName, this.field);
6157
6320
  }
6158
6321
 
6159
6322
  },
6160
6323
  methods: {
6161
- hide() {
6162
- this.innerVisible = false;
6163
- this.$emit('hide');
6324
+ validateFields(fieldName) {
6325
+ let fields = fieldName ? [fieldName] : ['name', 'event', 'script'];
6326
+ fields.forEach(field => {
6327
+ if (!this.innerRule[field]) {
6328
+ this.state[field] = false;
6329
+ this.state[`${field}_feedback`] = 'Заполните название';
6330
+ } else {
6331
+ this.state[field] = true;
6332
+ this.state[`${field}_feedback`] = null;
6333
+ }
6334
+ });
6164
6335
  },
6165
6336
 
6166
- getPropInputType(prop, propName) {
6167
- if (prop.type === 'string') {
6168
- return 'b-form-input';
6169
- } else {
6170
- return 'rb-boolean-single-option-input';
6171
- }
6337
+ copyToInnerFormConfig() {
6338
+ this.innerFormConfig = JSON.parse(JSON.stringify(this.formConfig));
6172
6339
  },
6173
6340
 
6174
- getPropInputPropData(prop, propName) {
6175
- if (prop.type === 'string') {
6176
- return {
6177
- type: 'text'
6178
- };
6179
- } else {
6180
- return {};
6181
- }
6182
- }
6341
+ applyRuleToInnerFormConfig() {
6342
+ if (this.innerFormConfig) {
6343
+ let foundRule = UtFormConfig.findRule(this.innerRule.id, this.innerFormConfig);
6183
6344
 
6184
- },
6345
+ if (!foundRule) {
6346
+ let foundField = UtFormConfig.findField(this.field.name, this.innerFormConfig);
6185
6347
 
6186
- created() {
6187
- this.innerVisible = this.visible;
6188
- this.field = this.value;
6348
+ if (foundField) {
6349
+ foundField.rules = foundField.rules ? foundField.rules : [];
6350
+ foundField.rules.push(this.rule);
6351
+ }
6352
+ } else {
6353
+ Object.assign(foundRule, this.innerRule);
6354
+ }
6355
+ }
6356
+ },
6189
6357
 
6190
- if (this.field && this.field.input) {
6191
- this.currentInputName = this.field.input.name;
6192
- }
6193
- }
6358
+ onActivateTab(index) {
6359
+ if (index > 0) {
6360
+ this.copyToInnerFormConfig();
6361
+ this.applyRuleToInnerFormConfig();
6362
+ }
6363
+ },
6194
6364
 
6195
- };
6365
+ getDefaultState() {
6366
+ return {
6367
+ name: null,
6368
+ event: null,
6369
+ script: null
6370
+ };
6371
+ },
6196
6372
 
6197
- /* script */
6373
+ getDefaultRule() {
6374
+ return {
6375
+ id: v4(),
6376
+ name: null,
6377
+ event: null,
6378
+ script: null
6379
+ };
6380
+ },
6381
+
6382
+ resetModal() {
6383
+ this.state = this.getDefaultState();
6384
+ this.innerRule = null;
6385
+ },
6386
+
6387
+ addVariableToScript(varName) {
6388
+ let r = this.innerRule;
6389
+ r.script = r.script ? r.script + varName : varName;
6390
+ },
6391
+
6392
+ addSetVariableToScript(field) {
6393
+ let r = this.innerRule;
6394
+ let setVariableScript = `doc['${field.name}'] = Значение;`;
6395
+ r.script = r.script ? r.script + setVariableScript : setVariableScript;
6396
+ },
6397
+
6398
+ addCallInputFunction(field) {
6399
+ let r = this.innerRule;
6400
+ let setVariableScript = `form.$refs['${field.name}'].Название функции();`;
6401
+ r.script = r.script ? r.script + setVariableScript : setVariableScript;
6402
+ },
6403
+
6404
+ onRuleSelected(ruleName) {
6405
+ let rule = this.rulePresets.find(rule => rule.name === ruleName);
6406
+
6407
+ if (rule) {
6408
+ Object.assign(this.innerRule, rule);
6409
+ this.innerRule.script = this.innerRule.script.trim();
6410
+ }
6411
+ },
6412
+
6413
+ onOk() {
6414
+ this.validateFields();
6415
+
6416
+ if (this.state.name && this.state.script) {
6417
+ if (this.onAfterOk) {
6418
+ this.onAfterOk(this.innerRule);
6419
+ }
6420
+
6421
+ this.$nextTick(() => {
6422
+ this.resetModal();
6423
+ this.$bvModal.hide(this.id);
6424
+ });
6425
+ }
6426
+ }
6427
+
6428
+ },
6429
+
6430
+ created() {
6431
+ this.copyToInnerFormConfig();
6432
+ }
6433
+
6434
+ };
6435
+
6436
+ /* script */
6437
+ const __vue_script__$3 = script$3;
6438
+ /* template */
6439
+
6440
+ var __vue_render__$3 = function () {
6441
+ var _vm = this;
6442
+
6443
+ var _h = _vm.$createElement;
6444
+
6445
+ var _c = _vm._self._c || _h;
6446
+
6447
+ return _c('b-modal', {
6448
+ attrs: {
6449
+ "id": _vm.id,
6450
+ "title": _vm.title,
6451
+ "modal-class": "rb-field-rule-form-modal",
6452
+ "size": "lg",
6453
+ "ok-title": "Сохранить правило",
6454
+ "cancel-variant": "outline-gray",
6455
+ "cancel-title": "Отмена"
6456
+ },
6457
+ on: {
6458
+ "ok": function ($event) {
6459
+ $event.preventDefault();
6460
+ return _vm.onOk.apply(null, arguments);
6461
+ }
6462
+ }
6463
+ }, [_c('b-card', {
6464
+ attrs: {
6465
+ "no-body": ""
6466
+ }
6467
+ }, [_c('b-tabs', {
6468
+ attrs: {
6469
+ "card": ""
6470
+ },
6471
+ on: {
6472
+ "activate-tab": _vm.onActivateTab
6473
+ }
6474
+ }, [_c('b-tab', {
6475
+ attrs: {
6476
+ "title": "Правило",
6477
+ "active": ""
6478
+ }
6479
+ }, [_vm.innerRule ? _c('b-form', [_c('b-form-row', [_c('b-col', {
6480
+ attrs: {
6481
+ "log": "12"
6482
+ }
6483
+ }, [_vm.rulePresets.length > 0 ? _c('b-form-group', {
6484
+ attrs: {
6485
+ "label": "Выбрать"
6486
+ },
6487
+ scopedSlots: _vm._u([{
6488
+ key: "description",
6489
+ fn: function () {
6490
+ return [_vm._v("\n Выберите готовое правило из списка и если нужно, измените\n ")];
6491
+ },
6492
+ proxy: true
6493
+ }], null, false, 3419583775)
6494
+ }, [_vm._v(" "), _c('b-form-select', {
6495
+ on: {
6496
+ "input": function ($event) {
6497
+ return _vm.onRuleSelected($event);
6498
+ }
6499
+ }
6500
+ }, _vm._l(_vm.rulePresets, function (r) {
6501
+ return _c('b-form-select-option', {
6502
+ key: r.name,
6503
+ attrs: {
6504
+ "value": r.name
6505
+ }
6506
+ }, [_vm._v("\n " + _vm._s(r.name) + "\n ")]);
6507
+ }), 1)], 1) : _vm._e()], 1), _vm._v(" "), _c('b-col', {
6508
+ attrs: {
6509
+ "lg": "12"
6510
+ }
6511
+ }, [_c('b-form-group', {
6512
+ attrs: {
6513
+ "label": "Название"
6514
+ },
6515
+ scopedSlots: _vm._u([{
6516
+ key: "description",
6517
+ fn: function () {
6518
+ return [_vm._v("\n Задайте уникальное название, чтобы отличать правило в списке\n ")];
6519
+ },
6520
+ proxy: true
6521
+ }], null, false, 3665649506)
6522
+ }, [_vm._v(" "), _c('b-form-input', {
6523
+ attrs: {
6524
+ "state": _vm.state.name,
6525
+ "invalid-feedback": _vm.state.name_feedback
6526
+ },
6527
+ model: {
6528
+ value: _vm.innerRule.name,
6529
+ callback: function ($$v) {
6530
+ _vm.$set(_vm.innerRule, "name", $$v);
6531
+ },
6532
+ expression: "innerRule.name"
6533
+ }
6534
+ })], 1)], 1), _vm._v(" "), _c('b-col', {
6535
+ attrs: {
6536
+ "lg": "12"
6537
+ }
6538
+ }, [_c('b-form-group', {
6539
+ attrs: {
6540
+ "label": "Событие"
6541
+ },
6542
+ scopedSlots: _vm._u([{
6543
+ key: "description",
6544
+ fn: function () {
6545
+ return [_vm._v("\n При возникновении этого события будет выполняться правило\n ")];
6546
+ },
6547
+ proxy: true
6548
+ }], null, false, 1461632685)
6549
+ }, [_vm._v(" "), _c('b-form-select', {
6550
+ attrs: {
6551
+ "state": _vm.state.event,
6552
+ "invalid-feedback": _vm.state.event_feedback
6553
+ },
6554
+ model: {
6555
+ value: _vm.innerRule.event,
6556
+ callback: function ($$v) {
6557
+ _vm.$set(_vm.innerRule, "event", $$v);
6558
+ },
6559
+ expression: "innerRule.event"
6560
+ }
6561
+ }, [_c('b-form-select-option', {
6562
+ attrs: {
6563
+ "value": 'input'
6564
+ }
6565
+ }, [_vm._v("\n Ввод значения\n ")]), _vm._v(" "), _c('b-form-select-option', {
6566
+ attrs: {
6567
+ "value": 'change'
6568
+ }
6569
+ }, [_vm._v("\n Изменение значения\n ")]), _vm._v(" "), _c('b-form-select-option', {
6570
+ attrs: {
6571
+ "value": 'click'
6572
+ }
6573
+ }, [_vm._v("\n Клик\n ")])], 1)], 1)], 1), _vm._v(" "), _c('b-col', {
6574
+ attrs: {
6575
+ "lg": "12"
6576
+ }
6577
+ }, [_c('b-form-group', {
6578
+ attrs: {
6579
+ "label": "Скрипт"
6580
+ },
6581
+ scopedSlots: _vm._u([{
6582
+ key: "description",
6583
+ fn: function () {
6584
+ return [_vm._v("\n Здесь указывается скрипт правила. Скрипт должен быть написан на языке\n javascript\n ")];
6585
+ },
6586
+ proxy: true
6587
+ }], null, false, 2031959747)
6588
+ }, [_vm._v(" "), _c('div', {
6589
+ staticClass: "rb-script-input"
6590
+ }, [_c('b-button-toolbar', [_c('b-dropdown', {
6591
+ staticClass: "mx-1",
6592
+ attrs: {
6593
+ "text": "Переменные",
6594
+ "variant": "outline-secondary",
6595
+ "size": "sm"
6596
+ }
6597
+ }, [_c('b-dropdown-item', {
6598
+ on: {
6599
+ "click": function ($event) {
6600
+ return _vm.addVariableToScript('doc');
6601
+ }
6602
+ }
6603
+ }, [_vm._v("\n Документ\n ")]), _vm._v(" "), _c('b-dropdown-item', {
6604
+ on: {
6605
+ "click": function ($event) {
6606
+ return _vm.addVariableToScript('form');
6607
+ }
6608
+ }
6609
+ }, [_vm._v("\n Форма\n ")]), _vm._v(" "), _c('b-dropdown-item', {
6610
+ on: {
6611
+ "click": function ($event) {
6612
+ return _vm.addVariableToScript('event');
6613
+ }
6614
+ }
6615
+ }, [_vm._v("\n Значение события\n ")])], 1), _vm._v(" "), _c('b-dropdown', {
6616
+ staticClass: "mx-1",
6617
+ attrs: {
6618
+ "text": "Задать значение",
6619
+ "variant": "outline-secondary",
6620
+ "size": "sm"
6621
+ }
6622
+ }, _vm._l(_vm.fields, function (f) {
6623
+ return _vm.fields ? _c('b-dropdown-item', {
6624
+ key: f.name,
6625
+ on: {
6626
+ "click": function ($event) {
6627
+ return _vm.addSetVariableToScript(f);
6628
+ }
6629
+ }
6630
+ }, [_vm._v("\n " + _vm._s(f.name) + "\n ")]) : _vm._e();
6631
+ }), 1), _vm._v(" "), _c('b-dropdown', {
6632
+ staticClass: "mx-1",
6633
+ attrs: {
6634
+ "text": "Вызвать функцию инпута",
6635
+ "variant": "outline-secondary",
6636
+ "size": "sm"
6637
+ }
6638
+ }, _vm._l(_vm.fields, function (f) {
6639
+ return _vm.fields ? _c('b-dropdown-item', {
6640
+ key: f.name,
6641
+ on: {
6642
+ "click": function ($event) {
6643
+ return _vm.addCallInputFunction(f);
6644
+ }
6645
+ }
6646
+ }, [_vm._v("\n " + _vm._s(f.name) + "\n ")]) : _vm._e();
6647
+ }), 1)], 1), _vm._v(" "), _c('b-form-textarea', {
6648
+ attrs: {
6649
+ "state": _vm.state.script,
6650
+ "invalid-feedback": _vm.state.script_feedback,
6651
+ "rows": "8"
6652
+ },
6653
+ model: {
6654
+ value: _vm.innerRule.script,
6655
+ callback: function ($$v) {
6656
+ _vm.$set(_vm.innerRule, "script", $$v);
6657
+ },
6658
+ expression: "innerRule.script"
6659
+ }
6660
+ })], 1)])], 1)], 1)], 1) : _vm._e()], 1), _vm._v(" "), _vm.innerFormConfig ? _c('b-tab', {
6661
+ attrs: {
6662
+ "title": "Протестировать правило"
6663
+ }
6664
+ }, [_c('doc-form', {
6665
+ attrs: {
6666
+ "form-config": _vm.innerFormConfig
6667
+ }
6668
+ })], 1) : _vm._e()], 1)], 1)], 1);
6669
+ };
6670
+
6671
+ var __vue_staticRenderFns__$3 = [];
6672
+ /* style */
6673
+
6674
+ const __vue_inject_styles__$3 = undefined;
6675
+ /* scoped */
6676
+
6677
+ const __vue_scope_id__$3 = undefined;
6678
+ /* module identifier */
6679
+
6680
+ const __vue_module_identifier__$3 = undefined;
6681
+ /* functional template */
6682
+
6683
+ const __vue_is_functional_template__$3 = false;
6684
+ /* style inject */
6685
+
6686
+ /* style inject SSR */
6687
+
6688
+ /* style inject shadow dom */
6689
+
6690
+ const __vue_component__$4 = /*#__PURE__*/normalizeComponent({
6691
+ render: __vue_render__$3,
6692
+ staticRenderFns: __vue_staticRenderFns__$3
6693
+ }, __vue_inject_styles__$3, __vue_script__$3, __vue_scope_id__$3, __vue_is_functional_template__$3, __vue_module_identifier__$3, false, undefined, undefined, undefined);
6694
+
6695
+ var FieldRuleFormModal = __vue_component__$4;
6696
+
6697
+ //
6698
+ var script$2 = {
6699
+ name: 'DocTemplateFieldSidebar',
6700
+ components: {
6701
+ FieldRuleFormModal
6702
+ },
6703
+ props: {
6704
+ value: {
6705
+ type: Object,
6706
+ default: null
6707
+ },
6708
+ visible: {
6709
+ type: Boolean,
6710
+ default: null
6711
+ },
6712
+ formConfig: Object
6713
+ },
6714
+
6715
+ data() {
6716
+ return {
6717
+ innerVisible: null,
6718
+ field: null,
6719
+ currentInputName: null,
6720
+ modalId: 'rb-field-rule-form-modal',
6721
+ ruleModalCfg: {
6722
+ rule: {},
6723
+ mode: 'ins'
6724
+ },
6725
+ rulesHash: v4()
6726
+ };
6727
+ },
6728
+
6729
+ computed: {
6730
+ inputOptions() {
6731
+ return this.field ? UtFormConstructor.getInputTypes(this.field) : [];
6732
+ },
6733
+
6734
+ iconCloseSidebar() {
6735
+ return UtFormConstructor.config.icons.iconCloseFieldSidebar;
6736
+ },
6737
+
6738
+ iconOpenSidebar() {
6739
+ return UtFormConstructor.config.icons.iconOpenFieldSidebar;
6740
+ },
6741
+
6742
+ iconAdd() {
6743
+ return UtFormConstructor.config.icons.iconAdd;
6744
+ },
6745
+
6746
+ rules() {
6747
+ return UtFormConstructor.getAvailableFieldRules(this.field);
6748
+ }
6749
+
6750
+ },
6751
+ watch: {
6752
+ visible() {
6753
+ this.innerVisible = this.visible;
6754
+ },
6755
+
6756
+ value() {
6757
+ this.field = this.value;
6758
+
6759
+ if (this.field && this.field.input) {
6760
+ this.currentInputName = this.field.input.name;
6761
+ }
6762
+ },
6763
+
6764
+ field() {
6765
+ this.$emit('input', this.field);
6766
+ this.$emit('change', this.field);
6767
+ },
6768
+
6769
+ currentInputName() {
6770
+ this.field.input = UtFormConstructor.getInputTypeByName(this.currentInputName, this.field);
6771
+ }
6772
+
6773
+ },
6774
+ methods: {
6775
+ hide() {
6776
+ this.innerVisible = false;
6777
+ this.$emit('hide');
6778
+ },
6779
+
6780
+ getPropInputType(prop, propName) {
6781
+ if (prop.type === 'string') {
6782
+ return 'b-form-input';
6783
+ } else {
6784
+ return 'rb-boolean-single-option-input';
6785
+ }
6786
+ },
6787
+
6788
+ getPropInputPropData(prop, propName) {
6789
+ if (prop.type === 'string') {
6790
+ return {
6791
+ type: 'text'
6792
+ };
6793
+ } else {
6794
+ return {};
6795
+ }
6796
+ },
6797
+
6798
+ addRule() {
6799
+ this.ruleModalCfg = {
6800
+ mode: 'ins',
6801
+ rule: {
6802
+ name: null,
6803
+ script: null
6804
+ },
6805
+ onAfterOk: rule => {
6806
+ this.field.rules = this.field.rules ? this.field.rules : [];
6807
+ this.field.rules.push({ ...rule
6808
+ });
6809
+ this.rulesHash = v4();
6810
+ }
6811
+ };
6812
+ this.$bvModal.show(this.modalId);
6813
+ },
6814
+
6815
+ editRule(rule, event) {
6816
+ if (event.target.classList && event.target.classList.contains('rb-remove-rule')) {
6817
+ return;
6818
+ }
6819
+
6820
+ this.ruleModalCfg = {
6821
+ mode: 'upd',
6822
+ rule: { ...rule
6823
+ },
6824
+ onAfterOk: modalRule => {
6825
+ Object.assign(rule, modalRule);
6826
+ }
6827
+ };
6828
+ this.$bvModal.show(this.modalId);
6829
+ },
6830
+
6831
+ removeRule(rule) {
6832
+ let index = this.field.rules.findIndex(r => r.id === rule.id);
6833
+
6834
+ if (index >= 0) {
6835
+ this.field.rules.splice(index, 1);
6836
+ }
6837
+
6838
+ this.rulesHash = v4();
6839
+ }
6840
+
6841
+ },
6842
+
6843
+ created() {
6844
+ this.innerVisible = this.visible;
6845
+ this.field = this.value;
6846
+
6847
+ if (this.field && this.field.input) {
6848
+ this.currentInputName = this.field.input.name;
6849
+ }
6850
+ }
6851
+
6852
+ };
6853
+
6854
+ /* script */
6198
6855
  const __vue_script__$2 = script$2;
6199
6856
  /* template */
6200
6857
 
@@ -6389,7 +7046,7 @@ var __vue_render__$2 = function () {
6389
7046
  staticClass: "rb-form-section"
6390
7047
  }, [_c('div', {
6391
7048
  staticClass: "rb-title"
6392
- }, [_vm._v("\n Значение по-умолчанию\n ")]), _vm._v(" "), _c('b-form-row', [_c('b-col', {
7049
+ }, [_vm._v("Значение по-умолчанию")]), _vm._v(" "), _c('b-form-row', [_c('b-col', {
6393
7050
  attrs: {
6394
7051
  "lg": "12"
6395
7052
  }
@@ -6407,7 +7064,55 @@ var __vue_render__$2 = function () {
6407
7064
  },
6408
7065
  expression: "field.defaultValue"
6409
7066
  }
6410
- }, 'component', _vm.field.input.propsData, false))], 1)], 1)], 1)], 1) : _vm._e()]) : _vm._e()], 1);
7067
+ }, 'component', _vm.field.input.propsData, false))], 1)], 1)], 1)], 1) : _vm._e(), _vm._v(" "), _c('div', {
7068
+ staticClass: "rb-form-section"
7069
+ }, [_c('div', {
7070
+ staticClass: "rb-title"
7071
+ }, [_vm._v("Правила")]), _vm._v(" "), _c('b-list-group', {
7072
+ attrs: {
7073
+ "data-hash": _vm.rulesHash
7074
+ }
7075
+ }, [_vm._l(_vm.field.rules, function (rule) {
7076
+ return _c('b-list-group-item', {
7077
+ key: rule.id,
7078
+ staticClass: "cursor-pointer d-flex justify-content-between align-items-center",
7079
+ attrs: {
7080
+ "data-hash": _vm.rulesHash
7081
+ },
7082
+ on: {
7083
+ "click": function ($event) {
7084
+ return _vm.editRule(rule, $event);
7085
+ }
7086
+ }
7087
+ }, [_c('rb-text', [_vm._v(_vm._s(rule.name))]), _vm._v(" "), _c('rb-icon', {
7088
+ staticClass: "rb-remove-rule",
7089
+ attrs: {
7090
+ "icon": "icon-close"
7091
+ },
7092
+ on: {
7093
+ "click": function ($event) {
7094
+ return _vm.removeRule(rule);
7095
+ }
7096
+ }
7097
+ })], 1);
7098
+ }), _vm._v(" "), _c('b-list-group-item', {
7099
+ staticClass: "cursor-pointer",
7100
+ on: {
7101
+ "click": _vm.addRule
7102
+ }
7103
+ }, [_c('rb-icon', {
7104
+ attrs: {
7105
+ "icon": _vm.iconAdd
7106
+ }
7107
+ }), _vm._v(" "), _c('rb-text', [_vm._v("Добавить правило ...")])], 1)], 2)], 1)]) : _vm._e(), _vm._v(" "), _c('field-rule-form-modal', {
7108
+ attrs: {
7109
+ "rule": _vm.ruleModalCfg.rule,
7110
+ "form-config": _vm.formConfig,
7111
+ "field": _vm.field,
7112
+ "mode": _vm.ruleModalCfg.mode,
7113
+ "on-after-ok": _vm.ruleModalCfg.onAfterOk
7114
+ }
7115
+ })], 1);
6411
7116
  };
6412
7117
 
6413
7118
  var __vue_staticRenderFns__$2 = [];
@@ -6429,12 +7134,12 @@ const __vue_is_functional_template__$2 = false;
6429
7134
 
6430
7135
  /* style inject shadow dom */
6431
7136
 
6432
- const __vue_component__$4 = /*#__PURE__*/normalizeComponent({
7137
+ const __vue_component__$3 = /*#__PURE__*/normalizeComponent({
6433
7138
  render: __vue_render__$2,
6434
7139
  staticRenderFns: __vue_staticRenderFns__$2
6435
7140
  }, __vue_inject_styles__$2, __vue_script__$2, __vue_scope_id__$2, __vue_is_functional_template__$2, __vue_module_identifier__$2, false, undefined, undefined, undefined);
6436
7141
 
6437
- var DocTemplateFieldSidebar = __vue_component__$4;
7142
+ var DocTemplateFieldSidebar = __vue_component__$3;
6438
7143
 
6439
7144
  //
6440
7145
  var script$1 = {
@@ -6479,24 +7184,28 @@ var script$1 = {
6479
7184
 
6480
7185
  computed: {
6481
7186
  iconAdd() {
6482
- return UtFormConfig.config.icons.iconAdd;
7187
+ return UtFormConstructor.config.icons.iconAdd;
6483
7188
  },
6484
7189
 
6485
7190
  iconEdit() {
6486
- return UtFormConfig.config.icons.iconEdit;
7191
+ return UtFormConstructor.config.icons.iconEdit;
6487
7192
  },
6488
7193
 
6489
7194
  iconDelete() {
6490
- return UtFormConfig.config.icons.iconDelete;
7195
+ return UtFormConstructor.config.icons.iconDelete;
6491
7196
  },
6492
7197
 
6493
7198
  iconDrag() {
6494
- return UtFormConfig.config.icons.iconDrag;
7199
+ return UtFormConstructor.config.icons.iconDrag;
6495
7200
  }
6496
7201
 
6497
7202
  },
6498
7203
  methods: {
6499
- showProperties(field) {
7204
+ showProperties(field, event) {
7205
+ if (event.target.classList && event.target.classList.contains('rb-remove-field')) {
7206
+ return;
7207
+ }
7208
+
6500
7209
  this.sidebarVisible = true;
6501
7210
  this.sidebarField = field;
6502
7211
  },
@@ -6570,12 +7279,7 @@ var script$1 = {
6570
7279
  let index = newIndex != null ? newIndex : -1;
6571
7280
 
6572
7281
  if (index < 0) {
6573
- column.fields.every((f, i) => {
6574
- if (field.name === f.name) {
6575
- index = i;
6576
- return false;
6577
- }
6578
- });
7282
+ index = column.fields.findIndex(f => field.name === f.name);
6579
7283
  }
6580
7284
 
6581
7285
  if (index >= 0) {
@@ -6655,7 +7359,7 @@ var __vue_render__$1 = function () {
6655
7359
  staticClass: "rb-form-constructor flex-fill"
6656
7360
  }, [_c('div', {
6657
7361
  staticClass: "rb-constructor-toolbar d-flex flex-row"
6658
- }, [_c('h4', [_vm._v("Верстка документа")]), _vm._v(" "), _c('div', {
7362
+ }, [_c('h4', [_vm._v("Добавить секцию: ")]), _vm._v(" "), _c('div', {
6659
7363
  staticClass: "rb-layout-buttons"
6660
7364
  }, [_c('b-button', {
6661
7365
  attrs: {
@@ -6667,7 +7371,7 @@ var __vue_render__$1 = function () {
6667
7371
  return _vm.addSection(1);
6668
7372
  }
6669
7373
  }
6670
- }, [_c('rb-text', [_vm._v("1 колонка")]), _vm._v(" "), _c('rb-icon', {
7374
+ }, [_c('rb-text', [_vm._v("Секция с 1 колонкой")]), _vm._v(" "), _c('rb-icon', {
6671
7375
  attrs: {
6672
7376
  "icon": _vm.iconAdd
6673
7377
  }
@@ -6681,7 +7385,7 @@ var __vue_render__$1 = function () {
6681
7385
  return _vm.addSection(2);
6682
7386
  }
6683
7387
  }
6684
- }, [_c('rb-text', [_vm._v("2 колонки")]), _vm._v(" "), _c('rb-icon', {
7388
+ }, [_c('rb-text', [_vm._v("Секция с 2 колонками")]), _vm._v(" "), _c('rb-icon', {
6685
7389
  attrs: {
6686
7390
  "icon": _vm.iconAdd
6687
7391
  }
@@ -6695,7 +7399,7 @@ var __vue_render__$1 = function () {
6695
7399
  return _vm.addSection(3);
6696
7400
  }
6697
7401
  }
6698
- }, [_c('rb-text', [_vm._v("3 колонки")]), _vm._v(" "), _c('rb-icon', {
7402
+ }, [_c('rb-text', [_vm._v("Секция с 3 колонками")]), _vm._v(" "), _c('rb-icon', {
6699
7403
  attrs: {
6700
7404
  "icon": _vm.iconAdd
6701
7405
  }
@@ -6797,7 +7501,7 @@ var __vue_render__$1 = function () {
6797
7501
  staticClass: "cursor-pointer",
6798
7502
  on: {
6799
7503
  "click": function ($event) {
6800
- return _vm.showProperties(field);
7504
+ return _vm.showProperties(field, $event);
6801
7505
  }
6802
7506
  }
6803
7507
  }, [_c('b-col', {
@@ -6817,6 +7521,7 @@ var __vue_render__$1 = function () {
6817
7521
  "icon": _vm.iconDrag
6818
7522
  }
6819
7523
  }), _vm._v(" "), _c('rb-text', [_vm._v(_vm._s(field.labelRu))]), _vm._v(" "), _c('rb-icon', {
7524
+ staticClass: "rb-remove-field",
6820
7525
  attrs: {
6821
7526
  "icon": _vm.iconDelete
6822
7527
  },
@@ -6841,7 +7546,8 @@ var __vue_render__$1 = function () {
6841
7546
  }), 1)]);
6842
7547
  }), 1)], 1), _vm._v(" "), _c('doc-template-field-sidebar', {
6843
7548
  attrs: {
6844
- "visible": _vm.sidebarVisible
7549
+ "visible": _vm.sidebarVisible,
7550
+ "form-config": _vm.formConfig
6845
7551
  },
6846
7552
  on: {
6847
7553
  "hide": function ($event) {
@@ -6883,56 +7589,58 @@ const __vue_is_functional_template__$1 = false;
6883
7589
 
6884
7590
  /* style inject shadow dom */
6885
7591
 
6886
- const __vue_component__$2 = /*#__PURE__*/normalizeComponent({
7592
+ const __vue_component__$1 = /*#__PURE__*/normalizeComponent({
6887
7593
  render: __vue_render__$1,
6888
7594
  staticRenderFns: __vue_staticRenderFns__$1
6889
7595
  }, __vue_inject_styles__$1, __vue_script__$1, __vue_scope_id__$1, __vue_is_functional_template__$1, __vue_module_identifier__$1, false, undefined, undefined, undefined);
6890
7596
 
6891
- var __vue_component__$3 = __vue_component__$2;
7597
+ var __vue_component__$2 = __vue_component__$1;
6892
7598
 
6893
- //
6894
- //
6895
- //
6896
- //
6897
- //
6898
- //
6899
- //
6900
- //
6901
- //
6902
- //
6903
- //
6904
- //
6905
- //
6906
- //
6907
- //
6908
- //
6909
- //
6910
- //
6911
- //
6912
- //
6913
- //
6914
- //
6915
- //
6916
- //
6917
7599
  //
6918
7600
  var script = {
6919
7601
  name: 'DocForm',
6920
7602
  props: {
6921
7603
  formConfig: Object,
7604
+ applyDefaultValues: {
7605
+ type: Boolean,
7606
+ default: true
7607
+ },
6922
7608
  doc: {
6923
7609
  type: Object,
6924
7610
  default: () => ({})
7611
+ },
7612
+ validationState: {
7613
+ type: Object,
7614
+ default: () => ({})
6925
7615
  }
6926
7616
  },
7617
+ methods: {
7618
+ onEventFired(eventName, event, field) {
7619
+ if (field.rules) {
7620
+ field.rules.forEach(rule => {
7621
+ if (rule.event === eventName && rule.script) {
7622
+ let ruleContext = UtFormConstructor.getRuleContext();
7623
+ ruleContext.form = this;
7624
+ ruleContext.event = event;
7625
+ ruleContext.eventName = eventName;
7626
+ UtFormConstructor.runRule(ruleContext, rule.script);
7627
+ }
7628
+ });
7629
+ }
7630
+ }
7631
+
7632
+ },
6927
7633
 
6928
7634
  created() {
6929
- this.formConfig.sections.forEach(r => {
6930
- r.columns.forEach(c => {
6931
- c.fields.forEach(f => {
6932
- this.doc[f.name] = f.defaultValue;
7635
+ if (this.applyDefaultValues) {
7636
+ this.formConfig.sections.forEach(r => {
7637
+ r.columns.forEach(c => {
7638
+ c.fields.forEach(f => {
7639
+ this.$set(this.doc, f.name, f.defaultValue == null ? null : f.defaultValue);
7640
+ });
6933
7641
  });
6934
7642
  });
6935
- });
7643
+ }
6936
7644
  }
6937
7645
 
6938
7646
  };
@@ -6959,14 +7667,10 @@ var __vue_render__ = function () {
6959
7667
  }, _vm._l(section.columns, function (column) {
6960
7668
  return _c('div', {
6961
7669
  key: column.index,
6962
- staticClass: "rb-form-column",
6963
- class: {
6964
- 'rb-single-column': section.columnCount === 1
6965
- }
6966
- }, _vm._l(column.fields, function (field) {
6967
- return _c('b-form-row', {
6968
- key: field.name,
6969
- staticClass: "cursor-pointer"
7670
+ staticClass: "rb-form-column"
7671
+ }, [_vm._l(column.fields, function (field) {
7672
+ return [field.visible ? _c('b-form-row', {
7673
+ key: field.name
6970
7674
  }, [_c('b-col', {
6971
7675
  attrs: {
6972
7676
  "lg": "12"
@@ -6978,7 +7682,24 @@ var __vue_render__ = function () {
6978
7682
  "label": field.labelRu
6979
7683
  }
6980
7684
  }, [_c(field.input.type, _vm._b({
7685
+ ref: field.name,
7686
+ refInFor: true,
6981
7687
  tag: "component",
7688
+ attrs: {
7689
+ "disabled": !field.editable,
7690
+ "state": _vm.validationState[field.name]
7691
+ },
7692
+ on: {
7693
+ "input": function ($event) {
7694
+ return _vm.onEventFired('input', $event, field);
7695
+ },
7696
+ "change": function ($event) {
7697
+ return _vm.onEventFired('change', $event, field);
7698
+ },
7699
+ "click": function ($event) {
7700
+ return _vm.onEventFired('click', $event, field);
7701
+ }
7702
+ },
6982
7703
  model: {
6983
7704
  value: _vm.doc[field.name],
6984
7705
  callback: function ($$v) {
@@ -6986,8 +7707,8 @@ var __vue_render__ = function () {
6986
7707
  },
6987
7708
  expression: "doc[field.name]"
6988
7709
  }
6989
- }, 'component', field.input.propsData, false))], 1)], 1)], 1);
6990
- }), 1);
7710
+ }, 'component', field.input.propsData, false))], 1)], 1)], 1) : _vm._e()];
7711
+ })], 2);
6991
7712
  }), 0)]);
6992
7713
  }), 0);
6993
7714
  };
@@ -7016,18 +7737,19 @@ const __vue_component__ = /*#__PURE__*/normalizeComponent({
7016
7737
  staticRenderFns: __vue_staticRenderFns__
7017
7738
  }, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined);
7018
7739
 
7019
- var __vue_component__$1 = __vue_component__;
7740
+ var DocForm = __vue_component__;
7020
7741
 
7021
7742
  /* eslint-disable import/prefer-default-export */
7022
7743
 
7023
7744
  var components = /*#__PURE__*/Object.freeze({
7024
7745
  __proto__: null,
7025
7746
  UtFormConfig: UtFormConfig,
7747
+ UtFormConstructor: UtFormConstructor,
7026
7748
  DocTemplateSectionModal: DocTemplateSectionModal,
7027
7749
  DocTemplateFacetList: DocTemplateFacetList,
7028
7750
  DocTemplateFieldSidebar: DocTemplateFieldSidebar,
7029
- DocTemplateConstructor: __vue_component__$3,
7030
- DocForm: __vue_component__$1
7751
+ DocTemplateConstructor: __vue_component__$2,
7752
+ DocForm: DocForm
7031
7753
  });
7032
7754
 
7033
7755
  // Import vue components
@@ -7039,4 +7761,4 @@ const install = function installRbDocumentFormConstructor(Vue) {
7039
7761
  });
7040
7762
  }; // Create module definition for Vue.use()
7041
7763
 
7042
- export { __vue_component__$1 as DocForm, __vue_component__$3 as DocTemplateConstructor, DocTemplateFacetList, DocTemplateFieldSidebar, DocTemplateSectionModal, UtFormConfig, install as default };
7764
+ export { DocForm, __vue_component__$2 as DocTemplateConstructor, DocTemplateFacetList, DocTemplateFieldSidebar, DocTemplateSectionModal, UtFormConfig, UtFormConstructor, install as default };