|
9 | 9 | @mousedown.stop |
10 | 10 | @pointerdown.stop |
11 | 11 | > |
| 12 | + <label |
| 13 | + v-if="requiredFields.length" |
| 14 | + class="field-settings-required w-full px-2 py-1 rounded-md hover:bg-neutral-100 flex items-center space-x-2 text-sm cursor-pointer" |
| 15 | + @click.stop |
| 16 | + > |
| 17 | + <input |
| 18 | + :checked="isAllRequired" |
| 19 | + :indeterminate="isMixedRequired" |
| 20 | + type="checkbox" |
| 21 | + class="toggle toggle-xs" |
| 22 | + :disabled="!editable" |
| 23 | + @change="handleToggleRequired($event.target.checked)" |
| 24 | + @click.stop |
| 25 | + > |
| 26 | + <span>{{ t('required') }}</span> |
| 27 | + </label> |
| 28 | + <label |
| 29 | + v-if="readOnlyFields.length" |
| 30 | + class="field-settings-read-only w-full px-2 py-1 rounded-md hover:bg-neutral-100 flex items-center space-x-2 text-sm cursor-pointer" |
| 31 | + @click.stop |
| 32 | + > |
| 33 | + <input |
| 34 | + :checked="isAllReadOnly" |
| 35 | + :indeterminate="isMixedReadOnly" |
| 36 | + type="checkbox" |
| 37 | + class="toggle toggle-xs" |
| 38 | + :disabled="!editable" |
| 39 | + @change="handleToggleReadOnly($event.target.checked)" |
| 40 | + @click.stop |
| 41 | + > |
| 42 | + <span>{{ t('read_only') }}</span> |
| 43 | + </label> |
| 44 | + <hr |
| 45 | + v-if="requiredFields.length || readOnlyFields.length" |
| 46 | + class="my-1 border-neutral-200" |
| 47 | + > |
| 48 | + <button |
| 49 | + v-if="showFont" |
| 50 | + class="w-full px-2 py-1 rounded-md hover:bg-neutral-100 flex items-center space-x-2 text-sm" |
| 51 | + @click.stop="openFontModal" |
| 52 | + > |
| 53 | + <IconTypography class="w-4 h-4" /> |
| 54 | + <span>{{ t('font') }}</span> |
| 55 | + </button> |
| 56 | + <button |
| 57 | + v-if="showCondition" |
| 58 | + class="w-full px-2 py-1 rounded-md hover:bg-neutral-100 flex items-center space-x-2 text-sm" |
| 59 | + @click.stop="openConditionModal" |
| 60 | + > |
| 61 | + <IconRouteAltLeft class="w-4 h-4" /> |
| 62 | + <span>{{ t('condition') }}</span> |
| 63 | + </button> |
| 64 | + <hr |
| 65 | + v-if="showFont || showCondition" |
| 66 | + class="my-1 border-neutral-200" |
| 67 | + > |
12 | 68 | <ContextSubmenu |
13 | 69 | :icon="IconLayoutAlignMiddle" |
14 | 70 | :label="t('align')" |
|
61 | 117 | <span>{{ t('height') }}</span> |
62 | 118 | </button> |
63 | 119 | </ContextSubmenu> |
64 | | - <hr |
65 | | - v-if="showFont || showCondition" |
66 | | - class="my-1 border-neutral-200" |
67 | | - > |
68 | | - <button |
69 | | - v-if="showFont" |
70 | | - class="w-full px-2 py-1 rounded-md hover:bg-neutral-100 flex items-center space-x-2 text-sm" |
71 | | - @click.stop="openFontModal" |
72 | | - > |
73 | | - <IconTypography class="w-4 h-4" /> |
74 | | - <span>{{ t('font') }}</span> |
75 | | - </button> |
76 | | - <button |
77 | | - v-if="showCondition" |
78 | | - class="w-full px-2 py-1 rounded-md hover:bg-neutral-100 flex items-center space-x-2 text-sm" |
79 | | - @click.stop="openConditionModal" |
80 | | - > |
81 | | - <IconRouteAltLeft class="w-4 h-4" /> |
82 | | - <span>{{ t('condition') }}</span> |
83 | | - </button> |
84 | 120 | <hr class="my-1 border-neutral-200"> |
85 | 121 | <button |
86 | 122 | class="w-full px-2 py-1 rounded-md hover:bg-neutral-100 flex items-center justify-between text-sm" |
@@ -192,6 +228,24 @@ export default { |
192 | 228 | return this.template.fields.find((f) => f.areas?.includes(area)) |
193 | 229 | }).filter(Boolean) |
194 | 230 | }, |
| 231 | + requiredFields () { |
| 232 | + return this.selectedFields.filter((f) => !['phone', 'stamp', 'verification', 'strikethrough', 'heading'].includes(f.type)) |
| 233 | + }, |
| 234 | + readOnlyFields () { |
| 235 | + return this.selectedFields.filter((f) => ['text', 'number', 'radio', 'multiple', 'select'].includes(f.type)) |
| 236 | + }, |
| 237 | + isAllRequired () { |
| 238 | + return this.requiredFields.every((f) => f.required) |
| 239 | + }, |
| 240 | + isMixedRequired () { |
| 241 | + return !this.isAllRequired && this.requiredFields.some((f) => f.required) |
| 242 | + }, |
| 243 | + isAllReadOnly () { |
| 244 | + return this.readOnlyFields.every((f) => f.readonly) |
| 245 | + }, |
| 246 | + isMixedReadOnly () { |
| 247 | + return !this.isAllReadOnly && this.readOnlyFields.some((f) => f.readonly) |
| 248 | + }, |
195 | 249 | isMac () { |
196 | 250 | return (navigator.userAgentData?.platform || navigator.platform)?.toLowerCase()?.includes('mac') |
197 | 251 | }, |
@@ -234,6 +288,16 @@ export default { |
234 | 288 | } |
235 | 289 | } |
236 | 290 | }, |
| 291 | + handleToggleRequired (value) { |
| 292 | + this.requiredFields.forEach((field) => { field.required = value }) |
| 293 | +
|
| 294 | + this.save() |
| 295 | + }, |
| 296 | + handleToggleReadOnly (value) { |
| 297 | + this.readOnlyFields.forEach((field) => { field.readonly = value }) |
| 298 | +
|
| 299 | + this.save() |
| 300 | + }, |
237 | 301 | onKeyDown (event) { |
238 | 302 | if (event.key === 'Escape') { |
239 | 303 | event.preventDefault() |
|
0 commit comments