f459d08e031e4756a5349657c70b1f909ae66d96.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. $(function () {
  2. 'use strict';
  3. var loginId = ko.observable(''),
  4. loginPassword = ko.observable(''),
  5. checkSaveId = ko.observable(false),
  6. disabledLoginButton = ko.observable(false),
  7. disabledIdTextBox = ko.observable(false),
  8. disabledPasswordTextBox = ko.observable(false),
  9. disabledCheckSaveId = ko.observable(false)
  10. ;
  11. // 디버깅 모드 설정(자동로그인 관련)
  12. //var debug = true;
  13. var debug = false;
  14. // 로그인 후 이동하게될 화면 설정
  15. //var viewAfterLogin = 'ExecutionSchedule';
  16. var overlayOptions = {
  17. width: '100%',
  18. height: '100%',
  19. visible: ko.observable(false),
  20. animation: null,
  21. shading: true,
  22. showingAction: function () {
  23. BWA.UserPanel.hide();
  24. },
  25. contentReadyAction: function (e) {
  26. BWA.LoginOverlay.handleCheckSaveId();
  27. }
  28. };
  29. function handleLoginFail(error) {
  30. utils.toast.show('로그인에 실패하였습니다.', 'error');
  31. }
  32. function handleAfterTryLogin() {
  33. disabledLoginButton(false);
  34. disabledIdTextBox(false);
  35. disabledPasswordTextBox(false);
  36. disabledCheckSaveId(false);
  37. BWA.LoadIndicator.promiseAlways();
  38. }
  39. BWA.LoginOverlay = {
  40. handleCheckSaveId: function() {
  41. $('.intro_login_container').parent().parent().css('z-index', 3000);
  42. //checkSaveId(false);
  43. checkSaveId($.cookie('checkSaveId') == "true" ? true : false);
  44. if (checkSaveId()) {
  45. var cookieId = $.cookie('id');
  46. loginId(cookieId);
  47. }
  48. else {
  49. var cookieId = "";
  50. loginId(cookieId);
  51. }
  52. if (debug) {
  53. loginId('admin');
  54. loginPassword('kanu123');
  55. //id('lee');
  56. //password('lee');
  57. }
  58. },
  59. overlayOptions: overlayOptions,
  60. getIdTextBoxOptions: function () {
  61. return {
  62. value: loginId,
  63. disabled: disabledIdTextBox,
  64. // cyim 2016.02.17 : 로그인화면 작업
  65. placeholder: ' username', //placeholder: $G('id'),
  66. // hcLee 2016 01 25 크롬은 문제없으나 IE 8,9,10에서는 동작안하는 버그 떄문에 직접코드 체크로 변경함
  67. /*enterKeyAction: function (e) {
  68. BWA.LoginOverlay.handleLoginButton();*/
  69. onKeyPress: function (e) {
  70. if (e.jQueryEvent.charCode == 13)
  71. BWA.LoginOverlay.handleLoginButton();
  72. }
  73. };
  74. },
  75. getPasswordTextBoxOptions: function () {
  76. return {
  77. value: loginPassword,
  78. disabled: disabledPasswordTextBox,
  79. mode: 'password',
  80. // cyim 2016.02.17 : 로그인화면 작업
  81. placeholder: ' password',//placeholder: $G('password'),
  82. // hcLee 2016 01 25 크롬은 문제없으나 IE 8,9,10에서는 동작안하는 버그 떄문에 직접코드 체크로 변경함
  83. /*enterKeyAction: function (e) {
  84. BWA.LoginOverlay.handleLoginButton();*/
  85. onKeyPress: function (e) {
  86. //if (e.jQueryEvent.char == '\n') { onKeyDown or onKeyUp의 경우는 이렇게
  87. if (e.jQueryEvent.charCode == 13) {
  88. $('#loginbtn').focus();
  89. BWA.LoginOverlay.handleLoginButton();
  90. //$('#userPassword').focus();
  91. }
  92. }
  93. };
  94. },
  95. getCheckBoxOptions: function () {
  96. return {
  97. value: checkSaveId,
  98. disabled: disabledCheckSaveId
  99. };
  100. },
  101. getButtonOptions: function () {
  102. return {
  103. // cyim 2016.02.17 : 로그인화면 작업 (이미지로 대체함)
  104. //icon: 'key',
  105. //text: $G('login'),
  106. disabled: disabledLoginButton,
  107. clickAction: BWA.LoginOverlay.handleLoginButton
  108. };
  109. },
  110. GetClientIP: function () {
  111. //return "127.0.0.1";
  112. /* node js
  113. require('dns').lookup(require('os').hostname(), function (err, add, fam) {
  114. //console.log('addr: ' + add);
  115. alert(add);
  116. })*/
  117. //alert(ko.observable(data.IpAddress));
  118. //return "127.0.0.1";
  119. var dfd = $.Deferred();
  120. var urlHeader = BemsWebApplication.config.endpoints.api[BemsWebApplication.config.mode];
  121. /*$.get("http://ipinfo.io", function(response) {
  122. //console.log(response.city, response.region, response.country);
  123. return dfd.resolve(true, response.ip);
  124. }, "jsonp");*/
  125. $.get(urlHeader+"/ClientAccess/ClientIpAddress", function (response) {
  126. if (response.ip === '::1') {
  127. response.ip = '127.0.0.1';
  128. }
  129. //console.log(response.city, response.region, response.country);
  130. return dfd.resolve(true, response.ip);
  131. });
  132. return dfd.promise();
  133. /*
  134. $.when($.get("http://ipinfo.io", function (response){return response.ip;
  135. }, "jsonp"))
  136. .done(function (ip) {
  137. return ip;
  138. });*/
  139. /*
  140. var xmlhttp;
  141. if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
  142. else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  143. xmlhttp.open("GET", "http://api.hostip.info/get_html.php", false);
  144. xmlhttp.send();
  145. var hostipInfo = xmlhttp.responseText.split("n");
  146. //for (var i=0; hostipInfo.length >= i; i++) {
  147. var ipAddress = hostipInfo[hostipInfo.length - 1].split(": ");
  148. //if ( ipAddress[0] == "IP" ) return ipAddress[1];
  149. var IP = ipAddress[1].split('\n');
  150. return IP[0]; */
  151. },
  152. handleLogoutButton: function () {
  153. // 로그아웃 히스토리 기록
  154. var loginHistoryModel = new BemsWebApplication.CmUserLoginHistoryViewModel();
  155. loginHistoryModel.SiteId = BWA.UserInfo.SiteId;
  156. loginHistoryModel.UserId = BWA.UserInfo.UserId;
  157. loginHistoryModel.Type('Log-Off');
  158. loginHistoryModel.TraceTime(new Date());
  159. //hcLee 2015 11 13
  160. //loginHistoryModel.IpAddress(BWA.LoginOverlay.GetClientIP());
  161. $.when(BWA.LoginOverlay.GetClientIP()).done(function (result, ip) {
  162. loginHistoryModel.IpAddress(ip);
  163. BWA.db.CmUserLoginHistory.insert(loginHistoryModel.toJS());
  164. BWA.UserInfo.logout();
  165. $.removeCookie('id');
  166. $.removeCookie('password');
  167. $.removeCookie('siteId');
  168. $.removeCookie('fromCenter')
  169. clearInterval(BemsWebApplication.app.timer); // hcLee 2015 08 07
  170. //2015 10 28 hcLee 초기화 문제 해결
  171. //alert(Request.UserHostAddress);
  172. //alert(BWA.LoginOverlay.GetClientIP());
  173. //location.reload();
  174. //window.
  175. //location.
  176. BWA.app.navigate('Login');
  177. BWA.LoginOverlay.handleCheckSaveId();
  178. });
  179. },
  180. handleLoginButton: function () {
  181. var siteId = BemsWebApplication.config.siteId;
  182. if ($.cookie('fromCenter')) {
  183. var userId = $.cookie('id');
  184. var userPassword = $.cookie('password');
  185. siteId = $.cookie('siteId') * 1;
  186. if (userId)loginId(userId);
  187. if (userPassword)loginPassword(userPassword);
  188. }
  189. BWA.UserInfo.IsLogin(false);
  190. //alert(password());
  191. if (_.isEmpty(loginId())) {
  192. utils.toast.show('아이디를 입력하여 주십시오.', 'error');
  193. $('#userId').focus();
  194. return;
  195. }
  196. if (_.isEmpty(loginPassword())) {
  197. utils.toast.show('비밀번호를 입력하여 주십시오.', 'error');
  198. $('#userPassword').focus();
  199. return;
  200. }
  201. $.cookie('checkSaveId', checkSaveId());
  202. if (checkSaveId()) {
  203. $.cookie('id',loginId());
  204. }
  205. disabledLoginButton(true);
  206. disabledIdTextBox(true);
  207. disabledPasswordTextBox(true);
  208. disabledCheckSaveId(true);
  209. var userDataSource = BWA.DataUtil.createDataSource({
  210. dataSourceOptions: {
  211. select: [
  212. 'SiteId', 'UserId', 'CompanyId', 'DepartmentId', 'PositionId', 'Name', 'Email', 'UserGroupId', 'BusinessFieldId', 'EmploymentStatus',
  213. 'CmCompany/Name', 'CmDepartment/Name', 'CmPosition/Name', 'CmBusinessField/Name'
  214. ],
  215. expand: ['CmCompany', 'CmDepartment', 'CmPosition', 'CmBusinessField'],
  216. extendOptions: {
  217. alterNames: {
  218. 'CmCompany/Name': 'CompanyName',
  219. 'CmDepartment/Name': 'DepartmentName',
  220. 'CmPosition/Name': 'PositionName',
  221. 'CmBusinessField/Name': 'BusinessFieldName'
  222. }
  223. }
  224. }
  225. }, 'CmUser');
  226. var userGroupPermissionDataSource = BWA.db.createDataSource('CmUserGroupPermission');
  227. var eq = BWA.DataUtil.constructEqualFilter;
  228. var and = BWA.DataUtil.andFilter;
  229. userDataSource.filter([
  230. //eq('SiteId', BemsWebApplication.config.siteId),
  231. [eq('SiteId', siteId), 'or', eq('SiteId', 0)], // hcLee 2016 06 09 수정
  232. 'and',
  233. eq('UserId',loginId()),
  234. 'and',
  235. eq('Passwd',loginPassword()),
  236. ]);
  237. BWA.LoadIndicator.show();
  238. userDataSource.load().done(function (user) {
  239. if (_.isEmpty(user)) {
  240. utils.toast.show('로그인에 실패하였습니다. 아이디 혹은 비밀번호가 다릅니다.', 'error');
  241. loginPassword("");
  242. return;
  243. }
  244. user = user[0];
  245. if (user.EmploymentStatus() == 2 || user.EmploymentStatus() == 3) {
  246. utils.toast.show('휴직/퇴사 사용자는 시스템에 로그인 할 수 없습니다.', 'error');
  247. return;
  248. }
  249. userGroupPermissionDataSource.filter([
  250. eq('SiteId', user.SiteId()),
  251. and,
  252. eq('UserGroupId', user.UserGroupId()),
  253. ]);
  254. userGroupPermissionDataSource.load().done(function (dbMenuPermissions) {
  255. BWA.DataUtil.copyViewModel(user, BWA.UserInfo);
  256. BWA.UserInfo.MenuPermissions(_.map(dbMenuPermissions, function (x) {
  257. return {
  258. MenuId: x.MenuId(),
  259. MenuPermission: x.MenuPermission()
  260. };
  261. }));
  262. // hcLee 2016 06 09
  263. if (BWA.UserInfo.SiteId() == 0) {
  264. BWA.UserInfo.IsCenter(true);
  265. //BWA.UserInfo.SiteId(1);
  266. }
  267. overlayOptions.visible(false);
  268. utils.toast.show('로그인에 성공하였습니다.');
  269. loginId("");
  270. loginPassword("");
  271. BWA.Code.PurchaseProgress.load();
  272. BWA.UserInfo.IsLogin(true);
  273. // 로그인 히스토리 기록
  274. var loginHistoryModel = new BemsWebApplication.CmUserLoginHistoryViewModel();
  275. loginHistoryModel.SiteId = BWA.UserInfo.SiteId;
  276. loginHistoryModel.UserId = BWA.UserInfo.UserId;
  277. loginHistoryModel.Type('Log-On');
  278. loginHistoryModel.TraceTime(new Date());
  279. //2015 11 13 hcLee
  280. //loginHistoryModel.IpAddress(BWA.LoginOverlay.GetClientIP());
  281. $.when(BWA.LoginOverlay.GetClientIP()).done(function (result, ip) {
  282. loginHistoryModel.IpAddress(ip);
  283. BWA.db.CmUserLoginHistory.insert(loginHistoryModel.toJS());
  284. var siteDataSource = BemsWebApplication.db.createDataSource('CmSite', true);
  285. var eq = BWA.DataUtil.constructEqualFilter;
  286. siteDataSource.filter([
  287. eq('SiteId', BWA.UserInfo.SiteId()),
  288. ]);
  289. var bAutoControl;
  290. siteDataSource.load().done(function (site) {
  291. //if (_.isEmpty(site) || site[0].IsControlSchedule() == false) {
  292. if (_.isEmpty(site)) return;
  293. bAutoControl = site[0].IsControlSchedule();
  294. // hcLee 공조기 제어 팝업
  295. //BWA.ControlPanel.show();
  296. BemsWebApplication.app.timer = setInterval(function () {
  297. var now = new Date();
  298. //if (bAutoControl == false && now.getHours () == site[0].ScheduleCheckHour() && (now.getMinutes() == 0) && (now.getSeconds() == 0)) {
  299. // 2016 06 21 두소장과 협의, 플래그가 true면 수동 제어 팝업, 스케줄 자동제어는 플래그 상관없이 동작 안하도록 막음
  300. if (bAutoControl == true && now.getHours () == site[0].ScheduleCheckHour() && (now.getMinutes() == 0) && (now.getSeconds() == 0)) {
  301. BWA.ControlPanel.show();
  302. }
  303. /* 제어팝업 데모 때문에 막음 2015 12 09
  304. if (bAutoControl == true && (now.getMinutes() == site[0].ScheduleCheckHour()) && BWA.UserInfo.IsScheduleUser() && (now.getSeconds() == 0)) {
  305. BWA.ControlPanel.show();
  306. }*/
  307. }, 1000);
  308. });
  309. BWA.BemsFmsMode.setBemsMode('bems');
  310. BWA.app.navigate('MainDashboard');
  311. });
  312. }).fail(handleLoginFail).always(handleAfterTryLogin);
  313. }).fail(handleLoginFail).always(handleAfterTryLogin);
  314. },
  315. isVisible: function () {
  316. return overlayOptions.visible();
  317. },
  318. show: function () {
  319. overlayOptions.visible(true);
  320. }
  321. };
  322. });