modal.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. const modal_controller = (function ($, window, document, undefined) {
  2. $(document).on('click', '.btn-open-modal', function() {
  3. $this = $(this);
  4. id = '#modal-' + $this.data('target');
  5. if (! isEmpty($this.data('class'))) {
  6. id = `${id}.${$this.data('class')}`
  7. $(id).data('class', $this.data('class'))
  8. // $this.data('class', '')
  9. }
  10. if (! isEmpty($this.data('variable'))) {
  11. moealSetFile = eval($this.data('variable'))
  12. }
  13. $(id).data('filter', '');
  14. if (! isEmpty($this.data('filter'))) {
  15. $(id).data('filter', $this.data('filter'))
  16. }
  17. // 모달 filter select box
  18. makeSelectBtnOptions(id, moealSetFile.SelectOptions, '.modal-filter-select');
  19. // 모달 orderBy select box + label
  20. setOrderByBtnAndLabel(id, moealSetFile.OrderByOptions);
  21. // 모달의 타이틀 넣어줌
  22. setLabel(`${id} #myModalLabel`, moealSetFile.General.Title);
  23. if (moealSetFile['ListVars']) {
  24. make_dynamic_table_css(`${id} table`, make_dynamic_table_px(moealSetFile['ListVars']['Size']))
  25. if ($(id).find('table').data('rowspan') > 1) {
  26. setThead(id, makeRowSpanThead(moealSetFile['ListVars']));
  27. } else {
  28. // 모달 테이블 th 넣어줌
  29. setThead(id, makeThead(moealSetFile['ListVars']));
  30. }
  31. let limit = $(id).find('.modal-line-select').find('option:selected').val();
  32. $(id).addClass('in');
  33. eval (`${$this.data('target')}_open(${limit})`);
  34. }
  35. $('.modal').draggable({ handle: ".modal-header" });
  36. $(id).modal('show');
  37. });
  38. // 모달의 ESC키 누를 시 모달 닫기
  39. shortcut.add('ESC',function () {
  40. $('.modal.show').modal('hide')
  41. })
  42. // 전체 모달 페이지 lines 변경 (전체)
  43. $(document).on('change', '.modal-line-select', function () {
  44. const params = make_parameter( $(this).data('target'), $(this).data('class') );
  45. eval ( `${$(this).data('target')}_open(${params.limit}, ${params.offset})` );
  46. });
  47. // 전체 모달 orderBy 클릭 (전체)
  48. $(document).on('change', '.modal-order-by-select', function () {
  49. const params = make_parameter( $(this).data('target'), $(this).data('class') );
  50. eval ( `${$(this).data('target')}_open(${params.limit}, ${$('.modal-order-by-select').data('offset')}, ${$('.modal-order-by-select').data('page')})` );
  51. });
  52. // 전체 모달 페이지네이션 클릭 (전체)
  53. $(document).on('click', '.pagination .page-link', function () {
  54. const params = make_parameter( $(this).data('target'), $(this).data('class') );
  55. eval ( `${$(this).data('target')}_open(${params.limit}, ${$(this).data('offset')}, ${$(this).data('page')})` );
  56. $('.modal-order-by-select').data('page', $(this).data('page'))
  57. $('.modal-order-by-select').data('offset', $(this).data('offset'))
  58. });
  59. // 아이템 모달의 검색 버튼 클릭 (전체)
  60. $(document).on('click', '.modal-search', function() {
  61. const params = make_parameter( $(this).data('target'), $(this).data('class') );
  62. eval ( `${$(this).data('target')}_open(${params.limit}, ${params.offset})` );
  63. });
  64. // 아이템 모달의 닫기 버튼 클릭 (전체)
  65. $(document).on('click', '.modal-close', function() {
  66. $('.search-moadal-text').val('');
  67. });
  68. $(document).on('click', '.modal .close', function() {
  69. $(this).closest('.modal').modal('hide')
  70. });
  71. // 아이템 모달의 검색 엔터 클릭 (전체)
  72. $(document).on('keydown', '.search-moadal-text', function(key) {
  73. if (key.keyCode == 13) {
  74. const params = make_parameter( $(this).data('target'), $(this).data('class') );
  75. eval ( `${$(this).data('target')}_open(${params.limit}, ${params.offset})` );
  76. }
  77. });
  78. // 전체 엔터키 검색 버튼
  79. $(document).keypress(function(e) {
  80. ['#modal-slip', '#modal-company', '#modal-item', '#modal-eyetest', '#modal-media'].forEach(id => {
  81. if ($(`${id}.show`).hasClass('in') && (e.keycode == 13 || e.which == 13)) {
  82. $(`${id}.show .modal-search`).trigger('click');
  83. }
  84. });
  85. });
  86. ['#modal-slip', '#modal-company', '#modal-item', '#modal-eyetest', '#modal-media'].forEach(id => {
  87. $(document).on('hide.bs.modal', id, function () {
  88. $(`${id}.show`).removeClass('in')
  89. });
  90. });
  91. setOrderByBtnAndLabel = (dom_val, OrderByOptions) => {
  92. if (makeSelectBtnOptions(dom_val, OrderByOptions, '.modal-order-by-select')) {
  93. setLabel(`${dom_val} #oderby-label`, moealSetFile.FormVars.Title.OrderBy)
  94. }
  95. }
  96. setLabel = (dom_val, title) => {
  97. $(dom_val).text(title);
  98. }
  99. makeRowSpanThead = (obj) => {
  100. let html = '';
  101. let topHtml = '<tr>';
  102. let bottomHtml = '<tr>';
  103. $.each(obj['Title'], function(k, v) {
  104. let format = obj['Format'][k].split('-');
  105. if (format[0] == 'top') {
  106. topHtml += `<th ${format[1]} ${obj['Hidden'][k]} style="width:${obj['Size'][k]}%;">${v}</th>`;
  107. } else if (format[0] == 'bottom') {
  108. bottomHtml += `<th ${format[1]} ${obj['Hidden'][k]} class="radius-r0 radius-l0" style="width:${obj['Size'][k]}%; border-top: 1px solid #ccc;">${v}</th>`;
  109. }
  110. });
  111. topHtml += '</tr>';
  112. bottomHtml += '</tr>';
  113. html = topHtml + bottomHtml;
  114. return html;
  115. }
  116. makeThead = (obj, checkbox_name = undefined) => {
  117. let html = '';
  118. $.each(obj['Title'], function(k, v) {
  119. if (obj['Title'][k] == '$Radio') {
  120. html += `<th class="p-0" ${obj['Hidden'][k]} style="width:${obj['Size'][k]}%;">
  121. </th>`;
  122. }
  123. else if (obj['Title'][k] == '$Check') {
  124. if (isEmpty(checkbox_name)) {
  125. checkbox_name = moealSetFile['QueryVars']['QueryName'] || 'bd-cud';
  126. }
  127. html += `<th class="p-0" ${obj['Hidden'][k]} style="width:${obj['Size'][k]}%;">
  128. <input type="checkbox" tabindex="-1" class="all-check" onclick="checkbox_all_checked(this, '${checkbox_name}-check')">
  129. </th>`;
  130. } else {
  131. html += `<th ${obj['Hidden'][k]} style="width:${obj['Size'][k]}%;">${v}</th>`;
  132. }
  133. });
  134. return html;
  135. }
  136. setThead = (dom_val, data) => {
  137. $(dom_val).find(`#table-head`).html(data);
  138. }
  139. set_thead_with_dom_value = (dom_val, data) => {
  140. $(dom_val).html(data);
  141. }
  142. mainModalGetsFocus = (dom_val, variable) => {
  143. $(dom_val).css('overflow', 'auto');
  144. id = dom_val;
  145. moealSetFile = variable;
  146. }
  147. })(jQuery, window, document);