check-dom.js 5.8 KB

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