AdminClassroomCreate.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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="classroomEntityCreate"
  15. :key="classroomEntityCreateKey"
  16. v-model:value="inputs"
  17. :title="'مشخصات ' + classroomTypeTitle"
  18. :api="api"
  19. :entity-id-key="entityIdKey"
  20. :entity-param-key="entityParamKey"
  21. :show-route-name="showPageRouteName"
  22. :show-close-button="false"
  23. :show-edit-button="false"
  24. :show-expand-button="false"
  25. :show-save-button="false"
  26. :show-reload-button="false">
  27. <template #after-form-builder>
  28. <div class="flex justify-end q-mt-md">
  29. <q-btn color="primary"
  30. :label="'ایجاد ' + classroomTypeTitle + ' جدید'"
  31. @click="createClassroom" />
  32. </div>
  33. </template>
  34. </entity-create>
  35. </div>
  36. </template>
  37. <script>
  38. import { shallowRef } from 'vue'
  39. import { EntityCreate } from 'quasar-crud'
  40. import Enums from 'src/assets/Enums/Enums.js'
  41. import { mixinWidget } from 'src/mixin/Mixins.js'
  42. import { APIGateway } from 'src/api/APIGateway.js'
  43. import { FormBuilderAssist } from 'quasar-form-builder'
  44. import { UnitCategory } from 'src/models/UnitCategory.js'
  45. import FormBuilderDateTime from 'src/components/FormBuilderCustumComponents/FormBuilderDateTime.vue'
  46. import FormBuilderInputEditor from 'src/components/FormBuilderCustumComponents/FormBuilderInputEditor.vue'
  47. const FormBuilderDateTimeComp = shallowRef(FormBuilderDateTime)
  48. const FormBuilderInputEditorComp = shallowRef(FormBuilderInputEditor)
  49. export default {
  50. name: 'Admin.Classroom.Create',
  51. components: {
  52. EntityCreate
  53. },
  54. mixins: [mixinWidget],
  55. data () {
  56. return {
  57. mounted: false,
  58. unitsLoading: false,
  59. classroomEntityCreateKey: Date.now(),
  60. newUnitLoading: false,
  61. newUnitName: null,
  62. newUnitSessionCount: null,
  63. api: APIGateway.classroom.APIAdresses.base,
  64. entityIdKey: 'id',
  65. entityParamKey: 'id',
  66. inputs: [
  67. { type: 'separator', name: 'space1', label: 'مشخصات', className: 'custom-separator', col: 'col-12' },
  68. { type: 'file', name: 'thumbnail', responseKey: 'thumbnail', label: 'آپلود عکس', col: 'col-md-3 col-12' },
  69. { type: 'file', name: 'codes', responseKey: 'codes', label: 'آیین نامه', col: 'col-md-3 col-12' },
  70. { type: 'separator', name: 'space', size: '0', col: 'col-md-12' },
  71. { type: 'select', name: 'category', responseKey: 'category', options: [], value: null, placeholder: ' ', label: 'دسته بندی', col: 'col-md-3 col-12' },
  72. { type: 'select', name: 'unit', responseKey: 'unit', options: [], value: null, placeholder: ' ', label: 'درس', col: 'col-md-3 col-12' },
  73. { type: 'select', name: 'holding_type', responseKey: 'holding_type', options: Enums.classroomHoldingTypes, value: null, placeholder: ' ', label: 'نوع برگزاری', col: 'col-md-3 col-12' },
  74. { type: 'input', name: 'price', responseKey: 'price', placeholder: ' ', label: 'هزینه برگزاری', col: 'col-md-3 col-12' },
  75. { type: 'input', name: 'live_streaming_url', responseKey: 'live_streaming_url', placeholder: ' ', label: 'لینک مکان مجازی', col: 'col-12' },
  76. { type: FormBuilderInputEditorComp, name: 'classroom_address', responseKey: 'classroom_address', placeholder: ' ', label: 'آدرس مکان فیزیکی', col: 'col-12' },
  77. {
  78. type: 'select',
  79. name: 'holding_year',
  80. responseKey: 'holding_year',
  81. options: [1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410],
  82. value: null,
  83. label: 'انتخاب سال',
  84. placeholder: ' ',
  85. col: 'col-md-3'
  86. },
  87. {
  88. type: 'select',
  89. name: 'holding_month',
  90. responseKey: 'holding_month',
  91. options: [
  92. 'فروردین',
  93. 'اردیبهشت',
  94. 'خرداد',
  95. 'تیر',
  96. 'مرداد',
  97. 'شهریور',
  98. 'مهر',
  99. 'آبان',
  100. 'آذر',
  101. 'دی',
  102. 'بهمن',
  103. 'اسفند'
  104. ],
  105. value: null,
  106. label: 'انتخاب ماه',
  107. placeholder: ' ',
  108. col: 'col-md-3'
  109. },
  110. { type: 'input', name: 'sessions_frequency', responseKey: 'sessions_frequency', placeholder: ' ', label: 'دوره تناوب', col: 'col-12' },
  111. { type: 'select', name: 'professor', responseKey: 'professor', options: [], value: null, placeholder: ' ', label: 'استاد', col: 'col-md-3 col-12' },
  112. { type: 'separator', name: 'space', label: 'مشخصات اندیشه جو', className: 'custom-separator', col: 'col-12' },
  113. // { type: 'select', name: 'audience_status_wwwww', responseKey: 'audience_status_wwwww', options: [], placeholder: ' ', label: 'وضعیت(؟)', col: 'col-md-3 col-12' },
  114. // { type: 'select', name: 'category1', responseKey: 'category1', options: [], placeholder: ' ', label: 'مجموعه(؟)', col: 'col-md-3 col-12' },
  115. { type: 'select', name: 'audience_gender_type', responseKey: 'audience_gender_type', options: Enums.genders, placeholder: ' ', label: 'جنسیت', col: 'col-md-3 col-12' },
  116. // { type: 'select', name: 'audience_bashgah_wwwww', responseKey: 'audience_bashgah_wwwww', options: [], placeholder: ' ', label: 'باشگاه(؟)', col: 'col-md-3 col-12' },
  117. { type: 'separator', name: 'space', label: 'تنظیمات', className: 'custom-separator', col: 'col-12' },
  118. { type: 'input', name: 'capacity', responseKey: 'capacity', placeholder: ' ', label: 'ظرفیت گروه درسی', col: 'col-md-3 col-12' },
  119. { type: 'input', name: 'allowed_absence_count', responseKey: 'allowed_absence_count', placeholder: ' ', label: 'تعداد مجاز غیبت', col: 'col-md-3 col-12' },
  120. { type: 'input', name: 'effective_absence_coefficient', responseKey: 'effective_absence_coefficient', placeholder: ' ', label: 'وزن نمره حضور و غیاب ', col: 'col-md-3 col-12' },
  121. { type: 'input', name: 'mandatory_assignment_count', responseKey: 'mandatory_assignment_count', placeholder: ' ', label: 'تعداد تکالیف اجباری', col: 'col-md-3 col-12' },
  122. { type: 'input', name: 'special_passing_mark', responseKey: 'special_passing_mark', placeholder: ' ', label: 'نمره قبولی مشروطی ها', col: 'col-md-3 col-12' },
  123. { type: 'input', name: 'minimum_conditional_passing_mark', responseKey: 'minimum_conditional_passing_mark', placeholder: ' ', label: 'نمره قبولی مشروط', col: 'col-md-3 col-12' },
  124. { type: 'input', name: 'minimum_clean_passing_mark', responseKey: 'minimum_clean_passing_mark', placeholder: ' ', label: 'نمره قبولی', col: 'col-md-3 col-12' },
  125. { type: 'separator', name: 'space', label: 'ثبت نام و حذف و اضافه', className: 'custom-separator', col: 'col-12' },
  126. { type: FormBuilderDateTimeComp, name: 'beginning_enrollment_period', responseKey: 'beginning_enrollment_period', outsideLabel: 'تاریخ شروع پیش ثبت نام', col: 'col-md-6 col-12' },
  127. { type: FormBuilderDateTimeComp, name: 'ending_enrollment_period', responseKey: 'ending_enrollment_period', outsideLabel: 'تاریخ پایان پیش ثبت نام', col: 'col-md-6 col-12' },
  128. { type: FormBuilderDateTimeComp, name: 'beginning_registration_period', responseKey: 'beginning_registration_period', outsideLabel: 'تاریخ شروع ثبت نام', col: 'col-md-6 col-12' },
  129. { type: FormBuilderDateTimeComp, name: 'ending_registration_period', responseKey: 'ending_registration_period', outsideLabel: 'تاریخ پایان ثبت نام', col: 'col-md-6 col-12' },
  130. { type: 'input', name: 'registration_period_refund_percent', responseKey: 'registration_period_refund_percent', placeholder: ' ', label: 'درصد برگشت هزینه انصراف در بازه ثبت نام', col: 'col-md-3 col-12' },
  131. { type: 'checkbox', name: 'allow_dropping_on_enrollment_period', responseKey: 'allow_dropping_on_enrollment_period', label: 'امکان حذف در بازه پیش ثبت نام', value: false, col: 'col-md-3 col-12' },
  132. { type: 'checkbox', name: 'allow_adding_on_registration_period', responseKey: 'allow_adding_on_registration_period', label: 'امکان اضافه کردن در بازه ثبت نام', value: false, col: 'col-md-3 col-12' },
  133. { type: 'checkbox', name: 'allow_dropping_on_registration_period', responseKey: 'allow_dropping_on_registration_period', label: 'امکان حذف ثبت نام در بازه ثبت نام', value: false, col: 'col-md-3 col-12' },
  134. { type: FormBuilderDateTimeComp, name: 'beginning_drop_add_period', responseKey: 'beginning_drop_add_period', outsideLabel: 'تاریخ شروع حذف و اضافه', col: 'col-md-6 col-12' },
  135. { type: FormBuilderDateTimeComp, name: 'ending_drop_add_period', responseKey: 'ending_drop_add_period', outsideLabel: 'تاریخ پایان حذف و اضافه', col: 'col-md-6 col-12' },
  136. { type: 'input', name: 'drop_add_period_refund_percent', responseKey: 'drop_add_period_refund_percent', placeholder: ' ', label: 'درصد برگشت هزینه انصراف در بازه حذف و اضافه', col: 'col-md-3 col-12' },
  137. { type: 'checkbox', name: 'allow_adding_on_drop_add_period', responseKey: 'allow_adding_on_drop_add_period', label: 'امکان اضافه شدن در بازه حذف و اضافه', value: false, col: 'col-md-3 col-12' },
  138. { type: 'checkbox', name: 'allow_dropping_on_drop_add_period', responseKey: 'allow_dropping_on_drop_add_period', label: 'امکان حذف در بازه حذف و اضافه', value: false, col: 'col-md-3 col-12' },
  139. { type: FormBuilderDateTimeComp, name: 'publish_time', responseKey: 'publish_time', outsideLabel: 'تاریخ انتشار', col: 'col-md-6 col-12' },
  140. { type: 'separator', name: 'space', label: 'قوانین', className: 'custom-separator', col: 'col-12' },
  141. { type: FormBuilderInputEditorComp, name: 'rules', responseKey: 'rules', label: 'قوانین', col: 'col-12' },
  142. { type: FormBuilderInputEditorComp, name: 'description', responseKey: 'description', label: 'توضیحات', col: 'col-12' },
  143. { type: FormBuilderInputEditorComp, name: 'specification', responseKey: 'specification', label: 'مشخصات', col: 'col-12' },
  144. { type: FormBuilderInputEditorComp, name: 'bulletin', responseKey: 'bulletin', label: 'تابلو اعلانات', col: 'col-12' },
  145. // -----------------------------------------------------------------------------------------------------------
  146. // { type: 'separator', name: 'space', label: 'موارد زیر در طرح نبودند', className: 'custom-separator', col: 'col-12' },
  147. // { type: 'select', name: 'audience_role', responseKey: 'audience_role', options: Enums.groups, placeholder: ' ', label: 'نقش', col: 'col-md-4 col-12' },
  148. { type: 'hidden', name: 'id', responseKey: 'id', label: 'id', col: 'col-md-3 col-12' }
  149. ]
  150. }
  151. },
  152. computed: {
  153. classroomTypeTitle () {
  154. const unitCategory = new UnitCategory({ type: this.localOptions.classroomType })
  155. return unitCategory.type_info.label
  156. },
  157. createPageRouteName () {
  158. if (this.localOptions.classroomType === 'TRAINING') {
  159. return 'Admin.Classroom.Create'
  160. }
  161. if (this.localOptions.classroomType === 'EVENT') {
  162. return 'Admin.Event.Create'
  163. }
  164. return 'Admin.Classroom.Create'
  165. },
  166. showPageRouteName () {
  167. if (this.localOptions.classroomType === 'TRAINING') {
  168. return 'Admin.Classroom.Show'
  169. }
  170. if (this.localOptions.classroomType === 'EVENT') {
  171. return 'Admin.Event.Show'
  172. }
  173. return 'Admin.Classroom.Show'
  174. },
  175. selectedCategoryId () {
  176. return FormBuilderAssist.getInputsByName(this.inputs, 'category')?.value
  177. }
  178. },
  179. watch: {
  180. selectedCategoryId () {
  181. FormBuilderAssist.setAttributeByName(this.inputs, 'space1', 'value', null)
  182. FormBuilderAssist.setAttributeByName(this.inputs, 'unit', 'options', [])
  183. this.getUnits(this.selectedCategoryId)
  184. }
  185. },
  186. mounted () {
  187. this.setClassroomTypeOfInputs()
  188. this.preLoadData()
  189. .then(() => {
  190. this.mounted = true
  191. })
  192. .catch(() => {
  193. })
  194. },
  195. methods: {
  196. setClassroomTypeOfInputs () {
  197. if (this.localOptions.classroomType === 'TRAINING') {
  198. FormBuilderAssist.setAttributeByName(this.inputs, 'professor', 'label', 'استاد')
  199. }
  200. if (this.localOptions.classroomType === 'EVENT') {
  201. FormBuilderAssist.setAttributeByName(this.inputs, 'professor', 'label', 'برگزار کننده')
  202. FormBuilderAssist.setAttributeByName(this.inputs, 'sessions_frequency', 'label', 'عنوان')
  203. FormBuilderAssist.setAttributeByName(this.inputs, 'unit', 'label', 'دسته')
  204. FormBuilderAssist.setAttributeByName(this.inputs, 'category', 'type', 'hidden') // unit -> category__type filter
  205. FormBuilderAssist.setAttributeByName(this.inputs, 'allowed_absence_count', 'type', 'hidden')
  206. FormBuilderAssist.setAttributeByName(this.inputs, 'effective_absence_coefficient', 'type', 'hidden')
  207. FormBuilderAssist.setAttributeByName(this.inputs, 'mandatory_assignment_count', 'type', 'hidden')
  208. FormBuilderAssist.setAttributeByName(this.inputs, 'special_passing_mark', 'type', 'hidden')
  209. FormBuilderAssist.setAttributeByName(this.inputs, 'minimum_conditional_passing_mark', 'type', 'hidden')
  210. FormBuilderAssist.setAttributeByName(this.inputs, 'minimum_clean_passing_mark', 'type', 'hidden')
  211. }
  212. },
  213. setInputAttr (name, attr, value) {
  214. this.$refs.classroomEntityCreate.setInputAttributeByName(name, attr, value)
  215. },
  216. preLoadData () {
  217. return new Promise((resolve, reject) => {
  218. const promise1 = this.getProfessors()
  219. const promise2 = this.getCategories()
  220. const promise3 = (this.localOptions.classroomType === 'EVENT') ? this.getUnits(null, this.localOptions.classroomType) : (Promise.resolve())
  221. this.$nextTick(() => {
  222. Promise.all([promise1, promise2, promise3])
  223. .then(() => {
  224. resolve()
  225. })
  226. .catch(() => {
  227. reject()
  228. })
  229. })
  230. })
  231. },
  232. getProfessors () {
  233. return APIGateway.user.index({ per_page: 9999, role: 'professor' })
  234. .then((users) => {
  235. FormBuilderAssist.setAttributeByName(this.inputs, 'professor', 'options', users.list.list.map(item => {
  236. return {
  237. value: item.id,
  238. label: this.getUserFullname(item)
  239. }
  240. }))
  241. })
  242. .catch(() => {})
  243. },
  244. getCategories () {
  245. return APIGateway.unitCategory.index({ per_page: 9999, type: this.localOptions.classroomType })
  246. .then((categories) => {
  247. FormBuilderAssist.setAttributeByName(this.inputs, 'category', 'options', categories.list.list.map(item => {
  248. return {
  249. value: item.id,
  250. label: item.title
  251. }
  252. }))
  253. })
  254. .catch(() => {})
  255. },
  256. getUnits (selectedcategoryId = null, categoryType = null) {
  257. this.unitsLoading = true
  258. APIGateway.unit.index({ per_page: 9999, category: selectedcategoryId, category__type: categoryType })
  259. .then((units) => {
  260. FormBuilderAssist.setAttributeByName(this.inputs, 'unit', 'options', units.list.list.map(item => {
  261. return {
  262. value: item.id,
  263. label: item.title
  264. }
  265. }))
  266. this.unitsLoading = false
  267. })
  268. .catch(() => {
  269. this.unitsLoading = false
  270. })
  271. },
  272. getUserFullname (user) {
  273. return user.firstname + ' ' + user.lastname
  274. },
  275. createClassroom () {
  276. this.$refs.classroomEntityCreate.createEntity()
  277. }
  278. }
  279. }
  280. </script>