You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

listcontrollerbuilder.business.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * Created by robin on 12/15/16.
  3. */
  4. (function () {
  5. 'use strict';
  6. angular.module('appSdk')
  7. .factory('listControllerBuilder', ['luBusyBusiness', 'AppUtilsBusiness', '$transitions',
  8. 'ItemsBusiness', 'itemTracker', '$state', '$q', '$mdDialog',
  9. function (luBusyBusiness, AppUtilsBusiness, $transitions,
  10. ItemsBusiness, itemTracker, $state, $q, $mdDialog) {
  11. var EditControllerBuilder = {};
  12. EditControllerBuilder.create = function ($scope, $stateParams) {
  13. $scope.busy = luBusyBusiness.reset();
  14. $scope.appUtils = AppUtilsBusiness;
  15. $scope.isModal = $stateParams.isModal != null && $stateParams.isModal;
  16. $scope.isFilterShown = false;
  17. $scope.defaultItem = $scope.business.initDbo({});
  18. $scope.items = null;
  19. $scope.selected = [];
  20. if ($scope.defaultOrder == null) {
  21. $scope.defaultOrder = undefined;
  22. }
  23. if (typeof defaultFilter !== 'function') {
  24. var defaultFilter = $scope.defaultFilter;
  25. if (defaultFilter == null) {
  26. defaultFilter = '';
  27. }
  28. $scope.defaultFilter = function () {
  29. return defaultFilter;
  30. };
  31. }
  32. if ($scope.defaultLimit == null) {
  33. $scope.defaultLimit = 20;
  34. }
  35. if ($scope.defaultPage == null) {
  36. $scope.defaultPage = 1;
  37. }
  38. $scope.query = {
  39. order: $scope.defaultOrder,
  40. filter: $scope.defaultFilter(),
  41. limit: $scope.defaultLimit,
  42. page: $scope.defaultPage
  43. };
  44. if ($scope.getAddItem == null) {
  45. $scope.getAddItem = function () {
  46. return null;
  47. };
  48. }
  49. $scope.showFilter = function(show) {
  50. $scope.isFilterShown = show;
  51. if (!$scope.isFilterShown) {
  52. var defaultFilter = $scope.defaultFilter();
  53. if ($scope.query.filter != defaultFilter) {
  54. $scope.query.filter = defaultFilter;
  55. $scope.getItems();
  56. }
  57. }
  58. };
  59. $scope.selectItem = function(item)
  60. {
  61. $mdDialog.hide(item);
  62. };
  63. $scope.addItemDialog = function()
  64. {
  65. var defaultItem = $scope.getAddItem();
  66. ItemsBusiness.addDialog($scope.itemType, defaultItem).then(function(data)
  67. {
  68. $mdDialog.hide(data);
  69. }, function (error) {
  70. $mdDialog.cancel(error);
  71. })
  72. };
  73. $scope.editItem = function(item)
  74. {
  75. ItemsBusiness.editDialog(item, true).then(function(data) {
  76. console.log(item, data);
  77. }, function (error) {});
  78. };
  79. $scope.askRemoveOne = function (item) {
  80. ItemsBusiness.deleteDialog(item, $scope.itemType + '.table').then(function(data)
  81. {
  82. $scope.getItems();
  83. }, function(error) {});
  84. };
  85. $scope.askRemoveSelected = function () {
  86. if ($scope.selected.length == 0) {
  87. return;
  88. }
  89. else if ($scope.selected.length == 1) {
  90. $scope.askRemoveOne($scope.selected[0]);
  91. }
  92. else {
  93. ItemsBusiness.deleteMultipleDialog($scope.selected, $scope.itemType + '.table')
  94. .then(function () {
  95. $scope.getItems();
  96. }, function (error) {
  97. });
  98. }
  99. };
  100. $scope.getOrderBy = function(orderBy)
  101. {
  102. return orderBy;
  103. };
  104. $scope.getItems = function()
  105. {
  106. $scope.selected = [];
  107. var orderBy = AppUtilsBusiness.convertOrderBy($scope.query.order);
  108. $scope.business.getMultiple($scope.getOrderBy(orderBy), $scope.query.filter, $scope.query.page - 1, $scope.query.limit, $scope.itemType + '.table').then(function(data)
  109. {
  110. $scope.items = data;
  111. }, function(error)
  112. {
  113. $scope.items = null;
  114. });
  115. };
  116. $scope.init = function()
  117. {
  118. if (!$scope.isModal) {
  119. $scope.getItems();
  120. }
  121. };
  122. };
  123. return EditControllerBuilder;
  124. }]);
  125. })();