Skip to content

Instantly share code, notes, and snippets.

@mohuk
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save mohuk/c0dd8534075e809387b6 to your computer and use it in GitHub Desktop.

Select an option

Save mohuk/c0dd8534075e809387b6 to your computer and use it in GitHub Desktop.
'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