eventman/angular_app/js/controllers.js

80 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-03-14 17:32:16 +01:00
'use strict';
2015-03-22 09:36:32 +01:00
/* Controllers; their method are available where specified with the ng-controller
* directive or for a given route (see app.js). They use some services to
* connect to the backend (see services.js). */
2015-03-15 18:00:08 +01:00
var eventManControllers = angular.module('eventManControllers', []);
2015-03-14 17:32:16 +01:00
2015-03-21 20:31:36 +01:00
2015-03-22 09:19:30 +01:00
/* A controller that can be used to navigate. */
2015-03-28 15:48:59 +01:00
eventManControllers.controller('NavigationCtrl', ['$location',
2015-03-20 22:47:21 +01:00
function ($location) {
this.go = function(url) {
$location.url(url);
};
}]
);
2015-03-14 17:32:16 +01:00
2015-03-21 11:34:55 +01:00
eventManControllers.controller('EventsListCtrl', ['$scope', 'Event',
function ($scope, Event) {
$scope.events = Event.all();
2015-03-15 18:00:08 +01:00
$scope.orderProp = 'begin-datetime';
2015-03-22 17:08:25 +01:00
$scope.remove = function(_id) {
Event.remove({'id': _id}, function() {
$scope.events = Event.all();
});
};
2015-03-15 18:00:08 +01:00
}]
);
2015-03-21 11:34:55 +01:00
eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', '$routeParams',
function ($scope, Event, $routeParams) {
2015-03-21 15:33:17 +01:00
if ($routeParams.id) {
$scope.event = Event.get($routeParams);
}
2015-03-22 09:19:30 +01:00
// store a new Event or update an existing one
2015-03-21 15:45:40 +01:00
$scope.save = function() {
if ($scope.event.id === undefined) {
2015-03-22 00:07:05 +01:00
$scope.event = Event.save($scope.event);
2015-03-21 15:45:40 +01:00
} else {
2015-03-22 00:07:05 +01:00
$scope.event = Event.update($scope.event);
2015-03-21 15:45:40 +01:00
}
};
2015-03-15 23:05:59 +01:00
}]
);
2015-03-21 11:34:55 +01:00
eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person',
function ($scope, Person) {
$scope.persons = Person.all();
2015-03-15 18:00:08 +01:00
$scope.orderProp = 'name';
2015-03-22 17:08:25 +01:00
$scope.remove = function(_id) {
Person.remove({'id': _id}, function() {
$scope.persons = Person.all();
});
};
2015-03-14 17:32:16 +01:00
}]
);
2015-03-15 23:05:59 +01:00
2015-03-21 11:34:55 +01:00
eventManControllers.controller('PersonDetailsCtrl', ['$scope', 'Person', '$routeParams',
function ($scope, Person, $routeParams) {
2015-03-21 16:48:00 +01:00
if ($routeParams.id) {
$scope.person = Person.get($routeParams);
}
2015-03-22 09:19:30 +01:00
// store a new Person or update an existing one
2015-03-21 16:48:00 +01:00
$scope.save = function() {
2015-03-21 18:29:19 +01:00
if ($scope.person.id === undefined) {
2015-03-22 00:07:05 +01:00
$scope.person = Person.save($scope.person);
2015-03-21 16:48:00 +01:00
} else {
2015-03-22 00:07:05 +01:00
$scope.person = Person.update($scope.person);
2015-03-21 16:48:00 +01:00
}
};
2015-03-15 23:05:59 +01:00
}]
);