mplus.core.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. "use strict";
  2. /**
  3. * mcare core
  4. * @extend Object
  5. * @description mcare 최상위
  6. */
  7. var mcare = function(){
  8. var self = this;
  9. /**
  10. * mcare core util
  11. */
  12. var mcareUtil = this.util = {
  13. /**
  14. * JSON.parse
  15. */
  16. parseJson : function(string){
  17. try{
  18. return JSON.parse(string);
  19. }catch(e){
  20. self.log(e, "mcare_util_parseJson" );
  21. }
  22. },
  23. /**
  24. * JSON.stringify
  25. */
  26. stringifyJson : function(jsonObj,replacer,space){
  27. try{
  28. return JSON.stringify(jsonObj,replacer,space);
  29. } catch(e){
  30. self.log(e, "mcare_util_parseJson" );
  31. }
  32. },
  33. /**
  34. * 날짜 형식 YYYY-MM-DD 텍스트로 포맷을 바꿔주는 유틸
  35. * @param date {date}
  36. * @return text { string } - ex)2015-08-21
  37. */
  38. simpleDateFormat : function( date ){
  39. try{
  40. var yyyy = date.getFullYear().toString(),
  41. mm = (date.getMonth()+1).toString(),
  42. dd = date.getDate().toString(),
  43. text = yyyy + "-" + (mm[1]?mm:"0"+mm[0]) + "-" + (dd[1]?dd:"0"+dd[0]);
  44. return text;
  45. } catch(e) {
  46. self.log(e, "mcare_util_simpleDateFormat" );
  47. }
  48. },
  49. /**
  50. * get 방식으로 넘어오는 파라미터 처리 유틸
  51. * @return paramObj {object} key:value object로 리턴
  52. */
  53. getParameter : function(){
  54. try{
  55. var paramObj = new Object();
  56. var query = window.location.search.substring(1),
  57. vars = query.split("&");
  58. for( var i=0; i < vars.length; i++ ){
  59. var pair = vars[i].split("=");
  60. paramObj[ pair[0] ] = pair[1];
  61. }
  62. return paramObj;
  63. } catch(e) {
  64. self.log(e, "mcare_util_getParameter" );
  65. }
  66. },
  67. /**
  68. * 날짜 string restore
  69. * @param string{string} ex)20151028 날짜 형태 YYYYMMDD 문자열
  70. * @return {string} YYYY-MM-DD 형태로 리턴
  71. */
  72. restoreDate : function( string ){
  73. try{
  74. return string.substr(0,4) + "-" + string.substr(4,2) + "-" + string.substr(6,2);
  75. } catch(e){
  76. self.log(e, "mcare_util_restoreDate" );
  77. }
  78. },
  79. /**
  80. * 입퇴원 string restore
  81. * @param string1 {string} ex)20151028 날짜 형태 YYYYMMDD 문자열
  82. * @param string2 {string} ex)20151028 날짜 형태 YYYYMMDD 문자열
  83. * @return {string} YYYY-MM-DD ~ YYYY-MM-DD 형태로 리턴
  84. */
  85. restoreDischarged : function( string1, string2 ){
  86. try{
  87. return this.restoreDate( string1 ) + " ~ " + this.restoreDate( string2 );
  88. } catch(e) {
  89. self.log(e, "mcare_util_restoreDischarged" );
  90. }
  91. },
  92. /**
  93. * 시간 string restore
  94. * @param string1 {string} ex)1500 시간 형태 HHMM 문자열
  95. * @return {string} HH:MM 형태로 리턴
  96. */
  97. restoreTime : function( string ){
  98. try{
  99. return string.substr(0,2)+":"+string.substr(2,2);
  100. } catch(e) {
  101. self.log(e, "mcare_util_restoreTime" );
  102. }
  103. },
  104. /**
  105. * 진료순번대기 확인 시간 가공
  106. * @param string {string} ex)20160118143323000 시간 형태 YYYYMMDDHHMMSSMI
  107. * @return {string} YYYY-MM-DD HH:MM 형태로 리턴
  108. */
  109. restoreCheckTime : function( string ){
  110. try{
  111. return string.substr(0,4) + "-" + string.substr(4,2) + "-" + string.substr(6,2) + " "+ string.substr(8,2)+":"+string.substr(10,2);
  112. } catch(e) {
  113. self.log(e, "mcare_util_restoreCheckTime" );
  114. }
  115. },
  116. /**
  117. * 번호표 발급 시간 가공
  118. * @param string {string} ex)201601181433 시간 형태 YYYYMMDDHHMM
  119. * @return {string} 오전/오후 HH:MM 형태로 리턴
  120. */
  121. restoreTicketTime : function( string ){
  122. try{
  123. var hh = parseInt(string.substr(8,2)),
  124. mm = parseInt(string.substr(10,2)),
  125. hour = (hh==0?'12':(hh>12?hh-12:hh));
  126. return (hh < 12 ? '오전' : '오후') + " "+ (hour<10?"0"+hour:hour) + "시 "+ (mm<10?"0"+mm:mm) + "분 발급";
  127. } catch(e) {
  128. self.log(e, "mcare_util_restoreTicketTime" );
  129. }
  130. },
  131. /**
  132. * 비밀번호 패턴 체크 정규식
  133. * @param password {string} 비밀번호 문자열
  134. * @return {object} result: boolean 결과, code(optional) 에러메시지 코드
  135. */
  136. validatePWD : function( password ){
  137. try{
  138. // javascript
  139. var patt_k = /([가-힣ㄱ-ㅎㅏ-ㅣ\x20])/i; // 한글 정규식
  140. var patt = /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).*$/; // 혼합 정규식
  141. var patt_3num1 = /(\w)\1\1/; // 같은 영문자&숫자 연속 3번 정규식
  142. var patt_3num2 = /([\{\}\[\]\/?.,;:|\)*~`!^\-_+<>@\#$%&\\\=\(\'\"])\1\1/; // 같은 특수문자 연속 3번 정규식
  143. var patt_cont = /(012)|(123)|(234)|(345)|(456)|(567)|(678)|(789)|(890)|(901)/; // 연속된 숫자 정규식
  144. var patt_eng = /(abc)|(bcd)|(cde)|(def)|(efg)|(fgh)|(ghi)|(hij)|(ijk)|(jkl)|(klm)|(lmn)|(mno)|(nop)|(opq)|(pqr)|(qrs)|(rst)|(stu)|(tuv)|(uvw)|(vwx)|(wxy)|(xyz)|(yxa)|(ABC)|(BCD)|(CDE)|(DEF)|(EFG)|(FGH)|(GHI)|(HIJ)|(IJK)|(JKL)|(KLM)|(LMN)|(MNO)|(NOP)|(OPQ)|(PQR)|(QRS)|(RST)|(STU)|(TUV)|(UVW)|(VWX)|(WXY)|(XYZ)|(YZA)/;
  145. //사용가능한 특수문자가 아닌 다른 걸 사용했을 때 확인하기 위해 특수문자만, 추출하는 변수
  146. var ext = (password.replace(/[a-zA-Z0-9]/gi,"")).replace( /[!@#$%^&*?_~]/gi, "");
  147. //한글
  148. if( patt_k.test( password ) ){
  149. return {"result":false,"code":"common013"};
  150. //문자 혼합
  151. } else if( !patt.test( password ) ){
  152. return {"result":false,"code":"common014"};
  153. //지정된 특수문자외 다른 문자 사용하면 공백이 아님
  154. } else if( ext !== "" ){
  155. return {"result":false,"code":"common024"};
  156. //같은 숫자, 문자 3자리
  157. } else if( patt_3num1.test( password ) ){
  158. return {"result":false,"code":"common015"};
  159. //같은 특수 문자 3자리
  160. } else if( patt_3num2.test( password ) ){
  161. return {"result":false,"code":"common016"};
  162. //연속 숫자3자리
  163. } else if( patt_cont.test( password ) ){
  164. return {"result":false,"code":"common017"};
  165. //연속 문자 3자리
  166. } else if( patt_eng.test( password ) ){
  167. return {"result":false,"code":"common018"};
  168. //8자리 이상
  169. } else if( password.length < 8 ){
  170. return {"result":false,"code":"common019"};
  171. }
  172. return {"result":true};
  173. } catch(e) {
  174. self.log(e, "mcare_util_validatePWD" );
  175. }
  176. },
  177. /**
  178. * 연도 텍스트 가져오기
  179. * @param date{date}
  180. * @return {string} YYYY 연도 텍스트
  181. */
  182. getYearText : function( date ){
  183. try{
  184. return date.getFullYear().toString();
  185. } catch(e) {
  186. self.log(e, "mcare_util_getYearText" );
  187. }
  188. },
  189. /**
  190. * 월 텍스트 가져오기
  191. * @param date {date}
  192. * @return {string} MM 월 텍스트
  193. */
  194. getMonthText : function( date ){
  195. try{
  196. var mm = (date.getMonth()+1).toString();
  197. return (mm[1]?mm:"0"+mm[0]);
  198. } catch(e) {
  199. self.log(e, "mcare_util_getMonthText" );
  200. }
  201. },
  202. /**
  203. * 일 텍스트 가져오기
  204. * @param date {date}
  205. * @return {string} DD 일 텍스트
  206. */
  207. getDayText : function( date ){
  208. try{
  209. var dd = date.getDate().toString();
  210. return (dd[1]?dd:"0"+dd[0]);
  211. } catch(e) {
  212. self.log(e, "mcare_util_getDayText" );
  213. }
  214. },
  215. /**
  216. * 일자 텍스트
  217. * @param date{date}
  218. * @return {string} YYYYMMDD 텍스트
  219. */
  220. getDateText : function( date ){
  221. try{
  222. return this.getYearText(date) + this.getMonthText(date) + this.getDayText(date);
  223. } catch(e) {
  224. self.log(e, "mcare_util_getDateText" );
  225. }
  226. },
  227. /**
  228. * 금액 숫자 포맷변환
  229. * @param obj{object} 텍스트 변환을 적용할 jqeury object ex) $(obj)
  230. * @param type {object} 라이브러리 options ( 아직 별도 구현안함 - 사용안할 수 있음)
  231. */
  232. numberFormat : function( obj, type ){
  233. try{
  234. //소수점 없이 3자리마다 , 적용
  235. $.each( obj, function(i){
  236. var item = obj[i];
  237. var num = $.number( $(item).text(),0,'.',',' );
  238. $(item).text(num);
  239. });
  240. } catch(e) {
  241. self.log(e, "mcare_util_numberFormat" );
  242. }
  243. },
  244. /**
  245. * menu param 을 사용하기 위해서 util 함수로 지정함
  246. */
  247. getMenuParam : function(key){
  248. try{
  249. if( menuParamObj[key] == undefined ){
  250. return null;
  251. }
  252. var obj = menuParamObj[key];
  253. if( obj["type"] === "STRING" ){
  254. return obj["value"].toString();
  255. } else if( obj["type"] === "NUMBER" ){
  256. return parseInt( obj["value"] );
  257. } else {
  258. return ( obj["value"] === "true" )? true : false;
  259. }
  260. } catch(e) {
  261. self.log(e, "mcare_util_getMenuParam" );
  262. return null;
  263. }
  264. },
  265. sortObj : function(list, key, type, order){
  266. function compare(a, b) {
  267. a = a[key];
  268. b = b[key];
  269. /*var type = (typeof(a) === 'string' ||
  270. typeof(b) === 'string') ? 'string' : 'number';*/
  271. var result;
  272. if (type === 'string') result = a.localeCompare(b);
  273. else result = a - b;
  274. return result;
  275. };
  276. var sortList;
  277. if(order == 'up'){
  278. sortList = list.sort(compare);
  279. }else{
  280. var sortList = list.sort(compare).reverse();
  281. }
  282. return sortList;
  283. }
  284. };
  285. /**
  286. * 이벤트 사용 객체
  287. */
  288. var mcareEvent = this.event = {
  289. /**
  290. * 동적 이벤트 등록
  291. * @param object {jquery object} 이벤트 등록할 jquery object - ex)$("#event")
  292. * @param type {string} event type - ex) click
  293. * @param callback {function} 이벤트 콜백 함수
  294. * @description 동적으로 dom 을 수정하거나 추가할 때, 이벤트 바인딩
  295. */
  296. addEvent : function( object, type, callback ){
  297. try {
  298. object.on( type, callback );
  299. } catch (e) {
  300. self.log(e, "mcare_event_addEvent" );
  301. }
  302. }
  303. };
  304. //다국어 처리를 위한 변수처리 - 각 페이지 jsp 별로 i18n을 선언. 없으면 그냥 객체
  305. var message = (typeof(i18n) !== "undefined")? new i18n() : {};
  306. /**
  307. * 다국어 메시지 가져오기
  308. * @param code 메시지 코드
  309. */
  310. this.getI18n = function( code ){
  311. try {
  312. return message.getMessage( code );
  313. } catch (e) {
  314. self.log(e, "mcare_message_getI18n" );
  315. }
  316. }
  317. /**
  318. * mcare core log function
  319. * @param exception
  320. * @param msg
  321. * @description 에러 로그
  322. */
  323. this.log = function(exception, msg){
  324. if( msg !== undefined ){
  325. console.log( msg );
  326. }
  327. console.log( "Error Name: " + exception.name + ", Error Msg: "+ exception.message );
  328. console.log( exception.stack );
  329. };
  330. /**
  331. * native 호출 뒤에 callback으로 script를 호출하기 위해 객체를 global로 설정
  332. * @param obj {function} 현재 페이지 스크립트 function
  333. */
  334. this.setGlobal = function( obj ){
  335. window.activeObj = obj;
  336. };
  337. /**
  338. * 통신 객체
  339. */
  340. var mcareAjax = this.ajax = {
  341. send : function(opt,successFn,errorFn){
  342. var sendOpt = $.extend(opt,{
  343. success: function(data){
  344. successFn(data);
  345. },
  346. error : function(xhr,d,t){
  347. errorFn(xhr,d,t);
  348. }
  349. })
  350. try{
  351. $.ajax(sendOpt);
  352. }catch(e){
  353. self.log(e, "mcare_ajax_send" );
  354. }
  355. }
  356. };
  357. };
  358. /**
  359. * mcare/core/admin
  360. * @extend mcare
  361. * @description mcare 관리자
  362. */
  363. var mcare_admin = function(){
  364. mcare.call(this);
  365. var self = this;
  366. //변수
  367. //종료 datepicker
  368. var endDatePicker = null,
  369. //시작 datepicker
  370. startDatePicker = null,
  371. //dropdown
  372. dropDownList = null,
  373. //chart
  374. chart = null;
  375. /**
  376. * kendo datepicker
  377. * @param $endDate 종료 datepicker 위치한 jquery object : ex) $("#endDate")
  378. * @param $strDate 시작 datepicker 위치한 jquery object : ex) $("#strDate")
  379. * @param $selectOption 검색 조건 dropdown 이 위치한 jquery object : ex) $("#select-option")
  380. * @description 관리자 화면에서 사용하는 공통된 datepicker생성 함수를 하나로 사용하도록 함
  381. */
  382. this.datePicker = function( $endDate, $strDate, $selectOption){
  383. try {
  384. var endValue = new Date(),
  385. startValue = new Date();
  386. endValue.setDate( endValue.getDate()-1 );
  387. startValue.setDate( startValue.getDate()-1 );
  388. endDatePicker = $endDate.kendoDatePicker({
  389. change: function(e) {
  390. var endDate = endDatePicker.value(),
  391. strDate = startDatePicker.value();
  392. if( endDate ) {
  393. endDate = new Date( endDate );
  394. endDate.setDate( endDate.getDate() );
  395. } else if( startDate ) {
  396. endDatePicker.min( new Date(startDate) );
  397. } else {
  398. endDate = new Date();
  399. }
  400. },
  401. value : endValue
  402. }).data("kendoDatePicker");
  403. startValue.setDate( startValue.getDate() - $selectOption.val() );
  404. startDatePicker = $strDate.kendoDatePicker({
  405. change: function(e) {
  406. var strDate = startDatePicker.value(),
  407. endDate = endDatePicker.value();
  408. if( strDate ) {
  409. strDate = new Date( strDate );
  410. strDate.setDate( strDate.getDate() );
  411. endDatePicker.min( strDate );
  412. } else if( endDate ) {
  413. } else {
  414. endDate = new Date();
  415. }
  416. },
  417. value : startValue
  418. }).data("kendoDatePicker");
  419. } catch (e) {
  420. self.log(e, "mcare_admin_datePicker" );
  421. }
  422. };
  423. /**
  424. * kendo dropdown
  425. * @param $selectOption 검색 조건 dropdown 이 위치한 jquery object : ex) $("#select-option")
  426. * @description 관리자 화면에서 공통적으로 사용하는 검색조건 dropdown 생성함수를 하나로 사용하도록 함
  427. */
  428. this.dropDownList = function( $selectOption, options ){
  429. try {
  430. var option = {
  431. change: function(e) {
  432. var endDate = new Date();
  433. endDate.setDate( endDate.getDate() - 1 );
  434. endDatePicker.value( endDate );
  435. var startValue = new Date();
  436. startValue.setDate( startValue.getDate() - 1 - Number( e.sender._selectedValue ) );
  437. startDatePicker.value( startValue );
  438. }
  439. };
  440. if( options ){
  441. option = options;
  442. }
  443. // 검색조건
  444. dropDownList = $selectOption.kendoDropDownList(option).data("kendoDropDownList");
  445. } catch (e) {
  446. self.log(e, "mcare_admin_dropDownList" );
  447. }
  448. };
  449. /**
  450. * 검색 조건 변경 이벤트 콜백
  451. * @param dataSource 검색 조건에 해당하는 내용을 불러올 데이터 소스
  452. * @description 관리자 화면에서 공통적으로 사용하는 검색 조건 변경 이벤트 콜백
  453. */
  454. this.search = function( dataSource, isPage ){
  455. try {
  456. var strDate = kendo.toString( startDatePicker.value(), "yyyyMMdd" ),
  457. endDate = kendo.toString( new Date( endDatePicker.value() + (60*60*24*1000) ), "yyyyMMdd");
  458. if( strDate <= endDate ) {
  459. if( isPage ){
  460. dataSource.page(1);
  461. } else {
  462. dataSource.read();
  463. }
  464. } else {
  465. alert( "조회할 수 없습니다" );
  466. return;
  467. }
  468. } catch (e) {
  469. self.log(e, "mcare_admin_search" );
  470. }
  471. };
  472. /**
  473. * chart
  474. * @param $chart 차트가 위치한 jquery object : ex) $("#chart")
  475. * @param type 차트 타입
  476. * @param option {object} 차트 옵션
  477. * @param data 차트데이터
  478. * @description 관리자 화면에서 사용하는 chart 생성함수
  479. */
  480. this.chart = function( $chart, type, options, data, $legend ){
  481. try {
  482. var ctx = $chart.get(0).getContext("2d");
  483. //차트 객체가 있으면 destroy 하고 다시 생성한다
  484. if( chart !== null && typeof chart.destroy === "function" ){
  485. chart.destroy();
  486. }
  487. switch( type.toLowerCase() ){
  488. case "line" : chart = new Chart(ctx).Line( data, options ); break;
  489. case "bar" : chart = new Chart(ctx).Bar( data, options ); break;
  490. case "radar" : chart = new Chart(ctx).Radar( data, options ); break;
  491. case "polararea" : chart = new Chart(ctx).PolarArea( data, options );break;
  492. case "pie" : chart = new Chart(ctx).Pie( data, options );break;
  493. case "doughnut" : chart = new Chart(ctx).Doughnut( data, options );break;
  494. default : chart = new Chart(ctx).Line( data, options ); break;
  495. }
  496. if( $legend !== undefined ){
  497. $legend.html( chart.generateLegend() );
  498. }
  499. } catch (e) {
  500. self.log(e, "mcare_admin_chart" );
  501. }
  502. };
  503. /**
  504. *
  505. */
  506. this.chartUpdate = function( labels,data ){
  507. chart.clear();
  508. chart.render( data );
  509. };
  510. /**
  511. * kendo grid
  512. * @param $grid 그리드가 위치한 jquery object : ex) $("#grid")
  513. * @param option 그리드 옵션
  514. * @description 관리자 화면에서 사용하는 kendo grid 생성함수
  515. */
  516. this.grid = function( $grid, option ){
  517. try {
  518. // 그리드
  519. return $grid.kendoGrid(option).data("kendoGrid");
  520. } catch (e) {
  521. self.log(e, "mcare_admin_grid" );
  522. }
  523. };
  524. /**
  525. * start datepicker 값
  526. * @return date object
  527. */
  528. this.getStartDatePickerValue = function(){
  529. try {
  530. return startDatePicker.value();
  531. } catch (e) {
  532. self.log(e, "mcare_admin_getStartDatePickerValue" );
  533. }
  534. };
  535. /**
  536. * end datepicker 값
  537. * @return date object
  538. */
  539. this.getEndDatePickerValue = function(){
  540. try {
  541. return endDatePicker.value();
  542. } catch (e) {
  543. self.log(e, "mcare_admin_getEndDatePickerValue" );
  544. }
  545. };
  546. /**
  547. * 트리 사용
  548. * @param $tree {jquery object} tree 가 위치할 jquery object ex $("#tree")
  549. * @param option {object} kendo tree option 정보
  550. */
  551. this.tree = function( $tree, option ){
  552. try {
  553. return $tree.kendoTreeView(option).data("kendoTreeView");
  554. } catch (e) {
  555. self.log(e, "mcare_admin_tree" );
  556. }
  557. };
  558. /**
  559. *
  560. */
  561. this.ajaxAdmin = function( opt, successFn, errorFn ){
  562. var sFn = function(data){
  563. if( data.msg !== undefined ){
  564. if( data.type !== undefined && data.type === "AuthException" ){
  565. window.location.href = contextPath + "/admin/login.page";
  566. } else {
  567. alert(data.msg);
  568. }
  569. } else {
  570. successFn(data);
  571. }
  572. };
  573. var eFn = function(xhr,d,t){
  574. errorFn(xhr,d,t);
  575. };
  576. try{
  577. self.ajax.send( opt, sFn, eFn );
  578. } catch(e) {
  579. self.log(e, "mcare_admin_ajaxAdmin" );
  580. }
  581. };
  582. /**
  583. * 글자수 bytes 체크
  584. */
  585. this.checkDescBytes = function(desc){
  586. desc.on("keyup paste",function(e){
  587. var length = getBytes($(this));
  588. $("#descLength").text( length );
  589. });
  590. function getBytes(obj){
  591. var limitByte = 500; //바이트의 최대크기, limitByte 를 초과할 수 없슴
  592. var totalByte = 0;
  593. var message = obj.val();
  594. for( var i =0; i < message.length; i++ ) {
  595. var currentByte = message.charCodeAt(i);
  596. if( currentByte > 128 ){
  597. totalByte += 2;
  598. } else {
  599. totalByte++;
  600. }
  601. }
  602. return totalByte;
  603. }
  604. };
  605. }
  606. /**
  607. * mcare/core/mobile
  608. * @extend mcare
  609. * @description mcare 모바일 어플리케이션
  610. */
  611. var mcare_mobile = function(){
  612. mcare.call(this);
  613. var self = this;
  614. //swipe
  615. var swipe = null;
  616. /**
  617. * android 단말기 인지 판별한다.
  618. */
  619. this.isAndroid = function() {
  620. try{
  621. return (/android/i.test(navigator.userAgent.toLowerCase()));
  622. } catch(e){
  623. self.log(e,"mcare_mobile_isAndroid");
  624. }
  625. }
  626. /**
  627. * iOS 단말기 인지 확인
  628. */
  629. this.isIos = function() {
  630. try{
  631. return (/iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase()));
  632. } catch(e) {
  633. self.log(e,"mcare_mobile_isIos");
  634. }
  635. }
  636. /**
  637. * 모바일인지 판별한다.
  638. */
  639. this.isMobile = function() {
  640. try {
  641. return (/iphone|ipad|ipod|android|opera\smini|opera\smobi|symbian|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
  642. } catch (e) {
  643. self.log(e,"mcare_mobile_isMobile");
  644. }
  645. }
  646. /**
  647. * 앱인지 판단한다.
  648. */
  649. this.isApp = function() {
  650. try {
  651. return (/mobile:Y/i.test(navigator.userAgent.toLowerCase()));
  652. } catch (e) {
  653. self.log(e,"mcare_mobile_isApp");
  654. }
  655. }
  656. /**
  657. * Native App 호출
  658. * javascripte -> native
  659. * @param reqParam {object} native에 전달할 데이터 정보가 담긴 객체
  660. */
  661. this.toNative = function( reqParam ){
  662. try {
  663. var data = self.util.stringifyJson( reqParam );
  664. if( self.isMobile() ){
  665. // 앱이 안드로이드일 경우
  666. if( self.isAndroid() ){
  667. window.Android.toNative( data );
  668. } else if( self.isIos() ){
  669. data = "jscall://toNative?" + data;
  670. location.href = data;
  671. // iframe으로 파라미터를 넘기니까 iOS에 한글 파라미터 전달씨 깨지는 현상이 발생한다.
  672. // 그래서 ?를 구분으로 파라미터 시작을 알리도록 수정하는데 만일을 위해 frame영역은 일단 주석 처리 한다.
  673. // data = "jscall://toNative:" + data;
  674. // var iframe = document.createElement("iframe");
  675. // iframe.setAttribute("src", data);
  676. // document.documentElement.appendChild(iframe);
  677. // iframe.parentNode.removeChild(iframe);
  678. // iframe = null;
  679. }
  680. }else{
  681. alert("App에서만 사용가능한 기능입니다.");
  682. }
  683. } catch (e) {
  684. self.log(e,"mcare_mobile_toNative");
  685. }
  686. };
  687. /**
  688. * 로딩 이미지 표시
  689. * @param order {string} show/hide
  690. * @description jqm loading wrapping
  691. */
  692. this.loading = function( order ){
  693. try{
  694. /*$.mobile.loading( order );*///에러
  695. if( order === "show" ){
  696. /*$("div.ui-panel-dismiss").css("z-index",9999900);*/
  697. $('#wrapLoding').css('display', 'block');
  698. } else {
  699. /*$("div.ui-panel-dismiss").css("z-index","");*/
  700. $('#wrapLoding').css('display', 'none');
  701. }
  702. } catch(e) {
  703. self.log(e,"mcare_mobile_loading");
  704. }
  705. };
  706. /**
  707. * 페이지 이동 메소드
  708. * @param address 이동할 주소
  709. * @description jqm changePage wrapping
  710. */
  711. this.changePage = function( address ){
  712. try {
  713. // $(":mobile-pagecontainer").pagecontainer();
  714. // $(":mobile-pagecontainer").pagecontainer("change",address);
  715. location.href = address;
  716. } catch (e) {
  717. self.log(e,"mcare_mobile_changePage");
  718. }
  719. };
  720. /**
  721. * 날짜 유효성 체크
  722. * @param $strData {object} 시작일 input jquery obj
  723. * @param $endDate {object} 종료일 input jquery obj
  724. * @description 날짜 유효성 체크를 하나로 일원화해서 상속받아 사용하도록함
  725. */
  726. this.dateValidation = function( $strDate, $endDate ){
  727. try{
  728. if( $strDate.val() === "" || $endDate.val() === "" ){
  729. self.alert( self.getI18n( "common007" ) ); //조회일자를 선택하세요
  730. return false;
  731. } else if( $strDate.val() > $endDate.val() ){
  732. self.alert( self.getI18n( "common008" ) ); //종료일이 시작일 이전일 수 없습니다.
  733. $endDate.focus();
  734. return false;
  735. } else if( !checkDateDiff( $strDate.val(), $endDate.val() ) ){
  736. self.alert( self.getI18n( "common009" ) ); //1년이상을 조회할 수 없습니다.
  737. return false;
  738. }
  739. return true;
  740. } catch(e) {
  741. self.log(e, "mcare_mobile_dateValidation" );
  742. }
  743. };
  744. /**
  745. * 날짜간 차이 계산 - 1년 기준
  746. * @parivate
  747. * @param strDate {string} strDate value
  748. * @param endDate {string} endDate value
  749. */
  750. var checkDateDiff = function( strDate, endDate ){
  751. try{
  752. var diff = getDateDiff( strDate, endDate );
  753. if( Math.abs(diff) > 1 ){
  754. return false;
  755. }
  756. return true;
  757. } catch(e) {
  758. self.log(e,"mcare_mobile_checkDateDiff");
  759. }
  760. // 날짜 차이 계산 함수 1년단위
  761. // date1 : 기준 날짜(YYYY-MM-DD), date2 : 대상 날짜(YYYY-MM-DD)
  762. function getDateDiff( date1,date2 ){
  763. var arrDate1 = date1.split("-");
  764. var getDate1 = new Date(parseInt(arrDate1[0]),parseInt(arrDate1[1])-1,parseInt(arrDate1[2]));
  765. var arrDate2 = date2.split("-");
  766. var getDate2 = new Date(parseInt(arrDate2[0]),parseInt(arrDate2[1])-1,parseInt(arrDate2[2]));
  767. var getDiffTime = getDate1.getTime() - getDate2.getTime();
  768. return Math.floor(getDiffTime / (1000 * 60 * 60 * 24 * 365));
  769. }
  770. };
  771. /**
  772. * 메인 화면 swipe
  773. * slick 라이브러리 사용
  774. * @param container {string} swipe container selector - ex) .swiper-container
  775. * @param option {object} 추가로 설정할 option - 참고 주소 : http://kenwheeler.github.io/slick/
  776. * @history 2015-10-01 slick 라이브러리로 교체 - https://github.com/kenwheeler/slick
  777. */
  778. this.swipe = function( container, option ){
  779. try{
  780. container.slick( option );
  781. } catch(e) {
  782. self.log(e,"mcare_mobile_swipe");
  783. }
  784. };
  785. /**
  786. * orientation 전환 함수 호출
  787. * @param mode {string} portrait | landscape
  788. */
  789. this.changeOrientation = function( mode ){
  790. var reqParam = {
  791. "type" : "command",
  792. "functionType" : "screen",
  793. "value" : {
  794. "orientation" : mode,
  795. "callbackFn":"window.activeObj.init"
  796. }
  797. };
  798. try{
  799. this.toNative( reqParam);
  800. } catch(e) {
  801. self.log(e,"mcare_mobile_changeOrientation");
  802. }
  803. };
  804. /**
  805. * 모바일 alert
  806. */
  807. this.alert = function( text ){
  808. try{
  809. /*if($("#mplusAlert").data('bs.modal') && $("#mplusAlert").data('bs.modal').isShown) $('#mplusAlert').modal('hide');*/
  810. $('.modal-backdrop').removeClass('in');
  811. $('.modal').modal('hide');
  812. var popup = $('#mplusAlert')/*,
  813. callback = popup.find(".popupCallback")*/;
  814. if( text === "" || text === undefined ){
  815. console.log( "text empty or undefined" );
  816. }
  817. var alertMsg = $("<p></p>").text(text);
  818. $('#mplusAlert .modal-body').empty();
  819. $('#mplusAlert .modal-body').append(alertMsg);
  820. /*if(callbackFn!=undefined&&callbackFn!=''){
  821. $('.alertBtn').hide();
  822. $('.confirmBtn').show();
  823. callback.on("click",function(e){
  824. e.preventDefault();
  825. var fnName = callbackFn;
  826. var fn = new Function(fnName);
  827. fn();
  828. $('#mplusAlert').modal('hide');
  829. });
  830. }else{*/
  831. /*};*/
  832. $('#mplusAlert').modal('show');
  833. } catch(e) {
  834. self.log(e,"mcare_mobile_popup");
  835. }
  836. };
  837. /**
  838. * 모바일 confirm
  839. */
  840. this.confirm = function( text, callback ){
  841. try{
  842. /*if($("#mplusConfirm").data('bs.modal') && $("#mplusConfirm").data('bs.modal').isShown) $('#mplusConfirm').modal('hide');*/
  843. $('.modal-backdrop').removeClass('in');
  844. $('.modal').modal('hide');
  845. var popup = $('#mplusConfirm'),
  846. callbackBtn = popup.find(".popupCallback"),
  847. cancel = popup.find(".popupCancel");
  848. if( text === "" || text === undefined ){
  849. console.log( "text empty or undefined" );
  850. }
  851. var alertMsg = $("<p></p>").text(text);
  852. $('#mplusConfirm .modal-body').empty();
  853. $('#mplusConfirm .modal-body').append(alertMsg);
  854. callbackBtn.unbind();
  855. callbackBtn.on("click",function(e){
  856. $('#mplusConfirm').modal('hide');
  857. callback(true);
  858. });
  859. $('#mplusConfirm').modal('show');
  860. } catch(e) {
  861. self.log(e,"mcare_mobile_popup");
  862. }
  863. };
  864. /**
  865. * history state change
  866. */
  867. this.stateChange = function( href, data ){
  868. try{
  869. var path = href.indexOf("&change=") >=0? href.substr(0,href.indexOf("&change=")) : href;
  870. var ua = navigator.userAgent.toLowerCase(),
  871. version = 0;
  872. if( this.isAndroid() ){
  873. version = parseFloat(ua.substr(ua.search(/android/) + 7, 4));
  874. if( version >= 5 ){
  875. window.history.replaceState({},document.title, path + "&change=true" + data );
  876. }
  877. }else if( this.isIos() ){
  878. version = parseFloat(ua.substr(ua.search(/ipad|iphone/), 30).match(/\d+_+\d/)[0].replace('_', '.'));
  879. if( version >= 9.3 ){
  880. window.history.replaceState({},document.title, path + "&change=true" + data );
  881. }
  882. }
  883. } catch(e) {
  884. self.log(e,"mcare_mobile_stateChange");
  885. }
  886. }
  887. this.getDomain = function() {
  888. var cmaDns=location.href;
  889. cmaDns=cmaDns.split("//");
  890. cmaDns = cmaDns[0] + "//"+cmaDns[1].substr(0,cmaDns[1].indexOf("/")); // http:// 를 포함해서 return;
  891. return cmaDns;
  892. };
  893. /**
  894. * fixed header가 ios에서 키보드로 인해서 바르게 동작하지 않는 문제
  895. *
  896. */
  897. this.headerFix = function(){
  898. $(".ui-page").off("focusin focusout");
  899. $("input").on("focus", function(){
  900. $("div[data-role=header]").css("position", "absolute");
  901. });
  902. $("input").on("blur",function(){
  903. $("div[data-role=header]").css("position", "fixed");
  904. });
  905. };
  906. }