common.js 5.6 KB

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