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.

112 lines
2.4 KiB

4 years ago
5 years ago
5 years ago
  1. <template>
  2. <base-card
  3. :disabled="!valid"
  4. :title="$t('labels.createLabel')"
  5. :agree-text="$t('generic.create')"
  6. :cancel-text="$t('generic.cancel')"
  7. @agree="create"
  8. @cancel="reset"
  9. >
  10. <template #content>
  11. <v-form
  12. ref="form"
  13. v-model="valid"
  14. >
  15. <v-alert
  16. v-show="showError"
  17. v-model="showError"
  18. type="error"
  19. dismissible
  20. >
  21. {{ $t('errors.labelCannotCreate') }}
  22. </v-alert>
  23. <v-text-field
  24. v-model="labelName"
  25. :rules="labelNameRules($t('rules.labelNameRules'))"
  26. :label="$t('labels.labelName')"
  27. prepend-icon="label"
  28. />
  29. <v-select
  30. v-model="suffixKey"
  31. :items="keys"
  32. :label="$t('labels.key')"
  33. prepend-icon="mdi-keyboard"
  34. />
  35. <v-color-picker
  36. v-model="color"
  37. :rules="colorRules($t('rules.colorRules'))"
  38. show-swatches
  39. hide-mode-switch
  40. width="800"
  41. mode="hexa"
  42. class="ma-2"
  43. />
  44. </v-form>
  45. </template>
  46. </base-card>
  47. </template>
  48. <script>
  49. import BaseCard from '@/components/molecules/BaseCard'
  50. import { colorRules, labelNameRules } from '@/rules/index'
  51. export default {
  52. components: {
  53. BaseCard
  54. },
  55. props: {
  56. createLabel: {
  57. type: Function,
  58. default: () => {},
  59. required: true
  60. },
  61. keys: {
  62. type: Array,
  63. default: () => [],
  64. required: true
  65. }
  66. },
  67. data() {
  68. return {
  69. valid: false,
  70. labelName: '',
  71. suffixKey: '',
  72. color: '',
  73. labelNameRules,
  74. colorRules,
  75. showError: false
  76. }
  77. },
  78. methods: {
  79. cancel() {
  80. this.$emit('close')
  81. },
  82. validate() {
  83. return this.$refs.form.validate()
  84. },
  85. reset() {
  86. this.$refs.form.reset()
  87. this.cancel('close')
  88. },
  89. create() {
  90. if (this.validate()) {
  91. this.createLabel({
  92. projectId: this.$route.params.id,
  93. text: this.labelName,
  94. prefix_key: null,
  95. suffix_key: this.suffixKey ? this.suffixKey : null,
  96. background_color: this.color.slice(0, 7), // #12345678 -> #123456
  97. text_color: '#ffffff'
  98. })
  99. .then(() => {
  100. this.reset()
  101. })
  102. .catch(() => {
  103. this.showError = true
  104. })
  105. }
  106. }
  107. }
  108. }
  109. </script>