create.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div class="flex justify-end">
  3. <q-btn flat
  4. color="grey"
  5. @click="$router.go(-1)">
  6. بازگشت
  7. >
  8. </q-btn>
  9. </div>
  10. <div class="AdminClassroomCreate">
  11. <q-linear-progress v-if="unitsLoading"
  12. indeterminate />
  13. <entity-create v-if="mounted"
  14. ref="entityCreate"
  15. :key="classroomEntityCreateKey"
  16. v-model:value="inputs"
  17. title="مشخصات پروژه"
  18. :api="api"
  19. :show-close-button="false"
  20. :show-edit-button="false"
  21. :show-expand-button="false"
  22. :show-save-button="false"
  23. :show-reload-button="false">
  24. <template #after-form-builder>
  25. <div class="flex justify-end q-mt-md">
  26. <q-btn color="primary"
  27. label="ایجاد پروژه جدید"
  28. @click="create" />
  29. </div>
  30. </template>
  31. </entity-create>
  32. </div>
  33. </template>
  34. <script>
  35. import { shallowRef } from 'vue'
  36. import { EntityCreate } from 'quasar-crud'
  37. import { Project } from 'src/models/Project.js'
  38. import { APIGateway } from 'src/api/APIGateway.js'
  39. import { FormBuilderAssist } from 'quasar-form-builder'
  40. import ContentsSelector from 'src/components/FormBuilderCustumComponents/ContentsSelector/ContentsSelector.vue'
  41. const ContentsSelectorComp = shallowRef(ContentsSelector)
  42. export default {
  43. name: 'Admin.Classroom.Create',
  44. components: {
  45. EntityCreate
  46. },
  47. data () {
  48. const classroomId = this.$route.params.classroom_id
  49. return {
  50. mounted: false,
  51. unitsLoading: false,
  52. classroomEntityCreateKey: Date.now(),
  53. newUnitLoading: false,
  54. newUnitName: null,
  55. newUnitSessionCount: null,
  56. api: APIGateway.classroom.APIAdresses.base,
  57. entityIdKey: 'id',
  58. entityParamKey: 'id',
  59. inputs: [
  60. { type: 'input', name: 'title', responseKey: 'title', label: 'عنوان پروژه', placeholder: ' ', col: 'col-md-6 col-12' },
  61. {
  62. type: 'select',
  63. name: 'type',
  64. responseKey: 'type',
  65. label: 'نوع پروژه',
  66. options: (new Project()).typeEnums,
  67. placeholder: ' ',
  68. col: 'col-md-3 col-12'
  69. },
  70. { type: 'dateTime', name: 'beginning_doing_period', responseKey: 'beginning_doing_period', label: 'زمان شروع', placeholder: ' ', col: 'col-md-6 col-12' },
  71. { type: 'dateTime', name: 'ending_doing_period', responseKey: 'ending_doing_period', label: 'زمان پایان', placeholder: ' ', col: 'col-md-6 col-12' },
  72. { type: 'separator', name: 'space', size: '0', col: 'col-md-12' },
  73. { type: 'inputEditor', name: 'correct_answer', responseKey: 'description', label: 'پاسخ صحیح', placeholder: ' ', col: 'col-12' },
  74. { type: 'inputEditor', name: 'description', responseKey: 'description', label: 'توضیحات پروژه', placeholder: ' ', col: 'col-12' },
  75. { type: ContentsSelectorComp, name: 'contents', responseKey: 'contents_info', col: 'col-12' },
  76. { type: 'hidden', name: 'classroom', responseKey: 'classroom', value: parseInt(classroomId) }
  77. ]
  78. }
  79. },
  80. computed: {
  81. selectedCategoryId () {
  82. return FormBuilderAssist.getInputsByName(this.inputs, 'category')?.value
  83. }
  84. },
  85. watch: {
  86. selectedCategoryId () {
  87. FormBuilderAssist.setAttributeByName(this.inputs, 'unit', 'value', null)
  88. FormBuilderAssist.setAttributeByName(this.inputs, 'unit', 'options', [])
  89. this.getUnits(this.selectedCategoryId)
  90. }
  91. },
  92. mounted () {
  93. this.mounted = true
  94. },
  95. methods: {
  96. create () {
  97. this.$refs.entityCreate.createEntity(false)
  98. .then((response) => {
  99. const classroomId = this.$route.params.classroom_id
  100. const projectId = response.data.id
  101. this.$router.push({ name: 'Admin.Classroom.Project.Show', params: { classroom_id: classroomId, project_id: projectId } })
  102. })
  103. .catch(() => {})
  104. }
  105. }
  106. }
  107. </script>