You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.4 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <base-card
  3. :disabled="!valid"
  4. :title="$t('labels.createLabel')"
  5. :agree-text="$t('generic.save')"
  6. :cancel-text="$t('generic.cancel')"
  7. @agree="$emit('save')"
  8. @cancel="$emit('cancel')"
  9. >
  10. <template #content>
  11. <v-form v-model="valid">
  12. <v-text-field
  13. :value="text"
  14. :label="$t('labels.labelName')"
  15. :rules="[rules.required, rules.counter, rules.nameDuplicated]"
  16. prepend-icon="label"
  17. single-line
  18. counter
  19. autofocus
  20. @input="updateValue('text', $event)"
  21. />
  22. <v-select
  23. :value="suffixKey"
  24. :items="shortkeys"
  25. :label="$t('labels.key')"
  26. :rules="[rules.keyDuplicated]"
  27. prepend-icon="mdi-keyboard"
  28. @input="updateValue('suffixKey', $event)"
  29. />
  30. <v-color-picker
  31. :value="backgroundColor"
  32. :rules="[rules.required]"
  33. show-swatches
  34. hide-mode-switch
  35. width="800"
  36. @input="updateValue('backgroundColor', $event)"
  37. />
  38. </v-form>
  39. </template>
  40. </base-card>
  41. </template>
  42. <script lang="ts">
  43. import Vue from 'vue'
  44. import BaseCard from '@/components/utils/BaseCard.vue'
  45. export default Vue.extend({
  46. components: {
  47. BaseCard
  48. },
  49. props: {
  50. text: {
  51. type: String,
  52. default: '',
  53. required: true
  54. },
  55. suffixKey: {
  56. type: String,
  57. default: null,
  58. },
  59. backgroundColor: {
  60. type: String,
  61. default: '#ffffff',
  62. required: true
  63. },
  64. usedNames: {
  65. type: Array,
  66. default: () => [],
  67. required: true
  68. },
  69. usedKeys: {
  70. type: Array,
  71. default: () => [],
  72. required: true
  73. }
  74. },
  75. data() {
  76. return {
  77. valid: false,
  78. rules: {
  79. required: (v: string) => !!v || 'Required',
  80. // @ts-ignore
  81. counter: (v: string) => (v && v.length <= 100) || this.$t('rules.labelNameRules').labelLessThan100Chars,
  82. // @ts-ignore
  83. nameDuplicated: (v: string) => (!this.usedNames.includes(v)) || this.$t('rules.labelNameRules').duplicated,
  84. // @ts-ignore
  85. keyDuplicated: (v: string) => !this.usedKeys.includes(v) || this.$t('rules.keyNameRules').duplicated,
  86. }
  87. }
  88. },
  89. computed: {
  90. shortkeys() {
  91. return '0123456789abcdefghijklmnopqrstuvwxyz'.split('')
  92. }
  93. },
  94. methods: {
  95. updateValue(key: string, value: string) {
  96. this.$emit(`update:${key}`, value);
  97. }
  98. }
  99. })
  100. </script>