eventman/angular_app/js/controllers.js

129 lines
3.9 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-28 17:42:27 +01:00
/* Controller for a group of date and time pickers. */
eventManControllers.controller('DatetimePickerCtrl', ['$scope',
function ($scope) {
$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
2015-03-28 18:20:23 +01:00
};
2015-03-28 17:42:27 +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-28 17:42:27 +01:00
$scope.eventForm.$dirty = false;
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
eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$routeParams', 'Person',
function ($scope, $routeParams, Person) {
2015-03-21 16:48:00 +01:00
if ($routeParams.id) {
$scope.person = Person.get($routeParams);
2015-04-04 14:15:52 +02:00
Person.getEvents($routeParams, function(data) {
$scope.events = data;
});
2015-03-21 16:48:00 +01:00
}
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
}]
);
2015-03-29 00:46:42 +01:00
eventManControllers.controller('ImportPersonsCtrl', ['$scope', '$log',
function ($scope, $log) {
$scope.ebCSVimport = function() {
$log.info("ImportPersonsCtrl");
$log.info($scope);
};
}]
);
2015-03-29 09:58:52 +02:00
2015-03-29 15:50:36 +02:00
eventManControllers.controller('FileUploadCtrl', ['$scope', '$log', '$upload', 'Event',
function ($scope, $log, $upload, Event) {
2015-03-29 15:05:01 +02:00
$scope.file = null;
$scope.reply = {};
2015-03-29 15:50:36 +02:00
$scope.events = Event.all();
2015-03-29 09:58:52 +02:00
$scope.upload = function(file, url) {
$log.info("FileUploadCtrl.upload");
$upload.upload({
url: url,
2015-03-29 15:50:36 +02:00
file: file,
fields: {targetEvent: $scope.targetEvent}
2015-03-29 15:05:01 +02:00
}).progress(function(evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
$log.debug('progress: ' + progressPercentage + '%');
}).success(function(data, status, headers, config) {
$scope.file = null;
$scope.reply = angular.fromJson(data);
2015-03-29 09:58:52 +02:00
});
};
}]
);