Skip to content

Instantly share code, notes, and snippets.

@rschwabco
Created June 10, 2013 14:23
Show Gist options
  • Save rschwabco/5749074 to your computer and use it in GitHub Desktop.
Save rschwabco/5749074 to your computer and use it in GitHub Desktop.
Leads
function HeaderController($scope, $location, Global) {
$scope.global = Global;
$scope.menu = [{
"title": "Tasks",
"link": "tasks"
}, {
"title": "Deals",
"link": "deals"
}];
$scope.isSelected = function(item) {
return '/' + item.link == $location.path();
};
$scope.init = function() {
};
}
//Controller
function LeadsController($scope, $routeParams, Leads){
$scope.type = $routeParams.type || 'general';
$scope.query = $routeParams.type ? {'type': $routeParams.type} : null;
$scope.add = function(email) {
if (!$scope.leads) $scope.leads = [];
var lead = new Leads({ email: email , plan: ''});
lead.$save(function(response) { $scope.leads.push(response); });
this.title = "";
}
$scope.remove = function(lead) {
lead.$remove();
for(var i in $scope.leads){
if($scope.leads[i] == lead) {
$scope.leads.splice(i, 1)
}
}
}
$scope.update = function(lead) {
if(!lead.updated) lead.updated = [];
lead.updated.push(new Date().getTime());
lead.$update();
}
$scope.init = function(){
Leads.query($scope.query,function(leads){
$scope.leads = leads;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment