$(function () { 'use strict'; var loginId = ko.observable(''), loginPassword = ko.observable(''), checkSaveId = ko.observable(false), disabledLoginButton = ko.observable(false), disabledIdTextBox = ko.observable(false), disabledPasswordTextBox = ko.observable(false), disabledCheckSaveId = ko.observable(false) ; // 디버깅 모드 설정(자동로그인 관련) //var debug = true; var debug = false; // 로그인 후 이동하게될 화면 설정 //var viewAfterLogin = 'ExecutionSchedule'; var overlayOptions = { width: '100%', height: '100%', visible: ko.observable(false), animation: null, shading: true, showingAction: function () { BWA.UserPanel.hide(); }, contentReadyAction: function (e) { BWA.LoginOverlay.handleCheckSaveId(); } }; function handleLoginFail(error) { utils.toast.show('로그인에 실패하였습니다.', 'error'); } function handleAfterTryLogin() { disabledLoginButton(false); disabledIdTextBox(false); disabledPasswordTextBox(false); disabledCheckSaveId(false); BWA.LoadIndicator.promiseAlways(); } BWA.LoginOverlay = { handleCheckSaveId: function() { $('.intro_login_container').parent().parent().css('z-index', 3000); //checkSaveId(false); checkSaveId($.cookie('checkSaveId') == "true" ? true : false); if (checkSaveId()) { var cookieId = $.cookie('id'); loginId(cookieId); } else { var cookieId = ""; loginId(cookieId); } if (debug) { loginId('admin'); loginPassword('kanu123'); //id('lee'); //password('lee'); } }, overlayOptions: overlayOptions, getIdTextBoxOptions: function () { return { value: loginId, disabled: disabledIdTextBox, // cyim 2016.02.17 : 로그인화면 작업 placeholder: ' username', //placeholder: $G('id'), // hcLee 2016 01 25 크롬은 문제없으나 IE 8,9,10에서는 동작안하는 버그 떄문에 직접코드 체크로 변경함 /*enterKeyAction: function (e) { BWA.LoginOverlay.handleLoginButton();*/ onKeyPress: function (e) { if (e.jQueryEvent.charCode == 13) BWA.LoginOverlay.handleLoginButton(); } }; }, getPasswordTextBoxOptions: function () { return { value: loginPassword, disabled: disabledPasswordTextBox, mode: 'password', // cyim 2016.02.17 : 로그인화면 작업 placeholder: ' password',//placeholder: $G('password'), // hcLee 2016 01 25 크롬은 문제없으나 IE 8,9,10에서는 동작안하는 버그 떄문에 직접코드 체크로 변경함 /*enterKeyAction: function (e) { BWA.LoginOverlay.handleLoginButton();*/ onKeyPress: function (e) { //if (e.jQueryEvent.char == '\n') { onKeyDown or onKeyUp의 경우는 이렇게 if (e.jQueryEvent.charCode == 13) { $('#loginbtn').focus(); BWA.LoginOverlay.handleLoginButton(); //$('#userPassword').focus(); } } }; }, getCheckBoxOptions: function () { return { value: checkSaveId, disabled: disabledCheckSaveId }; }, getButtonOptions: function () { return { // cyim 2016.02.17 : 로그인화면 작업 (이미지로 대체함) //icon: 'key', //text: $G('login'), disabled: disabledLoginButton, clickAction: BWA.LoginOverlay.handleLoginButton }; }, GetClientIP: function () { //return "127.0.0.1"; /* node js require('dns').lookup(require('os').hostname(), function (err, add, fam) { //console.log('addr: ' + add); alert(add); })*/ //alert(ko.observable(data.IpAddress)); //return "127.0.0.1"; var dfd = $.Deferred(); var urlHeader = BemsWebApplication.config.endpoints.api[BemsWebApplication.config.mode]; /*$.get("http://ipinfo.io", function(response) { //console.log(response.city, response.region, response.country); return dfd.resolve(true, response.ip); }, "jsonp");*/ $.get(urlHeader+"/ClientAccess/ClientIpAddress", function (response) { if (response.ip === '::1') { response.ip = '127.0.0.1'; } //console.log(response.city, response.region, response.country); return dfd.resolve(true, response.ip); }); return dfd.promise(); /* $.when($.get("http://ipinfo.io", function (response){return response.ip; }, "jsonp")) .done(function (ip) { return ip; });*/ /* var xmlhttp; if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest(); else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.open("GET", "http://api.hostip.info/get_html.php", false); xmlhttp.send(); var hostipInfo = xmlhttp.responseText.split("n"); //for (var i=0; hostipInfo.length >= i; i++) { var ipAddress = hostipInfo[hostipInfo.length - 1].split(": "); //if ( ipAddress[0] == "IP" ) return ipAddress[1]; var IP = ipAddress[1].split('\n'); return IP[0]; */ }, handleLogoutButton: function () { // 로그아웃 히스토리 기록 var loginHistoryModel = new BemsWebApplication.CmUserLoginHistoryViewModel(); loginHistoryModel.SiteId = BWA.UserInfo.SiteId; loginHistoryModel.UserId = BWA.UserInfo.UserId; loginHistoryModel.Type('Log-Off'); loginHistoryModel.TraceTime(new Date()); //hcLee 2015 11 13 //loginHistoryModel.IpAddress(BWA.LoginOverlay.GetClientIP()); $.when(BWA.LoginOverlay.GetClientIP()).done(function (result, ip) { loginHistoryModel.IpAddress(ip); BWA.db.CmUserLoginHistory.insert(loginHistoryModel.toJS()); BWA.UserInfo.logout(); $.removeCookie('id'); $.removeCookie('password'); $.removeCookie('siteId'); $.removeCookie('fromCenter') clearInterval(BemsWebApplication.app.timer); // hcLee 2015 08 07 //2015 10 28 hcLee 초기화 문제 해결 //alert(Request.UserHostAddress); //alert(BWA.LoginOverlay.GetClientIP()); //location.reload(); //window. //location. BWA.app.navigate('Login'); BWA.LoginOverlay.handleCheckSaveId(); }); }, handleLoginButton: function () { var siteId = BemsWebApplication.config.siteId; if ($.cookie('fromCenter')) { var userId = $.cookie('id'); var userPassword = $.cookie('password'); siteId = $.cookie('siteId') * 1; if (userId)loginId(userId); if (userPassword)loginPassword(userPassword); } BWA.UserInfo.IsLogin(false); //alert(password()); if (_.isEmpty(loginId())) { utils.toast.show('아이디를 입력하여 주십시오.', 'error'); $('#userId').focus(); return; } if (_.isEmpty(loginPassword())) { utils.toast.show('비밀번호를 입력하여 주십시오.', 'error'); $('#userPassword').focus(); return; } $.cookie('checkSaveId', checkSaveId()); if (checkSaveId()) { $.cookie('id',loginId()); } disabledLoginButton(true); disabledIdTextBox(true); disabledPasswordTextBox(true); disabledCheckSaveId(true); var userDataSource = BWA.DataUtil.createDataSource({ dataSourceOptions: { select: [ 'SiteId', 'UserId', 'CompanyId', 'DepartmentId', 'PositionId', 'Name', 'Email', 'UserGroupId', 'BusinessFieldId', 'EmploymentStatus', 'CmCompany/Name', 'CmDepartment/Name', 'CmPosition/Name', 'CmBusinessField/Name' ], expand: ['CmCompany', 'CmDepartment', 'CmPosition', 'CmBusinessField'], extendOptions: { alterNames: { 'CmCompany/Name': 'CompanyName', 'CmDepartment/Name': 'DepartmentName', 'CmPosition/Name': 'PositionName', 'CmBusinessField/Name': 'BusinessFieldName' } } } }, 'CmUser'); var userGroupPermissionDataSource = BWA.db.createDataSource('CmUserGroupPermission'); var eq = BWA.DataUtil.constructEqualFilter; var and = BWA.DataUtil.andFilter; userDataSource.filter([ //eq('SiteId', BemsWebApplication.config.siteId), [eq('SiteId', siteId), 'or', eq('SiteId', 0)], // hcLee 2016 06 09 수정 'and', eq('UserId',loginId()), 'and', eq('Passwd',loginPassword()), ]); BWA.LoadIndicator.show(); userDataSource.load().done(function (user) { if (_.isEmpty(user)) { utils.toast.show('로그인에 실패하였습니다. 아이디 혹은 비밀번호가 다릅니다.', 'error'); loginPassword(""); return; } user = user[0]; if (user.EmploymentStatus() == 2 || user.EmploymentStatus() == 3) { utils.toast.show('휴직/퇴사 사용자는 시스템에 로그인 할 수 없습니다.', 'error'); return; } userGroupPermissionDataSource.filter([ eq('SiteId', user.SiteId()), and, eq('UserGroupId', user.UserGroupId()), ]); userGroupPermissionDataSource.load().done(function (dbMenuPermissions) { BWA.DataUtil.copyViewModel(user, BWA.UserInfo); BWA.UserInfo.MenuPermissions(_.map(dbMenuPermissions, function (x) { return { MenuId: x.MenuId(), MenuPermission: x.MenuPermission() }; })); // hcLee 2016 06 09 if (BWA.UserInfo.SiteId() == 0) { BWA.UserInfo.IsCenter(true); //BWA.UserInfo.SiteId(1); } overlayOptions.visible(false); utils.toast.show('로그인에 성공하였습니다.'); loginId(""); loginPassword(""); BWA.Code.PurchaseProgress.load(); BWA.UserInfo.IsLogin(true); // 로그인 히스토리 기록 var loginHistoryModel = new BemsWebApplication.CmUserLoginHistoryViewModel(); loginHistoryModel.SiteId = BWA.UserInfo.SiteId; loginHistoryModel.UserId = BWA.UserInfo.UserId; loginHistoryModel.Type('Log-On'); loginHistoryModel.TraceTime(new Date()); //2015 11 13 hcLee //loginHistoryModel.IpAddress(BWA.LoginOverlay.GetClientIP()); $.when(BWA.LoginOverlay.GetClientIP()).done(function (result, ip) { loginHistoryModel.IpAddress(ip); BWA.db.CmUserLoginHistory.insert(loginHistoryModel.toJS()); var siteDataSource = BemsWebApplication.db.createDataSource('CmSite', true); var eq = BWA.DataUtil.constructEqualFilter; siteDataSource.filter([ eq('SiteId', BWA.UserInfo.SiteId()), ]); var bAutoControl; siteDataSource.load().done(function (site) { //if (_.isEmpty(site) || site[0].IsControlSchedule() == false) { if (_.isEmpty(site)) return; bAutoControl = site[0].IsControlSchedule(); // hcLee 공조기 제어 팝업 //BWA.ControlPanel.show(); BemsWebApplication.app.timer = setInterval(function () { var now = new Date(); //if (bAutoControl == false && now.getHours () == site[0].ScheduleCheckHour() && (now.getMinutes() == 0) && (now.getSeconds() == 0)) { // 2016 06 21 두소장과 협의, 플래그가 true면 수동 제어 팝업, 스케줄 자동제어는 플래그 상관없이 동작 안하도록 막음 if (bAutoControl == true && now.getHours () == site[0].ScheduleCheckHour() && (now.getMinutes() == 0) && (now.getSeconds() == 0)) { BWA.ControlPanel.show(); } /* 제어팝업 데모 때문에 막음 2015 12 09 if (bAutoControl == true && (now.getMinutes() == site[0].ScheduleCheckHour()) && BWA.UserInfo.IsScheduleUser() && (now.getSeconds() == 0)) { BWA.ControlPanel.show(); }*/ }, 1000); }); BWA.BemsFmsMode.setBemsMode('bems'); BWA.app.navigate('MainDashboard'); }); }).fail(handleLoginFail).always(handleAfterTryLogin); }).fail(handleLoginFail).always(handleAfterTryLogin); }, isVisible: function () { return overlayOptions.visible(); }, show: function () { overlayOptions.visible(true); } }; });