AdminEventQuestionCreate.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="AdminEventQuestionCreate"
  3. :style="localOptions.style">
  4. <div class="flex justify-end">
  5. <q-btn flat
  6. color="grey"
  7. @click="$router.go(-1)">
  8. بازگشت
  9. >
  10. </q-btn>
  11. </div>
  12. <entity-create v-if="mounted"
  13. ref="entityEdit"
  14. v-model:value="inputs"
  15. title="ایجاد سوال جدید"
  16. :api="api"
  17. :entity-id-key="entityIdKey"
  18. :entity-param-key="entityParamKey"
  19. :show-route-name="showRouteName"
  20. :show-close-button="false"
  21. :show-edit-button="false"
  22. :show-expand-button="false"
  23. :show-save-button="false"
  24. :show-reload-button="false"
  25. :redirect-after-edit="false"
  26. :after-load-input-data="afterLoadInputData" />
  27. </div>
  28. </template>
  29. <script>
  30. import { shallowRef } from 'vue'
  31. import { EntityCreate } from 'quasar-crud'
  32. import { mixinWidget } from 'src/mixin/Mixins.js'
  33. import { Question } from 'src/models/Question.js'
  34. import { APIGateway } from 'src/api/APIGateway.js'
  35. import BtnControl from 'src/components/Control/btn.vue'
  36. import { FormBuilderAssist } from 'quasar-form-builder'
  37. const BtnControlComp = shallowRef(BtnControl)
  38. export default {
  39. name: 'AdminEventQuestionCreate',
  40. components: {
  41. EntityCreate
  42. },
  43. mixins: [mixinWidget],
  44. data () {
  45. return {
  46. mounted: false,
  47. entityLoading: true,
  48. api: APIGateway.question.APIAdresses.base,
  49. entityIdKey: 'id',
  50. entityParamKey: 'id',
  51. showRouteName: 'Admin.Event.TestSet.Questions.Show',
  52. loadedData: new Question(),
  53. inputs: [
  54. { type: 'input', name: 'text', responseKey: 'text', label: 'سوال', placeholder: ' ', col: 'col-12' },
  55. { type: 'inputEditor', name: 'correct_answer', responseKey: 'correct_answer', label: 'پاسخ', placeholder: ' ', col: 'col-12' },
  56. { type: BtnControlComp, name: 'btn', label: 'ذخیره سوال', placeholder: ' ', atClick: () => {}, col: 'col-12 flex justify-end' },
  57. { type: 'hidden', name: 'type', responseKey: 'type', value: 'EVENT' }
  58. ]
  59. }
  60. },
  61. mounted() {
  62. this.setActionBtn()
  63. this.mounted = true
  64. },
  65. methods: {
  66. setActionBtn () {
  67. FormBuilderAssist.setAttributeByName(this.inputs, 'btn', 'atClick', this.edit)
  68. },
  69. afterLoadInputData () {
  70. this.entityLoading = false
  71. },
  72. edit() {
  73. this.entityLoading = true
  74. this.$refs.entityEdit.createEntity(false)
  75. .then((response) => {
  76. this.$router.push({ name: 'Admin.Event.TestSet.Questions.Show', params: { question_id: response.data.id } })
  77. this.entityLoading = false
  78. })
  79. .catch(() => {
  80. this.entityLoading = false
  81. })
  82. }
  83. }
  84. }
  85. </script>
  86. <style scoped lang="scss">
  87. .AdminEventQuestionCreate {
  88. .title {
  89. font-style: normal;
  90. font-weight: 700;
  91. font-size: 24px;
  92. line-height: 140%;
  93. color: #424242;
  94. margin-bottom: 27px;
  95. display: flex;
  96. flex-flow: row;
  97. position: relative;
  98. .static-title {
  99. }
  100. .dynamic-title {
  101. }
  102. .back-action {
  103. position: absolute;
  104. right: 0;
  105. top: 0;
  106. }
  107. }
  108. :deep(.form) {
  109. padding: 24px;
  110. }
  111. }
  112. </style>