AdminSessionTemplateQuestionCreate.vue 3.6 KB

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