config.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. //JS버전
  2. var today = new Date();
  3. const js_version = itp_fn_date_format(today);
  4. requirejs.config({
  5. baseUrl: ITP_CONTEXTPATH,
  6. paths: {
  7. 'jquery': 'js/jquery.min',
  8. 'jquery-ui': 'js/jquery-ui.min',
  9. 'jquery.bootstrap': 'bootstrap/dist/js/bootstrap.min',
  10. 'jquery.bootstrap.fileUpload': 'bootstrap-fileUpload/dist/bootstrap-FileUpload.js?version='+js_version,
  11. 'jquery.bootstrap.datepicker': 'bootstrap-datepicker/js/bootstrap-datepicker',
  12. 'jquery.bootstrap.datepicker.locale': 'bootstrap-datepicker/locales/bootstrap-datepicker.' + ITP_LANGUAGE + '.min',
  13. 'message.locale': 'js/app/locales/locale-' + ITP_LANGUAGE + '.js?version='+js_version,
  14. 'crypto': 'js/crypto', //Crypto 암호화 js
  15. },
  16. shim: {
  17. 'jquery.bootstrap': {
  18. deps: [
  19. 'jquery',
  20. 'jquery-ui'
  21. ]
  22. },
  23. 'jquery.bootstrap.fileUpload': {
  24. deps: ['jquery.bootstrap']
  25. },
  26. 'jquery.bootstrap.datepicker.locale': {
  27. deps: [
  28. 'jquery.bootstrap',
  29. 'jquery.bootstrap.datepicker'
  30. ]
  31. },
  32. }
  33. });
  34. require([
  35. 'jquery',
  36. 'jquery.bootstrap',
  37. 'jquery.bootstrap.datepicker.locale',
  38. 'message.locale'
  39. ], function($) {
  40. history.pushState(null, null, location.href);
  41. CommonObj.init();
  42. $('#ITP_BTN_HOME').on('click', function() {
  43. location.replace(MOBILE_CONTEXTPATH + '/app/main.html');
  44. });
  45. $('#ITP_MOBILE_BTN_MENU').on('click', function() {
  46. $('#ITP_MENU').toggle();
  47. $('#ITP_MENU').toggleClass('itp_open_nav');
  48. });
  49. $('#ITP_BTN_USER').on('click', function() {
  50. });
  51. $('#ITP_MOBILE_BTN_SETTING').on('click', function() {
  52. $('#ITP_MENU').toggle();
  53. });
  54. // 로그아웃 버튼
  55. $('#ITP_MOBILE_BTN_LOGOUT').click(function() {
  56. console.log('ITP_BTN_LOGOUT');
  57. fnLogout();
  58. });
  59. if(VIEW_PAGE !== 'LOGIN') {
  60. var data = JSON.parse(sessionStorage.getItem('itp_login_info'));
  61. CONN_KEY = data.connKey; //로그인 했을때 넣었던 키를 가져옴
  62. var callbackFn = function(result) {
  63. CODE_LIST = result.codeList;
  64. AUTH_MENU_LIST = result.authMenuList;
  65. ACT_LIST = result.actList;
  66. LOGIN_USER_INFO = result.userInfo;
  67. // 사용자 정보 만들기
  68. fn_make_user_info.init();
  69. // 왼쪽 메뉴 만들기
  70. fn_make_slide_menu.init();
  71. };
  72. fn_ajax_call('/api/session/data-app', null, callbackFn, 'GET');
  73. }
  74. });
  75. var itp_fn_logined_check = function(user_nm_update, fn) {
  76. var now, expiration, data = false;
  77. data = sessionStorage.getItem('itp_login_info');
  78. if(data) {
  79. data = JSON.parse(data);
  80. now = new Date();
  81. expiration = new Date(data.timestamp);
  82. expiration.setMinutes(expiration.getMinutes() + 60);
  83. if (now.getTime() > expiration.getTime()) {
  84. data = false;
  85. fnSessionOut();
  86. } else {
  87. sessionStorage.setItem('itp_login_info', JSON.stringify({
  88. timestamp: new Date(),
  89. connKey: data.connKey //Jwt키를 가져와서 세션 스토리지에 저장
  90. }));
  91. if(user_nm_update && user_nm_update == true) {
  92. if (fn !== undefined || typeof fn !== 'undefined') {
  93. fn();
  94. }
  95. }
  96. }
  97. } else {
  98. // 로그인 페이지로 이동
  99. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/login.html');
  100. }
  101. };
  102. var fn_make_user_info = {
  103. init : function() {
  104. this.set();
  105. },
  106. view: function() {
  107. $('#ITP_LOGIN_USER_NM').text(this.get('userNm'));
  108. $('#ITP_LOGIN_USER_ID').text(this.get('userId'));
  109. $('.name_info .fnBrnadNm').text(this.get('brandNm'));
  110. if(this.get('storeNm') !== '') {
  111. $('.name_info .fnStoreNm').text(this.get('storeNm'));
  112. } else {
  113. $('.name_info .fnLblDash').hide();
  114. $('.name_info .fnLblStoreNm').hide();
  115. }
  116. },
  117. isEmpty: function() {
  118. return sessionStorage.getItem('itp_manage_user_info') === null;
  119. },
  120. set: function() {
  121. if(this.isEmpty()) {
  122. sessionStorage.setItem('itp_manage_user_info', JSON.stringify(LOGIN_USER_INFO));
  123. } else {
  124. if(typeof(LOGIN_USER_INFO) == "string") {
  125. var sessionUserInfo = this.get();
  126. $.each(JSON.parse(LOGIN_USER_INFO), function(key, value) {
  127. sessionUserInfo[key] = value;
  128. });
  129. sessionStorage.setItem('itp_manage_user_info', JSON.stringify(sessionUserInfo));
  130. }
  131. }
  132. this.view();
  133. },
  134. get: function(key) {
  135. var sessionUserInfo = JSON.parse(sessionStorage.getItem('itp_manage_user_info'));
  136. return (key === undefined || key === null) ? sessionUserInfo : sessionUserInfo[key];
  137. }
  138. };
  139. var fn_make_slide_menu = {
  140. init: function() {
  141. $('.menu_select .panel-group').empty();
  142. this.make();
  143. },
  144. make: function() {
  145. var selector = '.menu_select .panel-group > .panel_list:last';
  146. $.each(AUTH_MENU_LIST, function(key, value) {
  147. if(value.level === 2) { // LEVEL2
  148. $('.menu_select .panel-group').append($('#ITP_AJAX_MAIN_SLIDE_LEVEL2_ROWCOPY').val());
  149. $(selector).find('.fnMenuNm').text(value.menuNm);
  150. $(selector).find('.accordion-toggle').attr('href', '#ITP_NAV_'+value.menuNo);
  151. $(selector).find('.panel-collapse').attr('id', 'ITP_NAV_'+value.menuNo);
  152. $(selector).find('.fnLevelBottomList').empty();
  153. } else if(value.level === 3) { // LEVEL3
  154. $(selector).find('.fnLevelBottomList').append($('#ITP_AJAX_MAIN_SLIDE_LEVEL3_ROWCOPY').val());
  155. $(selector + ' .fnLevelBottomList .itp_svg_in:last').find('.fnMenuNm').text(value.menuNm);
  156. $(selector + ' .fnLevelBottomList .itp_svg_in:last').attr('data-itp-nav-id', value.menuId);
  157. $(selector + ' .fnLevelBottomList .itp_svg_in:last').attr('data-conn-url', value.connUrl);
  158. $(selector + ' .fnLevelBottomList .itp_svg_in:last').attr('data-open-cd', value.openCd);
  159. $(selector + ' .fnLevelBottomList .itp_svg_in:last').attr('id', value.menuId + '_PAGE_NO');
  160. // $(selector + ' .fnLevelBottomList .itp_svg_in:last').find('.itp_nav_link').attr('data-itp-nav-id', value.menuId);
  161. // $(selector + ' .fnLevelBottomList .itp_svg_in:last').find('.itp_nav_link').attr('data-conn-url', value.connUrl);
  162. // $(selector + ' .fnLevelBottomList .itp_svg_in:last').find('.itp_nav_link').attr('data-open-cd', value.openCd);
  163. // $(selector + ' .fnLevelBottomList .itp_svg_in:last').find('.itp_nav_link').attr('id', value.menuId + '_PAGE_NO');
  164. }
  165. });
  166. this.action();
  167. },
  168. action: function() {
  169. var _this = this;
  170. $('#ITP_SIDEBAR .accordion-toggle').off('click').on('click', function() {
  171. console.log('accordion-toggle');
  172. });
  173. $('#ITP_SIDEBAR .itp_nav_link').off('click').on('click', function() {
  174. const id = $(this).attr('data-itp-nav-id');
  175. const connUrl = $(this).attr('data-conn-url');
  176. const openCd = $(this).attr('data-open-cd');
  177. console.log('connUrl ===> ' + connUrl + '\nopenCd ===> ' + openCd);
  178. if(openCd === 'C') {
  179. const href = MOBILE_CONTEXTPATH + connUrl;
  180. _this.loadPage(id, href);
  181. }
  182. });
  183. },
  184. loadPage: function(id, href, param) {
  185. //로그인체크
  186. itp_fn_logined_check();
  187. $.ajax({
  188. contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
  189. url: href,
  190. data: param,
  191. type: 'POST',
  192. dataType: 'html',
  193. async: false,
  194. timeout: 10000,
  195. beforeSend: function() {
  196. },
  197. complete: function() {
  198. },
  199. success: function(html) {
  200. $('#ITP_CONTAINER div.itp_mobile_contents').empty().append(html);
  201. //JS파일적용
  202. const js = "<script src=\"../js/app/"+id.substring(0, id.length - 5).toLowerCase()+"/ITP_"+id+".js?version="+js_version+"\"></script>";
  203. console.log(js);
  204. $('#ITP_CONTAINER #ITP_MOBILE_'+id+' #ITP_MOBILE_JS').append(js);
  205. $('#ITP_MENU').toggle();
  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 fnHashed(code) { //유니코드로 들어오는 해쉬키를 스트링으로 변환
  294. return decodeURIComponent(JSON.parse('"' + code.replace(/\"/g, '\\"') + '"'));
  295. }
  296. function fnLogout() { //로그아웃
  297. var callbackFn = function(result) {
  298. sessionStorage.removeItem('itp_login_info'); //Jwt 키 제거
  299. sessionStorage.removeItem('itp_manage_user_info'); //로그인 사용자 정보 제거
  300. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/login.html');
  301. };
  302. fn_ajax_call('/api/member/sign-out', null, callbackFn, 'PATCH');
  303. }
  304. function fnSessionOut() { //1시간 동안 아무것도 안할때 또는 강제 만료시킬때 사용
  305. var callbackFn = function(result) {
  306. sessionStorage.removeItem('itp_login_info'); //Jwt 키 제거
  307. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/login.html');
  308. };
  309. fn_ajax_call('/api/session/expire', null, callbackFn, 'PATCH');
  310. }
  311. // 2021.07.07 송호성 추가
  312. function fn_call_popup(type, popnm, container, popFn, args, returnType) {
  313. console.log('[ITP_CALL_POPUP] type = ' + type + ', popnm = ' + popnm);
  314. $.ajax({
  315. contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
  316. url: MOBILE_CONTEXTPATH + '/app/popup/'+type+'/'+popnm+'.html',
  317. type: 'POST',
  318. dataType: 'html',
  319. async: false,
  320. timeout: 10000,
  321. beforeSend: function() {
  322. //$('#ITP_OVERLAY').show();
  323. },
  324. complete: function() {
  325. //$('#ITP_OVERLAY').hide();
  326. },
  327. success: function(html) {
  328. var append = function() {
  329. var deferred = $.Deferred();
  330. try {
  331. $(container).empty();
  332. $(container).append(html);
  333. deferred.resolve();
  334. } catch(err) {
  335. deferred.reject(err);
  336. }
  337. return deferred.promise();
  338. };
  339. append().done(function() {
  340. const js = '<script src="'+MOBILE_CONTEXTPATH+'/js/app/popup/'+type+'/ITP_'+popnm+'.js?version='+js_version+'"></script>';
  341. $('#ITP_ASIDE #ITP_'+popnm+' #ITP_POPUP_JS').empty();
  342. $('#ITP_ASIDE #ITP_'+popnm+' #ITP_POPUP_JS').append(js);
  343. eval('itp_fn_' + popnm)(popFn, args, returnType);
  344. $('.modal.itp_modal .modal-content').draggable();
  345. });
  346. },
  347. error: function(xhr, status, error) {
  348. if (xhr.status == 401) location.href = MOBILE_CONTEXTPATH + '/';
  349. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failData);
  350. },
  351. fail: function() {
  352. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failData);
  353. }
  354. });
  355. };
  356. //AJAX 양식 (이렇게 사용하시면 됩니다.)
  357. function fn_ajax_call(href, param, fn, type) {
  358. $.ajax({
  359. contentType: 'application/json',
  360. url: DOMAIN + href,
  361. data: param,
  362. type: type,
  363. async: false,
  364. timeout: 10000,
  365. xhrFields: {
  366. withCredentials: true //Cross Domain 처리
  367. },
  368. beforeSend: function(xhr) {
  369. $('#ITP_OVERLAY').show();
  370. xhr.setRequestHeader('X-AUTH-TOKEN', CONN_KEY); //Jwt 토큰을 헤더에 담아서 보낸다.
  371. },
  372. complete: function() {
  373. $('#ITP_OVERLAY').hide();
  374. },
  375. success: function(result) {
  376. console.log(result);
  377. if (result.code !== undefined) { //성공시에도 메세지가 있으면 얼럿 예)저장되었습니다.
  378. itp_fn_modal_alert_ajax(result.message);
  379. }
  380. if (fn !== undefined || typeof fn !== 'undefined') fn(result);
  381. },
  382. error: function(xhr, status, error) {
  383. if (xhr.responseJSON !== undefined) { //실패시 서버에서 내려주는 메세지 얼럿
  384. itp_fn_modal_alert_ajax(xhr.responseJSON.message);
  385. if (xhr.status == 401) { //401에러가 떨어지면 로그인페이지로 이동
  386. sessionStorage.removeItem('itp_login_info'); //Jwt 키 제거
  387. $(location).attr('href', MOBILE_CONTEXTPATH + '/app/login.html');
  388. }
  389. } else {
  390. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failProcess);
  391. }
  392. },
  393. fail: function() {
  394. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failProcess);
  395. }
  396. });
  397. };
  398. function itp_fn_modal_alert(msg) {
  399. $('#ITP_MODAL_ALERT_CANCEL').hide();
  400. $('#ITP_MODAL_ALERT').modal('show');
  401. $('#ITP_MODAL_ALERT').find('.itp_alert_txt').html(msg);
  402. $('#ITP_MODAL_ALERT_CONFIRM').off('click');
  403. $('#ITP_MODAL_ALERT_CONFIRM').on('click', function() {
  404. $('#ITP_MODAL_ALERT').modal('hide');
  405. });
  406. };
  407. function itp_fn_modal_alert_ajax(msg) {
  408. $('#ITP_MODAL_ALERT_AJAX').modal('show');
  409. $('#ITP_MODAL_ALERT_AJAX').find('.itp_alert_txt').html(msg);
  410. $('#ITP_MODAL_ALERT_AJAX_CONFIRM').off('click');
  411. $('#ITP_MODAL_ALERT_AJAX_CONFIRM').on('click', function() {
  412. $('#ITP_MODAL_ALERT_AJAX').modal('hide');
  413. });
  414. };
  415. function itp_fn_modal_duplicate(label, input) {
  416. let msg = ITP_MSG_LOCALE.message.form.duplicate;
  417. msg = msg.replace('{0}', label);
  418. $('#ITP_MODAL_ALERT_CANCEL').hide();
  419. $('#ITP_MODAL_ALERT').modal('show');
  420. $('#ITP_MODAL_ALERT').find('.itp_alert_txt').html(msg);
  421. $('#ITP_MODAL_ALERT_CONFIRM').off('click');
  422. $('#ITP_MODAL_ALERT_CONFIRM').on('click', function() {
  423. $('#ITP_MODAL_ALERT').modal('hide');
  424. if (input != null) {
  425. $(input).focus();
  426. }
  427. });
  428. };
  429. function itp_fn_modal_confirm(msg, fn, args) {
  430. $('#ITP_MODAL_ALERT_CANCEL').show();
  431. $('#ITP_MODAL_ALERT').modal('show');
  432. $('#ITP_MODAL_ALERT').find('.itp_alert_txt').html(msg);
  433. if (fn !== undefined || typeof fn !== 'undefined') {
  434. $('#ITP_MODAL_ALERT_CONFIRM').off('click');
  435. $('#ITP_MODAL_ALERT_CONFIRM').on('click', function() {
  436. fn.callBack(args);
  437. $('#ITP_MODAL_ALERT').modal('hide');
  438. });
  439. }
  440. };
  441. function itp_fn_date_format(date, type) {
  442. let month = date.getMonth() + 1;
  443. let day = date.getDate();
  444. let hour = date.getHours();
  445. let minute = date.getMinutes();
  446. let second = date.getSeconds();
  447. month = month >= 10 ? month : '0' + month;
  448. day = day >= 10 ? day : '0' + day;
  449. hour = hour >= 10 ? hour : '0' + hour;
  450. minute = minute >= 10 ? minute : '0' + minute;
  451. second = second >= 10 ? second : '0' + second;
  452. if(type && type == 1) {
  453. return date.getFullYear() + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  454. } else if(type && type == 2) {
  455. return date.getFullYear() + '.' + month + '.' + day;
  456. } else if(type && type == 3) {
  457. return date.getFullYear() + '' + month + '' + day;
  458. } else {
  459. return date.getFullYear() + month + day + hour + minute + second;
  460. }
  461. }
  462. let itp_fn_form_validate = function(form, element, arry, msg, type) {
  463. var error = function(txt) {
  464. if (type != 'ONLYCHK') {
  465. if (msg == undefined || typeof msg == 'undefined') {
  466. msg = txt;
  467. }
  468. $(element).closest('.itp_ip').addClass('has-error');
  469. var error_msg = $('<span class="help-block">' + msg + '</span>');
  470. if($(element).parent('.input-group').length) {
  471. error_msg.insertAfter($(element).parent());
  472. } else {
  473. error_msg.insertAfter($(element));
  474. }
  475. }
  476. };
  477. if ($.inArray('empty', arry) > -1) {
  478. if ($(element).val() == '' || $(element).val() < 1) {
  479. error(ITP_MSG_LOCALE.message.form.mandatory);
  480. return false;
  481. }
  482. }
  483. if ($.inArray('emptyNum', arry) > -1) {
  484. if ($(element).val() == '' || $(element).val() < 0) {
  485. error(ITP_MSG_LOCALE.message.form.mandatory);
  486. return false;
  487. }
  488. }
  489. if ($.inArray('number', arry) > -1) {
  490. const regExp = /^[0-9]+$/;
  491. if (!regExp.test($(element).val())) {
  492. error(ITP_MSG_LOCALE.message.form.onlynumber);
  493. return false;
  494. }
  495. }
  496. if ($.inArray('float', arry) > -1) {
  497. if($(element).val() == '') return true;
  498. const regExp = /^\d+.?\d?\d?\d?$/;
  499. if (!regExp.test($(element).val())) {
  500. error(ITP_MSG_LOCALE.message.form.onlynumber);
  501. return false;
  502. }
  503. }
  504. if ($.inArray('tel', arry) > -1) {
  505. const regExp = /^\d{2,3}-\d{3,4}-\d{4}$/;
  506. if (!regExp.test($(element).val())) {
  507. error(ITP_MSG_LOCALE.message.form.wrongtelnumber);
  508. return false;
  509. }
  510. }
  511. if ($.inArray('email', arry) > -1) {
  512. const regExp = /^[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/i;
  513. if (!regExp.test($(element).val())) {
  514. error(ITP_MSG_LOCALE.message.form.wrongemail);
  515. return false;
  516. }
  517. }
  518. if ($.inArray('id', arry) > -1) {
  519. const regExp = /^[a-z]+[a-z0-9]{4,11}$/g;
  520. if (!regExp.test($(element).val())) {
  521. error(ITP_MSG_LOCALE.message.form.wronguserid);
  522. return false;
  523. }
  524. }
  525. if ($.inArray('id2', arry) > -1) {
  526. const regExp = /^[A-Za-z0-9+]*$/;
  527. if (!regExp.test($(element).val())) {
  528. error(ITP_MSG_LOCALE.message.form.wronguserid2);
  529. return false;
  530. }
  531. }
  532. if ($.inArray('password', arry) > -1) {
  533. const regExp = /^(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9])(?=.*[0-9]).{8,16}$/;
  534. if (!regExp.test($(element).val())) {
  535. error(ITP_MSG_LOCALE.message.form.wrongpassword);
  536. return false;
  537. }
  538. }
  539. if ($.inArray('url', arry) > -1) {
  540. const regExp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
  541. if (!regExp.test($(element).val())) {
  542. error(ITP_MSG_LOCALE.message.form.wronglink);
  543. return false;
  544. }
  545. }
  546. return true;
  547. };
  548. let itp_fn_form_event = {
  549. onKeyup: function(formId) {
  550. $(formId).find('input[data-key-up]').on('keyup', function() {
  551. let value = '';
  552. let arry = $(this).data('key-up').split(',');
  553. if ($.inArray('number', arry) > -1) {
  554. value = $(this).val().replace(/[^0-9]/g, "");
  555. }
  556. if ($.inArray('comma', arry) > -1) {
  557. value = $(this).val().replace(/[^0-9]/g, "")
  558. .replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  559. }
  560. if ($.inArray('regNo', arry) > -1) {
  561. value = $(this).val().replace(/[^0-9]/g, "")
  562. .replace(/(^[0-9]{3}|^0[0-9]{2})([0-9]+)?([0-9]{5})$/,"$1-$2-$3")
  563. }
  564. if ($.inArray('corpNo', arry) > -1) {
  565. if($(this).val().length > 13) return;
  566. value = $(this).val().replace(/[^0-9]/g, "")
  567. .replace(/(^[0-9]{6})([0-9]+)?([0-9]{7})$/,"######-#######")
  568. // .replace(/(\d{6})(\d{7})/, '######-#######')
  569. }
  570. if ($.inArray('tel', arry) > -1) {
  571. value = ($(this).val().startsWith('0')) ? $(this).val().replace(/[^0-9]/g, "")
  572. .replace(/(^02|^0505|^1[0-9]{3}|^0[0-9]{2})([0-9]+)?([0-9]{4})$/,"$1-$2-$3")
  573. .replace("--", "-") : '';
  574. }
  575. $(this).val(value);
  576. });
  577. },
  578. removeChar: function(formId) {
  579. $(formId).find('input[data-key-up]').each(function() {
  580. $(this).val($(this).val().replace(/[^0-9]/g, ""));
  581. });
  582. },
  583. isValid: function(formId, type) {
  584. var isValid = false;
  585. $(formId).find('input, select, checkbox, textarea').each(function(k) {
  586. if($(this).data('check-required')) {
  587. var arry = $(this).data('check-required').split(',');
  588. var alertMsg = $(this).data('alert-required');
  589. console.log(alertMsg);
  590. isValid = itp_fn_form_validate(formId, '#' + $(this).attr('id'), arry, undefined, alertMsg);
  591. if(!isValid) {
  592. if(alertMsg && alertMsg.length > 0) {
  593. // itp_fn_modal_alert($(this).data('alert-msg'));
  594. alert($(this).data('alert-msg'));
  595. }
  596. return false;
  597. }
  598. }
  599. });
  600. return isValid;
  601. }
  602. };
  603. let CommonObj = {
  604. init: function() {
  605. $.fn.serializeObject = function() {
  606. var result = {};
  607. var extend = function(i, element) {
  608. var node = result[element.name];
  609. if ('undefined' !== typeof node && node !== null) {
  610. if ($.isArray(node)) {
  611. node.push($.trim(element.value));
  612. } else {
  613. result[element.name] = [node, $.trim(element.value)];
  614. }
  615. } else {
  616. result[element.name] = $.trim(element.value);
  617. }
  618. }
  619. $.each(this.serializeArray(), extend);
  620. return result;
  621. };
  622. $.fn.extend({
  623. treed: function(o) {
  624. var openedClass = 'glyphicon-minus text-primary';
  625. var closedClass = 'glyphicon-plus text-primary';
  626. if (typeof o != 'undefined') {
  627. if (typeof o.openedClass != 'undefined') {
  628. openedClass = o.openedClass;
  629. }
  630. if (typeof o.closedClass != 'undefined') {
  631. closedClass = o.closedClass;
  632. }
  633. };
  634. var tree = $(this);
  635. tree.addClass('tree');
  636. tree.find('li').has('ul').each(function() {
  637. var branch = $(this);
  638. branch.find('.list-group-item').first().prepend('<i class="indicator glyphicon ' + closedClass + '"></i>');
  639. branch.addClass('branch');
  640. branch.on('click', function(e) {
  641. if (this == e.target) {
  642. var icon = $(this).find('.list-group-item').first().children('i:first');
  643. icon.toggleClass(openedClass + ' ' + closedClass);
  644. $(this).children('ul').children().toggle();
  645. }
  646. });
  647. branch.children('ul').children().toggle();
  648. //branch.children('ul').children().show();
  649. });
  650. tree.find('.branch .indicator').each(function() {
  651. $(this).on('click', function() {
  652. $(this).closest('li').click();
  653. return false;
  654. });
  655. });
  656. }
  657. });
  658. }
  659. };