common.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. const yearValidation = (year) => {
  2. const text = /^[0-9]+$/;
  3. if (!text.test(year) || year.length != 4) {
  4. iziToast.error({
  5. title: 'Error',
  6. message: 'Year is invalid',
  7. });
  8. return false;
  9. }
  10. }
  11. const numberWithCommas = (x) => {
  12. const parts = x.toString().split(".");
  13. parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  14. return parts.join(".");
  15. }
  16. var swalInit = swal.mixin({
  17. buttonsStyling: false,
  18. confirmButtonClass: 'btn btn-primary',
  19. cancelButtonClass: 'btn btn-light'
  20. }),
  21. alert = (msg, type, url, time = 500) => {
  22. swalInit.fire({
  23. title: 'Information',
  24. text: msg,
  25. type: ( type != undefined && type != '' ) ? type : 'info',
  26. timer: time
  27. }).then(function(){
  28. switch( url ){
  29. case 'reload' : location.reload(); break;
  30. default :
  31. if( url != undefined && url != '' ) window.location.replace(url);
  32. }
  33. });
  34. },
  35. ajax_from = async (data, url, async = false, callback = null) => {
  36. return $.ajax({
  37. headers : {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
  38. url : url,
  39. type : 'POST',
  40. data : data,
  41. dataType : 'json',
  42. async: async,
  43. success : function(response){
  44. if (callback) {
  45. callback(response)
  46. }
  47. },
  48. error : function(request,status,error){
  49. console.log('code:'+request.status+'\n'+'message:'+request.responseText+'\n'+'error:'+error);
  50. }
  51. })
  52. }
  53. get_table_no = (total, page, limit = 10) => {
  54. return total - ( page - 1 ) * limit;
  55. },
  56. // 검색 및 페이징, 라인 변경시 파라미터 생성 (전체)
  57. make_parameter = (_id, class_name = undefined) => {
  58. let id = `#modal-${_id}`;
  59. if (! isEmpty(class_name)) { id = `#modal-${_id}.${class_name}`; }
  60. const limit = $(id).find(`.modal-line-select`).val(),
  61. offset = 0;
  62. return {limit: limit, offset: offset}
  63. // filtername = $(`${id}`).find(`.modal-input`).val()?$(`${id}`).find(`.modal-select`).val():``,
  64. // filtervalue = $(`${id}`).find(`.modal-input`).val()?$(`${id}`).find(`.modal-input`).val():``;
  65. },
  66. make_pagination = (_id, total, page = 1, class_name = '') => {
  67. let id = `#modal-${_id}`;
  68. if (! isEmpty(class_name)) { id = `#modal-${_id}.${class_name}`; }
  69. let overFlow = false
  70. const limit = $(id).find(`.modal-line-select`).val(),
  71. totalPage = Math.ceil( total / limit ),
  72. pageGroup = Math.ceil( page / 5 ),
  73. last_ = pageGroup * 5,
  74. first = last_ - 4
  75. last = (overFlow = last_ > totalPage) ? totalPage : last_,
  76. links = `<li class="%active% page-item"><a data-offset="%offset%" data-page="%page%" class="page-link" data-target="%target%" data-class="%class%" href="#" onclick="return false;">%datas%</a></li>`;
  77. let next = last + 1,
  78. prev = first - 1,
  79. html = '';
  80. if (page <= 5) {
  81. html += `
  82. <li class="page-item disabled" aria-disabled="true">
  83. <span class="page-link" aria-hidden="true">&laquo;</span>
  84. </li>
  85. <li class="page-item disabled" aria-disabled="true">
  86. <span class="page-link" aria-hidden="true">&lsaquo;</span>
  87. </li>
  88. `
  89. } else {
  90. html += links.co_split({active: '', offset: 0, page: 1, datas: `&laquo;`, target: _id, class: class_name});
  91. html += links.co_split({active: '', offset: (prev - 1) * limit, page: prev, datas: `&lsaquo;`, target: _id, class: class_name});
  92. }
  93. for (let i = first; i <= last; i++) {
  94. if ( i >= 1 && i <= totalPage ) {
  95. const active = (page == i) ? ` active ` : ``,
  96. offset = (i - 1) * limit;
  97. html += links.co_split({active: active, offset: offset, page: i, datas: i, target: _id, class: class_name});
  98. }
  99. }
  100. if (! overFlow && ! (first + 5 > totalPage)) {
  101. html += links.co_split({active: '', offset: (next - 1) * limit, page: next, datas: `&rsaquo;`, target: _id, class: class_name});
  102. html += links.co_split({active: '', offset: (totalPage - 1) * limit, page: totalPage, datas: `&raquo;`, target: _id, class: class_name});
  103. } else {
  104. html += `
  105. <li class="page-item disabled" aria-disabled="true">
  106. <span class="page-link" aria-hidden="true">&rsaquo;</span>
  107. </li>
  108. <li class="page-item disabled" aria-disabled="true">
  109. <span class="page-link" aria-hidden="true">&raquo;</span>
  110. </li>
  111. `
  112. }
  113. $(id).find(`.pagination`).html(html);
  114. };
  115. String.prototype.co_split = String.prototype.co_split || function () {
  116. "use strict";
  117. let str = this.toString();
  118. if (arguments.length) {
  119. let t = typeof arguments[0],
  120. key,
  121. args = ("string" === t || "number" === t) ? Array.prototype.slice.call(arguments) : arguments[0];
  122. for (key in args) {
  123. str = str.replace(new RegExp("\\%" + key + "\\%", "gi"), args[key]);
  124. }
  125. }
  126. return str;
  127. };
  128. String.prototype.co_trim = String.prototype.co_trim || function () {
  129. "use strict";
  130. return this.replace(/ /gi, '');
  131. };
  132. function search_text_box_reset(id) {
  133. $(id).find('input[type="text"]:enabled').each(function(){
  134. $(this).val('');
  135. })
  136. }
  137. function getParameterByName(name) {
  138. name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  139. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search);
  140. return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  141. }
  142. function $ComTimer(){
  143. //prototype extend
  144. }
  145. $ComTimer.prototype = {
  146. comSecond : ""
  147. , fnCallback : function(){}
  148. , timer : ""
  149. , domId : ""
  150. , fnTimer : function(){
  151. var m = Math.floor(this.comSecond / 60) + "분 " + (this.comSecond % 60) + "초"; // 남은 시간 계산
  152. this.comSecond--; // 1초씩 감소
  153. this.domId.innerText = m;
  154. if (this.comSecond < 0) { // 시간이 종료 되었으면..
  155. clearInterval(this.timer); // 타이머 해제
  156. this.fnCallback()
  157. }
  158. }
  159. ,fnStop : function(){
  160. clearInterval(this.timer);
  161. }
  162. }