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.

206 lines
4.5 KiB

  1. <template>
  2. <v-card>
  3. <v-card-text v-if="isReady">
  4. <v-form
  5. ref="form"
  6. v-model="valid"
  7. >
  8. <v-row>
  9. <v-col
  10. cols="12"
  11. sm="6"
  12. >
  13. <h3>Name</h3>
  14. <v-text-field
  15. v-model="project.name"
  16. label="Add project name"
  17. :rules="projectNameRules($t('rules.projectNameRules'))"
  18. :disabled="!edit.name"
  19. single-line
  20. />
  21. </v-col>
  22. <v-col
  23. cols="12"
  24. sm="6"
  25. >
  26. <v-btn
  27. v-if="!edit.name"
  28. outlined
  29. color="grey"
  30. class="text-capitalize"
  31. @click="editProject('name')"
  32. >
  33. Edit
  34. </v-btn>
  35. <v-btn
  36. v-if="edit.name"
  37. outlined
  38. color="primary"
  39. class="text-capitalize"
  40. @click="doneEdit()"
  41. >
  42. Save
  43. </v-btn>
  44. <v-btn
  45. v-if="edit.name"
  46. outlined
  47. color="grey"
  48. class="text-capitalize"
  49. @click="cancelEdit()"
  50. >
  51. Cancel
  52. </v-btn>
  53. </v-col>
  54. </v-row>
  55. <v-row>
  56. <v-col
  57. cols="12"
  58. sm="6"
  59. >
  60. <h3>Description</h3>
  61. <v-text-field
  62. v-model="project.description"
  63. label="Add description"
  64. :rules="descriptionRules($t('rules.descriptionRules'))"
  65. :disabled="!edit.desc"
  66. single-line
  67. />
  68. </v-col>
  69. <v-col
  70. cols="12"
  71. sm="6"
  72. >
  73. <v-btn
  74. v-if="!edit.desc"
  75. outlined
  76. color="grey"
  77. class="text-capitalize"
  78. @click="editProject('desc')"
  79. >
  80. Edit
  81. </v-btn>
  82. <v-btn
  83. v-if="edit.desc"
  84. outlined
  85. color="primary"
  86. class="text-capitalize"
  87. @click="doneEdit()"
  88. >
  89. Save
  90. </v-btn>
  91. <v-btn
  92. v-if="edit.desc"
  93. outlined
  94. color="grey"
  95. class="text-capitalize"
  96. @click="cancelEdit()"
  97. >
  98. Cancel
  99. </v-btn>
  100. </v-col>
  101. </v-row>
  102. <v-row>
  103. <v-col
  104. cols="12"
  105. sm="6"
  106. >
  107. <h3>Shuffle</h3>
  108. <v-checkbox
  109. v-model="project.enableRandomizeDocOrder"
  110. :label="$t('overview.randomizeDocOrder')"
  111. />
  112. </v-col>
  113. </v-row>
  114. <v-row>
  115. <v-col
  116. cols="12"
  117. sm="6"
  118. >
  119. <h3>Collaboration</h3>
  120. <v-checkbox
  121. v-model="project.enableShareAnnotation"
  122. :label="$t('overview.shareAnnotations')"
  123. />
  124. </v-col>
  125. </v-row>
  126. </v-form>
  127. </v-card-text>
  128. </v-card>
  129. </template>
  130. <script>
  131. import { projectNameRules, descriptionRules } from '@/rules/index'
  132. export default {
  133. async fetch() {
  134. this.project = await this.$services.project.findById(this.projectId)
  135. },
  136. data() {
  137. return {
  138. project: {},
  139. beforeEditCache: {},
  140. edit: {
  141. name: false,
  142. desc: false
  143. },
  144. projectNameRules,
  145. descriptionRules,
  146. valid: false
  147. }
  148. },
  149. computed: {
  150. isReady() {
  151. return !!this.project
  152. },
  153. projectId() {
  154. return this.$route.params.id
  155. }
  156. },
  157. watch: {
  158. 'project.enableRandomizeDocOrder'() {
  159. this.doneEdit()
  160. },
  161. 'project.enableShareAnnotation'() {
  162. this.doneEdit()
  163. }
  164. },
  165. methods: {
  166. initEdit() {
  167. Object.keys(this.edit).forEach((v) => { this.edit[v] = false })
  168. },
  169. editProject(name) {
  170. this.cancelEdit()
  171. this.edit[name] = true
  172. Object.assign(this.beforeEditCache, this.project)
  173. },
  174. cancelEdit() {
  175. this.initEdit()
  176. Object.assign(this.project, this.beforeEditCache)
  177. },
  178. async doneEdit() {
  179. if (!this.validate()) {
  180. this.cancelEdit()
  181. return
  182. }
  183. try {
  184. await this.$services.project.update(this.project)
  185. this.beforeEditCache = {}
  186. this.$fetch()
  187. } finally {
  188. this.initEdit()
  189. }
  190. },
  191. validate() {
  192. return this.$refs.form.validate()
  193. }
  194. }
  195. }
  196. </script>