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.

93 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="label"
  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 BaseCard from '@/components/utils/BaseCard.vue'
  37. export default Vue.extend({
  38. components: {
  39. BaseCard
  40. },
  41. props: {
  42. name: {
  43. type: String,
  44. default: '',
  45. required: true
  46. },
  47. suffixKey: {
  48. type: String,
  49. default: null,
  50. },
  51. color: {
  52. type: String,
  53. default: '#ffffff',
  54. required: true
  55. },
  56. usedNames: {
  57. type: Array,
  58. default: () => [],
  59. required: true
  60. }
  61. },
  62. data() {
  63. return {
  64. valid: false,
  65. rules: {
  66. required: (v: string) => !!v || 'Required',
  67. // @ts-ignore
  68. counter: (v: string) => (v && v.length <= 100) || this.$t('rules.labelNameRules').labelLessThan100Chars,
  69. // @ts-ignore
  70. nameDuplicated: (v: string) => (!this.usedNames.includes(v)) || this.$t('rules.labelNameRules').duplicated,
  71. // @ts-ignore
  72. keyDuplicated: (v: string) => !this.usedKeys.includes(v) || this.$t('rules.keyNameRules').duplicated,
  73. }
  74. }
  75. },
  76. computed: {
  77. shortkeys() {
  78. return '0123456789abcdefghijklmnopqrstuvwxyz'.split('')
  79. }
  80. },
  81. methods: {
  82. updateValue(key: string, value: string) {
  83. this.$emit(`update:${key}`, value);
  84. }
  85. }
  86. })
  87. </script>