123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- BemsWebApplication.PointLocationMapping = function (params, viewInfo) {
- "use strict";
- var BUILDING_DEPTH = 1,
- FLOOR_DEPTH = 2,
- ZONE_DEPTH = 3;
- //권한설정
- var hasnotModificationPermission = ko.observable(true);
- //var buildingDataSource = BemsWebApplication.db.createDataSource('CmBuilding', true),
- var buildingDataSource = BemsWebApplication.db.createDataSource('CmBuilding', [('SiteId', '=', BWA.UserInfo.SiteId())]),
- floorDataSource = BemsWebApplication.db.createDataSource('CmFloor', true),
- zoneDataSource = BemsWebApplication.db.createDataSource('CmZone', true),
- factory = BemsWebApplication.Factory.PointLocationMapping,
- viewModel, gridView,
- popupVisible = ko.observable(false),
- selectedTreeItemData = ko.observable(null),
- selectedTreeItem = ko.observable(null), // 2015 11 12 hcLee 추가 기존 TreeItem -> TreeItemData 로 변경 하고 (위) 이거 추가함
- // selectedPoints = ko.observableArray(),
- dataSource = factory.getDataSource(),
- //dataSource. (dataSourceOptions).filter = ['SiteId', '=', BWA.UserInfo.SiteId()],
- dataGridOptions = utils.datagrid.defaultOptions({
- dxDataSource: dataSource,
- // datagridId: datagridId,
- dbId: 'BemsMonitoringPoint',
- width: '100%',
- height: 685,
- selection: {
- mode: 'multiple'
- },
- columns: factory.getColumns([
- { dataField: 'CmFacility/Name', width: '40%' },
- { dataField: 'Name', width: '40%' },
- { dataField: 'ValueType', width: '20%' }
- ]),
- wordWrapEnabled: true,
- paging: {
- pageSize: 19,
- enabled: true
- },
- pager: {
- },
- handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
- }
- });
- function refreshList() {
- var date = moment();
- }
- function handleButtonSearchPointView() {
- if (selectedTreeItemData() === null) {
- utils.toast.show('선택된 빌딩/층/존이 없습니다.', 'warning');
- return null;
- }
- viewModel.pointSearchPopup.show();
- }
- function handleClickTreeItem(element, data) {
- // 2015 11 12 hcLee 추가
- selectedTreeItem(data);
- var eq = BWA.DataUtil.constructEqualFilter;
- var depth = data.depth;
- data = data.data;
- selectedTreeItemData(data);
- var filter = [eq('SiteId', data.SiteId()), 'and'];
- var buildingId = null;
- var floorId = null;
- var zoneId = null;
- switch (depth) {
- case BUILDING_DEPTH: // building
- buildingId = data.BuildingId();
- break;
- case FLOOR_DEPTH: // floor
- buildingId = data.BuildingId();
- floorId = data.FloorId();
- break;
- case ZONE_DEPTH: // zone
- buildingId = data.BuildingId();
- floorId = data.FloorId();
- zoneId = data.ZoneId();
- break;
- }
- filter.push(eq('BuildingId', buildingId));
- filter.push('and');
- filter.push(eq('FloorId', floorId));
- filter.push('and');
- filter.push(eq('ZoneId', zoneId));
- viewModel.pointSearchPopup.setLocation(data.SiteId(), buildingId, floorId, zoneId);
- var datagrid = $('#datagrid').dxDataGrid('instance');
- datagrid.filter(filter);
- }
- function handleViewShowing() {
- //권한설정
- hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
- }
- function handleViewShown() {
- if (buildingDataSource._items.length != 0) {
- var data = selectedTreeItem();
- if (data != null)
- $('#locationTreeView').cwTreeView('reload', selectedTreeItem().parentData);
- }
- var eq = BWA.DataUtil.constructEqualFilter;
- $('#locationTreeView').cwTreeView({
- width: '30%',
- height: 'auto',
- // height: '480px',
- onClickTreeItem: handleClickTreeItem,
- delegateDataSource: function (data, alterObj) {
- var id = data.id;
- var depth = data.depth;
- var promise = null;
- switch (depth) {
- case 0:
- promise = buildingDataSource.load();
- break;
- case 1:
- floorDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- 'and',
- eq('BuildingId', data.data.BuildingId())
- ]);
- promise = floorDataSource.load();
- break;
- case 2:
- zoneDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- 'and',
- eq('BuildingId', data.data.BuildingId()),
- 'and',
- eq('FloorId', data.data.FloorId())
- ]);
- promise = zoneDataSource.load();
- break;
- }
- return promise;
- }
- });
- gridView = $('#datagrid').dxDataGrid('instance');
- // hcLee 2016 01 22
- if (selectedTreeItemData() === null) {
- var eq = BWA.DataUtil.constructEqualFilter;
- var filterInit = [eq('SiteId', -1)];
- //..var datagrid = $('#datagrid').dxDataGrid('instance');
- gridView.filter(filterInit);
- }
- $SearchView.setPopupVisibleObservable(null);
- //$SideMenu.showSideMenuIfWill(params.view);
- }
- function handleAddPoints(points) {
- if (points.length === 0) return;
- if (selectedTreeItemData() === 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 = selectedTreeItemData();
- 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();
- });
- console.log(points);
- return promise;
- }
- function handleRemoveSelectedPoints() {
- if (selectedTreeItemData() === null) {
- utils.toast.show('선택된 빌딩/층/존이 없습니다.', 'warning');
- return null;
- }
- var rows = gridView.getSelectedRowsData();
- 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.post(
- 'BemsMonitoringPoint/RemoveLocation', postData
- );
- promise.done(function () {
- utils.toast.show($G('successDatabaseProcessMsg'));
- gridView.clearSelection();
- gridView.refresh();
- });
- return promise;
- }
- viewModel = {
- viewShowing: handleViewShowing,
- hasnotModificationPermission: hasnotModificationPermission, //권한설정
- refreshList: refreshList,
- handleRemoveSelectedPoints: handleRemoveSelectedPoints,
- handleButtonSearchPointView: handleButtonSearchPointView,
- dataGridOptions: dataGridOptions,
- };
- viewModel.pointSearchPopup = BWA.Popup.PointSearch.create(viewModel, handleAddPoints);
- return $.extend(BWA.CommonView.create(params, viewInfo, viewModel.options, null, handleViewShown), viewModel);
- // return viewModel;
- };
|