(function (app, Controllers, angular) { Controllers.Admin = Controllers.Admin || {}; angular.extend(Controllers.Admin, { _default: function ($scope, Admin, $state, $e5aMessage) { $scope.message = null; Admin.getGroups(function (groups) { $scope.groups = groups; }); $scope.submit = function (leave) { if ((angular.isUndefined($scope.model.renewpasswd) && angular.isDefined($scope.model.newpasswd)) || (angular.isUndefined($scope.model.newpasswd) && angular.isDefined($scope.model.renewpasswd))) { $scope.message = { type: 'failure', text: 'Podaj nowe hasło 2 razy!' }; return; } else { var success = function () { $e5aMessage.success(); if (leave) { $scope.$clearCache(); $state.go('^.list'); } }; $scope.message = null; if (angular.isDefined($scope.model.id) && $scope.model.id > 0) { $scope.model.$update(success, $e5aMessage.failure); } else { $scope.model.$save(success, $e5aMessage.failure); } } }; $scope.remove = function (model) { bootbox.confirm("Czy na pewno usunąć admina: " + model.firstname + ' ' + model.lastname + "?", function (confirmed) { if (confirmed) { model.$remove(function () { $scope.$clearCache(); $e5aMessage.success(); $state.go('^.list'); }, $e5aMessage.failure); } }); }; }, List: function ($scope, Admin, StateService, $e5aBootbox, $e5aMessage) { StateService.state($scope); $scope.Model = Admin; $scope.remove = function (admin) { $e5aBootbox.removeConfirm({ message: "Czy na pewno usunąć admina: " + admin.firstname + ' ' + admin.lastname + "?" }).then(function () { admin.$remove(function () { $scope.$clearCache(); $e5aMessage.success(); }, $e5aMessage.failure); }); }; }, Add: function ($scope, Admin, $controller) { // wykonuje zawartość kontrolera _default $controller(Controllers.Admin._default, {'$scope': $scope}); $scope.model = new Admin(); $scope.model.$resolved = true; }, Edit: function ($scope, $stateParams, Admin, $controller) { // wykonuje zawartość kontrolera _default $controller(Controllers.Admin._default, {'$scope': $scope}); $scope.model = Admin.get({id: $stateParams.id}); }, NotificationsMenu: class { constructor($scope, $e5aMessage) { const ctrl = this; ctrl.messages = []; $e5aMessage.subscribe($scope, function ($event, value) { if (value.type === 'success') { value.class = { 'text-success': true, 'fa-warning': true }; } if (value.type === 'failure') { value.class = { 'text-failure': true, 'fa-warning': true }; } ctrl.messages = ctrl.messages.slice(0, 4); ctrl.messages.unshift(value); }); } } }); app.controller('Controllers.Admin.NotificationsMenu', Controllers.Admin.NotificationsMenu); })(app, Controllers, angular);