|
| 1 | +const BaseSelect = { |
| 2 | + name: "BaseSelect", |
| 3 | + |
| 4 | + props: { |
| 5 | + label: { |
| 6 | + type: String, |
| 7 | + default: "", |
| 8 | + }, |
| 9 | + labelTooltip: { |
| 10 | + type: String, |
| 11 | + default: "", |
| 12 | + }, |
| 13 | + selectClass: { |
| 14 | + type: String, |
| 15 | + default: "input", |
| 16 | + }, |
| 17 | + modelValue: { |
| 18 | + type: String, |
| 19 | + default: "", |
| 20 | + }, |
| 21 | + options: { |
| 22 | + type: Array, |
| 23 | + default: [], |
| 24 | + required: true, |
| 25 | + }, |
| 26 | + required: { |
| 27 | + type: Boolean, |
| 28 | + default: false, |
| 29 | + }, |
| 30 | + inline: { |
| 31 | + type: Boolean, |
| 32 | + default: false, |
| 33 | + }, |
| 34 | + grow: { |
| 35 | + type: Boolean, |
| 36 | + default: false, |
| 37 | + }, |
| 38 | + }, |
| 39 | + |
| 40 | + methods: { |
| 41 | + available(value, options) { |
| 42 | + return value |
| 43 | + ? options.map((option) => option.value).includes(value) |
| 44 | + : true; |
| 45 | + }, |
| 46 | + hasTooltip(labelTooltip) { |
| 47 | + return labelTooltip.length > 0; |
| 48 | + } |
| 49 | + }, |
| 50 | + |
| 51 | + template: ` |
| 52 | + <div v-bind:class="[inline ? 'inline-field' : 'field', grow ? 'grow' : '']"> |
| 53 | + <label v-bind:class="inline ? 'inline-input-label' : 'input-label'"> |
| 54 | + {{ label }} |
| 55 | + </label> |
| 56 | + <label v-bind:class="inline ? 'inline-input-label-tooltip' : 'input-label-tooltip'" v-if:"hasTooltip(labelTooltip)"> |
| 57 | + {{ labelTooltip }} |
| 58 | + </label> |
| 59 | + <select |
| 60 | + :value="modelValue" |
| 61 | + v-bind="$attrs" |
| 62 | + @change="$emit('update:modelValue', $event.target.value)" |
| 63 | + v-bind:class="[selectClass, { unavailable: !available(modelValue, options) }]" |
| 64 | + > |
| 65 | + <option v-if="!required && !available(modelValue, options)"></option> |
| 66 | + <option |
| 67 | + v-for="option in options" |
| 68 | + :value="option.value" |
| 69 | + :key="option" |
| 70 | + :selected="option.value === modelValue" |
| 71 | + >{{ option.label }}</option> |
| 72 | + <option |
| 73 | + v-if="!available(modelValue, options)" |
| 74 | + class="unavailable" |
| 75 | + :value="modelValue" |
| 76 | + >{{ modelValue }}</option> |
| 77 | + </select> |
| 78 | + </div> |
| 79 | + `, |
| 80 | +}; |
| 81 | + |
| 82 | +const BaseInput = { |
| 83 | + name: "BaseInput", |
| 84 | + props: { |
| 85 | + label: { |
| 86 | + type: String, |
| 87 | + default: "", |
| 88 | + }, |
| 89 | + labelTooltip: { |
| 90 | + type: String, |
| 91 | + default: "", |
| 92 | + }, |
| 93 | + inputClass: { |
| 94 | + type: String, |
| 95 | + default: "input", |
| 96 | + }, |
| 97 | + modelValue: { |
| 98 | + type: [String, Number], |
| 99 | + default: "", |
| 100 | + }, |
| 101 | + inline: { |
| 102 | + type: Boolean, |
| 103 | + default: false, |
| 104 | + }, |
| 105 | + grow: { |
| 106 | + type: Boolean, |
| 107 | + default: false, |
| 108 | + }, |
| 109 | + number: { |
| 110 | + type: Boolean, |
| 111 | + default: false, |
| 112 | + }, |
| 113 | + }, |
| 114 | + |
| 115 | + computed: { |
| 116 | + emptyClass() { |
| 117 | + if (this.modelValue === "") { |
| 118 | + return "empty"; |
| 119 | + } |
| 120 | + }, |
| 121 | + }, |
| 122 | + |
| 123 | + methods: { |
| 124 | + hasTooltip(labelTooltip) { |
| 125 | + return labelTooltip.length > 0; |
| 126 | + } |
| 127 | + }, |
| 128 | + |
| 129 | + template: ` |
| 130 | + <div v-bind:class="[inline ? 'inline-field' : 'field', grow ? 'grow' : '']"> |
| 131 | + <label v-bind:class="inline ? 'inline-input-label' : 'input-label'"> |
| 132 | + {{ label }} |
| 133 | + </label> |
| 134 | + <label v-bind:class="inline ? 'inline-input-label-tooltip' : 'input-label-tooltip'" v-if:"hasTooltip(labelTooltip)"> |
| 135 | + {{ labelTooltip }} |
| 136 | + </label> |
| 137 | + <input |
| 138 | + :value="modelValue" |
| 139 | + @input="$emit('update:modelValue', $event.target.value)" |
| 140 | + v-bind="$attrs" |
| 141 | + v-bind:class="inputClass" |
| 142 | + > |
| 143 | + </div> |
| 144 | + `, |
| 145 | +}; |
| 146 | + |
| 147 | +const SmartCellConfig = (ctx, info, extra_components, extra_data) => { |
| 148 | + return { |
| 149 | + components: { |
| 150 | + BaseInput: BaseInput, |
| 151 | + BaseSelect: BaseSelect, |
| 152 | + ...extra_components |
| 153 | + }, |
| 154 | + |
| 155 | + data() { |
| 156 | + return { |
| 157 | + fields: info.fields, |
| 158 | + ...extra_data |
| 159 | + }; |
| 160 | + }, |
| 161 | + |
| 162 | + methods: { |
| 163 | + handleFieldChange(event) { |
| 164 | + const { name: field, value } = event.target; |
| 165 | + |
| 166 | + if (field) { |
| 167 | + if (info.id == "evision.zoo") { |
| 168 | + ctx.pushEvent("update_field", { field, value }); |
| 169 | + } else { |
| 170 | + const sub_value = field.split(".").reduce((data, key) => data[key], this.fields); |
| 171 | + ctx.pushEvent("update_field", { field, value: sub_value }); |
| 172 | + } |
| 173 | + } |
| 174 | + }, |
| 175 | + } |
| 176 | + } |
| 177 | +}; |
| 178 | + |
| 179 | +export const Base = { |
| 180 | + BaseInput: BaseInput, |
| 181 | + BaseSelect: BaseSelect, |
| 182 | + SmartCellConfig: SmartCellConfig |
| 183 | +}; |
0 commit comments