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.

95 lines
2.1 KiB

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