123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588 |
- BemsWebApplication.Point = function (params, viewInfo) {
- "use strict";
- var VIRTUAL_FACILITY_ID = 1,
- FACILITY_ID = 2,
- //FACILITY_DEPTH = 2,
- FACILITY_DEPTH = 3, // hcLee
- BID_INSERT_VIRTUAL_FACILITY = 0,
- BID_EDIT_VIRTUAL_FACILITY = 1,
- BID_GENERATE_POINT = 2,
- BID_DELETE_POINT = 3;
- //권한설정
- var hasnotModificationPermission = ko.observable(true);
- var disabledButtons = [ko.observable(), ko.observable(), ko.observable(), ko.observable()];
- // 2016 06 03 hcLee 추가
- var facilityTypeDataSource = BemsWebApplication.db.createDataSource('BemsFacilityType');
- var BemsMonitoringPointInfo = ko.observableArray();
- var BemsMonitoringPointDataSource = BemsWebApplication.db.createDataSource('BemsMonitoringPoint');
- var RowName;
- var facilityDataSource = BWA.DataUtil.createDataSource({
- dataSourceOptions: {
- select: [
- 'SiteId', 'FacilityCode', 'Name', 'FacilityTypeId', 'BemsFacilityType/Name', 'IsVirtualFacility'
- ],
- expand: ['BemsFacilityType'],
- extendOptions: {
- forceOriginalField: true
- },
- paginate: false, // 페이징을 하지 않음
- }
- }, 'CmFacility'),
- factory = BemsWebApplication.Factory.PointLocationMapping,
- viewModel,
- popup = null,
- virtualFacilityPopup = null,
- popupVisible = ko.observable(false),
- eq = BWA.DataUtil.constructEqualFilter,
- selectedTreeData = ko.observable(null),
- selectedTreeItem = ko.observable(null);
- var commandButtonOptions = [{
- icon: 'add',
- id: 'create1',
- title: '가상시설등록',
- disabled: disabledButtons[BID_INSERT_VIRTUAL_FACILITY],
- action: handlePopupInsertVirtualFacility
- }, {
- icon: 'edit',
- id: 'create2',
- title: '가상시설수정',
- disabled: disabledButtons[BID_EDIT_VIRTUAL_FACILITY],
- action: handlePopupUpdateVirtualFacility
- }, {
- icon: 'add',
- id: 'create3',
- title: '관제점초기생성',
- disabled: disabledButtons[BID_GENERATE_POINT],
- action: generatePoints
- }, {
- icon: 'remove',
- id: 'delete',
- title: '관제점삭제',
- disabled: disabledButtons[BID_DELETE_POINT],
- action: handleRemoveSelectedPoints
- }];
- function handleClickTreeItem(element, data) {
- var eq = BWA.DataUtil.constructEqualFilter;
- selectedTreeItem(data);
- var filter;
- var depth = data.depth;
- var parentData = data.parentData;
- data = data.data;
- selectedTreeData(data);
- //if (depth !== FACILITY_DEPTH) {
- if (depth == 1) {
- if (data.Id === FACILITY_ID) {
- filter = getFacilityFilter();
- }
- else {
- filter = getVirtualFacilityFilter();
- }
- }
- else if (depth == 2) {
- filter = [
- eq('SiteId', BWA.UserInfo.SiteId()),
- 'and',
- //eq('FacilityTypeId', data.FacilityCode()),
- eq('FacilityTypeId', data.FacilityTypeId()),
- ];
- }
- else {
- filter = [
- eq('SiteId', BWA.UserInfo.SiteId()),
- 'and',
- eq('FacilityCode', data.FacilityCode()),
- ];
- }
- viewModel.setGridViewFilter(filter);
- }
- function getVirtualFacilityFilter() {
- // FacilityTypeId 99 은 가상설비의 타입 아이디 임
- return [
- ['SiteId', '=', BWA.UserInfo.SiteId()],
- 'and',
- ['FacilityTypeId', '=', 99],
- ];
- }
- function getFacilityFilter() {
- return [
- ['SiteId', '=', BWA.UserInfo.SiteId()],
- 'and',
- ['FacilityTypeId', '<', 99]
- ];
- }
- function handleViewShown() {
- hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
- if (hasnotModificationPermission()) {
- for (var i = 0; i < 4; i++) {
- commandButtonOptions[i].disabled(true);
- }
- } else {
- for (var i = 0; i < 4; i++) {
- commandButtonOptions[i].disabled(false);
- }
- }
- // start warning : 아래 코드는 화면이 열릴때 마다 확인 함. 성능상 이슈 발생 가능성이 있음
- if (facilityDataSource._items.length != 0) {
- var data = selectedTreeItem();
- if (data != null) $('#facilityTreeView').cwTreeView('reload', selectedTreeItem().parentData);
- }
- // end warning
- var eq = BWA.DataUtil.constructEqualFilter;
- $('#facilityTreeView').cwTreeView({
- width: '30%',
- height: 'auto',
- //maxDepth: 2,
- //height: '480px',
- onClickTreeItem: handleClickTreeItem,
- delegateDataSource: function (data, alterObj) {
- var id = data.id;
- var depth = data.depth;
- var promise = null;
- switch (depth) {
- case 0:
- var typeDeferred = new $.Deferred();
- promise = typeDeferred.promise();
- alterObj.IsFunction = false;
- typeDeferred.resolve([{
- Id: VIRTUAL_FACILITY_ID,
- Name: '가상시설'
- }, {
- Id: FACILITY_ID,
- Name: '일반시설'
- }
- ])
- break;
- case 1:
- var filter;
- switch (data.data.Id) {
- /*
- case VIRTUAL_FACILITY_ID:
- filter = getVirtualFacilityFilter();
- break;
- case FACILITY_ID:
- filter = getFacilityFilter();
- break;
- */
- case FACILITY_ID: filter = [['FacilityTypeId', '<', 99]]; break;
- case VIRTUAL_FACILITY_ID: filter = [['FacilityTypeId', '=', 99]]; break;
- }
- facilityTypeDataSource.filter(filter);
- promise = facilityTypeDataSource.load();
- //facilityDataSource.filter(filter);
- //promise = facilityDataSource.load();
- break;
- case 2:
- facilityDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- 'and',
- eq('FacilityTypeId', data.data.FacilityTypeId())
- ]);
- promise = facilityDataSource.load();
- break;
- }
- return promise;
- }
- });
- popup.handleViewShown();
- virtualFacilityPopup.handleViewShown();
- }
- function handleAddPoints(points) {
- if (points.length === 0) return;
- if (selectedTreeData() === null) {
- utils.toast.show('선택된 빌딩/층/존이 없습니다.', 'warning');
- return null;
- }
- var rows = window.utils.datagrid.getItems(gridView);
- points = _.map(points, function (item) {
- var facilityCode = item.FacilityCode;
- var propertyId = item.PropertyId;
- if (_.some(rows, function (x) {
- return (x.FacilityCode() === facilityCode && x.PropertyId === propertyId);
- })) {
- return null;
- }
- return item;
- });
- var data = selectedTreeData();
- var parameters = {
- BuildingId: data.BuildingId()
- };
- if (_.isUndefined(data.FloorId) === false) {
- parameters.FloorId = data.FloorId();
- if (_.isUndefined(data.ZoneId) === false) {
- parameters.ZoneId = data.ZoneId();
- }
- else {
- parameters.ZoneId = null;
- }
- }
- else {
- parameters.FloorId = null;
- parameters.ZoneId = null;
- }
- var postData = [];
- var itemKeys = ['SiteId', 'FacilityCode', 'PropertyId'];
- var toJS = BWA.DataUtil.convertHybridViewModelToJS;
- // $.each(points.concat(rows), function(i, item) {
- $.each(points, function (i, item) {
- item = toJS(_.pick(item, itemKeys));
- item = $.extend(item, parameters);
- postData.push(item);
- });
- parameters.SiteId = data.SiteId();
- var promise = BemsWebApplication.api.post(
- 'BemsMonitoringPoint/AddLocation', postData, parameters
- );
- promise.done(function () {
- utils.toast.show($G('successDatabaseProcessMsg'));
- gridView.refresh();
- });
- return promise;
- }
- function handlePopupInsertVirtualFacility() {
- virtualFacilityPopup.show();
- }
- function handlePopupUpdateVirtualFacility() {
- var item = selectedTreeItem();
- var isExist = ko.observable(false);
- if (_.isNull(item)) {
- utils.toast.show('가상시설을 선택해 주십시오.', 'warning');
- return;
- }
- if (item.depth !== FACILITY_DEPTH || item.parentData.data.Id === FACILITY_ID) {
- utils.toast.show('가상시설만 수정이 가능합니다.', 'warning');
- return;
- }
-
- if (item != null && item.depth === FACILITY_DEPTH) {
- facilityDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- 'and',
- eq('FacilityTypeId', item.data.FacilityTypeId())
- ]);
- facilityDataSource.load().done(function (result) {
- for (var i = 0; i < result.length; i++) {
- if (item.data.Name() == result[i].Name()) {
- isExist(true);
- }
- }
- if (_.isNull(item) || item.depth !== FACILITY_DEPTH || isExist() === false) {
- utils.toast.show('관제점을 등록할 시설을 선택하여 주십시오.', 'warning');
- }
- else {
- virtualFacilityPopup.show(BWA.DataUtil.convertViewModelToJS(selectedTreeData()), item.data.Name());
- }
- });
- }
- else {
- utils.toast.show('관제점을 등록할 시설을 선택하여 주십시오.', 'warning');
- }
- }
- function generatePoints() {
- var item = selectedTreeItem();
- if (_.isNull(item) ||
- (item.depth === 1 && item.data.Id !== FACILITY_ID) ||
- //(item.depth === 2 && item.parentData.data.Id !== FACILITY_ID) ||
- (item.depth === 2) ||
- (item.depth === 3 && item.parentData.parentData.data.Id !== FACILITY_ID)
- ) {
- utils.toast.show('모든 시설의 관제점을 재생성하려면 "일반시설"을 선택하시고, 아니면 특정 시설을 선택해 주십시오.', 'warning');
- return;
- }
- DevExpress.ui.dialog.confirm(
- '전체 혹은 선택된 시설의 관제점이 생성됩니다. 기존에 설정된 관제점 정보가 삭제됩니다. \n계속 진행하시겠습니까?',
- '관제점 생성'
- ).then(function (result) {
- if (result) {
- var data = item.data;
- var postData = {};
- switch (item.depth) {
- case 1: // 전체
- postData.SiteId = BWA.UserInfo.SiteId();
- postData.FacilityTypeId = null;
- postData.FacilityCode = null;
- break;
- case 2: // 2016 06 03 hcLee 추가
- postData.SiteId = BWA.UserInfo.SiteId();
- postData.FacilityTypeId = data.FacilityTypeId();
- postData.FacilityCode = null;
- break;
- case 3: // 특정 시설 // 2016 06 03 hcLee 수정 기존 2 -> 3으로 변경
- postData.SiteId = BWA.UserInfo.SiteId();
- postData.FacilityTypeId = data.FacilityTypeId();
- postData.FacilityCode = data.FacilityCode();
- break;
- }
- disabledButtons[BID_GENERATE_POINT](true);
- BWA.api.post('BemsMonitoringPoint/Generation', postData)
- .always(function () {
- disabledButtons[BID_GENERATE_POINT](false);
- }).done(function () {
- viewModel.refreshList();
- utils.toast.show('관제점 생성을 성공하였습니다.');
- });
- }
- });
- }
- function handleRemoveSelectedPoints() {
- var gridView = viewModel.gridView();
- var rows = gridView.getSelectedRowsData();
- if (_.isEmpty(rows)) {
- utils.toast.show('선택된 관제점이 없습니다.', 'warning');
- return;
- }
- // 삭제확인 메세지 박스 추가 hcLee 2016 06 03
- DevExpress.ui.dialog.confirm($G('deleteConfirmMsg'), "삭제").then(function (result) {
- if (result) {
- //handleConfirmDelete();
- var postData = [];
- var itemKeys = BWA.db.BemsMonitoringPoint.key();
- var toJS = BWA.DataUtil.convertHybridViewModelToJS;
- $.each(rows, function (i, item) {
- item = toJS(_.pick(item, itemKeys));
- postData.push(item);
- });
- var promise = BemsWebApplication.api.del(
- 'BemsMonitoringPoint', postData
- );
- promise.done(function () {
- utils.toast.show($G('successDatabaseProcessMsg'));
- gridView.clearSelection();
- gridView.refresh();
- });
- return promise;
- }
- });
- }
- viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'BemsMonitoringPoint', {
- dataSourceOptions: factory.getDataSourceOptions(),
- selection: {
- mode: 'multiple'
- },
- columns: factory.getColumns([
- { dataField: 'CmFacility/Name', width: '40%' },
- { dataField: 'Name', width: '40%' },
- //{ dataField: 'ValueType', width: '20%' },
- { dataField: 'BemsFuelType/Name', caption: '에너지원', width: '30%', alignment: 'center' },
- { dataField: 'BemsServiceType/Name', caption: '용도', width: '30%', alignment: 'center' },
- ]),
- searchViewItems: [
- { id: 'CmFacility/Name' },
- { id: 'Name' }
- ],
- popupWidth: 520,
- insertButtonText: $G('pointInsert'),
- useNumberColumn: false,
- hasnotModificationPermission: hasnotModificationPermission, //권한설정
- handleViewShown: handleViewShown,
- handleInitializeDataModelValue: function (dataModel) {
- popup.handleInitializeDataModelValue(dataModel);
- },
- handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
- popup.handleDataGridRowClick.apply(this, arguments);
- var data = clickRow.data;
- RowName = data.Name;
- },
- // 이름 중복 방지
- handlePopupShowing: function () {
- var item = selectedTreeItem();
- BemsMonitoringPointDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- 'and',
- eq('FacilityTypeId', item.data.FacilityTypeId())
- ]);
- BemsMonitoringPointDataSource.load().done(function (result) {
- BemsMonitoringPointInfo(result);
- });
- },
- beforeInsertingDataViewModel: function (dataModel, dbModelId) {
- var dfd = $.Deferred();
- var param = {
- SiteId: dataModel.SiteId(),
- FacilityCode: dataModel.FacilityCode()
- };
- var isDuplicated = false;
- for (var i = 0; i < BemsMonitoringPointInfo().length; i++) {
- if (dataModel.Name() == BemsMonitoringPointInfo()[i].Name()) {
- isDuplicated = true;
- break;
- }
- }
- if (!BWA.DataUtil.isValidInputValue(dataModel.Name()))
- return dfd.resolve(false, '저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)');
- else {
- if (isDuplicated)
- return dfd.resolve(false, '이미 동일 정보가 존재합니다.');
- else {
- $.when(BWA.api.post('BemsMonitoringPoint/GetMaxPropertyId', param))
- .done(function (newPid) {
- if (newPid > 0) {
- dataModel.PropertyId(newPid);
- dfd.resolve(true); // hcLee OK good, (true, false 또는 객체로 리턴가능함) 2015 11 19
- }
- else dfd.resolve(false, 'ProprttyId 자동 생성에 실패하였습니다!'); // hcLee OK good, (true, false 또는 객체로 리턴가능함) 2015 11 19
- });
- return dfd.promise();
- }
- }
- },
- beforeUpdateDataViewModel: function () {
- var isDuplicated = false;
- for (var i = 0; i < BemsMonitoringPointInfo().length; i++) {
- if (viewModel.dataModel.Name() == BemsMonitoringPointInfo()[i].Name() && RowName() != BemsMonitoringPointInfo()[i].Name()) {
- isDuplicated = true;
- break;
- }
- }
- if (!BWA.DataUtil.isValidInputValue(viewModel.dataModel.Name())) {
- utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
- return 0;
- }
- else {
- if (isDuplicated) {
- utils.toast.show('이미 동일 정보가 존재합니다.', 'error');
- return 0;
- }
- else
- return 2;
- }
- }
- //if (!isNewInPopup()) return true;
- });
- function InsertButtonClickAction() {
-
- var isExist = ko.observable(false);
- var item = selectedTreeItem();
- if (item != null && item.depth === FACILITY_DEPTH) {
- facilityDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- 'and',
- eq('FacilityTypeId', item.data.FacilityTypeId())
- ]);
- facilityDataSource.load().done(function (result) {
- for (var i = 0; i < result.length; i++) {
- if (item.data.Name() == result[i].Name()) {
- isExist(true);
- }
- }
- if (_.isNull(item) || item.depth !== FACILITY_DEPTH || isExist() === false) {
- utils.toast.show('관제점을 등록할 시설을 선택하여 주십시오.', 'warning');
- }
- else {
- viewModel.popupInsertView();
- }
- });
- }
- else {
- utils.toast.show('관제점을 등록할 시설을 선택하여 주십시오.', 'warning');
- }
- }
- viewModel.commandButtonOptions = commandButtonOptions;
- viewModel.handleRemoveSelectedPoints = handleRemoveSelectedPoints;
- popup = viewModel.popup = BWA.Popup.Point.create(viewModel, selectedTreeItem);
- virtualFacilityPopup = viewModel.virtualFacilityPopup = BWA.Popup.VirtualFacility.create(viewModel, selectedTreeItem);
- viewModel.popupInsertButtonOptions = {
- icon: 'add',
- id: 'create',
- title: '관제점등록',
- action: InsertButtonClickAction
- };
- return viewModel;
- };
|