d47ea80956a04eafc1df1705c48b062b438b38a7.svn-base 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. BemsWebApplication.Building = function(params, viewInfo) {
  2. "use strict";
  3. var BuildingInfo = ko.observableArray();
  4. var isEmptyData = true;;
  5. var CmBuilidngDataSource = BemsWebApplication.db.createDataSource('CmBuilding');
  6. var RowName;
  7. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'CmBuilding', {
  8. columns: [
  9. { dataField: 'BuildingId', caption: $G('number'), width: '20%', alignment: 'center' , sortOrder: 'desc' },
  10. { dataField: 'Name', caption: $G('buildingName'), width: '80%', alignment: 'center' },
  11. //utils.datagrid.columnIsUse( '20%' )
  12. ],
  13. popupWidth: 480,
  14. searchViewItems: [{ id: 'Name' }],
  15. handleViewShown: function() {
  16. },
  17. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  18. var data = clickRow.data;
  19. RowName = data.Name;
  20. popupVisible(true);
  21. },
  22. handleViewShowing: function () {
  23. CmBuilidngDataSource.filter([
  24. ["SiteId", "=", BWA.UserInfo.SiteId()]
  25. ]);
  26. CmBuilidngDataSource.load().done(function (CmBuilidng) {
  27. if (CmBuilidng.length == 0) {
  28. isEmptyData = true;
  29. $("#popupInsertButton").dxCommand("instance").option('disabled', false);
  30. }
  31. else {
  32. isEmptyData = false;
  33. $("#popupInsertButton").dxCommand("instance").option('disabled', true);
  34. }
  35. });
  36. },
  37. // 이름 중복 방지
  38. handlePopupShowing: function () {
  39. CmBuilidngDataSource.filter([
  40. ["SiteId", "=", BWA.UserInfo.SiteId()]
  41. ]);
  42. CmBuilidngDataSource.load().done(function (result) {
  43. BuildingInfo(result);
  44. });
  45. },
  46. beforeInsertingDataViewModel: function (dataModel, dbModelId) {
  47. var dfd = $.Deferred();
  48. var isDuplicated = false;
  49. for (var i = 0; i < BuildingInfo().length; i++) {
  50. if (dataModel.Name() == BuildingInfo()[i].Name()) {
  51. isDuplicated = true;
  52. }
  53. }
  54. if (!BWA.DataUtil.isValidInputValue(dataModel.Name()))
  55. return dfd.resolve(false, '저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)');
  56. else {
  57. if (isDuplicated)
  58. return dfd.resolve(false, '이미 동일 이름이 존재합니다.');
  59. else
  60. return dfd.resolve(true);
  61. }
  62. },
  63. beforeUpdateDataViewModel: function () {
  64. var isDuplicated = false;
  65. for (var i = 0; i < BuildingInfo().length; i++) {
  66. if (viewModel.dataModel.Name() == BuildingInfo()[i].Name() && RowName() != BuildingInfo()[i].Name()) {
  67. isDuplicated = true;
  68. }
  69. }
  70. if (!BWA.DataUtil.isValidInputValue(viewModel.dataModel.Name())) {
  71. utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
  72. return 0;
  73. }
  74. else {
  75. if (isDuplicated) {
  76. utils.toast.show('이미 동일 이름이 존재합니다.', 'error');
  77. return 0;
  78. }
  79. else
  80. return 2;
  81. }
  82. }
  83. });
  84. function InsertButtonClickAction() {
  85. if (!isEmptyData) {
  86. utils.toast.show('빌딩 명칭은 하나만 생성할 수 있습니다.', 'error');
  87. }
  88. else {
  89. viewModel.popupInsertView();
  90. }
  91. }
  92. viewModel.popupInsertButtonOptions = {
  93. icon: 'add',
  94. id: 'create',
  95. title: '등록',
  96. action: InsertButtonClickAction,
  97. disabled: !isEmptyData
  98. };
  99. return viewModel;
  100. };