rb-document-form-constructor 0.6.1 → 0.6.4

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,269 +1,272 @@
1
- <template>
2
- <b-modal :id="id"
3
- :title="title"
4
- modal-class="rb-field-rule-form-modal"
5
- size="lg"
6
- @ok.prevent="onOk"
7
- ok-title="Сохранить правило"
8
- cancel-variant="outline-gray"
9
- cancel-title="Отмена">
10
- <b-card no-body>
11
- <b-tabs card @activate-tab="onActivateTab">
12
- <b-tab title="Правило" active>
13
- <b-form v-if="innerRule">
14
- <b-form-row>
15
- <b-col log="12">
16
- <b-form-group label="Выбрать" v-if="rulePresets.length > 0">
17
- <template #description>
18
- Выберите готовое правило из списка и если нужно, измените
19
- </template>
20
- <b-form-select @input="onRuleSelected($event)">
21
- <b-form-select-option v-for="r in rulePresets" :key="r.name"
22
- :value="r.name">
23
- {{r.labelRu}} ({{r.name}})
24
- </b-form-select-option>
25
- </b-form-select>
26
- </b-form-group>
27
- </b-col>
28
- <b-col lg="12">
29
- <b-form-group label="Название">
30
- <template #description>
31
- Задайте уникальное название, чтобы отличать правило в списке
32
- </template>
33
- <b-form-input v-model="innerRule.name"
34
- :state="state.name"
35
- :invalid-feedback="state.name_feedback"
36
- ></b-form-input>
37
- </b-form-group>
38
- </b-col>
39
- <b-col lg="12">
40
- <b-form-group label="Событие">
41
- <template #description>
42
- При возникновении этого события будет выполняться правило
43
- </template>
44
- <b-form-select v-model="innerRule.event"
45
- :state="state.event"
46
- :invalid-feedback="state.event_feedback">
47
- <b-form-select-option :value="'input'">
48
- Ввод значения
49
- </b-form-select-option>
50
- <b-form-select-option :value="'change'">
51
- Изменение значения
52
- </b-form-select-option>
53
- <b-form-select-option :value="'click'">
54
- Клик
55
- </b-form-select-option>
56
- <b-form-select-option :value="'validate'">
57
- Валидация
58
- </b-form-select-option>
59
- </b-form-select>
60
- </b-form-group>
61
- </b-col>
62
- <b-col lg="12">
63
- <b-form-group label="Скрипт">
64
- <template #description>
65
- Здесь указывается скрипт правила. Скрипт должен быть написан на языке
66
- javascript
67
- </template>
68
- <div class="rb-script-input">
69
- <b-button-toolbar>
70
- <b-dropdown text="Переменные" variant="outline-secondary"
71
- size="sm" class="mx-1">
72
- <b-dropdown-item @click="addVariableToScript('doc')">
73
- Документ
74
- </b-dropdown-item>
75
- <b-dropdown-item @click="addVariableToScript('form')">
76
- Форма
77
- </b-dropdown-item>
78
- <b-dropdown-item @click="addVariableToScript('event')">
79
- Значение события
80
- </b-dropdown-item>
81
- </b-dropdown>
82
- <b-dropdown text="Задать значение" variant="outline-secondary"
83
- size="sm" class="mx-1">
84
- <b-dropdown-item v-for="f in fields" :key="f.name"
85
- v-if="fields" @click="addSetVariableToScript(f)">
86
- {{f.labelRu}} ({{f.name}})
87
- </b-dropdown-item>
88
- </b-dropdown>
89
- <b-dropdown text="Вызвать функцию инпута" variant="outline-secondary"
90
- size="sm" class="mx-1">
91
- <b-dropdown-item v-for="f in fields" :key="f.name"
92
- v-if="fields" @click="addCallInputFunction(f)">
93
- {{f.labelRu}} ({{f.name}})
94
- </b-dropdown-item>
95
- </b-dropdown>
96
- </b-button-toolbar>
97
- <b-form-textarea v-model="innerRule.script"
98
- :state="state.script"
99
- :invalid-feedback="state.script_feedback"
100
- rows="8"
101
- ref="scriptInput"
102
- ></b-form-textarea>
103
- </div>
104
- </b-form-group>
105
- </b-col>
106
- </b-form-row>
107
- </b-form>
108
- </b-tab>
109
- <b-tab title="Протестировать правило" v-if="innerFormConfig">
110
- <doc-form :form-config="innerFormConfig">
111
- </doc-form>
112
- </b-tab>
113
- </b-tabs>
114
- </b-card>
115
- </b-modal>
116
- </template>
117
-
118
- <script>
119
- import {UtFormConfig} from "../utils/UtFormConfig";
120
- import {v4 as uuidv4} from 'uuid';
121
- import {UtFormConstructor} from "../utils/UtFormConstructor";
122
- import DocForm from "./DocForm";
123
-
124
- export default {
125
- name: 'FieldRuleFormModal',
126
- components: {DocForm},
127
- props: {
128
- field: Object,
129
- rule: Object,
130
- formConfig: Object,
131
- mode: {type: String, default: 'ins'},
132
- onAfterOk: Function,
133
- },
134
- data() {
135
- return {
136
- id: 'rb-field-rule-form-modal',
137
- state: this.getDefaultState(),
138
- innerFormConfig: null,
139
- innerRule: null,
140
- }
141
- },
142
- computed: {
143
- title() {
144
- return this.mode === 'ins' ? 'Добавление правила' : 'Редактирование правила';
145
- },
146
- fields() {
147
- return UtFormConfig.getFields(this.formConfig);
148
- },
149
- rulePresets() {
150
- return UtFormConstructor.getAvailableFieldRules(this.field);
151
- }
152
- },
153
- watch: {
154
- formConfig() {
155
- this.copyToInnerFormConfig();
156
- },
157
- rule() {
158
- if (this.rule) {
159
- this.innerRule = this.rule;
160
- } else {
161
- this.innerRule = this.getDefaultRule();
162
- }
163
-
164
- }
165
- },
166
- methods: {
167
- validateFields(fieldName) {
168
- let fields = fieldName ? [fieldName] : ['name', 'event', 'script'];
169
- fields.forEach(field => {
170
- if (!this.innerRule[field]) {
171
- this.state[field] = false;
172
- this.state[`${field}_feedback`] = 'Заполните название';
173
- } else {
174
- this.state[field] = true;
175
- this.state[`${field}_feedback`] = null;
176
- }
177
- });
178
- },
179
- copyToInnerFormConfig() {
180
- this.innerFormConfig = JSON.parse(JSON.stringify(this.formConfig));
181
- },
182
- applyRuleToInnerFormConfig() {
183
- if (this.innerFormConfig) {
184
- let foundRule = UtFormConfig.findRule(this.innerRule.id, this.innerFormConfig);
185
-
186
- if (!foundRule) {
187
- let foundField = UtFormConfig.findField(
188
- this.field.name, this.innerFormConfig
189
- );
190
-
191
- if (foundField) {
192
- foundField.rules = foundField.rules ? foundField.rules : [];
193
- foundField.rules.push(this.rule);
194
- }
195
- } else {
196
- Object.assign(foundRule, this.innerRule);
197
- }
198
- }
199
- },
200
- onActivateTab(index) {
201
- if (index > 0) {
202
- this.copyToInnerFormConfig();
203
- this.applyRuleToInnerFormConfig();
204
- }
205
- },
206
- getDefaultState() {
207
- return {
208
- name: null,
209
- event: null,
210
- script: null,
211
- }
212
- },
213
- getDefaultRule() {
214
- return {
215
- id: uuidv4(),
216
- name: null,
217
- event: null,
218
- script: null,
219
- }
220
- },
221
- resetModal() {
222
- this.state = this.getDefaultState();
223
- this.innerRule = null;
224
- },
225
- addVariableToScript(varName) {
226
- let caretPosition = this.$refs.scriptInput.selectionStart;
227
- this.insertTextToScript(varName, caretPosition);
228
- },
229
- addSetVariableToScript(field) {
230
- let caretPosition = this.$refs.scriptInput.selectionStart;
231
- this.insertTextToScript(`doc['${field.name}'] = Значение;`, caretPosition);
232
- },
233
- addCallInputFunction(field) {
234
- let caretPosition = this.$refs.scriptInput.selectionStart;
235
- this.insertTextToScript(`form.$refs['${field.name}'][0].Название функции();`, caretPosition);
236
- },
237
- insertTextToScript(text, position) {
238
- position = position != null? position: this.script.length;
239
- this.innerRule.script = this.innerRule.script != null? this.innerRule.script: '';
240
- let scriptSplit = this.innerRule.script.split('');
241
- scriptSplit.splice(position, 0, text);
242
- this.innerRule.script = scriptSplit.join('');
243
- },
244
- onRuleSelected(ruleName) {
245
- let rule = this.rulePresets.find(rule => rule.name === ruleName);
246
- if(rule) {
247
- Object.assign(this.innerRule, rule);
248
- this.innerRule.script = this.innerRule.script.trim();
249
- }
250
- },
251
- onOk() {
252
- this.validateFields();
253
-
254
- if (this.state.name && this.state.script) {
255
- if (this.onAfterOk) {
256
- this.onAfterOk(this.innerRule);
257
- }
258
- this.$nextTick(() => {
259
- this.resetModal();
260
- this.$bvModal.hide(this.id);
261
- });
262
- }
263
- }
264
- },
265
- created() {
266
- this.copyToInnerFormConfig();
267
- }
268
- }
269
- </script>
1
+ <template>
2
+ <b-modal :id="id"
3
+ :title="title"
4
+ modal-class="rb-field-rule-form-modal"
5
+ size="lg"
6
+ @ok.prevent="onOk"
7
+ ok-title="Сохранить правило"
8
+ cancel-variant="outline-gray"
9
+ cancel-title="Отмена">
10
+ <b-card no-body>
11
+ <b-tabs card @activate-tab="onActivateTab">
12
+ <b-tab title="Правило" active>
13
+ <b-form v-if="innerRule">
14
+ <b-form-row>
15
+ <b-col log="12">
16
+ <b-form-group label="Выбрать" v-if="rulePresets.length > 0">
17
+ <template #description>
18
+ Выберите готовое правило из списка и если нужно, измените
19
+ </template>
20
+ <b-form-select @input="onRuleSelected($event)">
21
+ <b-form-select-option v-for="r in rulePresets" :key="r.name"
22
+ :value="r.name">
23
+ {{r.labelRu}} ({{r.name}})
24
+ </b-form-select-option>
25
+ </b-form-select>
26
+ </b-form-group>
27
+ </b-col>
28
+ <b-col lg="12">
29
+ <b-form-group label="Название">
30
+ <template #description>
31
+ Задайте уникальное название, чтобы отличать правило в списке
32
+ </template>
33
+ <b-form-input v-model="innerRule.name"
34
+ :state="state.name"
35
+ :invalid-feedback="state.name_feedback"
36
+ ></b-form-input>
37
+ </b-form-group>
38
+ </b-col>
39
+ <b-col lg="12">
40
+ <b-form-group label="Событие">
41
+ <template #description>
42
+ При возникновении этого события будет выполняться правило
43
+ </template>
44
+ <b-form-select v-model="innerRule.event"
45
+ :state="state.event"
46
+ :invalid-feedback="state.event_feedback">
47
+ <b-form-select-option :value="'input'">
48
+ Ввод значения
49
+ </b-form-select-option>
50
+ <b-form-select-option :value="'change'">
51
+ Изменение значения
52
+ </b-form-select-option>
53
+ <b-form-select-option :value="'click'">
54
+ Клик
55
+ </b-form-select-option>
56
+ <b-form-select-option :value="'validate'">
57
+ Валидация
58
+ </b-form-select-option>
59
+ <b-form-select-option :value="'defaultValue'">
60
+ Установить значение по умолчанию
61
+ </b-form-select-option>
62
+ </b-form-select>
63
+ </b-form-group>
64
+ </b-col>
65
+ <b-col lg="12">
66
+ <b-form-group label="Скрипт">
67
+ <template #description>
68
+ Здесь указывается скрипт правила. Скрипт должен быть написан на языке
69
+ javascript
70
+ </template>
71
+ <div class="rb-script-input">
72
+ <b-button-toolbar>
73
+ <b-dropdown text="Переменные" variant="outline-secondary"
74
+ size="sm" class="mx-1">
75
+ <b-dropdown-item @click="addVariableToScript('doc')">
76
+ Документ
77
+ </b-dropdown-item>
78
+ <b-dropdown-item @click="addVariableToScript('form')">
79
+ Форма
80
+ </b-dropdown-item>
81
+ <b-dropdown-item @click="addVariableToScript('event')">
82
+ Значение события
83
+ </b-dropdown-item>
84
+ </b-dropdown>
85
+ <b-dropdown text="Задать значение" variant="outline-secondary"
86
+ size="sm" class="mx-1">
87
+ <b-dropdown-item v-for="f in fields" :key="f.name"
88
+ v-if="fields" @click="addSetVariableToScript(f)">
89
+ {{f.labelRu}} ({{f.name}})
90
+ </b-dropdown-item>
91
+ </b-dropdown>
92
+ <b-dropdown text="Вызвать функцию инпута" variant="outline-secondary"
93
+ size="sm" class="mx-1">
94
+ <b-dropdown-item v-for="f in fields" :key="f.name"
95
+ v-if="fields" @click="addCallInputFunction(f)">
96
+ {{f.labelRu}} ({{f.name}})
97
+ </b-dropdown-item>
98
+ </b-dropdown>
99
+ </b-button-toolbar>
100
+ <b-form-textarea v-model="innerRule.script"
101
+ :state="state.script"
102
+ :invalid-feedback="state.script_feedback"
103
+ rows="8"
104
+ ref="scriptInput"
105
+ ></b-form-textarea>
106
+ </div>
107
+ </b-form-group>
108
+ </b-col>
109
+ </b-form-row>
110
+ </b-form>
111
+ </b-tab>
112
+ <b-tab title="Протестировать правило" v-if="innerFormConfig">
113
+ <doc-form :form-config="innerFormConfig">
114
+ </doc-form>
115
+ </b-tab>
116
+ </b-tabs>
117
+ </b-card>
118
+ </b-modal>
119
+ </template>
120
+
121
+ <script>
122
+ import {UtFormConfig} from "../utils/UtFormConfig";
123
+ import {v4 as uuidv4} from 'uuid';
124
+ import {UtFormConstructor} from "../utils/UtFormConstructor";
125
+ import DocForm from "./DocForm";
126
+
127
+ export default {
128
+ name: 'FieldRuleFormModal',
129
+ components: {DocForm},
130
+ props: {
131
+ field: Object,
132
+ rule: Object,
133
+ formConfig: Object,
134
+ mode: {type: String, default: 'ins'},
135
+ onAfterOk: Function,
136
+ },
137
+ data() {
138
+ return {
139
+ id: 'rb-field-rule-form-modal',
140
+ state: this.getDefaultState(),
141
+ innerFormConfig: null,
142
+ innerRule: null,
143
+ }
144
+ },
145
+ computed: {
146
+ title() {
147
+ return this.mode === 'ins' ? 'Добавление правила' : 'Редактирование правила';
148
+ },
149
+ fields() {
150
+ return UtFormConfig.getFields(this.formConfig);
151
+ },
152
+ rulePresets() {
153
+ return UtFormConstructor.getAvailableFieldRules(this.field);
154
+ }
155
+ },
156
+ watch: {
157
+ formConfig() {
158
+ this.copyToInnerFormConfig();
159
+ },
160
+ rule() {
161
+ if (this.rule) {
162
+ this.innerRule = this.rule;
163
+ } else {
164
+ this.innerRule = this.getDefaultRule();
165
+ }
166
+
167
+ }
168
+ },
169
+ methods: {
170
+ validateFields(fieldName) {
171
+ let fields = fieldName ? [fieldName] : ['name', 'event', 'script'];
172
+ fields.forEach(field => {
173
+ if (!this.innerRule[field]) {
174
+ this.state[field] = false;
175
+ this.state[`${field}_feedback`] = 'Заполните название';
176
+ } else {
177
+ this.state[field] = true;
178
+ this.state[`${field}_feedback`] = null;
179
+ }
180
+ });
181
+ },
182
+ copyToInnerFormConfig() {
183
+ this.innerFormConfig = JSON.parse(JSON.stringify(this.formConfig));
184
+ },
185
+ applyRuleToInnerFormConfig() {
186
+ if (this.innerFormConfig) {
187
+ let foundRule = UtFormConfig.findRule(this.innerRule.id, this.innerFormConfig);
188
+
189
+ if (!foundRule) {
190
+ let foundField = UtFormConfig.findField(
191
+ this.field.name, this.innerFormConfig
192
+ );
193
+
194
+ if (foundField) {
195
+ foundField.rules = foundField.rules ? foundField.rules : [];
196
+ foundField.rules.push(this.rule);
197
+ }
198
+ } else {
199
+ Object.assign(foundRule, this.innerRule);
200
+ }
201
+ }
202
+ },
203
+ onActivateTab(index) {
204
+ if (index > 0) {
205
+ this.copyToInnerFormConfig();
206
+ this.applyRuleToInnerFormConfig();
207
+ }
208
+ },
209
+ getDefaultState() {
210
+ return {
211
+ name: null,
212
+ event: null,
213
+ script: null,
214
+ }
215
+ },
216
+ getDefaultRule() {
217
+ return {
218
+ id: uuidv4(),
219
+ name: null,
220
+ event: null,
221
+ script: null,
222
+ }
223
+ },
224
+ resetModal() {
225
+ this.state = this.getDefaultState();
226
+ this.innerRule = null;
227
+ },
228
+ addVariableToScript(varName) {
229
+ let caretPosition = this.$refs.scriptInput.selectionStart;
230
+ this.insertTextToScript(varName, caretPosition);
231
+ },
232
+ addSetVariableToScript(field) {
233
+ let caretPosition = this.$refs.scriptInput.selectionStart;
234
+ this.insertTextToScript(`doc['${field.name}'] = Значение;`, caretPosition);
235
+ },
236
+ addCallInputFunction(field) {
237
+ let caretPosition = this.$refs.scriptInput.selectionStart;
238
+ this.insertTextToScript(`form.$refs['${field.name}'][0].Название функции();`, caretPosition);
239
+ },
240
+ insertTextToScript(text, position) {
241
+ position = position != null? position: this.script.length;
242
+ this.innerRule.script = this.innerRule.script != null? this.innerRule.script: '';
243
+ let scriptSplit = this.innerRule.script.split('');
244
+ scriptSplit.splice(position, 0, text);
245
+ this.innerRule.script = scriptSplit.join('');
246
+ },
247
+ onRuleSelected(ruleName) {
248
+ let rule = this.rulePresets.find(rule => rule.name === ruleName);
249
+ if(rule) {
250
+ Object.assign(this.innerRule, rule);
251
+ this.innerRule.script = this.innerRule.script.trim();
252
+ }
253
+ },
254
+ onOk() {
255
+ this.validateFields();
256
+
257
+ if (this.state.name && this.state.script) {
258
+ if (this.onAfterOk) {
259
+ this.onAfterOk(this.innerRule);
260
+ }
261
+ this.$nextTick(() => {
262
+ this.resetModal();
263
+ this.$bvModal.hide(this.id);
264
+ });
265
+ }
266
+ }
267
+ },
268
+ created() {
269
+ this.copyToInnerFormConfig();
270
+ }
271
+ }
272
+ </script>
@@ -1,75 +0,0 @@
1
- This webfont is generated by https://fontello.com open source project.
2
-
3
-
4
- ================================================================================
5
- Please, note, that you should obey original font licenses, used to make this
6
- webfont pack. Details available in LICENSE.txt file.
7
-
8
- - Usually, it's enough to publish content of LICENSE.txt file somewhere on your
9
- site in "About" section.
10
-
11
- - If your project is open-source, usually, it will be ok to make LICENSE.txt
12
- file publicly available in your repository.
13
-
14
- - Fonts, used in Fontello, don't require a clickable link on your site.
15
- But any kind of additional authors crediting is welcome.
16
- ================================================================================
17
-
18
-
19
- Comments on archive content
20
- ---------------------------
21
-
22
- - /font/* - fonts in different formats
23
-
24
- - /css/* - different kinds of css, for all situations. Should be ok with
25
- twitter bootstrap. Also, you can skip <i> style and assign icon classes
26
- directly to text elements, if you don't mind about IE7.
27
-
28
- - demo.html - demo file, to show your webfont content
29
-
30
- - LICENSE.txt - license info about source fonts, used to build your one.
31
-
32
- - config.json - keeps your settings. You can import it back into fontello
33
- anytime, to continue your work
34
-
35
-
36
- Why so many CSS files ?
37
- -----------------------
38
-
39
- Because we like to fit all your needs :)
40
-
41
- - basic file, <your_font_name>.css - is usually enough, it contains @font-face
42
- and character code definitions
43
-
44
- - *-ie7.css - if you need IE7 support, but still don't wish to put char codes
45
- directly into html
46
-
47
- - *-codes.css and *-ie7-codes.css - if you like to use your own @font-face
48
- rules, but still wish to benefit from css generation. That can be very
49
- convenient for automated asset build systems. When you need to update font -
50
- no need to manually edit files, just override old version with archive
51
- content. See fontello source code for examples.
52
-
53
- - *-embedded.css - basic css file, but with embedded WOFF font, to avoid
54
- CORS issues in Firefox and IE9+, when fonts are hosted on the separate domain.
55
- We strongly recommend to resolve this issue by `Access-Control-Allow-Origin`
56
- server headers. But if you ok with dirty hack - this file is for you. Note,
57
- that data url moved to separate @font-face to avoid problems with <IE9, when
58
- string is too long.
59
-
60
- - animate.css - use it to get ideas about spinner rotation animation.
61
-
62
-
63
- Attention for server setup
64
- --------------------------
65
-
66
- You MUST setup server to reply with proper `mime-types` for font files -
67
- otherwise some browsers will fail to show fonts.
68
-
69
- Usually, `apache` already has necessary settings, but `nginx` and other
70
- webservers should be tuned. Here is list of mime types for our file extensions:
71
-
72
- - `application/vnd.ms-fontobject` - eot
73
- - `application/x-font-woff` - woff
74
- - `application/x-font-ttf` - ttf
75
- - `image/svg+xml` - svg