standard.blade.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <div class="mb-1 pt-2 text-right btn-groups">
  2. <div class="btn-group">
  3. <button type="button" class="btn btn-sm btn-primary standard-act save-button" data-value="save" {{ $formPost['FormPostVars']['Hidden']['SaveButton'] }}>
  4. {{ $formPost['FormPostVars']['Title']['SaveButton'] }}
  5. </button>
  6. @include('front.dabory.erp.partial.select-btn-options', [
  7. 'selectBtns' => $formPost['SelectButtonOptions'],
  8. 'eventClassName' => 'standard-act',
  9. ])
  10. </div>
  11. <button type="button" id="modal-media-btn" hidden
  12. class="btn btn-success btn-open-modal">
  13. </button>
  14. </div>
  15. <div class="card mb-0 pb-0" id="standard-form">
  16. <div class="row m-1" id="frm">
  17. <input type="hidden" id="Id" name="Id" value="0">
  18. <input type="hidden" id="attached-files">
  19. @php
  20. $collection = collect($formPost['FormPostVars']['Title']);
  21. $chunk = $collection->splice($formPost['DisplayVars']['Chunk'] + 1);
  22. if ($formPost['DisplayVars']['Chunk'] == 999) {
  23. $cardWidth = [12, 0];
  24. } else {
  25. $cardWidth = [8, 4];
  26. }
  27. @endphp
  28. @foreach([$collection->all(), $chunk->all()] as $key => $chunk)
  29. <div class="{{ 'col-md-'.$cardWidth[$key] }} col-12 card-header-item px-0">
  30. <div class="card card-primary mb-1 mb-md-0 mb-lg-0 border-light">
  31. <div class="card-header p-0 mb-2"></div>
  32. <div class="card-body">
  33. @if($key === 1)
  34. <div class="form-group d-flex flex-column">
  35. <div class="d-flex align-items-center">
  36. <label class="m-0 mr-1">첨부화일들(이전 업로드 파일 복구 불가)</label>
  37. <button @click="addItem"><i class="fas fa-plus"></i></button>
  38. </div>
  39. <div class="d-flex align-items-center mb-2" v-for="(item, index) in attachedFiles">
  40. <input type="file" @change="handleFileChange(index)"
  41. class="cursor-pointer rounded w-100 form-control-uniform-custom mr-1" style="text-indent: 0;">
  42. <button @click="removeItem(index)"><i class="fas fa-minus"></i></button>
  43. </div>
  44. </div>
  45. @endif
  46. @foreach($chunk as $key => $title)
  47. @empty ($formPost['FormPostVars']['Ui'][$key]) @continue @endempty
  48. <div class="form-group d-flex flex-column mb-2">
  49. <label class="m-0">{{ $title }}</label>
  50. @switch($formPost['FormPostVars']['Ui'][$key])
  51. @case('postType')
  52. <select id="{{ $key }}" class="rounded w-100"
  53. maxlength="{{ $formPost['FormPostVars']['MaxLength'][$key] }}"
  54. {{ $formPost['FormPostVars']['Required'][$key] }}>
  55. </select>
  56. @break
  57. @case('select')
  58. <select id="{{ $key }}" class="rounded w-100"
  59. maxlength="{{ $formPost['FormPostVars']['MaxLength'][$key] }}"
  60. {{ $formPost['FormPostVars']['Required'][$key] }}>
  61. @foreach($formPost[$formPost['FormPostVars']['Format'][$key]] as $option)
  62. <option value="{{ $option['Value'] }}">{{ DataConverter::execute(null, $option['Caption']) ?? $option['Caption'] }}</option>
  63. @endforeach
  64. </select>
  65. @break
  66. @case('checkbox')
  67. <input type="checkbox" id="{{ $key }}" class="rounded" value="1"
  68. {{ $formPost['FormPostVars']['Required'][$key] }}>
  69. @break
  70. @case('text')
  71. <input type="text" id="{{ $key }}" class="rounded w-100" autocomplete="off"
  72. maxlength="{{ $formPost['FormPostVars']['MaxLength'][$key] }}"
  73. {{ $formPost['FormPostVars']['Required'][$key] }}>
  74. @break
  75. @case('date')
  76. <input type="date" id="{{ $key }}" class="rounded w-100"
  77. {{ $formPost['FormPostVars']['Required'][$key] }}>
  78. @break
  79. @case('time')
  80. <input type="time" id="{{ $key }}" class="rounded w-100"
  81. {{ $formPost['FormPostVars']['Required'][$key] }}>
  82. @break
  83. @case('datetime')
  84. <input type="text" id="{{ $key }}" name="datetime" class="rounded w-100"
  85. {{ $formPost['FormPostVars']['Required'][$key] }}>
  86. @break
  87. @case('editor')
  88. <div id="modal-memo">
  89. @include('components.web-editor')
  90. </div>
  91. @break
  92. @case('textarea')
  93. <textarea id="{{ $key }}" maxlength="{{ $formPost['FormPostVars']['MaxLength'][$key] }}"
  94. {{ $formPost['FormPostVars']['Required'][$key] }}></textarea>
  95. @break
  96. @case('media')
  97. <div class="d-flex">
  98. <input type="hidden" id="{{ $key }}">
  99. <input type="text" id="{{ $key . '-file-path' }}" class="rounded w-100 radius-r0" autocomplete="off"
  100. maxlength="{{ $formPost['FormPostVars']['MaxLength'][$key] }}"
  101. {{ $formPost['FormPostVars']['Required'][$key] }}>
  102. <button class="text-white rounded border-0 radius-l0 col-3 bg-green-600 border-green-600" onclick="FormPostStandard.show_media_modal()">찾기</button>
  103. </div>
  104. <div class="form-post-title">
  105. <div class="form-post-img-div">
  106. <img id="{{ $key . '-img' }}" class="mt-2 form-post-img" src="">
  107. </div>
  108. </div>
  109. @break
  110. @default
  111. @endswitch
  112. </div>
  113. @endforeach
  114. </div>
  115. </div>
  116. </div>
  117. @endforeach
  118. </div>
  119. </div>
  120. <div class="pt-0 mt-1 text-right btn-groups">
  121. <div class="btn-group">
  122. <button type="button" class="btn btn-sm btn-primary standard-act save-button" data-value="save" {{ $formPost['FormPostVars']['Hidden']['SaveButton'] }}>
  123. {{ $formPost['FormPostVars']['Title']['SaveButton'] }}
  124. </button>
  125. @include('front.dabory.erp.partial.select-btn-options', [
  126. 'selectBtns' => $formPost['SelectButtonOptions'],
  127. 'eventClassName' => 'standard-act',
  128. ])
  129. </div>
  130. </div>
  131. @once
  132. @push('js')
  133. <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
  134. <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
  135. <script src="{{ csset('/js/modals-controller/a-type/common.js') }}"></script>
  136. <script src="{{ csset('/js/components/web-editor.js') }}"></script>
  137. <script>
  138. const AttachedFiles = new Vue({
  139. el: '#standard-form',
  140. data: function () {
  141. return {
  142. attachedFiles: [null],
  143. };
  144. },
  145. computed: {
  146. },
  147. mounted () {
  148. },
  149. methods: {
  150. addItem: function () {
  151. this.attachedFiles.push(null)
  152. },
  153. removeItem: function (index) {
  154. return this.attachedFiles.splice(index, 1)
  155. },
  156. handleFileChange: function (index) {
  157. const file = event.target.files[0]; // 파일 선택을 받아옴
  158. this.$set(this.attachedFiles, index, file); // 파일을 배열에 추가
  159. },
  160. save: function () {
  161. console.log(this.attachedFiles)
  162. if (this.attachedFiles.length <= 0 || this.attachedFiles[0] === null) {
  163. return Atype.btn_act_save('#standard-form #frm', function () {
  164. $('#modal-select-popup.show').trigger('list.requery');
  165. $('#modal-select-popup.show').modal('hide');
  166. }, 'FormPostStandard');
  167. }
  168. let form = new FormData();
  169. form.append('_token', $('meta[name="csrf-token"]').attr('content'))
  170. form.append('fileCount', this.attachedFiles.length)
  171. this.attachedFiles.forEach((file, index) => {
  172. form.append('file' + index, file)
  173. })
  174. $.ajax({
  175. url: "/post-attached-files",
  176. type:'POST',
  177. data: form,
  178. processData: false,
  179. contentType: false,
  180. success: function(data) {
  181. $('#attached-files').val(data)
  182. Atype.btn_act_save('#standard-form #frm', function () {
  183. $('#modal-select-popup.show').trigger('list.requery');
  184. $('#modal-select-popup.show').modal('hide');
  185. }, 'FormPostStandard');
  186. },
  187. });
  188. }
  189. }
  190. });
  191. $(document).ready(async function() {
  192. let query = ''
  193. const postCode = FormPostStandard.formA['General']['PostCode']
  194. if (postCode) {
  195. query = `post_code='${postCode}'`
  196. if (postCode === 'integrated') {
  197. query = `sort = '400'`
  198. }
  199. }
  200. const response = await get_api_data('post-type-page', {
  201. PageVars: {
  202. Query: query,
  203. Limit: 100
  204. }
  205. })
  206. $('#PostTypeId').html(window.custom_create_options('Id', 'TypeTitle', response.data.Page));
  207. mediaModal = await include_media_library('media-body', 'post')
  208. $('input[name="datetime"]').daterangepicker({
  209. locale: {
  210. applyLabel: "확인",
  211. cancelLabel: "취소",
  212. daysOfWeek: ["일", "월", "화", "수", "목", "금", "토"],
  213. monthNames: ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"],
  214. format: "YYYY-MM-DD HH:mm:ss"
  215. },
  216. drops: 'auto',
  217. timePicker24Hour: true,
  218. timePicker: true,
  219. singleDatePicker: true,
  220. showDropdowns: true,
  221. applyButtonClasses: "btn-apply"
  222. });
  223. $('#dbupdate-form').find('#dbupdate-date').val(date_to_sting(new Date()))
  224. $('.standard-act').on('click', function () {
  225. switch( $(this).data('value') ) {
  226. case 'save': AttachedFiles.save(); break;
  227. case 'del': FormPostStandard.btn_act_del(); break;
  228. case 'copy': FormPostStandard.btn_act_copy(); break;
  229. case 'new': FormPostStandard.btn_act_new(); break;
  230. }
  231. });
  232. $(document).on('file.paste', '#modal-media', function (event, file_url_list, id_list) {
  233. $('#MediaId').val(id_list[0])
  234. FormPostStandard.set_featured_image(file_url_list[0])
  235. });
  236. });
  237. (function( FormPostStandard, $, undefined ) {
  238. FormPostStandard.formA = {!! json_encode($formPost) !!}
  239. FormPostStandard.show_media_modal = function () {
  240. $('#modal-media').data('target-id', '')
  241. PopupForm1FormBMediaForm.btn_act_new();
  242. $('#modal-media-btn').data('target', 'media')
  243. $('#modal-media-btn').data('variable', mediaModal)
  244. $('#modal-media-btn').trigger('click')
  245. }
  246. FormPostStandard.set_featured_image = function (file_path) {
  247. $('#MediaId-file-path').val(file_path)
  248. $('#MediaId-img').attr('src', window.env['MEDIA_URL'] + file_path)
  249. $('#MediaId-img').prop('hidden', false)
  250. }
  251. FormPostStandard.btn_act_del = function () {
  252. Atype.btn_act_del('#standard-form #frm', function () {
  253. $('#modal-select-popup.show').trigger('list.requery');
  254. $('#modal-select-popup.show').modal('hide');
  255. }, 'FormPostStandard')
  256. }
  257. FormPostStandard.btn_act_copy = function () {
  258. Atype.btn_act_copy('#standard-form #frm', function () {
  259. $('#modal-select-popup.show').trigger('list.requery');
  260. $('#modal-select-popup.show').modal('hide');
  261. }, 'FormPostStandard')
  262. }
  263. FormPostStandard.btn_act_new = function () {
  264. $('#modal-select-popup .modal-body button').removeClass('bg-grey-700 border-grey-700 bg-grey-700-hover')
  265. $('#modal-select-popup .modal-body thead th').removeClass('bg-grey-700')
  266. $('#modal-select-popup .modal-header').removeClass('bg-grey-700')
  267. $('#modal-select-popup .modal-header').addClass('bg-green-600 border-green-600')
  268. $('#modal-select-popup .modal-body .btn-group > button').addClass('bg-green-600 border-green-600 bg-green-600-hover')
  269. $('#modal-select-popup.form-post-standard .modal-dialog').css('maxWidth', FormPostStandard.formA['DisplayVars']['Width'] + 'px');
  270. Atype.set_parameter_callback(FormPostStandard.parameter)
  271. $('#MediaId-img').attr('src', '')
  272. $('#MediaId-img').prop('hidden', true)
  273. $('#standard-form').find('.fr-view').html('')
  274. Atype.btn_act_new('#standard-form #frm')
  275. AttachedFiles.attachedFiles = [ null ]
  276. }
  277. FormPostStandard.parameter = function () {
  278. const id = Number($('#standard-form').find('#Id').val())
  279. let parameter = { Id: id, UserId: window.User['UserId'], AttachedFiles: $('#attached-files').val() }
  280. for (const key in FormPostStandard.formA['FormPostVars']['Title']) {
  281. if (isEmpty(FormPostStandard.formA['FormPostVars']['Type'][key])) { continue }
  282. let result
  283. const value = $('#standard-form').find(`#${key}`).val()
  284. const format = FormPostStandard.formA['FormPostVars']['Type'][key]
  285. switch (format) {
  286. case 'YYYY-MM-DD': case 'YYYY.MM.DD': case 'YYYYMMDD':
  287. case 'YY-MM-DD': case 'YY.MM.DD': case 'YYMMDD':
  288. case 'yy-mm-dd': case 'yy.mm.dd': case 'yymmdd':
  289. result = moment(value).format(format);
  290. break;
  291. case 'string':
  292. result = String(value)
  293. break;
  294. case 'number':
  295. result = Number(value)
  296. break;
  297. case 'check':
  298. result = $('#standard-form').find(`#${key}`).prop('checked') ? '1': '0'
  299. break;
  300. case 'editor':
  301. const editor = new FroalaEditor("#standard-form #froala-editor", { key: window.env['FROALA_LICENSE_KEY'], attribution: false })
  302. if (editor.codeView.isActive()) {
  303. result = editor.codeView.get()
  304. editor.codeView.toggle()
  305. } else {
  306. result = editor.html.get()
  307. }
  308. break;
  309. default:
  310. break;
  311. }
  312. parameter[key] = result
  313. }
  314. if (id < 0) {
  315. parameter = { Id: id }
  316. }
  317. console.log(parameter)
  318. return parameter;
  319. }
  320. FormPostStandard.btn_act_new_callback = function () {
  321. FormPostStandard.btn_act_new()
  322. Atype.set_parameter_callback(FormPostStandard.parameter);
  323. }
  324. FormPostStandard.show_popup_callback = async function (id, c1) {
  325. FormPostStandard.btn_act_new()
  326. await FormPostStandard.fetch_standard(Number(id));
  327. }
  328. FormPostStandard.fetch_standard = async function (id) {
  329. let response = await get_api_data(FormPostStandard.formA['General']['PickApi'], {
  330. QueryVars: {
  331. QueryName: FormPostStandard.formA['General']['QueryName'],
  332. SimpleFilter: `mx.id=${id}`
  333. },
  334. PageVars: {
  335. Limit: 1
  336. }
  337. })
  338. // console.log(response)
  339. FormPostStandard.set_standard_ui(response)
  340. }
  341. FormPostStandard.set_standard_ui = async function (response) {
  342. if (isEmpty(response.data) || response.data.apiStatus) return;
  343. let post = response.data.Page[0];
  344. if (post['MediaId']) {
  345. const response = await get_api_data('media-pick', {
  346. Page: [ { Id: Number(post['MediaId']) } ]
  347. })
  348. const page = response.data['Page']
  349. if (page) {
  350. const file_url = page[0]['FileUrl']
  351. FormPostStandard.set_featured_image(file_url)
  352. }
  353. }
  354. console.log(post)
  355. $('#standard-form').find('#Id').val(post.Id)
  356. $('#standard-form').find('#attached-files').val(post.AttachedFiles)
  357. for (const key in FormPostStandard.formA['FormPostVars']['Title']) {
  358. if (isEmpty(FormPostStandard.formA['FormPostVars']['Ui'][key])) { continue }
  359. if (FormPostStandard.formA['FormPostVars']['Ui'][key] === 'editor') {
  360. $('#standard-form').find('.fr-view').html(post[key])
  361. } else if (FormPostStandard.formA['FormPostVars']['Ui'][key] === 'checkbox') {
  362. $('#standard-form').find(`#${key}`).prop('checked', post[key] === '1')
  363. } else {
  364. let value = format_conver_for(post[key], FormPostStandard.formA['FormPostVars']['Format'][key])
  365. $('#standard-form').find(`#${key}`).val(value)
  366. }
  367. }
  368. }
  369. }( window.FormPostStandard = window.FormPostStandard || {}, jQuery ));
  370. let mediaModal
  371. </script>
  372. @endpush
  373. @endonce