controllers.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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', '$state',
  8. function ($scope, $rootScope, $location, Setting, $state) {
  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.tickets || []).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.deleteEvent = 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.delete({'id': _id}, function() {
  88. $scope.events = Event.all();
  89. });
  90. });
  91. };
  92. $scope.updateOrded = function(key) {
  93. var new_order = [key];
  94. var inv_key;
  95. if (key && key[0] === '-') {
  96. inv_key = key.substring(1);
  97. } else {
  98. inv_key = '-' + key;
  99. }
  100. angular.forEach($scope.ticketsOrderProp,
  101. function(value, idx) {
  102. if (value !== key && value !== inv_key) {
  103. new_order.push(value);
  104. }
  105. }
  106. );
  107. $scope.ticketsOrderProp = new_order;
  108. };
  109. }]
  110. );
  111. eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', '$log', '$translate', '$rootScope',
  112. function ($scope, $state, Event, $log, $translate, $rootScope) {
  113. $scope.event = {};
  114. $scope.event.tickets = [];
  115. $scope.event.formSchema = {};
  116. $scope.eventFormDisabled = false;
  117. if ($state.params.id) {
  118. $scope.event = Event.get($state.params);
  119. if ($state.is('event.view') || !$rootScope.hasPermission('event|update')) {
  120. $scope.eventFormDisabled = true;
  121. }
  122. }
  123. // store a new Event or update an existing one
  124. $scope.save = function() {
  125. // avoid override of event.tickets list.
  126. var this_event = angular.copy($scope.event);
  127. if (this_event.tickets) {
  128. delete this_event.tickets;
  129. }
  130. if (this_event._id === undefined) {
  131. $scope.event = Event.save(this_event);
  132. } else {
  133. $scope.event = Event.update(this_event);
  134. }
  135. $scope.eventForm.$setPristine(false);
  136. };
  137. $scope.saveForm = function(easyFormGeneratorModel) {
  138. $scope.event.formSchema = easyFormGeneratorModel;
  139. $scope.save();
  140. };
  141. }]
  142. );
  143. eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Setting', '$log', '$translate', '$rootScope', 'EventUpdates', '$uibModal',
  144. function ($scope, $state, Event, EventTicket, Setting, $log, $translate, $rootScope, EventUpdates, $uibModal) {
  145. $scope.ticketsOrder = ["name", "surname"];
  146. $scope.countAttendees = 0;
  147. $scope.message = {};
  148. $scope.event = {};
  149. $scope.event.tickets = [];
  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: 'ticket_custom_field', in_event_details: true});
  156. $scope.registeredFilterOptions = {all: false};
  157. $scope.formFieldsMap = {};
  158. $scope.formFieldsMapRev = {};
  159. if ($state.params.id) {
  160. $scope.event = Event.get({id: $state.params.id}, function(data) {
  161. $scope.$watchCollection(function() {
  162. return $scope.event.tickets;
  163. }, function(new_collection, old_collection) {
  164. $scope.calcAttendees();
  165. }
  166. );
  167. if (!(data && data.formSchema)) {
  168. return;
  169. }
  170. $scope.formSchema = data.formSchema.edaFieldsModel;
  171. $scope.extractFormFields(data.formSchema.formlyFieldsModel);
  172. // Editing an existing ticket
  173. if ($state.params.ticket_id) {
  174. EventTicket.get({id: $state.params.id, ticket_id: $state.params.ticket_id}, function(data) {
  175. $scope.ticket = data;
  176. angular.forEach(data, function(value, key) {
  177. if (!$scope.formFieldsMapRev[key]) {
  178. return;
  179. }
  180. $scope.formData[$scope.formFieldsMapRev[key]] = value;
  181. });
  182. });
  183. }
  184. });
  185. // Managing the list of tickets.
  186. if ($state.is('event.tickets')) {
  187. $scope.allPersons = Event.group_persons({id: $state.params.id});
  188. // Handle WebSocket connection used to update the list of tickets.
  189. $scope.EventUpdates = EventUpdates;
  190. $scope.EventUpdates.open();
  191. $scope.$watchCollection(function() {
  192. return $scope.EventUpdates.data;
  193. }, function(new_collection, old_collection) {
  194. if (!($scope.EventUpdates.data && $scope.EventUpdates.data.update)) {
  195. $log.debug('no data received from the WebSocket');
  196. return;
  197. }
  198. var data = $scope.EventUpdates.data.update;
  199. $log.debug('received ' + data.action + ' action from websocket source ' + data.uuid + ' . Full data:');
  200. $log.debug(data);
  201. if ($rootScope.app_uuid == data.uuid) {
  202. $log.debug('do not process our own message');
  203. return false;
  204. }
  205. if (!$scope.event.tickets) {
  206. $scope.event.tickets = [];
  207. }
  208. var ticket_id = data._id || (data.ticket && data.ticket._id);
  209. var ticket_idx = $scope.event.tickets.findIndex(function(el, idx, array) {
  210. return ticket_id && (ticket_id == el._id);
  211. });
  212. if (ticket_idx != -1) {
  213. $log.debug('_id ' + data._id + ' found');
  214. } else {
  215. $log.debug('_id ' + data._id + ' not found');
  216. }
  217. if (data.action == 'update' && ticket_idx != -1 && $scope.event.tickets[ticket_idx] != data.ticket) {
  218. $scope.event.tickets[ticket_idx] = data.ticket;
  219. } else if (data.action == 'add' && ticket_idx == -1) {
  220. $scope._localAddTicket(data.ticket);
  221. } else if (data.action == 'delete' && ticket_idx != -1) {
  222. $scope._localRemoveTicket({_id: data._id});
  223. }
  224. }
  225. );
  226. }
  227. } else if ($state.is('tickets')) {
  228. $scope.tickets = EventTicket.all();
  229. }
  230. $scope.calcAttendees = function() {
  231. if (!($scope.event && $scope.event.tickets)) {
  232. $scope.countAttendees = 0;
  233. return;
  234. }
  235. var attendees = 0;
  236. angular.forEach($scope.event.tickets, function(value, key) {
  237. if (value.attended && !value.cancelled) {
  238. attendees += 1;
  239. }
  240. });
  241. $scope.countAttendees = attendees;
  242. };
  243. /* Stuff to do when a ticket is added, modified or removed locally. */
  244. $scope._localAddTicket = function(ticket, original_ticket) {
  245. if (!$state.is('event.tickets')) {
  246. return true;
  247. }
  248. var ret = true;
  249. if (!$scope.event.tickets) {
  250. $scope.event.tickets = [];
  251. }
  252. var ticket_idx = $scope.event.tickets.findIndex(function(el, idx, array) {
  253. return ticket._id == el._id;
  254. });
  255. if (ticket_idx != -1) {
  256. $log.warn('ticket already present: not added');
  257. ret = false;
  258. } else {
  259. $scope.event.tickets.push(ticket);
  260. }
  261. // Try to remove this person from the allPersons list using ID of the original entry or email.
  262. var field = null;
  263. var field_value = null;
  264. if (original_ticket && original_ticket._id) {
  265. field = '_id';
  266. field_value = original_ticket._id;
  267. } else if (ticket.email) {
  268. field = 'email';
  269. field_value = ticket.email;
  270. }
  271. if (field) {
  272. var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) {
  273. return field_value == el[field];
  274. });
  275. if (all_person_idx != -1) {
  276. $scope.allPersons.splice(all_person_idx, 1);
  277. }
  278. }
  279. return ret;
  280. };
  281. $scope._localUpdateTicket = function(ticket) {
  282. if (!$state.is('event.tickets')) {
  283. return;
  284. }
  285. if (!$scope.event.tickets) {
  286. $scope.event.tickets = [];
  287. }
  288. var ticket_idx = $scope.event.tickets.findIndex(function(el, idx, array) {
  289. return ticket._id == el._id;
  290. });
  291. if (ticket_idx == -1) {
  292. $log.warn('ticket not present: not updated');
  293. return false;
  294. }
  295. $scope.event.tickets[ticket_idx] = ticket;
  296. };
  297. $scope._localRemoveTicket = function(ticket) {
  298. if (!(ticket && ticket._id && $scope.event.tickets)) {
  299. return;
  300. }
  301. var ticket_idx = $scope.event.tickets.findIndex(function(el, idx, array) {
  302. return ticket._id == el._id;
  303. });
  304. if (ticket_idx == -1) {
  305. $log.warn('unable to find and delete ticket _id ' + ticket._id);
  306. return;
  307. }
  308. var removed_person = $scope.event.tickets.splice(ticket_idx, 1);
  309. // to be used to populate allPersons, if needed.
  310. var person = null;
  311. if (removed_person.length) {
  312. person = removed_person[0];
  313. } else {
  314. return;
  315. }
  316. if (!$scope.allPersons) {
  317. $scope.allPersons = [];
  318. }
  319. var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) {
  320. return person._id == el._id;
  321. });
  322. if (all_person_idx == -1 && person._id) {
  323. $scope.allPersons.push(person);
  324. }
  325. };
  326. $scope.buildTicketLabel = function(ticket) {
  327. var name = ticket.name || '';
  328. if (ticket.surname) {
  329. if (name) {
  330. name = name + ' ';
  331. }
  332. name = name + ticket.surname;
  333. }
  334. if (!name && ticket.email) {
  335. name = ticket.email;
  336. }
  337. if (!name) {
  338. name = 'ticket';
  339. }
  340. return name;
  341. };
  342. $scope.setTicketAttribute = function(ticket, key, value, callback, hideMessage) {
  343. $log.debug('setTicketAttribute for _id ' + ticket._id + ' key: ' + key + ' value: ' + value);
  344. var newData = {event_id: $state.params.id, _id: ticket._id};
  345. newData[key] = value;
  346. EventTicket.update(newData, function(data) {
  347. if (!(data && data._id && data.ticket)) {
  348. return;
  349. }
  350. if (callback) {
  351. callback(data);
  352. }
  353. if (!$state.is('event.tickets')) {
  354. return;
  355. }
  356. var ticket_idx = $scope.event.tickets.findIndex(function(el, idx, array) {
  357. return data._id == el._id;
  358. });
  359. if (ticket_idx == -1) {
  360. $log.warn('unable to find ticket _id ' + data._id);
  361. return;
  362. }
  363. if ($scope.event.tickets[ticket_idx] != data.ticket) {
  364. $scope.event.tickets[ticket_idx] = data.ticket;
  365. }
  366. if (key === 'attended' && !hideMessage) {
  367. var msg = {};
  368. var name = $scope.buildTicketLabel(data.ticket);
  369. if (value) {
  370. msg.message = name + ' successfully added to event ' + $scope.event.title;
  371. } else {
  372. msg.message = name + ' successfully removed from event ' + $scope.event.title;
  373. msg.isError = true;
  374. }
  375. $scope.showMessage(msg);
  376. }
  377. });
  378. };
  379. $scope.setTicketAttributeAndRefocus = function(ticket, key, value) {
  380. $scope.setTicketAttribute(ticket, key, value);
  381. $scope.query = '';
  382. };
  383. $scope._setAttended = function(ticket) {
  384. $scope.setTicketAttribute(ticket, 'attended', true, null, true);
  385. };
  386. $scope.deleteTicket = function(ticket) {
  387. EventTicket.delete({
  388. event_id: $state.params.id,
  389. ticket_id: ticket._id
  390. }, function() {
  391. $scope._localRemoveTicket(ticket);
  392. });
  393. };
  394. /* event listners; needed because otherwise, adding a ticket with the Quick add form,
  395. * we'd be changing the $scope outside of the AngularJS's $digest. */
  396. $rootScope.$on('event:ticket:new', function(evt, ticket, callback) {
  397. $scope._localAddTicket(ticket);
  398. if (callback) {
  399. callback(ticket);
  400. }
  401. });
  402. $rootScope.$on('event:ticket:update', function(evt, ticket) {
  403. if (!$scope.event.tickets) {
  404. $scope.event.tickets = [];
  405. }
  406. var ticket_idx = $scope.event.tickets.findIndex(function(el, idx, array) {
  407. return ticket._id == el._id;
  408. });
  409. if (ticket_idx == -1) {
  410. $log.debug('ticket not present: not updated');
  411. return false;
  412. }
  413. $scope.event.tickets[ticket_idx] = ticket;
  414. });
  415. $rootScope.$on('event:ticket:set-attr', function(evt, ticket, key, value, callback, hideMessage) {
  416. $scope.setTicketAttribute(ticket, key, value, callback, hideMessage);
  417. });
  418. $scope.addTicket = function(ticket, cb) {
  419. ticket.event_id = $state.params.id;
  420. EventTicket.add(ticket, function(ret_ticket) {
  421. $log.debug('addTicket');
  422. $log.debug(ret_ticket);
  423. $rootScope.$emit('event:ticket:new', ret_ticket, function() {
  424. $rootScope.$emit('event:ticket:set-attr', ret_ticket, 'attended', true, null, false);
  425. });
  426. if (cb) {
  427. cb(ticket);
  428. }
  429. if (!$state.is('event.tickets')) {
  430. $state.go('event.ticket.edit', {id: $scope.event._id, ticket_id: ret_ticket._id});
  431. } else {
  432. $scope.query = '';
  433. if ($scope.$close) {
  434. // Close the Quick ticket modal.
  435. $scope.$close();
  436. }
  437. }
  438. });
  439. };
  440. $scope.updateTicket = function(ticket, cb) {
  441. ticket.event_id = $state.params.id;
  442. EventTicket.update(ticket, function(t) {
  443. $rootScope.$emit('event:ticket:update', t.ticket);
  444. if (cb) {
  445. cb(t);
  446. }
  447. });
  448. };
  449. $scope.toggleCancelledTicket = function() {
  450. if (!$scope.ticket._id) {
  451. return;
  452. }
  453. $scope.ticket.cancelled = !$scope.ticket.cancelled;
  454. $scope.setTicketAttribute($scope.ticket, 'cancelled', $scope.ticket.cancelled, function() {
  455. $scope.guiOptions.dangerousActionsEnabled = false;
  456. });
  457. };
  458. $scope.openQuickAddTicket = function(_id) {
  459. var modalInstance = $uibModal.open({
  460. templateUrl: 'modal-quick-add-ticket.html',
  461. controller: 'EventTicketsCtrl'
  462. });
  463. modalInstance.result.then(function() {});
  464. };
  465. $scope.submitForm = function(dataModelSubmitted) {
  466. angular.forEach(dataModelSubmitted, function(value, key) {
  467. key = $scope.formFieldsMap[key] || key;
  468. $scope.ticket[key] = value;
  469. });
  470. if ($state.is('event.ticket.edit')) {
  471. $scope.updateTicket($scope.ticket, function() {
  472. $scope.showMessage({message: 'ticket successfully updated'});
  473. });
  474. } else {
  475. $scope.addTicket($scope.ticket);
  476. }
  477. };
  478. $scope.cancelForm = function() {
  479. if (!$state.is('event.tickets')) {
  480. $state.go('events');
  481. } else if ($scope.$close) {
  482. $scope.$close();
  483. }
  484. };
  485. $scope.extractFormFields = function(formlyFieldsModel) {
  486. if (!formlyFieldsModel) {
  487. return;
  488. }
  489. angular.forEach(formlyFieldsModel, function(row, idx) {
  490. if (!row.className == 'row') {
  491. return;
  492. }
  493. angular.forEach(row.fieldGroup || [], function(item, idx) {
  494. if (!(item.key && item.templateOptions && item.templateOptions.label)) {
  495. return;
  496. }
  497. var value = item.templateOptions.label.toLowerCase();
  498. $scope.formFieldsMap[item.key] = value;
  499. $scope.formFieldsMapRev[value] = item.key;
  500. });
  501. });
  502. };
  503. $scope.updateOrded = function(key) {
  504. var new_order = [key];
  505. var inv_key;
  506. if (key && key[0] === '-') {
  507. inv_key = key.substring(1);
  508. } else {
  509. inv_key = '-' + key;
  510. }
  511. angular.forEach($scope.ticketsOrder,
  512. function(value, idx) {
  513. if (value !== key && value !== inv_key) {
  514. new_order.push(value);
  515. }
  516. }
  517. );
  518. $scope.ticketsOrder = new_order;
  519. };
  520. $scope.showMessage = function(cfg) {
  521. $scope.message && $scope.message.show && $scope.message.show(cfg);
  522. };
  523. $scope.$on('$destroy', function() {
  524. $scope.EventUpdates && $scope.EventUpdates.close();
  525. });
  526. }]
  527. );
  528. eventManControllers.controller('UsersCtrl', ['$scope', '$rootScope', '$state', '$log', 'User', '$uibModal',
  529. function ($scope, $rootScope, $state, $log, User, $uibModal) {
  530. $scope.loginData = {};
  531. $scope.user = {};
  532. $scope.updateUserInfo = {};
  533. $scope.users = [];
  534. $scope.usersOrderProp = 'username';
  535. $scope.ticketsOrderProp = 'title';
  536. $scope.confirm_delete = 'Do you really want to delete this user?';
  537. $rootScope.$on('$translateChangeSuccess', function () {
  538. $translate('Do you really want to delete this user?').then(function (translation) {
  539. $scope.confirm_delete = translation;
  540. });
  541. });
  542. $scope.updateUsersList = function() {
  543. if ($state.is('users')) {
  544. $scope.users = User.all();
  545. }
  546. };
  547. $scope.updateUsersList();
  548. if ($state.is('user.edit') && $state.params.id) {
  549. $scope.user = User.get({id: $state.params.id}, function() {
  550. $scope.updateUserInfo = $scope.user;
  551. });
  552. }
  553. $scope.updateUser = function() {
  554. User.update($scope.updateUserInfo);
  555. };
  556. $scope.deleteUser = function(user_id) {
  557. var modalInstance = $uibModal.open({
  558. scope: $scope,
  559. templateUrl: 'modal-confirm-action.html',
  560. controller: 'ModalConfirmInstanceCtrl',
  561. resolve: {
  562. message: function() { return $scope.confirm_delete; }
  563. }
  564. });
  565. modalInstance.result.then(function() {
  566. User.delete({id: user_id}, $scope.updateUsersList);
  567. });
  568. };
  569. $scope.register = function() {
  570. User.add($scope.newUser, function(data) {
  571. $scope.login($scope.newUser);
  572. });
  573. };
  574. $scope.login = function(loginData) {
  575. if (!loginData) {
  576. loginData = $scope.loginData;
  577. }
  578. User.login(loginData, function(data) {
  579. if (!data.error) {
  580. $rootScope.readInfo(function(info) {
  581. $log.debug('logged in user: ' + info.user.username);
  582. $rootScope.clearError();
  583. $state.go('events');
  584. });
  585. }
  586. });
  587. };
  588. $scope.logout = function() {
  589. User.logout({}, function(data) {
  590. if (!data.error) {
  591. $rootScope.readInfo(function() {
  592. $log.debug('logged out user');
  593. $state.go('login');
  594. });
  595. }
  596. });
  597. };
  598. }]
  599. );
  600. eventManControllers.controller('FileUploadCtrl', ['$scope', '$log', '$upload', 'Event',
  601. function ($scope, $log, $upload, Event) {
  602. $scope.file = null;
  603. $scope.reply = {};
  604. $scope.events = Event.all();
  605. $scope.upload = function(file, url) {
  606. $log.debug("FileUploadCtrl.upload");
  607. $upload.upload({
  608. url: url,
  609. file: file,
  610. fields: {targetEvent: $scope.targetEvent}
  611. }).progress(function(evt) {
  612. var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
  613. $log.debug('progress: ' + progressPercentage + '%');
  614. }).success(function(data, status, headers, config) {
  615. $scope.file = null;
  616. $scope.reply = angular.fromJson(data);
  617. });
  618. };
  619. }]
  620. );