-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
73 lines (72 loc) · 2.6 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
angular.module('event', ['restangular', 'ngRoute']).
config(function ($routeProvider, RestangularProvider) {
$routeProvider.
when('/', {
controller: ListCtrl,
templateUrl: 'events.list.html'
}).
when('/edit/:eventId', {
controller: EditCtrl,
templateUrl: 'events.detail.html',
resolve: {
event : function (Restangular, $route) {
return Restangular.one('events', $route.current.params.eventId).get();
},
groups: function (Restangular) {
return Restangular.all('groups').getList().$object;
}
}
}).
when('/new', {
controller: CreateCtrl,
templateUrl: 'events.detail.html',
resolve: {
groups: function (Restangular) {
return Restangular.all('groups').getList().$object;
}
}
}).
otherwise({redirectTo: '/'});
RestangularProvider.setBaseUrl('https://api.mongolab.com/api/1/databases/beorg-app/collections');
RestangularProvider.setDefaultRequestParams({ apiKey: 'WB5ZDewHyirIssJSIylEHfljGaczWmYp' })
RestangularProvider.setRestangularFields({
id: '_id.$oid'
});
RestangularProvider.setRequestInterceptor(function (elem, operation, what) {
if (operation === 'put') {
elem._id = undefined;
return elem;
}
return elem;
})
});
function ListCtrl($scope, Restangular) {
$scope.events = Restangular.all("events").getList().$object;
$scope.groups = Restangular.all("groups").getList().$object;
}
function CreateCtrl($scope, $location, Restangular, groups) {
$scope.groups = groups;
$scope.save = function () {
Restangular.all('events').post($scope.event).then(function (event) {
$location.path('/list');
});
}
}
function EditCtrl($scope, $location, Restangular, event, groups) {
$scope.groups = groups;
var original = event;
$scope.event = Restangular.copy(original);
$scope.isClean = function () {
return angular.equals(original, $scope.event);
}
$scope.destroy = function () {
original.remove().then(function () {
$location.path('/list');
});
};
$scope.save = function () {
$scope.event.put().then(function () {
$location.path('/');
});
};
}