123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /**
- * Created by robin on 12/15/16.
- */
-
- (function () {
- 'use strict';
-
- angular.module('appSdk')
- .factory('ItemsBusiness', ['$mdDialog', '$q', '$injector', 'AppUtilsBusiness',
- function ($mdDialog, $q, $injector, AppUtilsBusiness) {
-
- var ItemsBusiness = {};
-
- ItemsBusiness.extendDeep = function extendDeep(dst) {
- angular.forEach(arguments, function(obj) {
- if (obj !== dst) {
- angular.forEach(obj, function(value, key) {
- if (dst[key] && dst[key].constructor && dst[key].constructor === Object) {
- extendDeep(dst[key], value);
- } else {
- dst[key] = value;
- }
- });
- }
- });
- return dst;
- };
-
- ItemsBusiness.editDialog = function (item, updateItem) {
- var deferred = $q.defer();
- $mdDialog.show({
- controller: item._itemType + 'EditController',
- templateUrl: 'views/' + item._itemType + 'edit.html',
- clickOutsideToClose: false,
- escapeToClose: false,
- locals: {
- $stateParams: {
- item: angular.copy(item),
- id: item.id,
- isModal: true
- }
- }
- }).then(function(data)
- {
- if (updateItem) {
- ItemsBusiness.extendDeep(item, data);
- }
- deferred.resolve(data);
- }, deferred.reject);
- return deferred.promise;
- };
-
- ItemsBusiness.addDialog = function (itemType, defaultItem) {
- return $mdDialog.show({
- controller: itemType + 'EditController',
- templateUrl: 'views/' + itemType + 'edit.html',
- clickOutsideToClose: false,
- escapeToClose: false,
- locals: {
- $stateParams: {
- item: defaultItem,
- id: null,
- isModal: true
- }
- }
- });
- };
-
- ItemsBusiness.deleteConfirmDialog = function (item) {
- var confirm = $mdDialog.confirm()
- .title(AppUtilsBusiness.tr('common.confirmDelete'))
- .textContent(AppUtilsBusiness.tr(item._itemType + '.deleteOne', {text: item.toString()}))
- .ok(AppUtilsBusiness.tr('common.delete'))
- .cancel(AppUtilsBusiness.tr('common.cancel'));
- return $mdDialog.show(confirm);
- };
-
- ItemsBusiness.deleteDialog = function (item, luBusyGroups) {
- var deferred = $q.defer();
- ItemsBusiness.deleteConfirmDialog(item).then(function()
- {
- var business = $injector.get(item._itemType + 'Business');
- business.deleteDbo(item.id, luBusyGroups)
- .then(deferred.resolve, deferred.reject);
- }, deferred.reject);
- return deferred.promise;
- };
-
- ItemsBusiness.deleteMultipleConfirmDialog = function (items) {
- var confirm = $mdDialog.confirm()
- .title(AppUtilsBusiness.tr('common.confirmDelete'))
- .textContent(AppUtilsBusiness.tr(items[0]._itemType + '.deleteMultiple', {count: items.length}))
- .ok(AppUtilsBusiness.tr('common.delete'))
- .cancel(AppUtilsBusiness.tr('common.cancel'));
- return $mdDialog.show(confirm);
- };
-
- ItemsBusiness.deleteMultipleDialog = function (items, luBusyGroups) {
- var deferred = $q.defer();
- ItemsBusiness.deleteMultipleConfirmDialog(items).then(function()
- {
- var business = $injector.get(items[0]._itemType + 'Business');
- ItemsBusiness.deleteFirst(items, business, deferred, luBusyGroups);
- }, deferred.reject);
- return deferred.promise;
- };
-
- ItemsBusiness.deleteFirst = function(items, business, deferred, luBusyGroups) {
- if (items.length == 0) {
- deferred.resolve();
- }
- else {
- business.deleteDbo(items[0].id, luBusyGroups)
- .then(function(data)
- {
- items.splice(0, 1);
- ItemsBusiness.deleteFirst(items, business, deferred, luBusyGroups);
- }, deferred.reject);
- }
- };
-
- ItemsBusiness.pickDialog = function (itemType) {
- return $mdDialog.show({
- controller: itemType + 'Controller',
- templateUrl: 'views/' + itemType + '.html',
- clickOutsideToClose: true,
- escapeToClose: true,
- locals: {
- $stateParams: {
- isModal: true
- }
- }
- });
- };
-
- return ItemsBusiness;
- }]);
- })();
|