mcare.core.js 27 KB

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