123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- $(function () {
- 'use strict';
- BWA.Popup = BWA.Popup || {};
- BWA.Popup.PointSearch = {
- create: function (viewModel, callbackClickAdd) {
- var BUILDING_DEPTH = 1,
- FLOOR_DEPTH = 2,
- ZONE_DEPTH = 3;
- var dataViewModel = new BemsWebApplication.BemsMonitoringPointViewModel(),
- popupVisible = ko.observable(false),
- gridViewFilter = ko.observable([]),
- factory = BemsWebApplication.Factory.PointLocationMapping,
- gridView = null,
- searchView = null,
- initialized = false,
- dataSource = factory.getDataSourceWithLocation(),
- //buildingDataSource = BemsWebApplication.db.createDataSource('CmBuilding', true),
- buildingDataSource = BemsWebApplication.db.createDataSource('CmBuilding', [('SiteId', '=', BWA.UserInfo.SiteId())]),
- floorDataSource = BemsWebApplication.db.createDataSource('CmFloor', [('SiteId', '=', BWA.UserInfo.SiteId())]),
- zoneDataSource = BemsWebApplication.db.createDataSource('CmZone', [('SiteId', '=', BWA.UserInfo.SiteId())]),
- buildingIdForSearch = ko.observable(0),
- floorIdForSearch = ko.observable(0),
- zoneIdForSearch = ko.observable(0),
- dataGridOptions = utils.datagrid.defaultOptions({
- //dxDataSource: dataSource,
- dxDataSource: BWA.DataUtil.createDataSource({
- dataSourceOptions: {
- store: BWA.odata.MonitoringPoint,
- map: function (item) {
- return BWA.db.createViewModelWithMultipleFK(item); // Ex class설정? hcLee 2016 01 22
- },
- filter: [
- ['SiteId', '=', BWA.UserInfo.SiteId()],
- 'and',
- ['FacilityTypeId', '<', 100]
- ]
- }
- }),
- //}, 'BemsMonitoringPoint'),
- // datagridId: datagridId,
- dbId: 'BemsMonitoringPoint',
- height: 610,
- selection: {
- mode: 'multiple'
- },
- //columns: factory.defaultColumns,
- columns: [
- { dataField: 'FacilityName', caption: $G('facilityName'), width: '30%', alignment: 'center' },
- { dataField: 'Name', caption: $G('pointName'), width: '35%', alignment: 'center' },
- {
- dataField: 'ValueType', caption: $G('valueType'), width: '10%', alignment: 'center', allowFilter: false,
- customizeText: function (cellInfo) {
- return $G.pointValueType(cellInfo.value);
- }
- },
- { dataField: 'Location', caption: $G('location'), width: '35%', alignment: 'center' },
- ],
- //cellPrepared: factory.cellPreparedFunc, // hcLee 2016 01 22 MonitoringPointEx에서 처리되므로 Factory.PointLocationMapping는 사용하면 안됨.
- wordWrapEnabled: true,
- handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
- }
- }
- );
- function handlePopupShowing(e) {
- }
- function refreshList() {
- gridView.filter(gridViewFilter());
- }
- function handlePopupButtonAddPoiint() {
- var rows = gridView.getSelectedRowsData();
- var promise = callbackClickAdd(rows);
- if (_.isNull(promise)) return;
- promise.then(function () {
- refreshList();
- });
- gridView.clearSelection();
- }
- function handlePopupButtonClose() {
- popupVisible(false);
- }
- function setLocation(siteId, buildingId, floorId, zoneId) {
- var eq = BWA.DataUtil.constructEqualFilter;
- var neq = BWA.DataUtil.constructNotEqualFilter;
- gridViewFilter([
- eq('SiteId', siteId),
- 'and',
- [
- neq('BuildingId', buildingId === null ? 0 : buildingId),
- 'or',
- neq('FloorId', floorId === null ? 0 : floorId),
- 'or',
- neq('ZoneId', zoneId === null ? 0 : zoneId)
- ]
- ]);
- if (_.isNull(gridView) === false) {
- refreshList();
- }
- }
- function handleClickTreeItem(element, data) {
- var eq = BWA.DataUtil.constructEqualFilter;
- var depth = data.depth;
- data = data.data;
- switch (depth) {
- case BUILDING_DEPTH: // building
- buildingIdForSearch(data.BuildingId());
- floorIdForSearch(0);
- zoneIdForSearch(0);
- break;
- case FLOOR_DEPTH: // floor
- buildingIdForSearch(data.BuildingId());
- floorIdForSearch(data.FloorId());
- zoneIdForSearch(0);
- break;
- case ZONE_DEPTH: // zone
- buildingIdForSearch(data.BuildingId());
- floorIdForSearch(data.FloorId());
- zoneIdForSearch(data.ZoneId());
- break;
- }
- }
- function handlePopupShown() {
- if (initialized === false) {
- gridView = $('#gridPointContainer').dxDataGrid('instance');
- initialized = true;
- }
- refreshList();
- searchView.show();
- }
- var toolbarItems = [
- { location: 'before', text: $G('point') },
- { location: 'after', widget: 'button', options: { text: $G('add'), icon: 'plus', clickAction: handlePopupButtonAddPoiint } },
- { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
- ];
- var popupOptions = {
- width: '900px',
- height: 'auto',
- visible: popupVisible,
- closeOnOutsideClick: false,
- shading: false,
- showingAction: handlePopupShowing,
- shownAction: handlePopupShown,
- animation: utils.popup.createAnimation()
- };
- searchView = BWA.Popup.SearchView.create({
- parentPopupId: 'popupSearchPoint',
- parentPopupVisible: popupVisible,
- searchItems: [
- { id: 'Location' },
- { id: 'FacilityName' },
- { id: 'Name' }
- ],
- handleInitializeUpdate: function () {
- $('#locationTreeViewInSearchViewPopup').cwTreeView({
- // width: '40%',
- // height: '480px',
- onClickTreeItem: handleClickTreeItem,
- delegateDataSource: BWA.DataUtil.getLocationDataSourceDelegateForTreeView(
- buildingDataSource,
- floorDataSource,
- zoneDataSource
- )
- });
- },
- handleSearch: function (filter, searchItems) {
- filter = [['SiteId', '=', BWA.UserInfo.SiteId()]].concat(filter)
- var eq = BWA.DataUtil.constructEqualFilter;
- var and = BWA.DataUtil.andFilter;
- if (searchItems.Location.check()) {
- filter = filter.concat([
- eq('BuildingId', buildingIdForSearch()),
- and,
- eq('FloorId', floorIdForSearch()),
- and,
- eq('ZoneId', zoneIdForSearch())
- ]);
- }
- gridView.filter(filter);
- console.log(filter);
- }
- });
- return {
- dataModel: dataViewModel,
- dataSource: dataSource,
- popupOptions: popupOptions,
- toolbarItems: toolbarItems,
- dataGridOptions: dataGridOptions,
- setLocation: setLocation,
- searchView: searchView,
- show: function () {
- popupVisible(true);
- }
- };
- }
- };
- });
|