123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694 |
- $(function () {
- 'use strict';
- // 디버깅 모드 설정(자동로그인 관련)
- //var debug = true;
- var debug = false;
- var eq = BWA.DataUtil.constructEqualFilter;
- // 로그인 후 이동하게될 화면 설정
- //var viewAfterLogin = 'ExecutionSchedule';
- var siteid = ko.observable(''),
- id = ko.observable(''),
- password = ko.observable(''),
- checkSaveId = ko.observable(false),
- disabledLoginButton = ko.observable(false),
- disabledIdTextBox = ko.observable(false),
- disabledPasswordTextBox = ko.observable(false),
- disabledCheckSaveId = ko.observable(false);
- var menuDataSource = BWA.db.createDataSource('CmMenu');
- var overlayOptions = {
- width: '100%',
- height: '100%',
- visible: ko.observable(false),
- animation: null,
- shading: true,
- showingAction: function () {
- BWA.UserPanel.hide();
- },
- shownAction: function () {
- if (BemsWebApplication.config.siteenable) {
- $('#imageId').attr('src', '/Images/Login/intro_login_box_2.png');
- document.getElementById("userId").className = "login_id_area_content2";
- document.getElementById("userPassword").className = "login_pw_area_content2";
- }
- else {
- $('#imageId').attr('src', '/Images/Login/intro_login_box.png');
- document.getElementById("userId").className = "login_id_area_content";
- document.getElementById("userPassword").className = "login_pw_area_content";
- }
- },
- contentReadyAction: function (e) {
- BWA.LoginOverlay.handleCheckSaveId();
- }
- };
- function handleLoginFail(error) {
- utils.toast.show('로그인에 실패하였습니다.', 'error');
- }
- function updateMenuHide(vid) {
- _.each($SideMenu.sideMenuSet, function (items, id) {
- (function MenuHide(array, id, exelement) {
- _.each(array, function (element) {
- if (element.viewId == (typeof (vid) == "object" ? vid.MenuId() : vid)) {
- element.show(false);
- if (exelement != null) {
- if (exelement.subMenus != null) {
- var cnt = 0;
- for (var i = 0; i < exelement.subMenus.length; i++) {
- if (exelement.subMenus[i].show() == false) {
- cnt++;
- if (exelement.subMenus.length == cnt) {
- exelement.show(false);
- }
- }
- }
- }
- }
- return;
- }
- if (element.subMenus) {
- return MenuHide(element.subMenus, (typeof (vid) == "object" ? vid.MenuId() : vid), element);
- }
- });
- })(items, id);
- })
- }
- //2018 02 19 hcLee
- function initMenu() {
- _.each($SideMenu.sideMenuSet, function (items, id) {
- (function MenuShow(array, id) {
- _.each(array, function (element) {
- element.show(true);
- if (element.subMenus) {
- return MenuShow(element.subMenus, id);
- }
- });
- })(items, id);
- })
- }
- 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');
- id(cookieId);
- var cookiesiteId = $.cookie('siteid');
- siteid(cookiesiteId);
- }
- else {
- var cookieId = "";
- id(cookieId);
- siteid(cookieId);
- }
- if (debug) {
- id('admin');
- password('kanu123');
- //id('lee');
- //password('lee');
- }
- },
- overlayOptions: overlayOptions,
- getsiteIdTextBoxOptions: function () {
- if (BemsWebApplication.config.siteenable) {
- return {
- value: siteid,
- disabled: disabledIdTextBox,
- visible: true,
- placeholder: ' siteID', //placeholder: $G('id'),
- };
- }
- else {
- return {
- value: siteid,
- disabled: disabledIdTextBox,
- visible: false,
- placeholder: ' siteID', //placeholder: $G('id'),
- };
- }
- },
- getIdTextBoxOptions: function () {
- return {
- value: id,
- 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: password,
- 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();
- if (!checkSaveId()) //2018 03 31 hcLee
- {
- $.removeCookie('id');
- $.removeCookie('siteId');
- }
- $.removeCookie('password');
- $.removeCookie('fromCenter')
- clearInterval(BemsWebApplication.app.timer); // hcLee 2015 08 07
- //2015 10 28 hcLee 초기화 문제 해결
- //alert(Request.UserHostAddress);
- //alert(BWA.LoginOverlay.GetClientIP());
- //2018 03 31 hcLee
- location.reload();
- //window.
- //location.
- /*
- BWA.app.navigate('Login');
- BWA.LoginOverlay.handleCheckSaveId();*/
- });
- },
- handleLoginButton: function () {
- var siteId;
- if (BemsWebApplication.config.siteenable) {
- siteId = parseInt(siteid());
- }
- else {
- siteId = BemsWebApplication.config.siteId;
- }
- if (BWA.config["center-mode"]) {
- if ($.cookie('fromCenter')) {
- var userId = $.cookie('id');
- var userPassword = $.cookie('password');
- siteId = $.cookie('siteId') * 1;
- if (userId) id(userId);
- if (userPassword) password(userPassword);
- if (siteId) siteid(siteId);
- }
- }
- BWA.UserInfo.IsLogin(false);
- //alert(password());
- if (BemsWebApplication.config.siteenable) {
- if (_.isEmpty(siteid())) {
- utils.toast.show('사이트 아이디를 입력하여 주십시오.', 'error');
- $('#siteId').focus();
- return;
- }
- }
- if (_.isEmpty(id())) {
- utils.toast.show('아이디를 입력하여 주십시오.', 'error');
- $('#userId').focus();
- return;
- }
- if (_.isEmpty(password())) {
- utils.toast.show('비밀번호를 입력하여 주십시오.', 'error');
- $('#userPassword').focus();
- return;
- }
- $.cookie('checkSaveId', checkSaveId());
- if (checkSaveId()) {
- $.cookie('id', id());
- $.cookie('siteid', siteid());
- }
- 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', 'CmUserGroup/Name'
- ],
- expand: ['CmCompany', 'CmDepartment', 'CmPosition', 'CmBusinessField', 'CmUserGroup'],
- extendOptions: {
- alterNames: {
- 'CmCompany/Name': 'CompanyName',
- 'CmDepartment/Name': 'DepartmentName',
- 'CmPosition/Name': 'PositionName',
- 'CmBusinessField/Name': 'BusinessFieldName',
- 'CmUserGroup/Name': 'UserGroupName',
- }
- }
- }
- }, 'CmUser');
- var userGroupPermissionDataSource = BWA.db.createDataSource('CmUserGroupPermission');
- // hcLee 2018 02 23
- var chartInfoDataSource = BWA.db.createDataSource('BemsChartInfo');
- var eq = BWA.DataUtil.constructEqualFilter;
- var and = BWA.DataUtil.andFilter;
- if (BemsWebApplication.config.siteenable) {
- userDataSource.filter([
- eq('SiteId', siteId), // hcLee 2016 06 09 수정
- 'and',
- eq('UserId', id()),
- 'and',
- eq('Passwd', password()),
- ]);
- }
- else {
- userDataSource.filter([
- [eq('SiteId', BemsWebApplication.config.siteId), 'or', eq('SiteId', 0)], // hcLee 2016 06 09 수정
- 'and',
- eq('UserId', id()),
- 'and',
- eq('Passwd', password()),
- ]);
- }
- BWA.LoadIndicator.show();
- userDataSource.load().done(function (user) {
- if (_.isEmpty(user)) {
- utils.toast.show('로그인에 실패하였습니다. 아이디 혹은 비밀번호가 다릅니다.', 'error');
- password("");
- 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()),
- ]);
- // hcLee 2018 02 23
- chartInfoDataSource.filter([eq('SiteId', user.SiteId()), and, eq('UseChart', true)]);
- $.when(userGroupPermissionDataSource.load(), chartInfoDataSource.load()
- ).done(function (dbMenuPermissions, chartInfos) {
- //userGroupPermissionDataSource.load().done(function (dbMenuPermissions) {
- BWA.DataUtil.copyViewModel(user, BWA.UserInfo);
- BWA.UserInfo.chartInfo(chartInfos[0]);
- BWA.UserInfo.MenuPermissions(_.map(dbMenuPermissions[0], 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);
- }
- var CmSite = BemsWebApplication.db.createDataSource('CmSite');
- CmSite.filter([
- ['SiteId', '=', BWA.UserInfo.SiteId()]
- ]);
- CmSite.load().done(function (result) {
- var dataArray = [];
- _.each(result, function (x) {
- dataArray.push({
- SiteName: x.Name()
- });
- BWA.Desktop.SiteName = dataArray[0].SiteName;
- $('#site-name').html(dataArray[0].SiteName);
- $('#version-name').html(BemsWebApplication.config.Version);
- });
- });
- overlayOptions.visible(false);
- utils.toast.show('로그인에 성공하였습니다.');
- id("");
- password("");
- 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);
- });
- initMenu(); //2018 02 19 hcLee
- //$SideMenu.sideMenuSet = [];
- /*
- if ($SideMenu.sideMenuSet.navConfiguration != undefined)
- delete $SideMenu.sideMenuSet.navConfiguration;*/
- //BWA.SetMenunavConfiguration();
- //BWA.SetMenunavMaterial();
- //$SideMenu.showSideMenuIfWill();
- // 2018 01 19 hcLee, admin이 아니면 메뉴설정은 안보인다.
- //if (BWA.UserInfo.UserId() != "admin")
- // 20190828 admin 계정을 제외한 사용자 정보 확인 페이지 차단
- if (BWA.UserInfo.UserId() == "admin")
- menuDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- eq('Used', false)
- ]);
- else {
- menuDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- [eq('Used', false), 'or', eq('MenuId', 'UserCheck')]
- ]);
- }
- menuDataSource.load().done(function (hideMenus) {
- $.each(hideMenus, function (i, item) {
- updateMenuHide(item);
- });
- if (BWA.UserInfo.UserId() != "admin") updateMenuHide('SetMenu');
- if (BWA.UserInfo.UserId() != "admin") updateMenuHide('SetChart');
- if (BWA.config['BemsFmsMode'] != 0) {
- if ($("#mode_button").dxButton("instance") != null) {
- $("#mode_button").dxButton("instance").option("visible", false);
- }
- } else {
- if ($("#mode_button").dxButton("instance") != null) {
- $("#mode_button").dxButton("instance").option("visible", true);
- }
- }
- if (BWA.config['BemsFmsMode'] == 2) {
- BWA.BemsFmsMode.setBemsMode(false);
- BWA.app.navigate('FacilityTaskReport');
- } else {
- BWA.BemsFmsMode.setBemsMode('bems');
- BWA.app.navigate('MainDashboard');
- }
- });
- });
- // 알람 정보를 출력하자
- if (BemsWebApplication.config.control) {
- AlarmLog();
- SetAlarmInfo();
- }
- }).fail(handleLoginFail).always(handleAfterTryLogin);
- }).fail(handleLoginFail).always(handleAfterTryLogin);
- },
- isVisible: function () {
- return overlayOptions.visible();
- },
- show: function () {
- overlayOptions.visible(true);
- }
- };
- // 알람 로그
- var alarm_image = false;
- // 알람 정보를 출력하자
- function SetAlarmInfo() {
- // 1초에 한번 TICK
- var alarm_timer = setInterval(function () {
- var now = new Date();
- var minute = now.getMinutes();
- var second = now.getSeconds();
- if (((minute == 1) || (minute == 16) || (minute == 31) || (minute == 46)) && (second == 10)) {
- // 팝업이 열려 있으면 닫았다가 다시 열자
- $("#PopupAlarm").dxPopup('instance').option('visible', false);
- // 알람 로그
- AlarmLog();
- }
- // 알람이 존재한다
- if (BWA.AlarmInfo.Alarm_Image_Change() == true) {
- if (alarm_image == false) {
- $("#alarm_button").dxButton("instance").option("type", "danger");
- alarm_image = true;
- }
- else {
- $("#alarm_button").dxButton("instance").option("type", "normal");
- alarm_image = false;
- }
- }
- else // 알람이 없다(알람 해제 실행시)
- {
- if ($("#alarm_button").dxButton("instance") != null) {
- $("#alarm_button").dxButton("instance").option("type", "normal");
- }
- alarm_image = false;
- }
- }, 1000);
- }
- function AlarmLog() {
- var BemsAlarmLogDataSource = BemsWebApplication.DataUtil.createDataSource({
- dataSourceOptions: {
- select: [
- 'CreatedDateTime', 'BemsAlarmSetting/FacilityName', 'BemsAlarmSetting/PointName', 'CurrentValue', 'BemsAlarmSetting/UpperLimit', 'BemsAlarmSetting/LowerLimit', 'SMSResult', 'EmailResult',
- 'SiteId', 'FacilityTypeId', 'FacilityCode', 'PropertyId', 'FormulaId'
- ],
- expand: ['BemsAlarmSetting'],
- extendOptions: {
- forceOriginalField: true,
- alterNames: {
- 'BemsAlarmSetting/FacilityName': 'FacilityName',
- 'BemsAlarmSetting/PointName': 'PointName',
- 'BemsAlarmSetting/UpperLimit': 'UpperLimit',
- 'BemsAlarmSetting/LowerLimit': 'LowerLimit'
- }
- },
- filter: [
- ['SiteId', '=', BWA.UserInfo.SiteId()],
- 'and',
- ['Conform', '=', false]
- ]
- }
- }, 'BemsAlarmLog');
- BemsAlarmLogDataSource.load().done(function (result) {
- if (result.length > 0) BWA.AlarmInfo.Alarm_Image_Change = true;
- else BWA.AlarmInfo.Alarm_Image_Change = false;
- var DataArrayInfo = [];
- _.each(result, function (x) {
- var temp = '';
- if (x.FormulaId() != 0) {
- temp = '성능분석';
- }
- else {
- if (x.FacilityTypeId() == 99) {
- temp = '가상시설';
- }
- else {
- temp = '일반시설';
- }
- }
- DataArrayInfo.push({
- CreatedDateTime: x.CreatedDateTime,
- Type: temp,
- FacilityName: x.FacilityName,
- PropertyName: x.PointName,
- CurrentValue: x.CurrentValue,
- UpperLimit: x.UpperLimit,
- LowerLimit: x.LowerLimit,
- SMSResult: x.SMSResult,
- EmailResult: x.EmailResult,
- Check: "확인",
- SiteId: x.SiteId,
- FacilityTypeId: x.FacilityTypeId,
- FacilityCode: x.FacilityCode,
- PropertyId: x.PropertyId,
- FormulaId: x.FormulaId
- });
- });
- //$("#gridContainer").dxDataGrid("instance").option("dataSource", DataArrayInfo);
- if (result.length > 0) // 알람 정보가 있을때만 팝업 출력
- {
- $("#PopupAlarm").dxPopup('instance').option('visible', true);
- }
- })
- }
- });
|