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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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) {}, function (error) {});
  76. };
  77. $scope.askRemoveOne = function (item) {
  78. ItemsBusiness.deleteDialog(item, $scope.itemType + '.table').then(function(data)
  79. {
  80. $scope.getItems();
  81. }, function(error) {});
  82. };
  83. $scope.askRemoveSelected = function () {
  84. if ($scope.selected.length == 0) {
  85. return;
  86. }
  87. else if ($scope.selected.length == 1) {
  88. $scope.askRemoveOne($scope.selected[0]);
  89. }
  90. else {
  91. ItemsBusiness.deleteMultipleDialog($scope.selected, $scope.itemType + '.table')
  92. .then(function () {
  93. $scope.getItems();
  94. }, function (error) {
  95. });
  96. }
  97. };
  98. $scope.getOrderBy = function(orderBy)
  99. {
  100. return orderBy;
  101. };
  102. $scope.getItems = function()
  103. {
  104. $scope.selected = [];
  105. var orderBy = AppUtilsBusiness.convertOrderBy($scope.query.order);
  106. $scope.business.getMultiple($scope.getOrderBy(orderBy), $scope.query.filter, $scope.query.page - 1, $scope.query.limit, $scope.itemType + '.table').then(function(data)
  107. {
  108. $scope.items = data;
  109. }, function(error)
  110. {
  111. $scope.items = null;
  112. });
  113. };
  114. $scope.init = function()
  115. {
  116. if (!$scope.isModal) {
  117. $scope.getItems();
  118. }
  119. };
  120. };
  121. return EditControllerBuilder;
  122. }]);
  123. })();