123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- /**
- * Created by robin on 12/15/16.
- */
-
- (function () {
- 'use strict';
-
- angular.module('appSdk')
- .factory('listControllerBuilder', ['luBusyBusiness', 'AppUtilsBusiness', '$transitions',
- 'ItemsBusiness', 'itemTracker', '$state', '$q', '$mdDialog',
- function (luBusyBusiness, AppUtilsBusiness, $transitions,
- ItemsBusiness, itemTracker, $state, $q, $mdDialog) {
-
- var EditControllerBuilder = {};
-
- EditControllerBuilder.create = function ($scope, $stateParams) {
-
- $scope.busy = luBusyBusiness.reset();
- $scope.appUtils = AppUtilsBusiness;
-
- $scope.isModal = $stateParams.isModal != null && $stateParams.isModal;
- $scope.isFilterShown = false;
-
- $scope.defaultItem = $scope.business.initDbo({});
- $scope.items = null;
- $scope.selected = [];
-
- if ($scope.defaultOrder == null) {
- $scope.defaultOrder = undefined;
- }
- if (typeof defaultFilter !== 'function') {
- var defaultFilter = $scope.defaultFilter;
- if (defaultFilter == null) {
- defaultFilter = '';
- }
- $scope.defaultFilter = function () {
- return defaultFilter;
- };
- }
- if ($scope.defaultLimit == null) {
- $scope.defaultLimit = 20;
- }
- if ($scope.defaultPage == null) {
- $scope.defaultPage = 1;
- }
-
- $scope.query = {
- order: $scope.defaultOrder,
- filter: $scope.defaultFilter(),
- limit: $scope.defaultLimit,
- page: $scope.defaultPage
- };
-
- if ($scope.getAddItem == null) {
- $scope.getAddItem = function () {
- return null;
- };
- }
-
- $scope.showFilter = function(show) {
- $scope.isFilterShown = show;
- if (!$scope.isFilterShown) {
- var defaultFilter = $scope.defaultFilter();
- if ($scope.query.filter != defaultFilter) {
- $scope.query.filter = defaultFilter;
- $scope.getItems();
- }
- }
- };
-
- $scope.selectItem = function(item)
- {
- $mdDialog.hide(item);
- };
-
- $scope.addItemDialog = function()
- {
- var defaultItem = $scope.getAddItem();
- ItemsBusiness.addDialog($scope.itemType, defaultItem).then(function(data)
- {
- $mdDialog.hide(data);
- }, function (error) {
- $mdDialog.cancel(error);
- })
- };
-
- $scope.editItem = function(item)
- {
- ItemsBusiness.editDialog(item, true).then(function(data) {}, function (error) {});
- };
-
- $scope.askRemoveOne = function (item) {
- ItemsBusiness.deleteDialog(item, $scope.itemType + '.table').then(function(data)
- {
- $scope.getItems();
- }, function(error) {});
- };
-
- $scope.askRemoveSelected = function () {
- if ($scope.selected.length == 0) {
- return;
- }
- else if ($scope.selected.length == 1) {
- $scope.askRemoveOne($scope.selected[0]);
- }
- else {
- ItemsBusiness.deleteMultipleDialog($scope.selected, $scope.itemType + '.table')
- .then(function () {
- $scope.getItems();
- }, function (error) {
- });
- }
- };
-
- $scope.getOrderBy = function(orderBy)
- {
- return orderBy;
- };
-
- $scope.getItems = function()
- {
- $scope.selected = [];
- var orderBy = AppUtilsBusiness.convertOrderBy($scope.query.order);
- $scope.business.getMultiple($scope.getOrderBy(orderBy), $scope.query.filter, $scope.query.page - 1, $scope.query.limit, $scope.itemType + '.table').then(function(data)
- {
- $scope.items = data;
- }, function(error)
- {
- $scope.items = null;
- });
- };
-
- $scope.init = function()
- {
- if (!$scope.isModal) {
- $scope.getItems();
- }
- };
- };
-
- return EditControllerBuilder;
- }]);
- })();
|