popup.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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.number': 'js/jquery.number',
  10. 'jquery.sortable': 'js/jquery.ui.sortable',
  11. 'jquery.grid.addons': 'plugins/grid.addons',
  12. 'jquery.bootstrap': 'bootstrap/dist/js/bootstrap.min',
  13. 'jquery.bootstrap.treeview': 'bootstrap/dist/js/bootstrap-treeview',
  14. 'jquery.bootstrap.fileUpload': 'bootstrap-fileUpload/dist/bootstrap-FileUpload',
  15. 'jquery.bootstrap.datepicker': 'bootstrap-datepicker/js/bootstrap-datepicker',
  16. 'jquery.bootstrap.datepicker.locale': 'bootstrap-datepicker/locales/bootstrap-datepicker.' + ITP_LANGUAGE + '.min',
  17. 'jquery.jqGrid': 'js/jquery.jqGrid',
  18. 'jquery.jqGrid.grouping': 'js/grid.grouping',
  19. 'jquery.jqGrid.inlinedit': 'js/grid.inlinedit',
  20. 'jquery.jqGrid.formedit': 'js/grid.formedit',
  21. 'jquery.jqGrid.celledit': 'js/grid.celledit',
  22. 'jquery.jqGrid.treegrid': 'js/grid.treegrid',
  23. 'jquery.jqGrid.fmatter': 'js/jquery.fmatter',
  24. 'jquery.jqGrid.locale': 'js/i18n/grid.locale-' + ITP_LANGUAGE,
  25. 'smarteditor2': 'se2/js/service/HuskyEZCreator',
  26. 'message.locale': 'js/app/locales/locale-' + ITP_LANGUAGE + '.js?version='+js_version,
  27. 'crypto': 'js/crypto' //Crypto 암호화 js
  28. },
  29. shim: {
  30. 'jquery.bootstrap': {
  31. deps: [
  32. 'jquery',
  33. 'jquery-ui'
  34. ]
  35. },
  36. 'jquery.bootstrap.treeview': {
  37. deps: ['jquery.bootstrap']
  38. },
  39. 'jquery.bootstrap.fileUpload': {
  40. deps: ['jquery.bootstrap']
  41. },
  42. 'jquery.bootstrap.datepicker.locale': {
  43. deps: [
  44. 'jquery.bootstrap',
  45. 'jquery.bootstrap.datepicker'
  46. ]
  47. },
  48. 'jquery.jqGrid.locale': {
  49. deps: [
  50. 'jquery.jqGrid',
  51. 'jquery.jqGrid.grouping',
  52. 'jquery.jqGrid.inlinedit',
  53. 'jquery.jqGrid.formedit',
  54. 'jquery.jqGrid.celledit',
  55. 'jquery.jqGrid.treegrid',
  56. 'jquery.jqGrid.fmatter'
  57. ]
  58. }
  59. }
  60. });
  61. require([
  62. 'jquery',
  63. 'jquery.bootstrap',
  64. 'jquery.bootstrap.datepicker.locale',
  65. 'jquery.jqGrid.locale',
  66. 'message.locale'
  67. ], function($) {
  68. $.jgrid.styleUI.Bootstrap.base.rowTable = 'table table-bordered table-striped';
  69. $.jgrid.defaults.styleUI = 'Bootstrap';
  70. $.jgrid.defaults.datatype = 'json';
  71. $.jgrid.defaults.mtype = 'POST';
  72. $.jgrid.defaults.width = 782;
  73. $.jgrid.defaults.height = '100%';
  74. $.jgrid.defaults.autowidth = true;
  75. $.jgrid.defaults.shrinkToFit = true;
  76. $.jgrid.defaults.viewrecords = true;
  77. $.jgrid.defaults.altRows = true;
  78. $.jgrid.defaults.loadonce = false;
  79. $.jgrid.defaults.resizable = true;
  80. $.jgrid.defaults.multiSort = false;
  81. $.jgrid.defaults.cellEdit = false;
  82. $.jgrid.defaults.multiselect = true;
  83. $.jgrid.defaults.multiboxonly = true;
  84. $.jgrid.defaults.outoencode = true;
  85. $.jgrid.defaults.cellsubmit = 'clientArray';
  86. $.jgrid.defaults.page = 1;
  87. $.jgrid.defaults.rowNum = 20;
  88. $.jgrid.defaults.rownumWidth = 50;
  89. //$.jgrid.defaults.multiselectWidth = 30;
  90. $.jgrid.defaults.jsonReader = {
  91. root: 'gridRows',
  92. page: 'gridPage',
  93. total: 'gridTotal',
  94. records: 'gridRecords',
  95. repeatitems: false,
  96. cell: 'cell'
  97. };
  98. $.jgrid.defaults.ajaxGridOptions = {
  99. contentType: 'application/json'
  100. };
  101. $.jgrid.defaults.treeGridModel = 'adjacency';
  102. $.jgrid.defaults.ExpandColClick = true;
  103. $.jgrid.defaults.tree_root_level = 0;
  104. $.jgrid.defaults.treeReader = {
  105. level_field: 'level',
  106. leaf_field: 'leaf'
  107. };
  108. history.pushState(null, null, location.href);
  109. window.onpopstate = function () {
  110. itp_fn_modal_alert(ITP_MSG_LOCALE.message.page.noBack);
  111. history.go(1);
  112. };
  113. $('[data-toggle="tooltip"]').tooltip();
  114. $('.modal.itp_modal .modal-content').draggable();
  115. $.fn.clearForm = function() {
  116. return this.each(function() {
  117. var type = this.type, tag = this.tagName.toLowerCase();
  118. if (tag == 'form')
  119. return $(':input',this).clearForm();
  120. if (type == 'text' || type == 'password' || tag == 'textarea'|| type == 'hidden')
  121. this.value = '';
  122. else if (type == 'checkbox' || type == 'radio')
  123. this.checked = false;
  124. else if (tag == 'select')
  125. this.selectedIndex = -1;
  126. });
  127. };
  128. $.fn.serializeObject = function() {
  129. var result = {};
  130. var extend = function(i, element) {
  131. var node = result[element.name];
  132. if ('undefined' !== typeof node && node !== null) {
  133. if ($.isArray(node)) {
  134. node.push($.trim(element.value));
  135. } else {
  136. result[element.name] = [node, $.trim(element.value)];
  137. }
  138. } else {
  139. result[element.name] = $.trim(element.value);
  140. }
  141. }
  142. $.each(this.serializeArray(), extend);
  143. return result;
  144. };
  145. $.fn.extend({
  146. treed: function(o) {
  147. var openedClass = 'glyphicon-minus text-primary';
  148. var closedClass = 'glyphicon-plus text-primary';
  149. if (typeof o != 'undefined') {
  150. if (typeof o.openedClass != 'undefined') {
  151. openedClass = o.openedClass;
  152. }
  153. if (typeof o.closedClass != 'undefined') {
  154. closedClass = o.closedClass;
  155. }
  156. };
  157. var tree = $(this);
  158. tree.addClass('tree');
  159. tree.find('li').has('ul').each(function() {
  160. var branch = $(this);
  161. branch.find('.list-group-item').first().prepend('<i class="indicator glyphicon ' + closedClass + '"></i>');
  162. branch.addClass('branch');
  163. branch.on('click', function(e) {
  164. if (this == e.target) {
  165. var icon = $(this).find('.list-group-item').first().children('i:first');
  166. icon.toggleClass(openedClass + ' ' + closedClass);
  167. $(this).children('ul').children().toggle();
  168. }
  169. });
  170. branch.children('ul').children().toggle();
  171. //branch.children('ul').children().show();
  172. });
  173. tree.find('.branch .indicator').each(function() {
  174. $(this).on('click', function() {
  175. $(this).closest('li').click();
  176. return false;
  177. });
  178. });
  179. }
  180. });
  181. var popNo = itp_fn_get_url_param('popNo');
  182. var preview = itp_fn_get_url_param('preview');
  183. $('#ITP_POPUP_CHK_TODAY').on('change', function() {
  184. //alert($('#ITP_POPUP_CHK_TODAY').is(':checked'));
  185. if(!preview || preview != 'Y') {
  186. if($('#ITP_POPUP_CHK_TODAY').is(':checked')) { // 오늘 하루 그만 보기
  187. itp_fn_set_cookie(popNo, "Y", 1);
  188. } else {
  189. itp_fn_set_cookie(popNo, "N", 1);
  190. }
  191. }
  192. });
  193. var data = JSON.parse(sessionStorage.getItem('itp_login_info'));
  194. if(data && data.connKey) {
  195. CONN_KEY = data.connKey; //로그인 했을때 넣었던 키를 가져옴
  196. }
  197. // 팝업번호
  198. // console.log(itp_fn_get_url_param('popNo'));
  199. const key = {popNo: popNo, viewCd: 'R'};
  200. var param = $.param(key);
  201. itp_fn_POPUP_info(param);
  202. });
  203. var itp_fn_POPUP_info = function(param) {
  204. fn_ajax_call('/api/pop/info-pop', param, itp_fn_POPUP_info_callback, 'GET');
  205. };
  206. var itp_fn_POPUP_info_callback = function(result) {
  207. // console.log(result);
  208. // C:내용입력, I:이미지
  209. $('head title').html(result.popNm); // 타이틀
  210. if(result.popTypeCd == 'C') {
  211. $('#ITP_POPUP .fnPopupPreview').html(result.popDesc.replace(/(\n|\r\n)/g, '<br>'));
  212. $('#ITP_POPUP .fnPopupPreview').css('padding', '6px 18px');
  213. } else if(result.popTypeCd == 'I') {
  214. $('#ITP_POPUP .fnPopupPreview').html('<img alt="'+result.popNm+'" src="'+result.fileUrl+'">');
  215. }
  216. };
  217. function fn_ajax_call(href, param, fn, type) {
  218. $.ajax({
  219. contentType: 'application/json',
  220. url: DOMAIN + href,
  221. data: param,
  222. type: type,
  223. async: false,
  224. timeout: 10000,
  225. xhrFields: {
  226. withCredentials: true //Cross Domain 처리
  227. },
  228. beforeSend: function(xhr) {
  229. $('#ITP_OVERLAY').show();
  230. xhr.setRequestHeader('X-AUTH-TOKEN', CONN_KEY); //Jwt 토큰을 헤더에 담아서 보낸다.
  231. },
  232. complete: function() {
  233. $('#ITP_OVERLAY').hide();
  234. },
  235. success: function(result) {
  236. if (result.code !== undefined) { //성공시에도 메세지가 있으면 얼럿 예)저장되었습니다.
  237. itp_fn_modal_alert_ajax(result.message);
  238. }
  239. if (fn !== undefined || typeof fn !== 'undefined') fn(result);
  240. },
  241. error: function(xhr, status, error) {
  242. if (xhr.responseJSON !== undefined) { //실패시 서버에서 내려주는 메세지 얼럿
  243. itp_fn_modal_alert_ajax(xhr.responseJSON.message);
  244. if (xhr.status == 401) { //401에러가 떨어지면 로그인페이지로 이동
  245. sessionStorage.removeItem('itp_login_info'); //Jwt 키 제거
  246. $(location).attr('href', ITP_CONTEXTPATH + '/login.html');
  247. }
  248. } else {
  249. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failProcess);
  250. }
  251. },
  252. fail: function() {
  253. itp_fn_modal_alert_ajax(ITP_MSG_LOCALE.message.ajax.failProcess);
  254. }
  255. });
  256. };
  257. function itp_fn_get_url_param(name) {
  258. var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
  259. if (results == null) {
  260. return null;
  261. } else {
  262. return results[1] || 0;
  263. }
  264. };
  265. function itp_fn_date_format(date, type) {
  266. let month = date.getMonth() + 1;
  267. let day = date.getDate();
  268. let hour = date.getHours();
  269. let minute = date.getMinutes();
  270. let second = date.getSeconds();
  271. month = month >= 10 ? month : '0' + month;
  272. day = day >= 10 ? day : '0' + day;
  273. hour = hour >= 10 ? hour : '0' + hour;
  274. minute = minute >= 10 ? minute : '0' + minute;
  275. second = second >= 10 ? second : '0' + second;
  276. if(type && type == 1) {
  277. return date.getFullYear() + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  278. } else {
  279. return date.getFullYear() + month + day + hour + minute + second;
  280. }
  281. };
  282. // 쿠키 가져오기
  283. var itp_fn_get_cookie = function (cname) {
  284. var name = cname + "=";
  285. var ca = document.cookie.split(';');
  286. for(var i=0; i<ca.length; i++) {
  287. var c = ca[i];
  288. while (c.charAt(0)==' ') c = c.substring(1);
  289. if (c.indexOf(name) != -1) return c.substring(name.length,c.length);
  290. }
  291. return "";
  292. }
  293. // 24시간 기준 쿠키 설정하기
  294. var itp_fn_set_cookie = function (cname, cvalue, exdays) {
  295. var todayDate = new Date();
  296. todayDate.setTime(todayDate.getTime() + (exdays*24*60*60*1000));
  297. var expires = "expires=" + todayDate.toUTCString();
  298. document.cookie = cname + "=" + cvalue + "; " + expires;
  299. }