f50696c08c1d5240b5fa3715cab350a0da81d4f9.svn-base 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. 
  2. $(function() {
  3. 'use strict';
  4. BWA.Popup = BWA.Popup || {};
  5. BWA.Popup.FormulaPointPopup = {
  6. //create: function(viewModel, selectedTreeItem) {
  7. create: function (viewModel) {
  8. var popupVisible = ko.observable(false);
  9. var facilityTypeDataSource = BemsWebApplication.db.createDataSource('BemsFacilityType'),
  10. serviceTypeDataSource = BemsWebApplication.db.createDataSource('BemsServiceType'),
  11. fuelTypeDataSource = BemsWebApplication.db.createDataSource('BemsFuelType'),
  12. pointBaseDataDataSource = BemsWebApplication.db.createDataSource('BemsMonitoringPointBaseData'),
  13. serviceTypes = ko.observableArray(),
  14. fuelTypes = ko.observableArray(),
  15. properties = ko.observableArray(),
  16. valueTypes = $G.ValueTypes,
  17. eq = BWA.DataUtil.constructEqualFilter,
  18. and = BWA.DataUtil.andFilter,
  19. viewModel = viewModel,
  20. dataModel = viewModel.dataModel = new BemsWebApplication.BemsMonitoringPointViewModel();
  21. dataModel.FacilityTypeName = ko.observable();
  22. dataModel.ServiceTypeName = ko.observable();
  23. dataModel.ValueTypeName = ko.observable();
  24. dataModel.FuelTypeName = ko.observable();
  25. dataModel.FacilityName = ko.observable();
  26. function getDoneFunc(koObservableArray) {
  27. return function(dbArray) {
  28. koObservableArray(dbArray);
  29. };
  30. }
  31. function handleInitializeDataModelValue(dataModel) {
  32. }
  33. function handleSelectBoxChangeProperty(e) {
  34. var property = _.find(properties(), function(x) {
  35. return x.PropertyId() === e.value;
  36. });
  37. if (property) {
  38. dataModel.Name(property.Name());
  39. }
  40. }
  41. function handleDataGridRowClick(id, dataGrid, clickRow) {
  42. var data = clickRow.data;
  43. var valueType = _.find(valueTypes, function (x) {
  44. return x.ValueType === data.ValueType();
  45. });
  46. dataModel.FacilityName(data['CmFacility/Name']());
  47. dataModel.FacilityTypeName(data['BemsFacilityType/Name']());
  48. dataModel.ServiceTypeName(data['BemsServiceType/Name']());
  49. dataModel.FuelTypeName(data['BemsFuelType/Name']());
  50. dataModel.ValueTypeName(valueType.Name);
  51. dataModel.Name(data.Name());
  52. dataModel.PropertyId(data.PropertyId());
  53. dataModel.Description(data.Description());
  54. popupVisible(true);
  55. }
  56. function handlePopupButtonClose() {
  57. popupVisible(false);
  58. }
  59. function handlePopupShowing(e) {
  60. //var item = selectedTreeItem();
  61. //if (item.depth !== 2) return;
  62. //var facility = item.data;
  63. //dataModel.SiteId(facility.SiteId());
  64. //dataModel.FacilityCode(facility.FacilityCode());
  65. //dataModel.FacilityTypeId(facility.FacilityTypeId());
  66. //dataModel.FacilityTypeName(facility['BemsFacilityType/Name']());
  67. //dataModel.FacilityName(facility.Name());
  68. ////dataModel.IsAccumulated(true);
  69. //pointBaseDataDataSource.filter([
  70. // eq('FacilityTypeId', dataModel.FacilityTypeId())
  71. //]);
  72. //pointBaseDataDataSource.load().done(getDoneFunc(properties));
  73. //var data = clickRow.data;
  74. //var valueType = _.find(valueTypes, function(x) {
  75. // return x.ValueType === data.ValueType();
  76. //});
  77. //
  78. //popupVisible(true);
  79. }
  80. function handlePopupShown() {
  81. }
  82. var toolbarItems = [
  83. { location: 'before', text: $G('point') },
  84. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
  85. ];
  86. var popupOptions = {
  87. width: '520px',
  88. height: 'auto',
  89. visible: popupVisible,
  90. closeOnOutsideClick: false,
  91. shading: false,
  92. showingAction: handlePopupShowing,
  93. shownAction: handlePopupShown,
  94. animation: utils.popup.createAnimation()
  95. };
  96. return {
  97. popupOptions: popupOptions,
  98. toolbarItems: toolbarItems,
  99. serviceTypes: serviceTypes,
  100. fuelTypes: fuelTypes,
  101. properties: properties,
  102. valueTypes: valueTypes,
  103. handleDataGridRowClick: handleDataGridRowClick,
  104. handleSelectBoxChangeProperty: handleSelectBoxChangeProperty,
  105. handleInitializeDataModelValue: handleInitializeDataModelValue,
  106. show: function () {
  107. popupVisible(true);
  108. }
  109. };
  110. }
  111. }
  112. });