config.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. //JS버전
  2. var today = new Date();
  3. const js_version = itp_fn_date_format(today);
  4. const CMD_PAGE_MOVE_PARAM = 'PAGE_MOVE_PARAM';
  5. requirejs.config({
  6. baseUrl: ITP_CONTEXTPATH,
  7. waitSeconds: 0,
  8. paths: {
  9. 'jquery': 'js/jquery.min',
  10. 'jquery-ui': 'js/jquery-ui.min',
  11. 'jquery.bootstrap': 'bootstrap/dist/js/bootstrap.min',
  12. 'jquery.bootstrap.fileUpload': 'bootstrap-fileUpload/dist/bootstrap-FileUpload.js?version='+js_version,
  13. 'jquery.bootstrap.datepicker': 'bootstrap-datepicker/js/bootstrap-datepicker',
  14. 'jquery.bootstrap.datepicker.locale': 'bootstrap-datepicker/locales/bootstrap-datepicker.' + ITP_LANGUAGE + '.min',
  15. 'message.locale': 'js/app/locales/locale-' + ITP_LANGUAGE + '.js?version='+js_version,
  16. 'crypto': 'js/crypto', //Crypto 암호화 js
  17. },
  18. shim: {
  19. 'jquery.bootstrap': {
  20. deps: [
  21. 'jquery',
  22. 'jquery-ui'
  23. ]
  24. },
  25. 'jquery.bootstrap.fileUpload': {
  26. deps: ['jquery.bootstrap']
  27. },
  28. 'jquery.bootstrap.datepicker.locale': {
  29. deps: [
  30. 'jquery.bootstrap',
  31. 'jquery.bootstrap.datepicker'
  32. ]
  33. },
  34. }
  35. });
  36. require([
  37. 'jquery',
  38. 'jquery.bootstrap',
  39. 'jquery.bootstrap.datepicker.locale',
  40. 'message.locale'
  41. ], function($) {
  42. history.pushState(null, null, location.href);
  43. CommonObj.init();
  44. $('#ITP_MOBILE_BTN_HOME').on('click', function() {
  45. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/main.html');
  46. });
  47. $('#ITP_MOBILE_BTN_MENU').on('click', function() {
  48. $('#ITP_MENU').toggle();
  49. });
  50. $('#ITP_MOBILE_BTN_SETTING').on('click', function() {
  51. $('#ITP_MENU').toggle();
  52. });
  53. $('#ITP_BTN_NAV_CLOSE').on('click', function() {
  54. $('#ITP_MENU').toggle();
  55. });
  56. // 로그아웃 버튼
  57. $('#ITP_MOBILE_BTN_LOGOUT').click(function() {
  58. fnLogout();
  59. });
  60. if(VIEW_PAGE !== 'LOGIN' && VIEW_PAGE !== 'PAY') {
  61. var data = JSON.parse(sessionStorage.getItem('itp_login_info'));
  62. CONN_KEY = data.connKey; //로그인 했을때 넣었던 키를 가져옴
  63. var callbackFn = function(result) {
  64. CODE_LIST = result.codeList;
  65. AUTH_MENU_LIST = result.authMenuList;
  66. ACT_LIST = result.actList;
  67. LOGIN_USER_INFO = result.userInfo;
  68. // 사용자 정보 만들기
  69. fn_make_user_info.init();
  70. // 왼쪽 메뉴 만들기
  71. fn_make_slide_menu.init();
  72. };
  73. fn_ajax_call('/api/session/data-app', null, callbackFn, 'GET');
  74. }
  75. });
  76. var itp_fn_logined_check = function(user_nm_update, fn) {
  77. var now, expiration, data = false;
  78. data = sessionStorage.getItem('itp_login_info');
  79. if(data) {
  80. data = JSON.parse(data);
  81. now = new Date();
  82. expiration = new Date(data.timestamp);
  83. expiration.setMinutes(expiration.getMinutes() + 60);
  84. if (now.getTime() > expiration.getTime()) {
  85. data = false;
  86. fnSessionOut();
  87. } else {
  88. sessionStorage.setItem('itp_login_info', JSON.stringify({
  89. timestamp: new Date(),
  90. connKey: data.connKey //Jwt키를 가져와서 세션 스토리지에 저장
  91. }));
  92. if(user_nm_update && user_nm_update == true) {
  93. if (fn !== undefined || typeof fn !== 'undefined') {
  94. fn();
  95. }
  96. }
  97. }
  98. } else {
  99. // 로그인 페이지로 이동
  100. if($(location).attr('pathname').indexOf('login.html') < 0)
  101. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/login.html');
  102. }
  103. };
  104. var fn_make_user_info = {
  105. init : function() {
  106. this.set();
  107. },
  108. view: function() {
  109. $('#ITP_LOGIN_USER_NM').text(this.get('userNm'));
  110. $('#ITP_LOGIN_USER_ID').text(this.get('userId'));
  111. $('.name_info .fnBrnadNm').text(this.get('brandNm'));
  112. if(this.get('storeNm') !== '') {
  113. $('.name_info .fnStoreNm').text(this.get('storeNm'));
  114. } else {
  115. $('.name_info .fnLblDash').hide();
  116. $('.name_info .fnLblStoreNm').hide();
  117. }
  118. },
  119. isEmpty: function() {
  120. return sessionStorage.getItem('itp_manage_user_info') === null;
  121. },
  122. set: function() {
  123. if(this.isEmpty()) {
  124. sessionStorage.setItem('itp_manage_user_info', JSON.stringify(LOGIN_USER_INFO));
  125. } else {
  126. if(typeof(LOGIN_USER_INFO) == "string") {
  127. var sessionUserInfo = this.get();
  128. $.each(JSON.parse(LOGIN_USER_INFO), function(key, value) {
  129. sessionUserInfo[key] = value;
  130. });
  131. sessionStorage.setItem('itp_manage_user_info', JSON.stringify(sessionUserInfo));
  132. }
  133. }
  134. this.view();
  135. },
  136. get: function(key) {
  137. var sessionUserInfo = JSON.parse(sessionStorage.getItem('itp_manage_user_info'));
  138. return (key === undefined || key === null) ? sessionUserInfo : sessionUserInfo[key];
  139. }
  140. };
  141. var fn_make_slide_menu = {
  142. init: function() {
  143. $('.itp_open_nav .panel-group').empty();
  144. this.make();
  145. },
  146. make: function() {
  147. var selector = '#ITP_SIDEBAR .panel-group > .panel-default:last';
  148. $('#ITP_SIDEBAR .panel-group').empty();
  149. $.each(AUTH_MENU_LIST, function(key, value) {
  150. if(value.level === 2) { // LEVEL2
  151. $('#ITP_SIDEBAR .panel-group').append($('#ITP_AJAX_MAIN_SIDE_LEVEL2_ROWCOPY').val());
  152. $(selector).find('.fnMenuNm').text(value.menuNm);
  153. $(selector).find('.accordion-toggle').attr('href', '#ITP_NAV_'+value.menuNo);
  154. $(selector).find('.panel-collapse').attr('id', 'ITP_NAV_'+value.menuNo);
  155. $(selector).find('.fnLevelBottomList').empty();
  156. } else if(value.level === 3) { // LEVEL3
  157. $(selector).find('.fnLevelBottomList').append($('#ITP_AJAX_MAIN_SIDE_LEVEL3_ROWCOPY').val());
  158. $(selector + ' .fnLevelBottomList .itp_svg_in:last').find('.fnMenuNm').text(value.menuNm);
  159. $(selector + ' .fnLevelBottomList .itp_svg_in:last').find('.itp_nav_link').attr('data-itp-nav-id', value.menuId);
  160. $(selector + ' .fnLevelBottomList .itp_svg_in:last').find('.itp_nav_link').attr('data-conn-url', value.connUrl);
  161. $(selector + ' .fnLevelBottomList .itp_svg_in:last').find('.itp_nav_link').attr('data-open-cd', value.openCd);
  162. $(selector + ' .fnLevelBottomList .itp_svg_in:last').find('.itp_nav_link').attr('id', value.menuId + '_PAGE_NO');
  163. }
  164. });
  165. this.action();
  166. },
  167. action: function() {
  168. var _this = this;
  169. $('#ITP_SIDEBAR .accordion-toggle').off('click').on('click', function(e) {
  170. $(this).find('i.indicator').toggleClass('glyphicon-chevron-down');
  171. });
  172. $('#ITP_SIDEBAR .itp_nav_link').off('click').on('click', function() {
  173. const id = $(this).attr('data-itp-nav-id');
  174. const connUrl = $(this).attr('data-conn-url');
  175. const openCd = $(this).attr('data-open-cd');
  176. console.log('connUrl ===> ' + connUrl);
  177. if(openCd === 'C') {
  178. const href = MOBILE_CONTEXTPATH + connUrl;
  179. _this.loadPage(id, href);
  180. $('#ITP_MENU').toggle();
  181. $('.name_info .fnMenuNm').text($(this).find('.fnMenuNm').text() + '|');
  182. }
  183. });
  184. $('#ITP_SIDEBAR .panel-group > .panel-default:first').find('.accordion-toggle').trigger('click');
  185. },
  186. loadPage: function(id, href, param) {
  187. //로그인체크
  188. itp_fn_logined_check();
  189. $.ajax({
  190. contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
  191. url: href,
  192. data: param,
  193. type: 'POST',
  194. dataType: 'html',
  195. async: false,
  196. timeout: 10000,
  197. beforeSend: function() {
  198. },
  199. complete: function() {
  200. },
  201. success: function(html) {
  202. $('#ITP_CONTAINER div.itp_mobile_contents').empty().append(html);
  203. //JS파일적용
  204. const js = "<script src=\"../js/app/"+id.substring(0, id.length - 5).toLowerCase()+"/ITP_"+id+".js?version="+js_version+"\"></script>";
  205. $('#ITP_CONTAINER #ITP_MOBILE_'+id+' #ITP_MOBILE_JS').append(js);
  206. },
  207. error: function(xhr, status, error) {
  208. if (xhr.status == 401) location.href = MOBILE_CONTEXTPATH + '/app/';
  209. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failPage);
  210. },
  211. fail: function() {
  212. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failPage);
  213. }
  214. });
  215. }
  216. };
  217. function fn_make_select(options, code, select_id, all_show_yn, all_name) { //셀렉트 박스 만들기
  218. $select_id = $('#' + select_id);
  219. $select_id.empty();
  220. $.each(options, function(key, value) {
  221. if (value.codeCd == code) {
  222. if(all_show_yn == undefined || all_show_yn == true) {
  223. if(all_name == undefined || all_name == '') {
  224. $('<option/>', {'value': '', 'text': value.codeNm}).prependTo($select_id);
  225. } else {
  226. $('<option/>', {'value': '', 'text': all_name}).prependTo($select_id);
  227. }
  228. }
  229. $.each(value.codeDtlList, function(k, val) {
  230. $('<option/>', {
  231. 'value': val.codeDtlCd,
  232. 'text': val.codeDtlNm
  233. }).appendTo($select_id);
  234. });
  235. return false;
  236. }
  237. });
  238. };
  239. function fn_make_select_upper_menu(options, select_id, all_show_yn, all_name) { //셀렉트 박스 만들기
  240. $select_id = $('#' + select_id);
  241. $select_id.empty();
  242. if(all_show_yn == true) {
  243. $('<option/>', {'value': '', 'text': all_name}).prependTo($select_id);
  244. }
  245. $.each(options, function(key, value) {
  246. if (value.level == 3) {
  247. $('<option/>', {
  248. 'value': value.menuNo,
  249. 'text': value.menuNm
  250. }).appendTo($select_id);
  251. }
  252. });
  253. };
  254. function fn_make_select_brand(options, select_id, all_show_yn, all_name) { //브랜드 셀렉트 박스 만들기
  255. $select_id = $('#' + select_id);
  256. $select_id.empty();
  257. if(all_show_yn == true) {
  258. $('<option/>', {'value': '', 'text': all_name}).prependTo($select_id);
  259. }
  260. $.each(options, function(key, value) {
  261. $('<option/>', {
  262. 'value': value.brandId, // 브랜드코드
  263. 'text': value.brandNm // 브랜드명
  264. }).appendTo($select_id);
  265. });
  266. };
  267. function fn_make_select_item_class(options, select_id, all_show_yn, all_name) { //브랜드 셀렉트 박스 만들기
  268. $select_id = $('#' + select_id);
  269. $select_id.empty();
  270. if(all_show_yn == true) {
  271. $('<option/>', {'value': '', 'text': all_name}).prependTo($select_id);
  272. }
  273. $.each(options, function(key, value) {
  274. $('<option/>', {
  275. 'value': value.itemClass, // 브랜드코드
  276. 'text': value.itemClassNm // 브랜드명
  277. }).appendTo($select_id);
  278. });
  279. };
  280. function fn_make_select_store(options, select_id, all_show_yn, all_name, all_value) { //매장 셀렉트 박스 만들기
  281. $select_id = $('#' + select_id);
  282. $select_id.empty();
  283. if(all_show_yn == true) {
  284. $('<option/>', {'value': !all_value || all_value == undefined ? '' : all_value, 'text': all_name}).prependTo($select_id);
  285. }
  286. $.each(options, function(key, value) {
  287. $('<option/>', {
  288. 'value': value.storeId, // 매장번호
  289. 'text': value.storeNm // 매장명
  290. }).appendTo($select_id);
  291. });
  292. }
  293. function fn_make_select_whs(options, select_id, all_show_yn, all_name) { //창고 셀렉트 박스 만들기
  294. $select_id = $('#' + select_id);
  295. $select_id.empty();
  296. if(all_show_yn == true) {
  297. $('<option/>', {'value': '', 'text': all_name}).prependTo($select_id);
  298. }
  299. $.each(options, function(key, value) {
  300. $('<option/>', {
  301. 'value': value.whsId, // 창고아이디
  302. 'text': value.whsNm // 창고명
  303. }).appendTo($select_id);
  304. });
  305. };
  306. function fn_make_select_location(options, select_id, all_show_yn, all_name) { //위치 셀렉트 박스 만들기
  307. $select_id = $('#' + select_id);
  308. $select_id.empty();
  309. if(all_show_yn == true) {
  310. $('<option/>', {'value': '', 'text': all_name}).prependTo($select_id);
  311. }
  312. $.each(options, function(key, value) {
  313. $('<option/>', {
  314. 'value': value.location, // 로케이션
  315. 'text': value.locationNm // 로케이션명
  316. }).appendTo($select_id);
  317. });
  318. };
  319. function fnHashed(code) { //유니코드로 들어오는 해쉬키를 스트링으로 변환
  320. return decodeURIComponent(JSON.parse('"' + code.replace(/\"/g, '\\"') + '"'));
  321. }
  322. function fnLogout() { //로그아웃
  323. var callbackFn = function(result) {
  324. sessionStorage.removeItem('itp_login_info'); //Jwt 키 제거
  325. sessionStorage.removeItem('itp_manage_user_info'); //로그인 사용자 정보 제거
  326. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/login.html');
  327. };
  328. fn_ajax_call('/api/member/sign-out', null, callbackFn, 'PATCH');
  329. }
  330. function fnSessionOut() { //1시간 동안 아무것도 안할때 또는 강제 만료시킬때 사용
  331. var callbackFn = function(result) {
  332. sessionStorage.removeItem('itp_login_info'); //Jwt 키 제거
  333. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/login.html');
  334. };
  335. fn_ajax_call('/api/session/expire', null, callbackFn, 'PATCH');
  336. }
  337. // 2021.07.07 송호성 추가
  338. function fn_call_popup(type, popnm, container, popFn, args, returnType) {
  339. console.log('[ITP_CALL_POPUP] type = ' + type + ', popnm = ' + popnm);
  340. var contextPath = returnType === 'S' ? ITP_CONTEXTPATH : MOBILE_CONTEXTPATH;
  341. $.ajax({
  342. contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
  343. url: contextPath + '/app/popup/'+type+'/'+popnm+'.html',
  344. type: 'POST',
  345. dataType: 'html',
  346. async: false,
  347. timeout: 10000,
  348. beforeSend: function() {
  349. //$('#ITP_OVERLAY').show();
  350. },
  351. complete: function() {
  352. //$('#ITP_OVERLAY').hide();
  353. },
  354. success: function(html) {
  355. var append = function() {
  356. var deferred = $.Deferred();
  357. try {
  358. $(container).empty();
  359. $(container).append(html);
  360. deferred.resolve();
  361. } catch(err) {
  362. deferred.reject(err);
  363. }
  364. return deferred.promise();
  365. };
  366. append().done(function() {
  367. const js = '<script src="'+contextPath+'/js/app/popup/'+type+'/ITP_'+popnm+'.js?version='+js_version+'"></script>';
  368. $('#ITP_ASIDE #ITP_'+popnm+' #ITP_POPUP_JS').empty();
  369. $('#ITP_ASIDE #ITP_'+popnm+' #ITP_POPUP_JS').append(js);
  370. eval('itp_fn_' + popnm)(popFn, args, returnType);
  371. $('.modal.itp_modal .modal-content').draggable();
  372. });
  373. },
  374. error: function(xhr, status, error) {
  375. if (xhr.status == 401) location.href = contextPath + '/';
  376. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failData);
  377. },
  378. fail: function() {
  379. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failData);
  380. }
  381. });
  382. };
  383. //AJAX 양식 (이렇게 사용하시면 됩니다.)
  384. function fn_ajax_call(href, param, fn, type, errFn) {
  385. $.ajax({
  386. contentType: 'application/json',
  387. url: DOMAIN + href,
  388. data: param,
  389. type: type,
  390. async: false,
  391. timeout: 10000,
  392. xhrFields: {
  393. withCredentials: true //Cross Domain 처리
  394. },
  395. beforeSend: function(xhr) {
  396. $('#ITP_OVERLAY').show();
  397. var data = JSON.parse(sessionStorage.getItem('itp_login_info'));
  398. xhr.setRequestHeader('X-AUTH-TOKEN', (data) ? data.connKey : null); //Jwt 토큰을 헤더에 담아서 보낸다.
  399. // xhr.setRequestHeader('X-AUTH-TOKEN', CONN_KEY); //Jwt 토큰을 헤더에 담아서 보낸다.
  400. },
  401. complete: function() {
  402. $('#ITP_OVERLAY').hide();
  403. },
  404. success: function(result) {
  405. if (result.code !== undefined) { //성공시에도 메세지가 있으면 얼럿 예)저장되었습니다.
  406. itp_fn_modal_alert_ajax(result.message);
  407. }
  408. if (fn !== undefined || typeof fn !== 'undefined') fn(result);
  409. },
  410. error: function(xhr, status, error) {
  411. if (xhr.responseJSON !== undefined) { //실패시 서버에서 내려주는 메세지 얼럿
  412. itp_fn_modal_alert_ajax(xhr.responseJSON.message);
  413. if (xhr.status == 401) { //401에러가 떨어지면 로그인페이지로 이동
  414. sessionStorage.removeItem('itp_login_info'); //Jwt 키 제거
  415. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/login.html');
  416. }
  417. } else {
  418. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failProcess);
  419. }
  420. if (errFn !== undefined || typeof errFn !== 'undefined') errFn();
  421. },
  422. fail: function() {
  423. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failProcess);
  424. if (errFn !== undefined || typeof errFn !== 'undefined') errFn();
  425. }
  426. });
  427. };
  428. function itp_fn_modal_alert(msg) {
  429. $('#ITP_MODAL_ALERT_CANCEL').hide();
  430. $('#ITP_MODAL_ALERT').modal('show');
  431. $('#ITP_MODAL_ALERT').find('.itp_alert_txt').html(msg);
  432. $('#ITP_MODAL_ALERT_CONFIRM').off('click');
  433. $('#ITP_MODAL_ALERT_CONFIRM').on('click', function() {
  434. $('#ITP_MODAL_ALERT').modal('hide');
  435. });
  436. };
  437. function itp_fn_modal_alert_ajax(msg) {
  438. $('#ITP_MODAL_ALERT_AJAX').modal('show');
  439. $('#ITP_MODAL_ALERT_AJAX').find('.itp_alert_txt').html(msg);
  440. $('#ITP_MODAL_ALERT_AJAX_CONFIRM').off('click');
  441. $('#ITP_MODAL_ALERT_AJAX_CONFIRM').on('click', function() {
  442. $('#ITP_MODAL_ALERT_AJAX').modal('hide');
  443. });
  444. };
  445. function itp_fn_modal_duplicate(label, input) {
  446. let msg = ITP_MSG_LOCALE.message.form.duplicate;
  447. msg = msg.replace('{0}', label);
  448. $('#ITP_MODAL_ALERT_CANCEL').hide();
  449. $('#ITP_MODAL_ALERT').modal('show');
  450. $('#ITP_MODAL_ALERT').find('.itp_alert_txt').html(msg);
  451. $('#ITP_MODAL_ALERT_CONFIRM').off('click');
  452. $('#ITP_MODAL_ALERT_CONFIRM').on('click', function() {
  453. $('#ITP_MODAL_ALERT').modal('hide');
  454. if (input != null) {
  455. $(input).focus();
  456. }
  457. });
  458. };
  459. function itp_fn_modal_confirm(msg, fn, args) {
  460. $('#ITP_MODAL_ALERT_CANCEL').show();
  461. $('#ITP_MODAL_ALERT').modal('show');
  462. $('#ITP_MODAL_ALERT').find('.itp_alert_txt').html(msg);
  463. if (fn !== undefined || typeof fn !== 'undefined') {
  464. $('#ITP_MODAL_ALERT_CONFIRM').off('click');
  465. $('#ITP_MODAL_ALERT_CONFIRM').on('click', function() {
  466. fn.callBack(args);
  467. $('#ITP_MODAL_ALERT').modal('hide');
  468. });
  469. }
  470. }
  471. let itp_fn_form_validate = function(form, element, arry, msg, type) {
  472. var error = function(txt) {
  473. if (type != 'ONLYCHK') {
  474. if (msg == undefined || typeof msg == 'undefined') {
  475. msg = txt;
  476. }
  477. $(element).closest('.itp_ip').addClass('has-error');
  478. var error_msg = $('<span class="help-block">' + msg + '</span>');
  479. if($(element).parent('.input-group').length) {
  480. error_msg.insertAfter($(element).parent());
  481. } else {
  482. error_msg.insertAfter($(element));
  483. }
  484. }
  485. };
  486. if ($.inArray('empty', arry) > -1) {
  487. if ($(element).val() == '' || $(element).val() < 1) {
  488. error(ITP_MSG_LOCALE.message.form.mandatory);
  489. return false;
  490. }
  491. }
  492. if ($.inArray('emptyNum', arry) > -1) {
  493. if ($(element).val() == '' || $(element).val() < 0) {
  494. error(ITP_MSG_LOCALE.message.form.mandatory);
  495. return false;
  496. }
  497. }
  498. if ($.inArray('number', arry) > -1) {
  499. const regExp = /^[0-9]+$/;
  500. if (!regExp.test($(element).val())) {
  501. error(ITP_MSG_LOCALE.message.form.onlynumber);
  502. return false;
  503. }
  504. }
  505. if ($.inArray('float', arry) > -1) {
  506. if($(element).val() == '') return true;
  507. const regExp = /^\d+.?\d?\d?\d?$/;
  508. if (!regExp.test($(element).val())) {
  509. error(ITP_MSG_LOCALE.message.form.onlynumber);
  510. return false;
  511. }
  512. }
  513. if ($.inArray('tel', arry) > -1) {
  514. const regExp = /^\d{2,3}-\d{3,4}-\d{4}$/;
  515. if (!regExp.test($(element).val())) {
  516. error(ITP_MSG_LOCALE.message.form.wrongtelnumber);
  517. return false;
  518. }
  519. }
  520. if ($.inArray('email', arry) > -1) {
  521. const regExp = /^[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/i;
  522. if (!regExp.test($(element).val())) {
  523. error(ITP_MSG_LOCALE.message.form.wrongemail);
  524. return false;
  525. }
  526. }
  527. if ($.inArray('id', arry) > -1) {
  528. const regExp = /^[a-z]+[a-z0-9]{4,11}$/g;
  529. if (!regExp.test($(element).val())) {
  530. error(ITP_MSG_LOCALE.message.form.wronguserid);
  531. return false;
  532. }
  533. }
  534. if ($.inArray('id2', arry) > -1) {
  535. const regExp = /^[A-Za-z0-9+]*$/;
  536. if (!regExp.test($(element).val())) {
  537. error(ITP_MSG_LOCALE.message.form.wronguserid2);
  538. return false;
  539. }
  540. }
  541. if ($.inArray('password', arry) > -1) {
  542. const regExp = /^(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9])(?=.*[0-9]).{8,16}$/;
  543. if (!regExp.test($(element).val())) {
  544. error(ITP_MSG_LOCALE.message.form.wrongpassword);
  545. return false;
  546. }
  547. }
  548. if ($.inArray('url', arry) > -1) {
  549. const regExp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
  550. if (!regExp.test($(element).val())) {
  551. error(ITP_MSG_LOCALE.message.form.wronglink);
  552. return false;
  553. }
  554. }
  555. return true;
  556. };
  557. let itp_fn_form_clear_validate = function(modal, form) {
  558. $(form).find('.itp_ip').removeClass('has-error');
  559. $(form).find('.help-block').remove();
  560. if (modal != null) {
  561. $(modal).on('hidden.bs.modal', function() {
  562. $(form).find('.itp_ip').removeClass('has-error');
  563. $(form).find('.help-block').remove();
  564. });
  565. }
  566. };
  567. let itp_fn_form_event = {
  568. onKeyup: function(formId) {
  569. $(formId).find('input[data-key-up]').on('keyup', function() {
  570. let value = '';
  571. let arry = $(this).data('key-up').split(',');
  572. if ($.inArray('number', arry) > -1) {
  573. value = $(this).val().replace(/[^0-9]/g, "");
  574. }
  575. if ($.inArray('comma', arry) > -1) {
  576. value = $(this).val().replace(/[^0-9]/g, "")
  577. .replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  578. }
  579. if ($.inArray('regNo', arry) > -1) {
  580. value = $(this).val().replace(/[^0-9]/g, "")
  581. .replace(/(^[0-9]{3}|^0[0-9]{2})([0-9]+)?([0-9]{5})$/,"$1-$2-$3")
  582. }
  583. if ($.inArray('corpNo', arry) > -1) {
  584. if($(this).val().length > 13) return;
  585. value = $(this).val().replace(/[^0-9]/g, "")
  586. .replace(/(^[0-9]{6})([0-9]+)?([0-9]{7})$/,"######-#######")
  587. // .replace(/(\d{6})(\d{7})/, '######-#######')
  588. }
  589. if ($.inArray('tel', arry) > -1) {
  590. value = ($(this).val().startsWith('0')) ? $(this).val().replace(/[^0-9]/g, "")
  591. .replace(/(^02|^0505|^1[0-9]{3}|^0[0-9]{2})([0-9]+)?([0-9]{4})$/,"$1-$2-$3")
  592. .replace("--", "-") : '';
  593. }
  594. $(this).val(value);
  595. });
  596. },
  597. removeChar: function(formId) {
  598. $(formId).find('input[data-key-up]').each(function() {
  599. $(this).val($(this).val().replace(/[^0-9]/g, ""));
  600. });
  601. },
  602. isValid: function(formId, type) {
  603. var isValid = false;
  604. $(formId).find('input, select, checkbox, textarea').each(function(k) {
  605. if($(this).data('check-required')) {
  606. var arry = $(this).data('check-required').split(',');
  607. var alertMsg = $(this).data('alert-required');
  608. isValid = itp_fn_form_validate(formId, '#' + $(this).attr('id'), arry, undefined, alertMsg);
  609. if(!isValid) {
  610. if(alertMsg && alertMsg.length > 0) {
  611. itp_fn_modal_alert($(this).data('alert-msg'));
  612. // alert($(this).data('alert-msg'));
  613. }
  614. return false;
  615. }
  616. }
  617. });
  618. return isValid;
  619. }
  620. };
  621. let itp_fn_payment = {
  622. call: function(param, fn) {
  623. this.popup(param, fn);
  624. },
  625. popup: function(param, fn) {
  626. // 결제 팝업 결과
  627. var popFn = function(rowDataPop) {
  628. if(fn) fn(rowDataPop);
  629. };
  630. // 결제 팝업
  631. // 결제타입코드 : 10(선불(충전)), 20(후불(결제)), 30(후불(선결제))
  632. var args = {
  633. 'payTpCd': param.loanDvsn,
  634. 'brandId': param.brandId,
  635. 'storeId': param.storeId
  636. };
  637. fn_call_popup('biz', 'BIZPOP_PO_PAYMENT', '#ITP_ASIDE', popFn, args, 'M');
  638. }
  639. };
  640. let itp_fn_call_app = {
  641. barcode: function() {
  642. },
  643. payment: function(param) {
  644. location.replace('app:payment:' + param);
  645. },
  646. backPress: function() {
  647. location.replace('app:pageBack');
  648. }
  649. };
  650. let CommonObj = {
  651. listSize: 10,
  652. jsonParam: function(formId) {
  653. const param = $(formId).serializeObject();
  654. param.gridSize = this.listSize;
  655. return JSON.stringify(param);
  656. },
  657. init: function() {
  658. $('.modal.itp_modal .modal-content').draggable();
  659. $.fn.serializeObject = function() {
  660. var result = {};
  661. var extend = function(i, element) {
  662. var node = result[element.name];
  663. if ('undefined' !== typeof node && node !== null) {
  664. if ($.isArray(node)) {
  665. node.push($.trim(element.value));
  666. } else {
  667. result[element.name] = [node, $.trim(element.value)];
  668. }
  669. } else {
  670. result[element.name] = $.trim(element.value);
  671. }
  672. }
  673. $.each(this.serializeArray(), extend);
  674. return result;
  675. };
  676. $.fn.extend({
  677. treed: function(o) {
  678. var openedClass = 'glyphicon-minus text-primary';
  679. var closedClass = 'glyphicon-plus text-primary';
  680. if (typeof o != 'undefined') {
  681. if (typeof o.openedClass != 'undefined') {
  682. openedClass = o.openedClass;
  683. }
  684. if (typeof o.closedClass != 'undefined') {
  685. closedClass = o.closedClass;
  686. }
  687. };
  688. var tree = $(this);
  689. tree.addClass('tree');
  690. tree.find('li').has('ul').each(function() {
  691. var branch = $(this);
  692. branch.find('.list-group-item').first().prepend('<i class="indicator glyphicon ' + closedClass + '"></i>');
  693. branch.addClass('branch');
  694. branch.on('click', function(e) {
  695. if (this == e.target) {
  696. var icon = $(this).find('.list-group-item').first().children('i:first');
  697. icon.toggleClass(openedClass + ' ' + closedClass);
  698. $(this).children('ul').children().toggle();
  699. }
  700. });
  701. branch.children('ul').children().toggle();
  702. //branch.children('ul').children().show();
  703. });
  704. tree.find('.branch .indicator').each(function() {
  705. $(this).on('click', function() {
  706. $(this).closest('li').click();
  707. return false;
  708. });
  709. });
  710. }
  711. });
  712. },
  713. getParameter: function(name) {
  714. var rtnval = '';
  715. var nowAddress = unescape(location.href);
  716. var parameters = (nowAddress.slice(nowAddress.indexOf('?') + 1,
  717. nowAddress.length)).split('&');
  718. for (var i = 0; i < parameters.length; i++) {
  719. var varName = parameters[i].split('=')[0];
  720. if (varName.toUpperCase() === name.toUpperCase()) {
  721. rtnval = parameters[i].split('=')[1];
  722. break;
  723. }
  724. }
  725. return rtnval;
  726. },
  727. comma: {
  728. set: function(str) {
  729. str = String(str);
  730. return str.replace(/(\d)(?=(?:\d{3})+(?!\d))/g, '$1,');
  731. },
  732. remove: function(str) {
  733. str = String(str);
  734. return str.replace(/[^\d]+/g, '');
  735. }
  736. },
  737. currency: {
  738. add: function(val, curr) {
  739. return CommonObj.comma.set(val).concat((curr === undefined) ? '원' : curr);
  740. },
  741. remove: function(val) {
  742. return val.replace(/[^0-9]/g, '');
  743. }
  744. },
  745. onlyNumber: function(str) {
  746. return (str) ? str.replace(/[^0-9]/g, '') : str;
  747. },
  748. isApp: (/oqpo_android|oqpo_ios/).test(navigator.userAgent.toLowerCase())
  749. };
  750. function itp_fn_date_format(date, type) {
  751. let month = date.getMonth() + 1;
  752. let day = date.getDate();
  753. let hour = date.getHours();
  754. let minute = date.getMinutes();
  755. let second = date.getSeconds();
  756. month = month >= 10 ? month : '0' + month;
  757. day = day >= 10 ? day : '0' + day;
  758. hour = hour >= 10 ? hour : '0' + hour;
  759. minute = minute >= 10 ? minute : '0' + minute;
  760. second = second >= 10 ? second : '0' + second;
  761. if(type && type == 1) {
  762. return date.getFullYear() + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  763. } else if(type && type == 2) {
  764. return date.getFullYear() + '.' + month + '.' + day;
  765. } else if(type && type == 3) {
  766. return date.getFullYear() + '' + month + '' + day;
  767. } else if(type && type == 4) {
  768. return date.getFullYear() + '-' + month + '-' + day;
  769. } else {
  770. return date.getFullYear() + month + day + hour + minute + second;
  771. }
  772. }
  773. function itp_fn_date_add(type, iAdd) {
  774. var date = new Date();
  775. if(type === 'Y') date.setFullYear(date.getFullYear() + iAdd);
  776. else if(type === 'M') date.setMonth(date.getMonth() + iAdd);
  777. else if(type === 'D') date.setDate(date.getDate() + iAdd);
  778. return itp_fn_date_format(date, 4);
  779. }
  780. function itp_fn_fire_window_resize() {
  781. var evt = document.createEvent('HTMLEvents');
  782. evt.initEvent('resize', true, false);
  783. window.dispatchEvent(evt);
  784. };
  785. const ITP_DATE_LANGUAGE = (function() {
  786. let lang = ITP_LANGUAGE;
  787. if (lang == 'en') {lang = ITP_LANGUAGE + '-GB';}
  788. var agrs = {language: lang};
  789. return agrs;
  790. }());