lib.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. const CheckDecimal = x => {
  2. const realStringObj = obj && obj.toString();
  3. if (!jQuery.isArray(obj) && (realStringObj - parseFloat(realStringObj) + 1) >= 0) return false;
  4. const parts = x.toString().split(".");
  5. parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  6. return parts.join(".");
  7. }
  8. const CheckMail = email => {
  9. const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  10. const result = re.test(String(email).toLowerCase());
  11. // !result && alert('Email is invalid !!!', 'error');
  12. return result;
  13. }
  14. const CheckNum = input => !isNaN(input);
  15. const LenCheck = (input, length) => {
  16. return input.length <= length;
  17. }
  18. const CheckMinMax = (elm, min, max) => {
  19. const length = $(elm).val().length;
  20. if (length < min || length > max) {
  21. $(elm).empty();
  22. $(elm).focus();
  23. }
  24. }
  25. function setCookie(cookieName, value, expirationDate) {
  26. var cookieValue = escape(value) + ((expirationDate == null) ? '' : '; expires=' + expirationDate.toUTCString()) + ';path=/';
  27. document.cookie = cookieName + '=' + cookieValue;
  28. }
  29. function getCookie(cookieName) {
  30. var name = cookieName + '=';
  31. var decodedCookie = decodeURIComponent(document.cookie);
  32. var cookieArray = decodedCookie.split(';');
  33. for (var i = 0; i < cookieArray.length; i++) {
  34. var cookie = cookieArray[i];
  35. while (cookie.charAt(0) == ' ') {
  36. cookie = cookie.substring(1);
  37. }
  38. if (cookie.indexOf(name) == 0) {
  39. return cookie.substring(name.length, cookie.length);
  40. }
  41. }
  42. return '';
  43. }
  44. function makeTwoDigit(number) {
  45. return number < 10 ? '0' + number : number.toString();
  46. }
  47. function isEmptyArr(arr) {
  48. if(Array.isArray(arr) && arr.length === 0) {
  49. return true;
  50. }
  51. return false;
  52. }
  53. const CheckSSN = ssn => {
  54. const ssnPattern = /^[0-9]{3}\-?[0-9]{2}\-?[0-9]{4}$/;
  55. return ssnPattern.test(ssn);
  56. }
  57. const CheckRequired = inputList => {
  58. inputList.forEach(item => {
  59. const value = item.val();
  60. if (value == null || value == '' || value == undefined) {
  61. alert(`${item.data('name')} is required !!!`, 'error');
  62. return false;
  63. }
  64. })
  65. };
  66. const ComfirmPasswd = (pass, confirmPass) => pass === confirmPass;
  67. const DisableInput = elm => $(elm).prop('disabled', function (i, v) {
  68. return !v;
  69. });
  70. const BlinkObject = elm => {
  71. $(elm).fadeOut('slow', function () {
  72. $(this).fadeIn('slow', function () {
  73. BlinkObject(this);
  74. });
  75. });
  76. }
  77. const InitCheckBox = (data, name) => {
  78. let html = '';
  79. data.forEach(item => {
  80. html += `<input type="checkbox" name="${name}" value="${item}"> ${item}`;
  81. });
  82. return html;
  83. }
  84. const InitRadio = (data, name) => {
  85. let html = '';
  86. data.forEach(item => {
  87. html += `<input type="radio" name="${name}" value="${item}"> ${item}`;
  88. });
  89. return html;
  90. }
  91. const InitSelect = (data, name) => `<select name="${name}">${ArrayToOption(data)}</select>`;
  92. const ArrayToOption = array => {
  93. let html = '';
  94. array.forEach(item => {
  95. html += `<option value="${item}">${item}</option>`
  96. });
  97. return html;
  98. }
  99. function commaCheck($this) {
  100. $($this).val(function (index, value) {
  101. value = value.replace(/,/g, '');
  102. return numberWithCommas(value);
  103. });
  104. }
  105. function minusComma(value) {
  106. let formNumber = "" + trim(value);
  107. // 문자제거
  108. // value = formNumber.toString().replace(/[^\d]+/g, "");
  109. // 콤마제거
  110. value = formNumber.toString().replace(/,/g, "");
  111. return value;
  112. }
  113. function rand(min, max) {
  114. return Math.floor(Math.random() * (max - min)) + min;
  115. }
  116. function format_decimal(val, number) {
  117. let format = decimal_convert(number);
  118. // 소수점 버린다.
  119. return numeral(Math.floor(val).toFixed(number)).format(format);
  120. // 소수점 반올림.
  121. return numeral(parseFloat(val).toFixed(number)).format(format);
  122. }
  123. function fill_zero(width, str) {
  124. return (str.length && width > 0) ? str + '.' + new Array(width + 1).join('0') : str;
  125. }
  126. function decimal_convert(point_name) {
  127. return fill_zero(parseInt(point_name), '0,0')
  128. }
  129. function remove_tag( html ) {
  130. return html.replace(/(<([^>]+)>)/gi, "");
  131. }
  132. function formatDateString(inputString) {
  133. // Split the input string into an array of substrings with two characters each
  134. const chunks = inputString.match(/.{1,2}/g) || [];
  135. // Initialize an empty result string
  136. let result = '';
  137. // Iterate through the chunks and process accordingly
  138. for (const chunk of chunks) {
  139. // Check if the chunk is "00"
  140. if (chunk === "00") {
  141. // If it is, break out of the loop
  142. break;
  143. }
  144. // Otherwise, add the chunk to the result string
  145. result += chunk;
  146. }
  147. return result;
  148. }
  149. function is_localhost() {
  150. if (location.hostname === 'localhost' || location.hostname === '127.0.0.1') {
  151. return true
  152. }
  153. return false
  154. }
  155. function get_clusterize_rows_in_block() {
  156. return 10
  157. // return is_localhost() ? 10 : 10
  158. }
  159. function remove_comma_and_arithmetic(a, b, type) {
  160. switch (type) {
  161. case 'plus':
  162. return Number(minusComma(a)) + Number(minusComma(b))
  163. case 'minus':
  164. return Number(minusComma(a)) - Number(minusComma(b))
  165. }
  166. }
  167. function unixtimeFormatDate(data) {
  168. moment.locale('ko')
  169. return moment(new Date(data * 1000)).format('YYYY-MM-DD HH:mm:ss (dd)')
  170. }
  171. function format_result(data, format, display_vars = undefined) {
  172. let result = data
  173. if(isHtmlEncoded(result)){
  174. result = htmlDecode(result);
  175. }
  176. switch (format) {
  177. case 'YYYY-MM-DD': case 'YYYY.MM.DD': case 'YYYYMMDD':
  178. case 'YY-MM-DD': case 'YY.MM.DD': case 'YYMMDD':
  179. case 'yy-mm-dd': case 'yy.mm.dd': case 'yymmdd':
  180. result = isEmpty(data) ? '' : moment(data).format(format.toUpperCase());
  181. break;
  182. case 'unixtime':
  183. result = isEmpty(data) ? '' : moment(new Date(data * 1000)).format('YY-MM-DD HH:mm:ss');
  184. break;
  185. case 'unix-yy.mm.dd':
  186. result = isEmpty(data) ? '' : moment(new Date(data * 1000)).format('YY-MM-DD');
  187. break;
  188. case '$_ThumbNail':
  189. const w = display_vars['ListWidth'] === 0 ? '100%' : display_vars['ListWidth'] + 'px';
  190. const h = display_vars['ListHeight'] === 0 ? '100%' : display_vars['ListHeight'] + 'px';
  191. result = `
  192. <div class="thumb-nail-title" style="height: ${h};">
  193. <div class="thumb-nail-img-div">
  194. <img src="${window.env['MEDIA_URL'] + data}" style="max-width:${w}; max-height:${h};"
  195. class="thumb-nail-img" onerror="this.src='/images/folder.jpg'">
  196. </div>
  197. </div>
  198. `;
  199. // <div class="m-auto" style="width: 100px; height: 100px; overflow: hidden; margin:0 auto;">
  200. // <img src="${window.env['MEDIA_URL'] + data}" style="width: 100%; height: 100%; object-fit: cover;" onerror="this.src='/images/folder.jpg'"
  201. // </div>
  202. break;
  203. case '$_FileName':
  204. let path_list = data.split('/')
  205. result = path_list[path_list.length - 1];
  206. break;
  207. case 'check':
  208. if (data == 1 || data == true) {
  209. result = '✓';
  210. } else {
  211. result = '';
  212. }
  213. break;
  214. case 'unique':
  215. result = data.split("'").join('');
  216. break;
  217. case 'date_month':
  218. result = isEmpty(data) ? '' : moment(data).format('YY.MM');
  219. break;
  220. case 'date_week':
  221. result = isEmpty(data) ? '' : `${moment(data).format('YY.MM')}-${moment(data).isoWeek()}`;
  222. break;
  223. case 'remove_tag':
  224. result = remove_tag(data);
  225. break;
  226. default:
  227. if (! isEmpty(format) && format.match(/[A-Za-z]+\s*\(\s*'(.*?)\'\s*\)\s*/)) {
  228. const func_name = format.replace(')', `, '${data}')`);
  229. try {
  230. result = eval(`format_func_${func_name}`);
  231. } catch (err) {
  232. result = 'Invalid';
  233. }
  234. }
  235. break;
  236. }
  237. return result;
  238. }
  239. function htmlDecode(str) {
  240. const parser = new DOMParser();
  241. const doc = parser.parseFromString(str, 'text/html');
  242. return doc.documentElement.textContent;
  243. }
  244. function isHtmlEncoded(str) {
  245. const htmlEntitiesPattern = /&[a-zA-Z0-9#]{2,6};/;
  246. return htmlEntitiesPattern.test(str);
  247. }
  248. function format_conver_for(data, format, display_vars = undefined, is_split_column = false) {
  249. if (is_split_column) {
  250. if (format.includes('|')) {
  251. let data_list = data.split('|||');
  252. let format_list = format.split('|');
  253. let result_list = [];
  254. format_list.forEach(function (format, index) {
  255. if (format.startsWith("^")) {
  256. format = format.substring(1);
  257. }
  258. result_list.push(format_result(data_list[index], format, display_vars))
  259. });
  260. let r = '';
  261. result_list.forEach(function (result, index) {
  262. if (index >= result_list.length -1) {
  263. r += result
  264. } else {
  265. if (format_list[index + 1].includes('^')) {
  266. r += result + '<br/>'
  267. } else {
  268. r += result + ' | '
  269. }
  270. }
  271. })
  272. return r
  273. }
  274. }
  275. return format_result(data, format, display_vars)
  276. }
  277. function format_func_decimal(...argv) {
  278. const format = capitalize(camelCase(argv[0])) + 'Point';
  279. let data;
  280. if (window.User[format] == undefined) {
  281. return 'Invalid';
  282. }
  283. switch (argv.length) {
  284. case 2:
  285. data = format_decimal(argv[1], window.User[format]);
  286. break;
  287. case 3:
  288. data = format_decimal(argv[2], window.User[format])
  289. if (argv[1] === 'nz' && (isEmpty(data) || data == 0)) { data = 0; }
  290. else if (argv[1] === 'zn' && (isEmpty(data) || data == 0)) { data = ''; }
  291. break;
  292. }
  293. if (argv[1] === '') {
  294. return ''
  295. }
  296. return data;
  297. }
  298. function format_func_status_update(value, data) {
  299. return { Field: 'Status', Value: format_func_status_rev(value, data), };
  300. }
  301. function format_func_status_code_update(value, data) {
  302. return { Field: 'Status', Value: data, };
  303. }
  304. function format_func_status_rev(value, data) {
  305. const status = Object.values(window.CodeTitle['status'][value]).filter(status => status.Title == data)
  306. if (isEmptyArr(status)) { return data; }
  307. return _.first(status)['Code'];
  308. }
  309. function format_func_status(value, data) {
  310. if (window.CodeTitle['status'] && window.CodeTitle['status'][value][data]) {
  311. return window.CodeTitle['status'][value][data]['Title'];
  312. }
  313. return 'Invalid';
  314. }
  315. function format_func_sort_update(value, data) {
  316. return { Field: 'Sort', Value: format_func_sort_rev(value, data), };
  317. }
  318. function format_func_sort_code_update(value, data) {
  319. return { Field: 'Sort', Value: data, };
  320. }
  321. function format_func_sort_rev(value, data) {
  322. const sort = Object.values(window.CodeTitle['sort'][value]).filter(sort => sort.Title == data)
  323. if (isEmptyArr(sort)) { return data; }
  324. return _.first(sort)['Code'];
  325. }
  326. function format_func_sort(value, data) {
  327. if (window.CodeTitle['sort'] && window.CodeTitle['sort'][value][data]) {
  328. return window.CodeTitle['sort'][value][data]['Title'];
  329. }
  330. return 'Invalid';
  331. }
  332. function format_func_deal_type_update(value, data) {
  333. return { Field: 'DealType', Value: format_func_deal_type_rev(value, data), };
  334. }
  335. function format_func_deal_type_rev(value, data) {
  336. const deal_type = Object.values(window.CodeTitle['deal-type'][value]).filter(deal_type => deal_type.Title == data)
  337. if (isEmptyArr(deal_type)) { return data; }
  338. return _.first(deal_type)['Code'];
  339. }
  340. function format_func_deal_type(value, data) {
  341. if (window.CodeTitle['deal-type'] && window.CodeTitle['deal-type'][value][data]) {
  342. return window.CodeTitle['deal-type'][value][data]['Title'];
  343. }
  344. return 'Invalid';
  345. }
  346. function format_func_paymethod_rev(value, data) {
  347. const paymethod = Object.values(window.CodeTitle['paymethod'][value]).filter(paymethod => paymethod.Title == data)
  348. if (isEmptyArr(paymethod)) { return data; }
  349. return _.first(paymethod)['Code'];
  350. }
  351. function format_func_paymethod(value, data) {
  352. if (window.CodeTitle['paymethod'] && window.CodeTitle['paymethod'][value][data]) {
  353. return window.CodeTitle['paymethod'][value][data]['Title'];
  354. }
  355. return 'Invalid';
  356. }
  357. function format_func_situation_rev(value, data) {
  358. const situation = Object.values(window.CodeTitle['situation'][value]).filter(situation => situation.Title == data)
  359. if (isEmptyArr(situation)) { return data; }
  360. return _.first(situation)['Code'];
  361. }
  362. function format_func_situation(value, data) {
  363. if (window.CodeTitle['situation'] && window.CodeTitle['situation'][value][data]) {
  364. return window.CodeTitle['situation'][value][data]['Title'];
  365. }
  366. return 'Invalid';
  367. }
  368. function format_func_bill_type_update(value, data) {
  369. return { Field: 'BillType', Value: format_func_deal_type_rev(value, data), };
  370. }
  371. function format_func_bill_type_rev(value, data) {
  372. const bill_type = Object.values(window.CodeTitle['bill-type'][value]).filter(bill_type => bill_type.Title == data)
  373. if (isEmptyArr(bill_type)) { return data; }
  374. return _.first(bill_type)['Code'];
  375. }
  376. function format_func_bill_type(value, data) {
  377. if (window.CodeTitle['bill-type'] && window.CodeTitle['bill-type'][value][data]) {
  378. return window.CodeTitle['bill-type'][value][data]['Title'];
  379. }
  380. return 'Invalid';
  381. }
  382. function format_func_setup_code_update(value, data) {
  383. return { Field: 'SetupCode', Value: format_func_setup_code_rev(value, data), };
  384. }
  385. function format_func_setup_code_rev(value, data) {
  386. const setup_code = Object.values(window.CodeTitle['setup-code'][value]).filter(setup_code => setup_code.Title == data)
  387. if (isEmptyArr(setup_code)) { return data; }
  388. return _.first(setup_code)['Code'];
  389. }
  390. function format_func_setup_code(value, data) {
  391. if (window.CodeTitle['setup-code'] && window.CodeTitle['setup-code'][value][data]) {
  392. return window.CodeTitle['setup-code'][value][data]['Title'];
  393. }
  394. return 'Invalid';
  395. }
  396. function format_func_expose_type_update(value, data) {
  397. return { Field: 'ExposeType', Value: format_func_expose_type_rev(value, data), };
  398. }
  399. function format_func_expose_type_rev(value, data) {
  400. const expose_type = Object.values(window.CodeTitle['expose-type'][value]).filter(expose_type => expose_type.Title == data)
  401. if (isEmptyArr(expose_type)) { return data; }
  402. return _.first(expose_type)['Code'];
  403. }
  404. function format_func_expose_type(value, data) {
  405. if (window.CodeTitle['expose-type'] && window.CodeTitle['expose-type'][value][data]) {
  406. return window.CodeTitle['expose-type'][value][data]['Title'];
  407. }
  408. return 'Invalid';
  409. }
  410. function format_func_ship_type_update(value, data) {
  411. return { Field: 'ShipType', Value: format_func_ship_type_rev(value, data), };
  412. }
  413. function format_func_ship_type_rev(value, data) {
  414. const ship_type = Object.values(window.CodeTitle['ship-type'][value]).filter(ship_type => ship_type.Title == data)
  415. if (isEmptyArr(ship_type)) { return data; }
  416. return _.first(ship_type)['Code'];
  417. }
  418. function format_func_ship_type(value, data) {
  419. if (window.CodeTitle['ship-type'] && window.CodeTitle['ship-type'][value][data]) {
  420. return window.CodeTitle['ship-type'][value][data]['Title'];
  421. }
  422. return 'Invalid';
  423. }
  424. function format_func_delay_type_update(value, data) {
  425. return { Field: 'DelayType', Value: format_func_delay_type_rev(value, data), };
  426. }
  427. function format_func_delay_type_rev(value, data) {
  428. const delay_type = Object.values(window.CodeTitle['delay-type'][value]).filter(delay_type => delay_type.Title == data)
  429. if (isEmptyArr(delay_type)) { return data; }
  430. return _.first(delay_type)['Code'];
  431. }
  432. function format_func_delay_type(value, data) {
  433. if (window.CodeTitle['delay-type'] && window.CodeTitle['delay-type'][value][data]) {
  434. return window.CodeTitle['delay-type'][value][data]['Title'];
  435. }
  436. return 'Invalid';
  437. }
  438. function format_func_cargo_type_update(value, data) {
  439. return { Field: 'CargoType', Value: format_func_cargo_type_rev(value, data), };
  440. }
  441. function format_func_cargo_type_rev(value, data) {
  442. const cargo_type = Object.values(window.CodeTitle['cargo-type'][value]).filter(cargo_type => cargo_type.Title == data)
  443. if (isEmptyArr(cargo_type)) { return data; }
  444. return _.first(cargo_type)['Code'];
  445. }
  446. function format_func_cargo_type(value, data) {
  447. if (window.CodeTitle['cargo-type'] && window.CodeTitle['cargo-type'][value][data]) {
  448. return window.CodeTitle['cargo-type'][value][data]['Title'];
  449. }
  450. return 'Invalid';
  451. }
  452. function format_func_condition_type_update(value, data) {
  453. return { Field: 'ConditionType', Value: format_func_condition_type_rev(value, data), };
  454. }
  455. function format_func_condition_type_rev(value, data) {
  456. const condition_type = Object.values(window.CodeTitle['condition-type'][value]).filter(condition_type => condition_type.Title == data)
  457. if (isEmptyArr(condition_type)) { return data; }
  458. return _.first(condition_type)['Code'];
  459. }
  460. function format_func_condition_type(value, data) {
  461. if (window.CodeTitle['condition-type'] && window.CodeTitle['condition-type'][value][data]) {
  462. return window.CodeTitle['condition-type'][value][data]['Title'];
  463. }
  464. return 'Invalid';
  465. }
  466. function format_func_body_situation_update(value, data) {
  467. return { Field: 'BodySituation', Value: format_func_body_situation_rev(value, data), };
  468. }
  469. function format_func_body_situation_rev(value, data) {
  470. const body_situation = Object.values(window.CodeTitle['body-situation'][value]).filter(body_situation => body_situation.Title == data)
  471. if (isEmptyArr(body_situation)) { return data; }
  472. return _.first(body_situation)['Code'];
  473. }
  474. function format_func_body_situation(value, data) {
  475. if (window.CodeTitle['body-situation'] && window.CodeTitle['body-situation'][value][data]) {
  476. return window.CodeTitle['body-situation'][value][data]['Title'];
  477. }
  478. return 'Invalid';
  479. }
  480. function formatPhoneNumber(phoneNumber) {
  481. // Remove any non-numeric characters
  482. let cleaned = phoneNumber.replace(/\D/g, '');
  483. // Check if the number starts with 010 and is 11 digits long
  484. if (cleaned.length === 11 && cleaned.startsWith('010')) {
  485. return cleaned.replace(/(\d{3})(\d{4})(\d{4})/, '$1-$2-$3');
  486. } else {
  487. // Return the input if it doesn't match the expected format
  488. return 'Invalid phone number format';
  489. }
  490. }
  491. function check_dom_input_number(dom_array) {
  492. let arr = dom_array.filter(el => isNaN($(el).val()))
  493. arr.forEach(el => $(el).val('') );
  494. if (! isEmptyArr(arr)) {
  495. iziToast.error({
  496. title: 'Error',
  497. message: $('#please-enter-a-number').text(),
  498. });
  499. return true;
  500. }
  501. return false;
  502. }
  503. function show_iziToast_msg(data, callback = undefined) {
  504. if (isEmpty(data['apiStatus'])) {
  505. iziToast.success({
  506. title: 'Success',
  507. message: $('#action-completed').text(),
  508. });
  509. if (callback) {
  510. callback()
  511. }
  512. } else {
  513. iziToast.error({
  514. title: 'Error',
  515. message: data.body ?? $('#api-request-failed-please-check').text(),
  516. });
  517. }
  518. }
  519. // function show_iziToast_msg(page, callback = undefined) {
  520. // if (page) {
  521. // iziToast.success({
  522. // title: 'Success',
  523. // message: $('#action-completed').text(),
  524. // });
  525. // if (callback) {
  526. // callback()
  527. // }
  528. // } else {
  529. // console.log(page)
  530. // iziToast.error({
  531. // title: 'Error',
  532. // message: page.data.body ?? $('#api-request-failed-please-check').text(),
  533. // });
  534. // }
  535. // }
  536. const generate_random_string = (num) => {
  537. const characters ='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  538. let result = '';
  539. const charactersLength = characters.length;
  540. for (let i = 0; i < num; i++) {
  541. result += characters.charAt(Math.floor(Math.random() * charactersLength));
  542. }
  543. return result;
  544. }
  545. function find_menu_info(data, find_code) {
  546. return data.filter(menu => menu['MenuCode'] === find_code)[0]
  547. }
  548. async function show_recrystallize_server(print_vars, type, vars) {
  549. let simple_filter = '', list_type1_vars = ''
  550. switch (type) {
  551. case 'formB':
  552. simple_filter = vars
  553. break
  554. case 'type1':
  555. list_type1_vars = vars
  556. break
  557. }
  558. if (isEmpty(window.env['REPORT_SERVER_URL'])) {
  559. return iziToast.error({ title: 'Error', message: 'REPORT_SERVER_URL 의 지정 내용이 없어 PDF를 생성할 수 없습니다.' })
  560. }
  561. const response = await get_api_data('list-type1-page', {
  562. QueryVars: {
  563. QueryName: print_vars['QueryName'],
  564. SimpleFilter: simple_filter
  565. },
  566. ListType1Vars: {
  567. ...list_type1_vars,
  568. IsntPageReturn: true,
  569. IsCrystalReport: true,
  570. IsDownloadList: true,
  571. IsAddTotalLine: false,
  572. }
  573. })
  574. // console.log(response)
  575. if (response.data['apiStatus']) {
  576. return iziToast.error({ title: 'Error', message: response.data['body'] ?? $('#api-request-failed-please-check').text() })
  577. }
  578. const reportName = print_vars['ReportPath']
  579. let url = window.env['REPORT_SERVER_URL'] + '?reportName=' + reportName + '&listToken='
  580. + response.data['ListType1Vars']['ListToken'] + '&ofcCode=' + window.User['OfcCode']
  581. if (print_vars['ExportFmt']) {
  582. url = url + '&exportfmt=' + print_vars['ExportFmt']
  583. }
  584. switch (print_vars['ExportFmt']) {
  585. case '':
  586. case 'PDF':
  587. window.open(url)
  588. break
  589. default:
  590. location.href = url
  591. break
  592. }
  593. // window.open(url)
  594. }
  595. async function show_popup(component, width, variable = '', namespace = 'window') {
  596. const popupOption = eval(namespace).popupOptions.filter(option => option.Component.includes(component))
  597. if (isEmpty(popupOption)) { return }
  598. const modal_class_name = popupOption[0]['ModalClassName'];
  599. $(`#modal-select-popup.${modal_class_name} .modal-dialog`).css('max-width', `${width}px`)
  600. eval(capitalize(camelCase(modal_class_name))).btn_act_new_callback(variable)
  601. $(`#modal-select-popup.${modal_class_name}`).modal('show')
  602. }
  603. function groupBy (data, key) {
  604. return data.reduce(function (carry, el) {
  605. var group = el[key];
  606. if (carry[group] === undefined) {
  607. carry[group] = []
  608. }
  609. carry[group].push(el)
  610. return carry
  611. }, {})
  612. }
  613. function isEmptyObject(obj){
  614. if (obj.constructor === Object && Object.keys(obj).length === 0) return true;
  615. return false;
  616. }
  617. function check_login() {
  618. if (isEmpty(window.Member)) {
  619. // location.href = '/member-login-broker'
  620. return false
  621. }
  622. return true
  623. }
  624. function chunk(data = [], size = 1) {
  625. const arr = [];
  626. for (let i = 0; i < data.length; i += size) {
  627. arr.push(data.slice(i, i + size));
  628. }
  629. return arr;
  630. }
  631. function addIdParameter(url, idValue) {
  632. const urlObj = new URL(url, window.location.origin); // Assuming a relative URL, we need a base URL for URL parsing
  633. const params = urlObj.searchParams;
  634. if (!params.has('id')) {
  635. params.append('id', idValue);
  636. }
  637. return urlObj.toString();
  638. }