Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

items.business.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * Created by robin on 12/15/16.
  3. */
  4. (function () {
  5. 'use strict';
  6. angular.module('appSdk')
  7. .factory('ItemsBusiness', ['$mdDialog', '$q', '$injector', 'AppUtilsBusiness',
  8. function ($mdDialog, $q, $injector, AppUtilsBusiness) {
  9. var ItemsBusiness = {};
  10. ItemsBusiness.extendDeep = function extendDeep(dst) {
  11. angular.forEach(arguments, function(obj) {
  12. if (obj !== dst) {
  13. angular.forEach(obj, function(value, key) {
  14. if (dst[key] && dst[key].constructor && dst[key].constructor === Object) {
  15. extendDeep(dst[key], value);
  16. } else {
  17. dst[key] = value;
  18. }
  19. });
  20. }
  21. });
  22. return dst;
  23. };
  24. ItemsBusiness.editDialog = function (item, updateItem) {
  25. var deferred = $q.defer();
  26. $mdDialog.show({
  27. controller: item._itemType + 'EditController',
  28. templateUrl: 'views/' + item._itemType + 'edit.html',
  29. clickOutsideToClose: false,
  30. escapeToClose: false,
  31. locals: {
  32. $stateParams: {
  33. item: angular.copy(item),
  34. id: item.id,
  35. isModal: true
  36. }
  37. }
  38. }).then(function(data)
  39. {
  40. if (updateItem) {
  41. ItemsBusiness.extendDeep(item, data);
  42. }
  43. deferred.resolve(data);
  44. }, deferred.reject);
  45. return deferred.promise;
  46. };
  47. ItemsBusiness.addDialog = function (itemType, defaultItem) {
  48. return $mdDialog.show({
  49. controller: itemType + 'EditController',
  50. templateUrl: 'views/' + itemType + 'edit.html',
  51. clickOutsideToClose: false,
  52. escapeToClose: false,
  53. locals: {
  54. $stateParams: {
  55. item: defaultItem,
  56. id: null,
  57. isModal: true
  58. }
  59. }
  60. });
  61. };
  62. ItemsBusiness.deleteConfirmDialog = function (item) {
  63. var confirm = $mdDialog.confirm()
  64. .title(AppUtilsBusiness.tr('common.confirmDelete'))
  65. .textContent(AppUtilsBusiness.tr(item._itemType + '.deleteOne', {text: item.toString()}))
  66. .ok(AppUtilsBusiness.tr('common.delete'))
  67. .cancel(AppUtilsBusiness.tr('common.cancel'));
  68. return $mdDialog.show(confirm);
  69. };
  70. ItemsBusiness.deleteDialog = function (item, luBusyGroups) {
  71. var deferred = $q.defer();
  72. ItemsBusiness.deleteConfirmDialog(item).then(function()
  73. {
  74. var business = $injector.get(item._itemType + 'Business');
  75. business.deleteDbo(item.id, luBusyGroups)
  76. .then(deferred.resolve, deferred.reject);
  77. }, deferred.reject);
  78. return deferred.promise;
  79. };
  80. ItemsBusiness.deleteMultipleConfirmDialog = function (items) {
  81. var confirm = $mdDialog.confirm()
  82. .title(AppUtilsBusiness.tr('common.confirmDelete'))
  83. .textContent(AppUtilsBusiness.tr(items[0]._itemType + '.deleteMultiple', {count: items.length}))
  84. .ok(AppUtilsBusiness.tr('common.delete'))
  85. .cancel(AppUtilsBusiness.tr('common.cancel'));
  86. return $mdDialog.show(confirm);
  87. };
  88. ItemsBusiness.deleteMultipleDialog = function (items, luBusyGroups) {
  89. var deferred = $q.defer();
  90. ItemsBusiness.deleteMultipleConfirmDialog(items).then(function()
  91. {
  92. var business = $injector.get(items[0]._itemType + 'Business');
  93. ItemsBusiness.deleteFirst(items, business, deferred, luBusyGroups);
  94. }, deferred.reject);
  95. return deferred.promise;
  96. };
  97. ItemsBusiness.deleteFirst = function(items, business, deferred, luBusyGroups) {
  98. if (items.length == 0) {
  99. deferred.resolve();
  100. }
  101. else {
  102. business.deleteDbo(items[0].id, luBusyGroups)
  103. .then(function(data)
  104. {
  105. items.splice(0, 1);
  106. ItemsBusiness.deleteFirst(items, business, deferred, luBusyGroups);
  107. }, deferred.reject);
  108. }
  109. };
  110. ItemsBusiness.pickDialog = function (itemType) {
  111. return $mdDialog.show({
  112. controller: itemType + 'Controller',
  113. templateUrl: 'views/' + itemType + '.html',
  114. clickOutsideToClose: true,
  115. escapeToClose: true,
  116. locals: {
  117. $stateParams: {
  118. isModal: true
  119. }
  120. }
  121. });
  122. };
  123. return ItemsBusiness;
  124. }]);
  125. })();