check-dom.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. function select_box_first_selected(dom_val) {
  2. $(`${dom_val} option:eq(0)`).prop('selected', true);
  3. }
  4. function first_dom_focus(dom_val) {
  5. $(dom_val).each(function() {
  6. let this_val = $(this).val() || '';
  7. if ($(this).prop('required') && !this_val.co_trim()) {
  8. $(this).focus();
  9. return false;
  10. }
  11. })
  12. return;
  13. }
  14. function dom_required_check(dom_val) {
  15. let msg = false;
  16. $(dom_val).each(function() {
  17. let this_val = $(this).val() || ''
  18. if($(this).prop('required') && !this_val.co_trim()) {
  19. const label_txt = $(this).closest('.form-group').find('label').text()
  20. if (label_txt) {
  21. iziToast.warning({ title: 'Warning', message: label_txt.split('*')[0] + ' ' + $('#no-data-found').text()});
  22. }
  23. msg = true;
  24. }
  25. })
  26. first_dom_focus(dom_val);
  27. return msg
  28. }
  29. function befo_del_copy_id(argObj = '#frm') {
  30. let bool = false;
  31. const $thisinput = $(argObj).find('input[name="Id"]');
  32. if ($thisinput.prop( 'disabled' ) || $thisinput.val() == '0') {
  33. bool = true;
  34. }
  35. return bool;
  36. }
  37. function set_as_response_id(value, argObj = '#frm') {
  38. if ($(argObj).find('input[name="Id"]').val() >= 0) {
  39. $(argObj).find('input[name="Id"]').val(value)
  40. } else {
  41. $(argObj).find('input[name="Id"]').val(0)
  42. }
  43. }
  44. function get_current_table_tr_index(dom_val) {
  45. let tr = $(dom_val).closest('tr')
  46. // tbody에서 현재tr index 가져옴,
  47. return $(tr).prevAll().length;
  48. }
  49. function confirm_message_shw_and_delete(callback) {
  50. swalInit.fire({
  51. title: $('#comfirm-delete').text(),
  52. text: $('#can-not-recover-after-delete').text(),
  53. type: 'question',
  54. showCancelButton: true,
  55. confirmButtonClass: 'btn btn-danger',
  56. cancelButtonClass: 'btn btn-primary',
  57. confirmButtonText: $('#delete').text(),
  58. cancelButtonText: $('#cancel').text(),
  59. }).then((result) => {
  60. if (result.value) {
  61. callback()
  62. }
  63. });
  64. }
  65. function handleEnterPressedinNormalCell(event, callback) {
  66. if ((event.which && event.which == 13) || event.keyCode && event.keyCode == 13) {
  67. document.activeElement.blur();
  68. callback(event.target);
  69. }
  70. }
  71. function enter_pressed_auto_search(event, callback = undefined) {
  72. if ((event.which && event.which == 13) || event.keyCode && event.keyCode == 13) {
  73. if (isEmpty(callback)) {
  74. let dom_val = '#modal-' + $(event.target).data('target');
  75. $(`${dom_val}.show`).find('.modal-search').trigger('click');
  76. } else {
  77. callback();
  78. }
  79. document.activeElement.blur();
  80. }
  81. }
  82. function checkbox_all_checked($this, name) {
  83. $($this).closest('table').find(`input[name='${name}']`).each(function(index) {
  84. if ($($this).is(':checked') == $(this).is(':checked')) {
  85. $(this).trigger('click');
  86. }
  87. $(this).prop('checked', ! $($this).is(':checked'));
  88. $(this).trigger('click');
  89. })
  90. }
  91. function table_head_check_box_reset(dom_val) {
  92. $(dom_val).find('thead .all-check').prop('checked', false);
  93. $(dom_val).find('thead .all-check').trigger('change');
  94. }
  95. function deactivate_button_group(argObj = null) {
  96. if (! isEmpty(argObj)) {
  97. $(argObj['save_spinner_btn']).prop('hidden', false)
  98. $(argObj['btn_group']).prop('hidden', true)
  99. } else {
  100. $('.save-spinner-btn').prop('hidden', false)
  101. $('.btn-group').prop('hidden', true)
  102. }
  103. }
  104. function activate_button_group(argObj = null) {
  105. if (! isEmpty(argObj)) {
  106. $(argObj['save_spinner_btn']).prop('hidden', true)
  107. $(argObj['btn_group']).prop('hidden', false)
  108. } else {
  109. $('.save-spinner-btn').prop('hidden', true)
  110. $('.btn-group').prop('hidden', false)
  111. }
  112. }
  113. function input_box_reset_for(argObj, exception_name = [], attr_name = 'id') {
  114. // id 초기화
  115. $(argObj).find('input[name="Id"]').val(0)
  116. $(argObj).find('#remarks-preview').html('')
  117. // select 초기화
  118. $(argObj).find('select').each(function () {
  119. $(this).find(`option:eq(0)`).prop('selected', true)
  120. });
  121. // text 초기화
  122. $(argObj).find('input[type=text]').each(function () {
  123. if (exception_name.includes($(this).attr(attr_name))) return;
  124. this.value = '';
  125. });
  126. // email 초기화
  127. $(argObj).find('input[type=email]').each(function () {
  128. if (exception_name.includes($(this).attr(attr_name))) return;
  129. this.value = '';
  130. });
  131. // textarea 초기화
  132. $(argObj).find('textarea').each(function () {
  133. this.value = '';
  134. });
  135. // checkbox 초기화
  136. $(argObj).find('input[type=checkbox]').each(function () {
  137. $(this).prop('checked', false)
  138. });
  139. // radio 초기화
  140. $(argObj).find('input[type=radio]').each(function () {
  141. $(this).prop('checked', false)
  142. });
  143. // file 초기화
  144. $(argObj).find('input[type=file]').each(function () {
  145. if (exception_name.includes($(this).attr(attr_name))) return;
  146. this.value = '';
  147. });
  148. }
  149. function verify_email(dom_val) { // 이메일 검증 스크립트 작성
  150. const pattern = /^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$/i;
  151. let result = false;
  152. $(dom_val).find('input[type=email]').each(function () {
  153. // 검증에 사용할 정규식 변수 regExp에 저장
  154. result = ! ($(this).val().match(pattern) != null);
  155. if (result) {
  156. $(this).focus();
  157. return false;
  158. }
  159. });
  160. return result;
  161. }
  162. function get_radio_value_for(dom_val, name) {
  163. return $(dom_val).find(`:input:radio[name=${name}]:checked`).val()
  164. }
  165. function set_radio_value_for(dom_val, name, value) {
  166. return $(dom_val).find(`:input:radio[name=${name}]:input[value=${value}]`).attr('checked', true);
  167. }