d2c78c035518a64e64a056b3bb1618ef08fd91d3.svn-base 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. BemsWebApplication.PointLocationMapping = function (params, viewInfo) {
  2. "use strict";
  3. var BUILDING_DEPTH = 1,
  4. FLOOR_DEPTH = 2,
  5. ZONE_DEPTH = 3;
  6. //권한설정
  7. var hasnotModificationPermission = ko.observable(true);
  8. //var buildingDataSource = BemsWebApplication.db.createDataSource('CmBuilding', true),
  9. var buildingDataSource = BemsWebApplication.db.createDataSource('CmBuilding', [('SiteId', '=', BWA.UserInfo.SiteId())]),
  10. floorDataSource = BemsWebApplication.db.createDataSource('CmFloor', true),
  11. zoneDataSource = BemsWebApplication.db.createDataSource('CmZone', true),
  12. factory = BemsWebApplication.Factory.PointLocationMapping,
  13. viewModel, gridView,
  14. popupVisible = ko.observable(false),
  15. selectedTreeItemData = ko.observable(null),
  16. selectedTreeItem = ko.observable(null), // 2015 11 12 hcLee 추가 기존 TreeItem -> TreeItemData 로 변경 하고 (위) 이거 추가함
  17. // selectedPoints = ko.observableArray(),
  18. dataSource = factory.getDataSource(),
  19. //dataSource. (dataSourceOptions).filter = ['SiteId', '=', BWA.UserInfo.SiteId()],
  20. dataGridOptions = utils.datagrid.defaultOptions({
  21. dxDataSource: dataSource,
  22. // datagridId: datagridId,
  23. dbId: 'BemsMonitoringPoint',
  24. width: '100%',
  25. height: 685,
  26. selection: {
  27. mode: 'multiple'
  28. },
  29. columns: factory.getColumns([
  30. { dataField: 'CmFacility/Name', width: '40%' },
  31. { dataField: 'Name', width: '40%' },
  32. { dataField: 'ValueType', width: '20%' }
  33. ]),
  34. wordWrapEnabled: true,
  35. paging: {
  36. pageSize: 19,
  37. enabled: true
  38. },
  39. pager: {
  40. },
  41. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  42. }
  43. });
  44. function refreshList() {
  45. var date = moment();
  46. }
  47. function handleButtonSearchPointView() {
  48. if (selectedTreeItemData() === null) {
  49. utils.toast.show('선택된 빌딩/층/존이 없습니다.', 'warning');
  50. return null;
  51. }
  52. viewModel.pointSearchPopup.show();
  53. }
  54. function handleClickTreeItem(element, data) {
  55. // 2015 11 12 hcLee 추가
  56. selectedTreeItem(data);
  57. var eq = BWA.DataUtil.constructEqualFilter;
  58. var depth = data.depth;
  59. data = data.data;
  60. selectedTreeItemData(data);
  61. var filter = [eq('SiteId', data.SiteId()), 'and'];
  62. var buildingId = null;
  63. var floorId = null;
  64. var zoneId = null;
  65. switch (depth) {
  66. case BUILDING_DEPTH: // building
  67. buildingId = data.BuildingId();
  68. break;
  69. case FLOOR_DEPTH: // floor
  70. buildingId = data.BuildingId();
  71. floorId = data.FloorId();
  72. break;
  73. case ZONE_DEPTH: // zone
  74. buildingId = data.BuildingId();
  75. floorId = data.FloorId();
  76. zoneId = data.ZoneId();
  77. break;
  78. }
  79. filter.push(eq('BuildingId', buildingId));
  80. filter.push('and');
  81. filter.push(eq('FloorId', floorId));
  82. filter.push('and');
  83. filter.push(eq('ZoneId', zoneId));
  84. viewModel.pointSearchPopup.setLocation(data.SiteId(), buildingId, floorId, zoneId);
  85. var datagrid = $('#datagrid').dxDataGrid('instance');
  86. datagrid.filter(filter);
  87. }
  88. function handleViewShowing() {
  89. //권한설정
  90. hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
  91. }
  92. function handleViewShown() {
  93. if (buildingDataSource._items.length != 0) {
  94. var data = selectedTreeItem();
  95. if (data != null)
  96. $('#locationTreeView').cwTreeView('reload', selectedTreeItem().parentData);
  97. }
  98. var eq = BWA.DataUtil.constructEqualFilter;
  99. $('#locationTreeView').cwTreeView({
  100. width: '30%',
  101. height: 'auto',
  102. // height: '480px',
  103. onClickTreeItem: handleClickTreeItem,
  104. delegateDataSource: function (data, alterObj) {
  105. var id = data.id;
  106. var depth = data.depth;
  107. var promise = null;
  108. switch (depth) {
  109. case 0:
  110. promise = buildingDataSource.load();
  111. break;
  112. case 1:
  113. floorDataSource.filter([
  114. eq('SiteId', BWA.UserInfo.SiteId()),
  115. 'and',
  116. eq('BuildingId', data.data.BuildingId())
  117. ]);
  118. promise = floorDataSource.load();
  119. break;
  120. case 2:
  121. zoneDataSource.filter([
  122. eq('SiteId', BWA.UserInfo.SiteId()),
  123. 'and',
  124. eq('BuildingId', data.data.BuildingId()),
  125. 'and',
  126. eq('FloorId', data.data.FloorId())
  127. ]);
  128. promise = zoneDataSource.load();
  129. break;
  130. }
  131. return promise;
  132. }
  133. });
  134. gridView = $('#datagrid').dxDataGrid('instance');
  135. // hcLee 2016 01 22
  136. if (selectedTreeItemData() === null) {
  137. var eq = BWA.DataUtil.constructEqualFilter;
  138. var filterInit = [eq('SiteId', -1)];
  139. //..var datagrid = $('#datagrid').dxDataGrid('instance');
  140. gridView.filter(filterInit);
  141. }
  142. $SearchView.setPopupVisibleObservable(null);
  143. //$SideMenu.showSideMenuIfWill(params.view);
  144. }
  145. function handleAddPoints(points) {
  146. if (points.length === 0) return;
  147. if (selectedTreeItemData() === null) {
  148. utils.toast.show('선택된 빌딩/층/존이 없습니다.', 'warning');
  149. return null;
  150. }
  151. var rows = window.utils.datagrid.getItems(gridView);
  152. points = _.map(points, function (item) {
  153. var facilityCode = item.FacilityCode;
  154. var propertyId = item.PropertyId;
  155. if (_.some(rows, function (x) {
  156. return (x.FacilityCode() === facilityCode && x.PropertyId === propertyId);
  157. })) {
  158. return null;
  159. }
  160. return item;
  161. });
  162. var data = selectedTreeItemData();
  163. var parameters = {
  164. BuildingId: data.BuildingId()
  165. };
  166. if (_.isUndefined(data.FloorId) === false) {
  167. parameters.FloorId = data.FloorId();
  168. if (_.isUndefined(data.ZoneId) === false) {
  169. parameters.ZoneId = data.ZoneId();
  170. }
  171. else {
  172. parameters.ZoneId = null;
  173. }
  174. }
  175. else {
  176. parameters.FloorId = null;
  177. parameters.ZoneId = null;
  178. }
  179. var postData = [];
  180. var itemKeys = ['SiteId', 'FacilityCode', 'PropertyId'];
  181. var toJS = BWA.DataUtil.convertHybridViewModelToJS;
  182. // $.each(points.concat(rows), function(i, item) {
  183. $.each(points, function (i, item) {
  184. item = toJS(_.pick(item, itemKeys));
  185. item = $.extend(item, parameters);
  186. postData.push(item);
  187. });
  188. parameters.SiteId = data.SiteId();
  189. var promise = BemsWebApplication.api.post(
  190. 'BemsMonitoringPoint/AddLocation', postData, parameters
  191. );
  192. promise.done(function () {
  193. utils.toast.show($G('successDatabaseProcessMsg'));
  194. gridView.refresh();
  195. });
  196. console.log(points);
  197. return promise;
  198. }
  199. function handleRemoveSelectedPoints() {
  200. if (selectedTreeItemData() === null) {
  201. utils.toast.show('선택된 빌딩/층/존이 없습니다.', 'warning');
  202. return null;
  203. }
  204. var rows = gridView.getSelectedRowsData();
  205. var postData = [];
  206. var itemKeys = BWA.db.BemsMonitoringPoint.key();
  207. var toJS = BWA.DataUtil.convertHybridViewModelToJS;
  208. $.each(rows, function (i, item) {
  209. item = toJS(_.pick(item, itemKeys));
  210. postData.push(item);
  211. });
  212. var promise = BemsWebApplication.api.post(
  213. 'BemsMonitoringPoint/RemoveLocation', postData
  214. );
  215. promise.done(function () {
  216. utils.toast.show($G('successDatabaseProcessMsg'));
  217. gridView.clearSelection();
  218. gridView.refresh();
  219. });
  220. return promise;
  221. }
  222. viewModel = {
  223. viewShowing: handleViewShowing,
  224. hasnotModificationPermission: hasnotModificationPermission, //권한설정
  225. refreshList: refreshList,
  226. handleRemoveSelectedPoints: handleRemoveSelectedPoints,
  227. handleButtonSearchPointView: handleButtonSearchPointView,
  228. dataGridOptions: dataGridOptions,
  229. };
  230. viewModel.pointSearchPopup = BWA.Popup.PointSearch.create(viewModel, handleAddPoints);
  231. return $.extend(BWA.CommonView.create(params, viewInfo, viewModel.options, null, handleViewShown), viewModel);
  232. // return viewModel;
  233. };