448829fa0ac2626b6348ad7f79e99515de212dbd.svn-base 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. $(function () {
  2. 'use strict';
  3. BWA.Popup = BWA.Popup || {};
  4. BWA.Popup.PointSearch = {
  5. create: function (viewModel, callbackClickAdd) {
  6. var BUILDING_DEPTH = 1,
  7. FLOOR_DEPTH = 2,
  8. ZONE_DEPTH = 3;
  9. var dataViewModel = new BemsWebApplication.BemsMonitoringPointViewModel(),
  10. popupVisible = ko.observable(false),
  11. gridViewFilter = ko.observable([]),
  12. factory = BemsWebApplication.Factory.PointLocationMapping,
  13. gridView = null,
  14. searchView = null,
  15. initialized = false,
  16. dataSource = factory.getDataSourceWithLocation(),
  17. //buildingDataSource = BemsWebApplication.db.createDataSource('CmBuilding', true),
  18. buildingDataSource = BemsWebApplication.db.createDataSource('CmBuilding', [('SiteId', '=', BWA.UserInfo.SiteId())]),
  19. floorDataSource = BemsWebApplication.db.createDataSource('CmFloor', [('SiteId', '=', BWA.UserInfo.SiteId())]),
  20. zoneDataSource = BemsWebApplication.db.createDataSource('CmZone', [('SiteId', '=', BWA.UserInfo.SiteId())]),
  21. buildingIdForSearch = ko.observable(0),
  22. floorIdForSearch = ko.observable(0),
  23. zoneIdForSearch = ko.observable(0),
  24. dataGridOptions = utils.datagrid.defaultOptions({
  25. //dxDataSource: dataSource,
  26. dxDataSource: BWA.DataUtil.createDataSource({
  27. dataSourceOptions: {
  28. store: BWA.odata.MonitoringPoint,
  29. map: function (item) {
  30. return BWA.db.createViewModelWithMultipleFK(item); // Ex class설정? hcLee 2016 01 22
  31. },
  32. filter: [
  33. ['SiteId', '=', BWA.UserInfo.SiteId()],
  34. 'and',
  35. ['FacilityTypeId', '<', 100]
  36. ]
  37. }
  38. }),
  39. //}, 'BemsMonitoringPoint'),
  40. // datagridId: datagridId,
  41. dbId: 'BemsMonitoringPoint',
  42. height: 610,
  43. selection: {
  44. mode: 'multiple'
  45. },
  46. //columns: factory.defaultColumns,
  47. columns: [
  48. { dataField: 'FacilityName', caption: $G('facilityName'), width: '30%', alignment: 'center' },
  49. { dataField: 'Name', caption: $G('pointName'), width: '35%', alignment: 'center' },
  50. {
  51. dataField: 'ValueType', caption: $G('valueType'), width: '10%', alignment: 'center', allowFilter: false,
  52. customizeText: function (cellInfo) {
  53. return $G.pointValueType(cellInfo.value);
  54. }
  55. },
  56. { dataField: 'Location', caption: $G('location'), width: '35%', alignment: 'center' },
  57. ],
  58. //cellPrepared: factory.cellPreparedFunc, // hcLee 2016 01 22 MonitoringPointEx에서 처리되므로 Factory.PointLocationMapping는 사용하면 안됨.
  59. wordWrapEnabled: true,
  60. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  61. }
  62. }
  63. );
  64. function handlePopupShowing(e) {
  65. }
  66. function refreshList() {
  67. gridView.filter(gridViewFilter());
  68. }
  69. function handlePopupButtonAddPoiint() {
  70. var rows = gridView.getSelectedRowsData();
  71. var promise = callbackClickAdd(rows);
  72. if (_.isNull(promise)) return;
  73. promise.then(function () {
  74. refreshList();
  75. });
  76. gridView.clearSelection();
  77. }
  78. function handlePopupButtonClose() {
  79. popupVisible(false);
  80. }
  81. function setLocation(siteId, buildingId, floorId, zoneId) {
  82. var eq = BWA.DataUtil.constructEqualFilter;
  83. var neq = BWA.DataUtil.constructNotEqualFilter;
  84. gridViewFilter([
  85. eq('SiteId', siteId),
  86. 'and',
  87. [
  88. neq('BuildingId', buildingId === null ? 0 : buildingId),
  89. 'or',
  90. neq('FloorId', floorId === null ? 0 : floorId),
  91. 'or',
  92. neq('ZoneId', zoneId === null ? 0 : zoneId)
  93. ]
  94. ]);
  95. if (_.isNull(gridView) === false) {
  96. refreshList();
  97. }
  98. }
  99. function handleClickTreeItem(element, data) {
  100. var eq = BWA.DataUtil.constructEqualFilter;
  101. var depth = data.depth;
  102. data = data.data;
  103. switch (depth) {
  104. case BUILDING_DEPTH: // building
  105. buildingIdForSearch(data.BuildingId());
  106. floorIdForSearch(0);
  107. zoneIdForSearch(0);
  108. break;
  109. case FLOOR_DEPTH: // floor
  110. buildingIdForSearch(data.BuildingId());
  111. floorIdForSearch(data.FloorId());
  112. zoneIdForSearch(0);
  113. break;
  114. case ZONE_DEPTH: // zone
  115. buildingIdForSearch(data.BuildingId());
  116. floorIdForSearch(data.FloorId());
  117. zoneIdForSearch(data.ZoneId());
  118. break;
  119. }
  120. }
  121. function handlePopupShown() {
  122. if (initialized === false) {
  123. gridView = $('#gridPointContainer').dxDataGrid('instance');
  124. initialized = true;
  125. }
  126. refreshList();
  127. searchView.show();
  128. }
  129. var toolbarItems = [
  130. { location: 'before', text: $G('point') },
  131. { location: 'after', widget: 'button', options: { text: $G('add'), icon: 'plus', clickAction: handlePopupButtonAddPoiint } },
  132. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
  133. ];
  134. var popupOptions = {
  135. width: '900px',
  136. height: 'auto',
  137. visible: popupVisible,
  138. closeOnOutsideClick: false,
  139. shading: false,
  140. showingAction: handlePopupShowing,
  141. shownAction: handlePopupShown,
  142. animation: utils.popup.createAnimation()
  143. };
  144. searchView = BWA.Popup.SearchView.create({
  145. parentPopupId: 'popupSearchPoint',
  146. parentPopupVisible: popupVisible,
  147. searchItems: [
  148. { id: 'Location' },
  149. { id: 'FacilityName' },
  150. { id: 'Name' }
  151. ],
  152. handleInitializeUpdate: function () {
  153. $('#locationTreeViewInSearchViewPopup').cwTreeView({
  154. // width: '40%',
  155. // height: '480px',
  156. onClickTreeItem: handleClickTreeItem,
  157. delegateDataSource: BWA.DataUtil.getLocationDataSourceDelegateForTreeView(
  158. buildingDataSource,
  159. floorDataSource,
  160. zoneDataSource
  161. )
  162. });
  163. },
  164. handleSearch: function (filter, searchItems) {
  165. filter = [['SiteId', '=', BWA.UserInfo.SiteId()]].concat(filter)
  166. var eq = BWA.DataUtil.constructEqualFilter;
  167. var and = BWA.DataUtil.andFilter;
  168. if (searchItems.Location.check()) {
  169. filter = filter.concat([
  170. eq('BuildingId', buildingIdForSearch()),
  171. and,
  172. eq('FloorId', floorIdForSearch()),
  173. and,
  174. eq('ZoneId', zoneIdForSearch())
  175. ]);
  176. }
  177. gridView.filter(filter);
  178. console.log(filter);
  179. }
  180. });
  181. return {
  182. dataModel: dataViewModel,
  183. dataSource: dataSource,
  184. popupOptions: popupOptions,
  185. toolbarItems: toolbarItems,
  186. dataGridOptions: dataGridOptions,
  187. setLocation: setLocation,
  188. searchView: searchView,
  189. show: function () {
  190. popupVisible(true);
  191. }
  192. };
  193. }
  194. };
  195. });