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.

109 lines
2.5 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="mdiLabel"
  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="mdiKeyboard"
  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 { mdiLabel, mdiKeyboard } from '@mdi/js'
  45. import BaseCard from '@/components/utils/BaseCard.vue'
  46. export default Vue.extend({
  47. components: {
  48. BaseCard
  49. },
  50. props: {
  51. text: {
  52. type: String,
  53. default: '',
  54. required: true
  55. },
  56. suffixKey: {
  57. type: String,
  58. default: null,
  59. },
  60. backgroundColor: {
  61. type: String,
  62. default: '#ffffff',
  63. required: true
  64. },
  65. usedNames: {
  66. type: Array,
  67. default: () => [],
  68. required: true
  69. },
  70. usedKeys: {
  71. type: Array,
  72. default: () => [],
  73. required: true
  74. }
  75. },
  76. data() {
  77. return {
  78. valid: false,
  79. rules: {
  80. required: (v: string) => !!v || 'Required',
  81. // @ts-ignore
  82. counter: (v: string) => (v && v.length <= 100) || this.$t('rules.labelNameRules').labelLessThan100Chars,
  83. // @ts-ignore
  84. nameDuplicated: (v: string) => (!this.usedNames.includes(v)) || this.$t('rules.labelNameRules').duplicated,
  85. // @ts-ignore
  86. keyDuplicated: (v: string) => !this.usedKeys.includes(v) || this.$t('rules.keyNameRules').duplicated,
  87. },
  88. mdiLabel,
  89. mdiKeyboard
  90. }
  91. },
  92. computed: {
  93. shortkeys() {
  94. return '0123456789abcdefghijklmnopqrstuvwxyz'.split('')
  95. }
  96. },
  97. methods: {
  98. updateValue(key: string, value: string) {
  99. this.$emit(`update:${key}`, value);
  100. }
  101. }
  102. })
  103. </script>