| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 | $(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);        }    };});
 |