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.

113 lines
2.3 KiB

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