Last active
August 29, 2015 14:01
-
-
Save mohuk/c0dd8534075e809387b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| angular.module('SampleApp',[]) | |
| .controller('SampleAdminsCtrl', function ($scope, Admins, AdminsServ) { | |
| //Admins is a route resolve | |
| //$scope.Admins will hold whatever Admins object brings in itself | |
| $scope.isAdminView = true; | |
| $scope.Admins = Admins; | |
| //onViewPortals is a ngClick handler which calls in a service function upon a condition | |
| $scope.onViewPortals = function(admin){ | |
| if(AdminsServ.IsAdminGlobal(admin.AdminTypeId)) | |
| AdminsServ.ShowAdminIsGlobalMessage(admin); | |
| else | |
| AdminsServ.ShowAssignedPortalsModal(admin.PortalList); | |
| } | |
| //onDeleteAdmin calls a function which returns a promise | |
| //promise behaves differently on reject and resolve | |
| //each reject and resolve contains a condition according to which code is executed | |
| $scope.onDeleteAdmin = function(admin){ | |
| AdminsServ.ShowDeleteConfirmationModal(admin).then(function(shouldDelete){ | |
| if(shouldDelete) | |
| _.remove($scope.Admins, admin); | |
| else | |
| AdminsServ.doNothing(); | |
| }, function(res){ | |
| if(res.status == 401) | |
| AdminsServ.goHome(); | |
| else | |
| AdminsServ.showErrorMessage(); | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment