controllers.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. 'use strict';
  2. /* Controllers; their method are available where specified with the ng-controller
  3. * directive or for a given route/state (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', ['$scope', '$rootScope', '$location', 'Setting', 'Info',
  8. function ($scope, $rootScope, $location, Setting, Info) {
  9. $scope.logo = {};
  10. $scope.getLocation = function() {
  11. return $location.absUrl();
  12. };
  13. $scope.go = function(url) {
  14. $location.url(url);
  15. };
  16. Setting.query({setting: 'logo'}, function(data) {
  17. if (data && data.length) {
  18. $scope.logo = data[0];
  19. }
  20. });
  21. $scope.isActive = function(view) {
  22. if (view === $location.path()) {
  23. return true;
  24. }
  25. if (view[view.length-1] !== '/') {
  26. view = view + '/';
  27. }
  28. return $location.path().indexOf(view) == 0;
  29. };
  30. }]
  31. );
  32. /* Controller for a group of date and time pickers. */
  33. eventManControllers.controller('DatetimePickerCtrl', ['$scope',
  34. function ($scope) {
  35. $scope.open = function($event) {
  36. $event.preventDefault();
  37. $event.stopPropagation();
  38. $scope.opened = true;
  39. };
  40. }]
  41. );
  42. /* Controller for modals. */
  43. eventManControllers.controller('ModalConfirmInstanceCtrl', ['$scope', '$uibModalInstance', 'message',
  44. function ($scope, $uibModalInstance, message) {
  45. $scope.message = message;
  46. $scope.ok = function () {
  47. $uibModalInstance.close($scope);
  48. };
  49. $scope.cancel = function () {
  50. $uibModalInstance.dismiss('cancel');
  51. };
  52. }]
  53. );
  54. eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal', '$log', '$translate', '$rootScope', '$state',
  55. function ($scope, Event, $uibModal, $log, $translate, $rootScope, $state) {
  56. $scope.tickets = [];
  57. $scope.events = Event.all(function(events) {
  58. if (events && $state.is('tickets')) {
  59. angular.forEach(events, function(evt, idx) {
  60. var evt_tickets = (evt.persons || []).slice(0);
  61. angular.forEach(evt_tickets, function(obj, obj_idx) {
  62. obj.event_title = evt.title;
  63. obj.event_id = evt._id;
  64. });
  65. $scope.tickets.push.apply($scope.tickets, evt_tickets || []);
  66. });
  67. }
  68. });
  69. $scope.eventsOrderProp = "-begin_date";
  70. $scope.ticketsOrderProp = ["name", "surname"];
  71. $scope.confirm_delete = 'Do you really want to delete this event?';
  72. $rootScope.$on('$translateChangeSuccess', function () {
  73. $translate('Do you really want to delete this event?').then(function (translation) {
  74. $scope.confirm_delete = translation;
  75. });
  76. });
  77. $scope.remove = function(_id) {
  78. var modalInstance = $uibModal.open({
  79. scope: $scope,
  80. templateUrl: 'modal-confirm-action.html',
  81. controller: 'ModalConfirmInstanceCtrl',
  82. resolve: {
  83. message: function() { return $scope.confirm_delete; }
  84. }
  85. });
  86. modalInstance.result.then(function() {
  87. Event.remove({'id': _id}, function() {
  88. $scope.events = Event.all();
  89. }
  90. );
  91. });
  92. };
  93. $scope.updateOrded = function(key) {
  94. var new_order = [key];
  95. var inv_key;
  96. if (key && key[0] === '-') {
  97. inv_key = key.substring(1);
  98. } else {
  99. inv_key = '-' + key;
  100. }
  101. angular.forEach($scope.ticketsOrderProp,
  102. function(value, idx) {
  103. if (value !== key && value !== inv_key) {
  104. new_order.push(value);
  105. }
  106. }
  107. );
  108. $scope.ticketsOrderProp = new_order;
  109. };
  110. }]
  111. );
  112. eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', '$log', '$translate', '$rootScope',
  113. function ($scope, $state, Event, $log, $translate, $rootScope) {
  114. $scope.event = {};
  115. $scope.event.persons = [];
  116. $scope.event.formSchema = {};
  117. $scope.eventFormDisabled = false;
  118. if ($state.params.id) {
  119. $scope.event = Event.get($state.params);
  120. if ($state.is('event.view') || !$rootScope.hasPermission('event|update')) {
  121. $scope.eventFormDisabled = true;
  122. }
  123. }
  124. // store a new Event or update an existing one
  125. $scope.save = function() {
  126. // avoid override of event.persons list.
  127. var this_event = angular.copy($scope.event);
  128. if (this_event.persons) {
  129. delete this_event.persons;
  130. }
  131. if (this_event._id === undefined) {
  132. $scope.event = Event.save(this_event);
  133. } else {
  134. $scope.event = Event.update(this_event);
  135. }
  136. $scope.eventForm.$setPristine(false);
  137. };
  138. $scope.saveForm = function(easyFormGeneratorModel) {
  139. $scope.event.formSchema = easyFormGeneratorModel;
  140. $scope.save();
  141. };
  142. }]
  143. );
  144. eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Person', 'Setting', '$log', '$translate', '$rootScope', 'EventUpdates', '$uibModal',
  145. function ($scope, $state, Event, EventTicket, Person, Setting, $log, $translate, $rootScope, EventUpdates, $uibModal) {
  146. $scope.personsOrder = ["name", "surname"];
  147. $scope.countAttendees = 0;
  148. $scope.message = {};
  149. $scope.event = {};
  150. $scope.ticket = {}; // current ticket, for the event.ticket.* states
  151. $scope.tickets = []; // list of all tickets, for the 'tickets' state
  152. $scope.formSchema = {};
  153. $scope.formData = {};
  154. $scope.guiOptions = {dangerousActionsEnabled: false};
  155. $scope.customFields = Setting.query({setting: 'person_custom_field', in_event_details: true});
  156. $scope.formFieldsMap = {};
  157. $scope.formFieldsMapRev = {};
  158. if ($state.params.id) {
  159. $scope.event = Event.get({id: $state.params.id}, function(data) {
  160. $scope.$watchCollection(function() {
  161. return $scope.event.persons;
  162. }, function(prev, old) {
  163. $scope.calcAttendees();
  164. }
  165. );
  166. if (!(data && data.formSchema)) {
  167. return;
  168. }
  169. $scope.formSchema = data.formSchema.edaFieldsModel;
  170. $scope.extractFormFields(data.formSchema.formlyFieldsModel);
  171. // Editing an existing ticket
  172. if ($state.params.ticket_id) {
  173. EventTicket.get({id: $state.params.id, ticket_id: $state.params.ticket_id}, function(data) {
  174. $scope.ticket = data;
  175. angular.forEach(data, function(value, key) {
  176. if (!$scope.formFieldsMapRev[key]) {
  177. return;
  178. }
  179. $scope.formData[$scope.formFieldsMapRev[key]] = value;
  180. });
  181. });
  182. }
  183. });
  184. // Managing the list of tickets.
  185. if ($state.is('event.tickets')) {
  186. $scope.allPersons = Event.group_persons({id: $state.params.id});
  187. // Handle WebSocket connection used to update the list of persons.
  188. $scope.EventUpdates = EventUpdates;
  189. $scope.EventUpdates.open();
  190. $scope.$watchCollection(function() {
  191. return $scope.EventUpdates.data;
  192. }, function(prev, old) {
  193. if (!($scope.EventUpdates.data && $scope.EventUpdates.data.update)) {
  194. return;
  195. }
  196. var data = $scope.EventUpdates.data.update;
  197. $log.debug('received ' + data.action + ' action from websocket source ' + data.uuid);
  198. if ($rootScope.app_uuid == data.uuid) {
  199. $log.debug('do not process our own message');
  200. return false;
  201. }
  202. if (!$scope.event.persons) {
  203. $scope.event.persons = [];
  204. }
  205. var person_idx = $scope.event.persons.findIndex(function(el, idx, array) {
  206. return data._id == el._id;
  207. });
  208. if (person_idx != -1) {
  209. $log.debug('_id ' + data._id + ' found');
  210. } else {
  211. $log.debug('_id ' + data._id + ' not found');
  212. }
  213. if (data.action == 'update' && person_idx != -1 && $scope.event.persons[person_idx] != data.person) {
  214. $scope.event.persons[person_idx] = data.person;
  215. } else if (data.action == 'add' && person_idx == -1) {
  216. $scope._localAddTicket(data.person);
  217. } else if (data.action == 'delete' && person_idx != -1) {
  218. $scope._localRemoveTicket({_id: data._id});
  219. }
  220. }
  221. );
  222. }
  223. } else if ($state.is('tickets')) {
  224. $scope.tickets = EventTicket.all();
  225. }
  226. $scope.calcAttendees = function() {
  227. if (!($scope.event && $scope.event.persons)) {
  228. $scope.countAttendees = 0;
  229. return;
  230. }
  231. var attendees = 0;
  232. angular.forEach($scope.event.persons, function(value, key) {
  233. if (value.attended && !value.cancelled) {
  234. attendees += 1;
  235. }
  236. });
  237. $scope.countAttendees = attendees;
  238. };
  239. /* Stuff to do when a ticket is added, modified or removed locally. */
  240. $scope._localAddTicket = function(ticket, original_person) {
  241. var ret = true;
  242. if (!$scope.event.persons) {
  243. $scope.event.persons = [];
  244. }
  245. var ticket_idx = $scope.event.persons.findIndex(function(el, idx, array) {
  246. return ticket._id == el._id;
  247. });
  248. if (ticket_idx != -1) {
  249. $log.warn('ticket already present: not added');
  250. ret = false;
  251. } else {
  252. $scope.event.persons.push(ticket);
  253. }
  254. // Try to remove this person from the allPersons list using ID or email.
  255. var field = null;
  256. var field_value = null;
  257. if (original_person && original_person._id) {
  258. field = '_id';
  259. field_value = original_person._id;
  260. } else if (ticket.email) {
  261. field = 'email';
  262. field_value = ticket.email;
  263. }
  264. if (field) {
  265. var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) {
  266. return field_value == el[field];
  267. });
  268. if (all_person_idx != -1) {
  269. $scope.allPersons.splice(all_person_idx, 1);
  270. }
  271. }
  272. return ret;
  273. };
  274. $scope._localUpdateTicket = function(ticket) {
  275. if (!$scope.event.persons) {
  276. $scope.event.persons = [];
  277. }
  278. var ticket_idx = $scope.event.persons.findIndex(function(el, idx, array) {
  279. return ticket._id == el._id;
  280. });
  281. if (ticket_idx == -1) {
  282. $log.warn('ticket not present: not updated');
  283. return false;
  284. }
  285. $scope.event.persons[ticket_idx] = ticket;
  286. };
  287. $scope._localRemoveTicket = function(person) {
  288. if (!(person && person._id && $scope.event.persons)) {
  289. return;
  290. }
  291. var person_idx = $scope.event.persons.findIndex(function(el, idx, array) {
  292. return person._id == el._id;
  293. });
  294. if (person_idx == -1) {
  295. $log.warn('unable to find and delete ticket _id ' + person._id);
  296. return;
  297. }
  298. var removed_person = $scope.event.persons.splice(person_idx, 1);
  299. // to be used to populate allPersons, if needed.
  300. if (removed_person.length) {
  301. person = removed_person[0];
  302. }
  303. var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) {
  304. return person._id == el._id;
  305. });
  306. if (all_person_idx == -1 && person._id) {
  307. $scope.allPersons.push(person);
  308. }
  309. };
  310. $scope.setTicketAttribute = function(person, key, value, callback, hideMessage) {
  311. $log.debug('setTicketAttribute for _id ' + person._id + ' key: ' + key + ' value: ' + value);
  312. var newData = {event_id: $state.params.id, _id: person._id};
  313. newData[key] = value;
  314. EventTicket.update(newData, function(data) {
  315. if (!(data && data._id && data.person)) {
  316. return;
  317. }
  318. var person_idx = $scope.event.persons.findIndex(function(el, idx, array) {
  319. return data._id == el._id;
  320. });
  321. if (person_idx == -1) {
  322. $log.warn('unable to find ticket _id ' + _id);
  323. return;
  324. }
  325. if ($scope.event.persons[person_idx] != data.person) {
  326. $scope.event.persons[person_idx] = data.person;
  327. }
  328. if (callback) {
  329. callback(data);
  330. }
  331. if (key === 'attended' && !hideMessage) {
  332. var msg = {};
  333. if (value) {
  334. msg.message = '' + person.name + ' ' + person.surname + ' successfully added to event ' + $scope.event.title;
  335. } else {
  336. msg.message = '' + person.name + ' ' + person.surname + ' successfully removed from event ' + $scope.event.title;
  337. msg.isError = true;
  338. }
  339. $scope.showMessage(msg);
  340. }
  341. });
  342. };
  343. $scope.setTicketAttributeAndRefocus = function(person, key, value) {
  344. $scope.setTicketAttribute(person, key, value);
  345. $scope.query = '';
  346. };
  347. $scope._setAttended = function(person) {
  348. $scope.setTicketAttribute(person, 'attended', true, null, true);
  349. };
  350. $scope.deleteTicket = function(person) {
  351. EventTicket.delete({
  352. event_id: $state.params.id,
  353. ticket_id: person._id
  354. }, function() {
  355. $scope._localRemoveTicket(person);
  356. });
  357. };
  358. $scope.addTicket = function(person) {
  359. person.event_id = $state.params.id;
  360. EventTicket.add(person, function(ticket) {
  361. $log.debug('addTicket');
  362. $log.debug(ticket);
  363. $scope._localAddTicket(ticket, person);
  364. if (!$state.is('event.tickets')) {
  365. $state.go('event.ticket.edit', {id: $scope.event._id, ticket_id: ticket._id});
  366. } else {
  367. $scope.query = '';
  368. $scope._setAttended(ticket);
  369. if ($scope.$close) {
  370. $scope.$close();
  371. }
  372. }
  373. });
  374. };
  375. $scope.updateTicket = function(ticket, cb) {
  376. ticket.event_id = $state.params.id;
  377. EventTicket.update(ticket, function(t) {
  378. $scope._localUpdateTicket(t.person);
  379. if (cb) {
  380. cb(t);
  381. }
  382. });
  383. };
  384. $scope.toggleCancelledTicket = function() {
  385. if (!$scope.ticket._id) {
  386. return;
  387. }
  388. $scope.ticket.cancelled = !$scope.ticket.cancelled;
  389. $scope.setTicketAttribute($scope.ticket, 'cancelled', $scope.ticket.cancelled, function() {
  390. $scope.guiOptions.dangerousActionsEnabled = false;
  391. });
  392. };
  393. $scope.openQuickAddTicket = function(_id) {
  394. var modalInstance = $uibModal.open({
  395. templateUrl: 'modal-quick-add-ticket.html',
  396. controller: 'EventTicketsCtrl'
  397. });
  398. modalInstance.result.then(function() {
  399. });
  400. };
  401. $scope.submitForm = function(dataModelSubmitted) {
  402. angular.forEach(dataModelSubmitted, function(value, key) {
  403. key = $scope.formFieldsMap[key] || key;
  404. $scope.ticket[key] = value;
  405. });
  406. if (!$state.params.ticket_id) {
  407. $scope.addTicket($scope.ticket);
  408. } else {
  409. $scope.updateTicket($scope.ticket);
  410. }
  411. };
  412. $scope.cancelForm = function() {
  413. if (!$state.is('event.tickets')) {
  414. $state.go('events');
  415. } else if ($scope.$close) {
  416. $scope.$close();
  417. }
  418. };
  419. $scope.extractFormFields = function(formlyFieldsModel) {
  420. if (!formlyFieldsModel) {
  421. return;
  422. }
  423. angular.forEach(formlyFieldsModel, function(row, idx) {
  424. if (!row.className == 'row') {
  425. return;
  426. }
  427. angular.forEach(row.fieldGroup || [], function(item, idx) {
  428. if (!(item.key && item.templateOptions && item.templateOptions.label)) {
  429. return;
  430. }
  431. var value = item.templateOptions.label.toLowerCase();
  432. $scope.formFieldsMap[item.key] = value;
  433. $scope.formFieldsMapRev[value] = item.key;
  434. });
  435. });
  436. };
  437. $scope.updateOrded = function(key) {
  438. var new_order = [key];
  439. var inv_key;
  440. if (key && key[0] === '-') {
  441. inv_key = key.substring(1);
  442. } else {
  443. inv_key = '-' + key;
  444. }
  445. angular.forEach($scope.personsOrder,
  446. function(value, idx) {
  447. if (value !== key && value !== inv_key) {
  448. new_order.push(value);
  449. }
  450. }
  451. );
  452. $scope.personsOrder = new_order;
  453. };
  454. $scope.showMessage = function(cfg) {
  455. $scope.message.show(cfg);
  456. };
  457. $scope.$on('$destroy', function() {
  458. $scope.EventUpdates && $scope.EventUpdates.close();
  459. });
  460. }]
  461. );
  462. eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person', 'Setting', '$uibModal', '$translate', '$rootScope',
  463. function ($scope, Person, Setting, $uibModal, $translate, $rootScope) {
  464. $scope.persons = Person.all();
  465. $scope.personsOrder = ["name", "surname"];
  466. $scope.customFields = Setting.query({setting: 'person_custom_field',
  467. in_persons_list: true});
  468. $scope.confirm_delete = 'Do you really want to delete this person?';
  469. $rootScope.$on('$translateChangeSuccess', function () {
  470. $translate('Do you really want to delete this person?').then(function (translation) {
  471. $scope.confirm_delete = translation;
  472. });
  473. });
  474. $scope.updateOrded = function(key) {
  475. var new_order = [key];
  476. var inv_key;
  477. if (key && key[0] === '-') {
  478. inv_key = key.substring(1);
  479. } else {
  480. inv_key = '-' + key;
  481. }
  482. angular.forEach($scope.personsOrder,
  483. function(value, idx) {
  484. if (value !== key && value !== inv_key) {
  485. new_order.push(value);
  486. }
  487. }
  488. );
  489. $scope.personsOrder = new_order;
  490. };
  491. $scope.setAttribute = function(person, key, value) {
  492. var data = {_id: person._id};
  493. data[key] = value;
  494. Person.update(data, function() {
  495. $scope.persons = Person.all();
  496. });
  497. };
  498. $scope.remove = function(_id) {
  499. var modalInstance = $uibModal.open({
  500. scope: $scope,
  501. templateUrl: 'modal-confirm-action.html',
  502. controller: 'ModalConfirmInstanceCtrl',
  503. resolve: {
  504. message: function() { return $scope.confirm_delete; }
  505. }
  506. });
  507. modalInstance.result.then(function() {
  508. Person.remove({'id': _id}, function() {
  509. $scope.persons = Person.all();
  510. }
  511. );
  512. });
  513. };
  514. }]
  515. );
  516. eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$state', 'Person', 'Event', 'Setting', '$log',
  517. function ($scope, $state, Person, Event, Setting, $log) {
  518. $scope.personsOrderProp = 'name';
  519. $scope.eventsOrderProp = '-begin_date';
  520. $scope.addToEvent = '';
  521. $scope.customFields = Setting.query({setting: 'person_custom_field',
  522. in_persons_list: true});
  523. if ($state.params.id) {
  524. $scope.person = Person.get($state.params);
  525. $scope.events = Person.getEvents({_id: $state.arams.id, all: true});
  526. } else {
  527. $scope.events = Event.all();
  528. }
  529. // store a new Person or update an existing one
  530. $scope.save = function() {
  531. if ($scope.person._id === undefined) {
  532. $scope.person = new Person($scope.person);
  533. $scope.person.$save(function(person) {
  534. if ($scope.addToEvent) {
  535. var data = angular.copy(person);
  536. data.person_id = data._id;
  537. data._id = $scope.addToEvent;
  538. data.attended = false;
  539. Event.addPerson(data);
  540. }
  541. });
  542. } else {
  543. $scope.person = Person.update($scope.person, function(data) {
  544. if ($scope.addToEvent) {
  545. var data = angular.copy($scope.person);
  546. data._id = $scope.addToEvent;
  547. data.person_id = $scope.person._id;
  548. data.attended = false;
  549. Event.addPerson(data);
  550. }
  551. });
  552. }
  553. $scope.personForm.$setPristine(false);
  554. };
  555. $scope.setTicketAttributeAtEvent = function(evnt, key, value) {
  556. var attrs = {_id: evnt._id, person_id: $state.params.id};
  557. attrs[key] = value;
  558. Event.updatePerson(attrs,
  559. function(data) {
  560. $scope.events = Person.getEvents({_id: $state.params.id, all: true});
  561. }
  562. );
  563. };
  564. $scope.switchRegistered = function(evnt, person, add) {
  565. $log.debug('PersonDetailsCtrl.switchRegistered.event_id: ' + evnt._id);
  566. $log.debug('PersonDetailsCtrl.switchRegistered.person_id: ' + person._id);
  567. $log.debug('PersonDetailsCtrl.switchRegistered.add: ' + add);
  568. if (add) {
  569. var data = angular.copy(person);
  570. data._id = evnt._id;
  571. data.person_id = person._id;
  572. data.attended = false;
  573. Event.addPerson(data,
  574. function(data) {
  575. $scope.events = Person.getEvents({_id: $state.params.id, all: true});
  576. }
  577. );
  578. } else {
  579. Event.deletePerson({_id: evnt._id, person_id: person._id},
  580. function(data) {
  581. $scope.events = Person.getEvents({_id: $state.params.id, all: true});
  582. }
  583. );
  584. }
  585. };
  586. }]
  587. );
  588. eventManControllers.controller('LoginCtrl', ['$scope', '$rootScope', '$state', '$log', 'User',
  589. function ($scope, $rootScope, $state, $log, User) {
  590. $scope.loginData = {};
  591. $scope.register = function() {
  592. User.add($scope.newUser, function(data) {
  593. $scope.login($scope.newUser);
  594. });
  595. };
  596. $scope.login = function(loginData) {
  597. if (!loginData) {
  598. loginData = $scope.loginData;
  599. }
  600. User.login(loginData, function(data) {
  601. if (!data.error) {
  602. $rootScope.readInfo(function() {
  603. $rootScope.clearError();
  604. $state.go('events');
  605. });
  606. }
  607. });
  608. };
  609. $scope.logout = function() {
  610. User.logout({}, function(data) {
  611. if (!data.error) {
  612. $rootScope.readInfo(function() {
  613. $state.go('events');
  614. });
  615. }
  616. });
  617. };
  618. }]
  619. );
  620. eventManControllers.controller('FileUploadCtrl', ['$scope', '$log', '$upload', 'Event',
  621. function ($scope, $log, $upload, Event) {
  622. $scope.file = null;
  623. $scope.reply = {};
  624. $scope.events = Event.all();
  625. $scope.upload = function(file, url) {
  626. $log.debug("FileUploadCtrl.upload");
  627. $upload.upload({
  628. url: url,
  629. file: file,
  630. fields: {targetEvent: $scope.targetEvent}
  631. }).progress(function(evt) {
  632. var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
  633. $log.debug('progress: ' + progressPercentage + '%');
  634. }).success(function(data, status, headers, config) {
  635. $scope.file = null;
  636. $scope.reply = angular.fromJson(data);
  637. });
  638. };
  639. }]
  640. );