controllers.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. 'use strict';
  2. /* Controllers; their method are available where specified with the ng-controller
  3. * directive or for a given route (see app.js). They use some services to
  4. * connect to the backend (see services.js). */
  5. var eventManControllers = angular.module('eventManControllers', []);
  6. /* A controller that can be used to navigate. */
  7. eventManControllers.controller('NavigationCtrl', ['$location',
  8. function ($location) {
  9. this.go = function(url) {
  10. $location.url(url);
  11. };
  12. }]
  13. );
  14. /* Controller for a group of date and time pickers. */
  15. eventManControllers.controller('DatetimePickerCtrl', ['$scope',
  16. function ($scope) {
  17. $scope.open = function($event) {
  18. $event.preventDefault();
  19. $event.stopPropagation();
  20. $scope.opened = true;
  21. };
  22. }]
  23. );
  24. eventManControllers.controller('EventsListCtrl', ['$scope', 'Event',
  25. function ($scope, Event) {
  26. $scope.events = Event.all();
  27. $scope.orderProp = 'begin-datetime';
  28. $scope.remove = function(_id) {
  29. Event.remove({'id': _id}, function() {
  30. $scope.events = Event.all();
  31. });
  32. };
  33. }]
  34. );
  35. eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', '$routeParams',
  36. function ($scope, Event, $routeParams) {
  37. if ($routeParams.id) {
  38. $scope.event = Event.get($routeParams);
  39. }
  40. // store a new Event or update an existing one
  41. $scope.save = function() {
  42. if ($scope.event.id === undefined) {
  43. $scope.event = Event.save($scope.event);
  44. } else {
  45. $scope.event = Event.update($scope.event);
  46. }
  47. $scope.eventForm.$dirty = false;
  48. };
  49. }]
  50. );
  51. eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person',
  52. function ($scope, Person) {
  53. $scope.persons = Person.all();
  54. $scope.orderProp = 'name';
  55. $scope.remove = function(_id) {
  56. Person.remove({'id': _id}, function() {
  57. $scope.persons = Person.all();
  58. });
  59. };
  60. }]
  61. );
  62. eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$routeParams', 'Person', 'Action',
  63. function ($scope, $routeParams, Person, Action) {
  64. if ($routeParams.id) {
  65. $scope.person = Person.get($routeParams);
  66. Action.get({person_id: $routeParams.id}, function(data) {
  67. $scope.actions = angular.fromJson(data).actions;
  68. });
  69. }
  70. // store a new Person or update an existing one
  71. $scope.save = function() {
  72. if ($scope.person.id === undefined) {
  73. $scope.person = Person.save($scope.person);
  74. } else {
  75. $scope.person = Person.update($scope.person);
  76. }
  77. };
  78. }]
  79. );
  80. eventManControllers.controller('ImportPersonsCtrl', ['$scope', '$log',
  81. function ($scope, $log) {
  82. $scope.ebCSVimport = function() {
  83. $log.info("ImportPersonsCtrl");
  84. $log.info($scope);
  85. };
  86. }]
  87. );
  88. eventManControllers.controller('FileUploadCtrl', ['$scope', '$log', '$upload', 'Event',
  89. function ($scope, $log, $upload, Event) {
  90. $scope.file = null;
  91. $scope.reply = {};
  92. $scope.events = Event.all();
  93. $scope.upload = function(file, url) {
  94. $log.info("FileUploadCtrl.upload");
  95. $upload.upload({
  96. url: url,
  97. file: file,
  98. fields: {targetEvent: $scope.targetEvent}
  99. }).progress(function(evt) {
  100. var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
  101. $log.debug('progress: ' + progressPercentage + '%');
  102. }).success(function(data, status, headers, config) {
  103. $scope.file = null;
  104. $scope.reply = angular.fromJson(data);
  105. });
  106. };
  107. }]
  108. );