Created
January 2, 2015 07:41
-
-
Save wcadap/68ba7a9492fe893398c4 to your computer and use it in GitHub Desktop.
This file contains 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
contactApp.controller('contactController', | |
['$scope', 'contactDataService', '$location', | |
function categoryController($scope, contactDataService) { | |
$scope.contacts = []; | |
loadContactData(); | |
function loadContactData() { | |
contactDataService.getContacts() | |
.then(function () { | |
$scope.contacts = contactDataService.contacts; | |
}, | |
function () { | |
//Error goes here... | |
}) | |
.then(function () { | |
$scope.isBusy = false; | |
}); | |
}; | |
}]); | |
contactApp.controller('contactAddController', | |
['$scope', 'contactDataService', '$window', | |
function categoryController($scope, contactDataService,$window) { | |
$scope.contact = {}; | |
$scope.isEdit = false; | |
$scope.cancel = function () { | |
$window.location = "#/mycontacts"; | |
}; | |
$scope.saveContact = function () { | |
if ($scope.contactForm.$invalid) return; | |
contactDataService.addContact($scope.contact) | |
.then(function () { | |
$window.location = "#/mycontacts"; | |
}, | |
function () { | |
//Error | |
}) | |
}; | |
}]); | |
contactApp.controller('contactEditController', | |
['$scope', 'contactDataService', '$window','$routeParams','$modal', | |
function categoryController($scope, contactDataService, $window,$routeParams,$modal) { | |
$scope.contact = {}; | |
$scope.isEdit = true; | |
var lFirstChange = true; | |
if ($routeParams.id) { | |
$scope.contact = contactDataService.findContactById($routeParams.id); | |
$scope.$watchCollection('contact', function () { | |
if (!lFirstChange) { | |
$('#deleteButton').hide(400); | |
} | |
lFirstChange = false; | |
}); | |
} | |
$scope.cancel = function () { | |
$window.location = "#/mycontacts"; | |
}; | |
$scope.modalDelete = function (size, contact) { | |
var modalInstance = $modal.open({ | |
templateUrl: 'app/contact/html/deleteModal.html', | |
controller: function ($scope, $modalInstance,contact) { | |
$scope.contact = contact; | |
$scope.cancel = function () { | |
$modalInstance.dismiss('cancel'); | |
}; | |
$scope.ok = function (contact) { | |
contactDataService.deleteContact(contact.id) | |
.then(function () { | |
$window.location = "#/mycontacts"; | |
$modalInstance.close(contact); | |
}, | |
function () { | |
//Error | |
}) | |
}; | |
}, | |
size: size, | |
resolve: { | |
contact: function () { | |
return contact; | |
} | |
} | |
}); | |
}; | |
$scope.saveContact = function () { | |
if ($scope.contactForm.$invalid) return; | |
contactDataService.updateContact($scope.contact) | |
.then(function () { | |
$window.location = "#/mycontacts"; | |
}, | |
function () { | |
//Error | |
}) | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment