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
|
2015-04-08 21:55:23 +02:00
|
|
|
* directive or for a given route/state (see app.js). They use some services to
|
2015-03-22 09:36:32 +01:00
|
|
|
* 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. */
|
2016-05-29 11:34:39 +02:00
|
|
|
eventManControllers.controller('NavigationCtrl', ['$scope', '$rootScope', '$location', 'Setting', 'Info',
|
|
|
|
function ($scope, $rootScope, $location, Setting, Info) {
|
2015-05-10 10:30:37 +02:00
|
|
|
$scope.logo = {};
|
|
|
|
|
2016-06-19 22:27:18 +02:00
|
|
|
$scope.getLocation = function() {
|
|
|
|
return $location.absUrl();
|
|
|
|
};
|
|
|
|
|
2015-05-10 10:30:37 +02:00
|
|
|
$scope.go = function(url) {
|
2015-03-20 22:47:21 +01:00
|
|
|
$location.url(url);
|
|
|
|
};
|
2015-04-05 10:13:00 +02:00
|
|
|
|
2015-05-10 10:30:37 +02:00
|
|
|
Setting.query({setting: 'logo'}, function(data) {
|
|
|
|
if (data && data.length) {
|
|
|
|
$scope.logo = data[0];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.isActive = function(view) {
|
2015-04-05 10:25:16 +02:00
|
|
|
if (view === $location.path()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (view[view.length-1] !== '/') {
|
|
|
|
view = view + '/';
|
|
|
|
}
|
|
|
|
return $location.path().indexOf(view) == 0;
|
2015-04-05 10:13:00 +02:00
|
|
|
};
|
2015-03-20 22:47:21 +01:00
|
|
|
}]
|
|
|
|
);
|
|
|
|
|
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-05-03 17:33:52 +02:00
|
|
|
/* Controller for modals. */
|
2016-07-02 00:05:50 +02:00
|
|
|
eventManControllers.controller('ModalConfirmInstanceCtrl', ['$scope', '$uibModalInstance', 'message',
|
|
|
|
function ($scope, $uibModalInstance, message) {
|
2015-05-03 17:33:52 +02:00
|
|
|
$scope.message = message;
|
|
|
|
|
|
|
|
$scope.ok = function () {
|
2016-07-02 00:05:50 +02:00
|
|
|
$uibModalInstance.close($scope);
|
2015-05-03 17:33:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.cancel = function () {
|
2016-07-02 00:05:50 +02:00
|
|
|
$uibModalInstance.dismiss('cancel');
|
2015-05-03 17:33:52 +02:00
|
|
|
};
|
|
|
|
}]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2016-07-02 00:05:50 +02:00
|
|
|
eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal', '$log', '$translate', '$rootScope',
|
|
|
|
function ($scope, Event, $uibModal, $log, $translate, $rootScope) {
|
2015-03-21 11:34:55 +01:00
|
|
|
$scope.events = Event.all();
|
2016-04-25 13:40:03 +02:00
|
|
|
$scope.eventsOrderProp = "-begin_date";
|
2015-03-22 17:08:25 +01:00
|
|
|
|
2015-05-17 10:38:11 +02:00
|
|
|
$scope.confirm_delete = 'Do you really want to delete this event?';
|
2015-05-16 13:30:18 +02:00
|
|
|
$rootScope.$on('$translateChangeSuccess', function () {
|
2015-05-17 10:38:11 +02:00
|
|
|
$translate('Do you really want to delete this event?').then(function (translation) {
|
2015-05-16 13:30:18 +02:00
|
|
|
$scope.confirm_delete = translation;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-03-22 17:08:25 +01:00
|
|
|
$scope.remove = function(_id) {
|
2016-07-02 00:05:50 +02:00
|
|
|
var modalInstance = $uibModal.open({
|
2015-05-03 17:33:52 +02:00
|
|
|
scope: $scope,
|
|
|
|
templateUrl: 'modal-confirm-action.html',
|
|
|
|
controller: 'ModalConfirmInstanceCtrl',
|
|
|
|
resolve: {
|
2015-05-16 13:30:18 +02:00
|
|
|
message: function() { return $scope.confirm_delete; }
|
2015-05-03 17:33:52 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
modalInstance.result.then(function() {
|
|
|
|
Event.remove({'id': _id}, function() {
|
|
|
|
$scope.events = Event.all();
|
|
|
|
}
|
|
|
|
);
|
2015-03-22 17:08:25 +01:00
|
|
|
});
|
|
|
|
};
|
2015-03-15 18:00:08 +01:00
|
|
|
}]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2016-07-02 19:05:28 +02:00
|
|
|
eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', '$log', '$translate', '$rootScope',
|
|
|
|
function ($scope, $state, Event, $log, $translate, $rootScope) {
|
2015-05-01 16:30:53 +02:00
|
|
|
$scope.event = {};
|
2015-05-01 16:42:55 +02:00
|
|
|
$scope.event.persons = [];
|
2016-06-19 15:12:40 +02:00
|
|
|
$scope.event.formSchema = {};
|
2016-06-24 23:11:57 +02:00
|
|
|
$scope.eventFormDisabled = false;
|
2016-07-02 14:49:39 +02:00
|
|
|
|
|
|
|
if ($state.params.id) {
|
|
|
|
$scope.event = Event.get($state.params);
|
|
|
|
if ($state.is('event.view') || !$rootScope.hasPermission('event|update')) {
|
|
|
|
$scope.eventFormDisabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// store a new Event or update an existing one
|
|
|
|
$scope.save = function() {
|
|
|
|
// avoid override of event.persons list.
|
|
|
|
var this_event = angular.copy($scope.event);
|
|
|
|
if (this_event.persons) {
|
|
|
|
delete this_event.persons;
|
|
|
|
}
|
|
|
|
if (this_event._id === undefined) {
|
|
|
|
$scope.event = Event.save(this_event);
|
|
|
|
} else {
|
|
|
|
$scope.event = Event.update(this_event);
|
|
|
|
}
|
|
|
|
$scope.eventForm.$setPristine(false);
|
|
|
|
};
|
2016-07-02 20:40:18 +02:00
|
|
|
|
|
|
|
$scope.saveForm = function(easyFormGeneratorModel) {
|
|
|
|
$scope.event.formSchema = easyFormGeneratorModel;
|
|
|
|
$scope.save();
|
|
|
|
};
|
2016-07-02 14:49:39 +02:00
|
|
|
}]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2016-07-02 19:05:28 +02:00
|
|
|
eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Person', 'Setting', '$log', '$translate', '$rootScope', 'EventUpdates', '$uibModal',
|
|
|
|
function ($scope, $state, Event, EventTicket, Person, Setting, $log, $translate, $rootScope, EventUpdates, $uibModal) {
|
2016-07-02 14:49:39 +02:00
|
|
|
$scope.personsOrder = ["name", "surname"];
|
|
|
|
$scope.countAttendees = 0;
|
|
|
|
$scope.message = {};
|
|
|
|
$scope.event = {};
|
2016-07-02 20:40:18 +02:00
|
|
|
$scope.ticket = {}; // current ticket, for the event.ticket.* states
|
2016-07-02 14:49:39 +02:00
|
|
|
$scope.formSchema = {};
|
|
|
|
$scope.formData = {};
|
2016-07-02 19:05:28 +02:00
|
|
|
$scope.guiOptions = {dangerousActionsEnabled: false};
|
2016-04-17 15:28:02 +02:00
|
|
|
$scope.customFields = Setting.query({setting: 'person_custom_field', in_event_details: true});
|
2015-04-18 19:43:40 +02:00
|
|
|
|
2016-07-02 14:49:39 +02:00
|
|
|
$scope.formFieldsMap = {};
|
|
|
|
$scope.formFieldsMapRev = {};
|
|
|
|
|
|
|
|
if ($state.params.id) {
|
|
|
|
$scope.event = Event.get({id: $state.params.id}, function(data) {
|
2015-04-08 21:55:23 +02:00
|
|
|
$scope.$watchCollection(function() {
|
|
|
|
return $scope.event.persons;
|
|
|
|
}, function(prev, old) {
|
|
|
|
$scope.calcAttendees();
|
2015-04-26 01:10:58 +02:00
|
|
|
}
|
|
|
|
);
|
2016-07-02 14:49:39 +02:00
|
|
|
if (!(data && data.formSchema)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$scope.formSchema = data.formSchema.edaFieldsModel;
|
|
|
|
$scope.extractFormFields(data.formSchema.formlyFieldsModel);
|
2015-04-26 01:10:58 +02:00
|
|
|
|
2016-07-02 20:40:18 +02:00
|
|
|
// Editing an existing ticket
|
2016-07-02 14:49:39 +02:00
|
|
|
if ($state.params.ticket_id) {
|
|
|
|
EventTicket.get({id: $state.params.id, ticket_id: $state.params.ticket_id}, function(data) {
|
|
|
|
$scope.ticket = data;
|
|
|
|
angular.forEach(data, function(value, key) {
|
|
|
|
if (!$scope.formFieldsMapRev[key]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$scope.formData[$scope.formFieldsMapRev[key]] = value;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-06-24 23:11:57 +02:00
|
|
|
|
2016-07-02 20:40:18 +02:00
|
|
|
// Managing the list of tickets.
|
2016-06-19 16:58:38 +02:00
|
|
|
if ($state.is('event.tickets')) {
|
2016-06-02 22:03:51 +02:00
|
|
|
$scope.allPersons = Person.all();
|
|
|
|
|
2015-05-05 21:42:57 +02:00
|
|
|
// Handle WebSocket connection used to update the list of persons.
|
|
|
|
$scope.EventUpdates = EventUpdates;
|
|
|
|
$scope.EventUpdates.open();
|
|
|
|
$scope.$watchCollection(function() {
|
|
|
|
return $scope.EventUpdates.data;
|
|
|
|
}, function(prev, old) {
|
2016-04-10 17:21:46 +02:00
|
|
|
if (!($scope.EventUpdates.data && $scope.EventUpdates.data.update)) {
|
2015-05-05 21:42:57 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-04-10 17:21:46 +02:00
|
|
|
var data = $scope.EventUpdates.data.update;
|
2016-04-24 16:03:49 +02:00
|
|
|
$log.debug('received ' + data.action + ' action from websocket source ' + data.uuid);
|
|
|
|
if ($rootScope.app_uuid == data.uuid) {
|
|
|
|
$log.debug('do not process our own message');
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-10 19:39:12 +02:00
|
|
|
if (!$scope.event.persons) {
|
|
|
|
$scope.event.persons = [];
|
|
|
|
}
|
2016-04-10 17:21:46 +02:00
|
|
|
var person_idx = $scope.event.persons.findIndex(function(el, idx, array) {
|
2016-07-02 20:40:18 +02:00
|
|
|
return data._id == el._id;
|
2016-04-10 17:21:46 +02:00
|
|
|
});
|
2016-07-02 13:46:39 +02:00
|
|
|
$log.debug(data);
|
2016-04-10 19:39:12 +02:00
|
|
|
if (person_idx != -1) {
|
2016-07-02 13:46:39 +02:00
|
|
|
$log.debug('_id ' + data._id + ' found');
|
2016-04-10 19:39:12 +02:00
|
|
|
} else {
|
2016-07-02 13:46:39 +02:00
|
|
|
$log.debug('_id ' + data._id + ' not found');
|
2016-04-10 19:39:12 +02:00
|
|
|
}
|
2016-04-10 18:45:30 +02:00
|
|
|
|
|
|
|
if (data.action == 'update' && person_idx != -1 && $scope.event.persons[person_idx] != data.person) {
|
2016-04-10 19:39:12 +02:00
|
|
|
$scope.event.persons[person_idx] = data.person;
|
2016-04-10 18:45:30 +02:00
|
|
|
} else if (data.action == 'add' && person_idx == -1) {
|
2016-07-02 14:49:39 +02:00
|
|
|
$scope._localAddTicket(data.person);
|
2016-04-10 19:39:12 +02:00
|
|
|
} else if (data.action == 'delete' && person_idx != -1) {
|
2016-07-02 20:40:18 +02:00
|
|
|
$scope._localRemoveTicket({_id: data._id});
|
2016-04-10 17:21:46 +02:00
|
|
|
}
|
2015-04-26 01:10:58 +02:00
|
|
|
}
|
2015-05-05 21:42:57 +02:00
|
|
|
);
|
|
|
|
}
|
2015-03-21 15:33:17 +01:00
|
|
|
}
|
2015-04-18 19:43:40 +02:00
|
|
|
|
2015-04-08 21:55:23 +02:00
|
|
|
$scope.calcAttendees = function() {
|
|
|
|
if (!($scope.event && $scope.event.persons)) {
|
2016-04-17 15:28:02 +02:00
|
|
|
$scope.countAttendees = 0;
|
2015-04-08 21:55:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var attendees = 0;
|
|
|
|
angular.forEach($scope.event.persons, function(value, key) {
|
2016-06-26 16:54:08 +02:00
|
|
|
if (value.attended && !value.cancelled) {
|
2015-04-08 21:55:23 +02:00
|
|
|
attendees += 1;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$scope.countAttendees = attendees;
|
|
|
|
};
|
|
|
|
|
2016-07-02 20:40:18 +02:00
|
|
|
/* Stuff to do when a ticket is added, modified or removed locally. */
|
|
|
|
|
2016-07-02 14:49:39 +02:00
|
|
|
$scope._localAddTicket = function(person) {
|
2016-04-17 15:28:02 +02:00
|
|
|
if (!$scope.event.persons) {
|
|
|
|
$scope.event.persons = [];
|
|
|
|
}
|
2016-04-24 14:51:05 +02:00
|
|
|
var person_idx = $scope.event.persons.findIndex(function(el, idx, array) {
|
2016-07-02 13:46:39 +02:00
|
|
|
return person._id == el._id;
|
2016-04-24 14:51:05 +02:00
|
|
|
});
|
|
|
|
if (person_idx != -1) {
|
|
|
|
$log.debug('person already present: not added');
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-17 15:28:02 +02:00
|
|
|
$scope.event.persons.push(person);
|
|
|
|
};
|
|
|
|
|
2016-07-02 20:40:18 +02:00
|
|
|
$scope._localUpdateTicket(ticket) {
|
2016-07-02 13:46:39 +02:00
|
|
|
if (!$scope.event.persons) {
|
|
|
|
$scope.event.persons = [];
|
|
|
|
}
|
|
|
|
var ticket_idx = $scope.event.persons.findIndex(function(el, idx, array) {
|
2016-07-02 20:40:18 +02:00
|
|
|
return ticket._id == el._id;
|
2016-07-02 13:46:39 +02:00
|
|
|
});
|
|
|
|
if (ticket_idx == -1) {
|
|
|
|
$log.debug('person not present: not updated');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$scope.event.persons[ticket_idx] = ticket;
|
|
|
|
});
|
|
|
|
|
2016-07-02 20:40:18 +02:00
|
|
|
$scope._localRemoveTicket = function(person) {
|
|
|
|
$log.debug('_localRemoveAttendee');
|
|
|
|
$log.debug(person);
|
|
|
|
if (!(person && person._id && $scope.event.persons)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var person_idx = $scope.event.persons.findIndex(function(el, idx, array) {
|
|
|
|
return person._id == el._id;
|
2015-04-07 22:43:54 +02:00
|
|
|
});
|
2016-07-02 20:40:18 +02:00
|
|
|
if (person_idx == -1) {
|
|
|
|
$log.warn('unable to find and delete ticket _id ' + person._id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var removed_person = $scope.event.persons.splice(person_idx, 1);
|
|
|
|
// to be used to populate allPersons, if needed.
|
|
|
|
if (removed_person.length) {
|
|
|
|
person = removed_person[0];
|
|
|
|
}
|
|
|
|
var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) {
|
|
|
|
return person._id == el._id;
|
|
|
|
});
|
|
|
|
if (all_person_idx == -1 && person._id) {
|
|
|
|
$scope.allPersons.push(person);
|
|
|
|
}
|
2016-06-06 21:44:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope._setAttended = function(person) {
|
|
|
|
$scope.setPersonAttribute(person, 'attended', true, function() {
|
|
|
|
var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) {
|
2016-07-02 13:46:39 +02:00
|
|
|
return person._id == el._id;
|
2016-06-06 21:44:04 +02:00
|
|
|
});
|
|
|
|
if (all_person_idx != -1) {
|
|
|
|
$scope.allPersons.splice(all_person_idx, 1);
|
|
|
|
}
|
|
|
|
}, true);
|
2015-04-07 22:43:54 +02:00
|
|
|
};
|
|
|
|
|
2016-04-17 15:28:02 +02:00
|
|
|
$scope.setPersonAttribute = function(person, key, value, callback, hideMessage) {
|
2016-07-02 14:49:39 +02:00
|
|
|
$log.debug('EventDetailsCtrl.setPersonAttribute.event_id: ' + $state.params.id);
|
2016-07-02 13:46:39 +02:00
|
|
|
$log.debug('EventDetailsCtrl.setPersonAttribute._id: ' + person._id);
|
2015-04-18 19:43:40 +02:00
|
|
|
$log.debug('EventDetailsCtrl.setPersonAttribute.key: ' + key + ' value: ' + value);
|
2016-07-02 14:49:39 +02:00
|
|
|
var newData = {event_id: $state.params.id, _id: person._id};
|
|
|
|
newData[key] = value;
|
|
|
|
EventTicket.update(newData, function(data) {
|
|
|
|
if (!(data && data._id && data.person)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var person_idx = $scope.event.persons.findIndex(function(el, idx, array) {
|
|
|
|
return data._id == el._id;
|
|
|
|
});
|
|
|
|
if (person_idx == -1) {
|
|
|
|
$log.warn('unable to find ticket _id ' + _id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($scope.event.persons[person_idx] != data.person) {
|
|
|
|
$scope.event.persons[person_idx] = data.person;
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
callback(data);
|
|
|
|
}
|
|
|
|
if (key === 'attended' && !hideMessage) {
|
|
|
|
var msg = {};
|
|
|
|
if (value) {
|
|
|
|
msg.message = '' + person.name + ' ' + person.surname + ' successfully added to event ' + $scope.event.title;
|
|
|
|
} else {
|
|
|
|
msg.message = '' + person.name + ' ' + person.surname + ' successfully removed from event ' + $scope.event.title;
|
|
|
|
msg.isError = true;
|
2015-04-21 23:34:26 +02:00
|
|
|
}
|
2016-07-02 14:49:39 +02:00
|
|
|
$scope.showMessage(msg);
|
|
|
|
}
|
2015-04-18 19:43:40 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-04-19 20:27:49 +02:00
|
|
|
$scope.setPersonAttributeAndRefocus = function(person, key, value) {
|
|
|
|
$scope.setPersonAttribute(person, key, value);
|
|
|
|
$scope.query = '';
|
|
|
|
};
|
|
|
|
|
2016-07-02 20:40:18 +02:00
|
|
|
$scope.removeAttendee = function(person) {
|
|
|
|
EventTicket.delete({
|
|
|
|
event_id: $state.params.id,
|
|
|
|
ticket_id: person._id
|
|
|
|
}, function() {
|
|
|
|
$scope._localRemoveTicket(person);
|
2016-04-17 15:28:02 +02:00
|
|
|
});
|
2016-07-02 20:40:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.addTicket = function(person) {
|
|
|
|
person.event_id = $state.params.id;
|
|
|
|
EventTicket.add(person, function(ticket) {
|
|
|
|
$log.debug(ticket);
|
|
|
|
$scope._localAddTicket(ticket);
|
|
|
|
if (!$state.is('event.tickets')) {
|
|
|
|
$state.go('event.ticket.edit', {id: $scope.event._id, ticket_id: ticket._id});
|
|
|
|
} else {
|
|
|
|
$scope.query = '';
|
|
|
|
$scope._setAttended(ticket);
|
|
|
|
if ($scope.$close) {
|
|
|
|
$scope.$close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.updateTicket = function(ticket, cb) {
|
|
|
|
ticket.event_id = $state.params.id;
|
|
|
|
EventTicket.update(ticket, function(t) {
|
|
|
|
$scope._localUpdateTicket(t.person);
|
|
|
|
if (cb) {
|
|
|
|
cb(t);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleTicket = function() {
|
|
|
|
if (!$scope.ticket._id) {
|
2016-04-17 15:28:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-07-02 20:40:18 +02:00
|
|
|
$scope.ticket.cancelled = !$scope.ticket.cancelled;
|
|
|
|
$scope.setPersonAttribute($scope.ticket, 'cancelled', $scope.ticket.cancelled, function() {
|
|
|
|
$scope.guiOptions.dangerousActionsEnabled = false;
|
2016-04-17 20:40:44 +02:00
|
|
|
});
|
2016-04-17 15:28:02 +02:00
|
|
|
};
|
|
|
|
|
2016-07-02 20:40:18 +02:00
|
|
|
$scope.openQuickAddTicket = function(_id) {
|
|
|
|
var modalInstance = $uibModal.open({
|
|
|
|
templateUrl: 'modal-quick-add-ticket.html',
|
|
|
|
controller: 'EventTicketsCtrl'
|
|
|
|
});
|
|
|
|
modalInstance.result.then(function() {
|
2015-04-05 00:55:59 +02:00
|
|
|
});
|
2015-04-04 17:26:00 +02:00
|
|
|
};
|
2015-04-21 23:34:26 +02:00
|
|
|
|
2016-07-02 20:40:18 +02:00
|
|
|
$scope.submitForm = function(dataModelSubmitted) {
|
|
|
|
angular.forEach(dataModelSubmitted, function(value, key) {
|
|
|
|
key = $scope.formFieldsMap[key] || key;
|
|
|
|
$scope.ticket[key] = value;
|
|
|
|
});
|
|
|
|
if (!$state.params.ticket_id) {
|
|
|
|
$scope.addTicket($scope.ticket);
|
|
|
|
} else {
|
|
|
|
$scope.updateTicket($scope.ticket);
|
|
|
|
}
|
2016-06-18 20:01:17 +02:00
|
|
|
};
|
|
|
|
|
2016-07-02 20:40:18 +02:00
|
|
|
$scope.cancelForm = function() {
|
|
|
|
if (!$state.is('event.tickets')) {
|
|
|
|
$state.go('events');
|
|
|
|
} else if ($scope.$close) {
|
|
|
|
$scope.$close();
|
|
|
|
}
|
2015-04-21 23:34:26 +02:00
|
|
|
};
|
2015-04-26 12:42:47 +02:00
|
|
|
|
2016-06-19 15:12:40 +02:00
|
|
|
$scope.extractFormFields = function(formlyFieldsModel) {
|
|
|
|
if (!formlyFieldsModel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
angular.forEach(formlyFieldsModel, function(row, idx) {
|
|
|
|
if (!row.className == 'row') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
angular.forEach(row.fieldGroup || [], function(item, idx) {
|
|
|
|
if (!(item.key && item.templateOptions && item.templateOptions.label)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var value = item.templateOptions.label.toLowerCase();
|
|
|
|
|
|
|
|
$scope.formFieldsMap[item.key] = value;
|
|
|
|
$scope.formFieldsMapRev[value] = item.key;
|
|
|
|
});
|
2016-06-07 23:21:08 +02:00
|
|
|
});
|
2016-06-19 15:12:40 +02:00
|
|
|
};
|
2016-06-07 23:21:08 +02:00
|
|
|
|
2016-07-02 14:49:39 +02:00
|
|
|
$scope.updateOrded = function(key) {
|
|
|
|
var new_order = [key];
|
|
|
|
var inv_key;
|
|
|
|
if (key && key[0] === '-') {
|
|
|
|
inv_key = key.substring(1);
|
|
|
|
} else {
|
|
|
|
inv_key = '-' + key;
|
|
|
|
}
|
|
|
|
angular.forEach($scope.personsOrder,
|
|
|
|
function(value, idx) {
|
|
|
|
if (value !== key && value !== inv_key) {
|
|
|
|
new_order.push(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
$scope.personsOrder = new_order;
|
|
|
|
};
|
|
|
|
|
2016-07-02 20:40:18 +02:00
|
|
|
$scope.showMessage = function(cfg) {
|
|
|
|
$scope.message.show(cfg);
|
2016-06-07 23:21:08 +02:00
|
|
|
};
|
2016-07-02 14:49:39 +02:00
|
|
|
|
|
|
|
$scope.$on('$destroy', function() {
|
|
|
|
$scope.EventUpdates && $scope.EventUpdates.close();
|
|
|
|
});
|
2016-06-07 23:21:08 +02:00
|
|
|
}]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2016-07-02 00:05:50 +02:00
|
|
|
eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person', 'Setting', '$uibModal', '$translate', '$rootScope',
|
|
|
|
function ($scope, Person, Setting, $uibModal, $translate, $rootScope) {
|
2015-03-21 11:34:55 +01:00
|
|
|
$scope.persons = Person.all();
|
2015-05-02 09:58:53 +02:00
|
|
|
$scope.personsOrder = ["name", "surname"];
|
2015-04-18 17:33:42 +02:00
|
|
|
$scope.customFields = Setting.query({setting: 'person_custom_field',
|
|
|
|
in_persons_list: true});
|
|
|
|
|
2015-05-17 10:38:11 +02:00
|
|
|
$scope.confirm_delete = 'Do you really want to delete this person?';
|
2015-05-16 13:30:18 +02:00
|
|
|
$rootScope.$on('$translateChangeSuccess', function () {
|
2015-05-17 10:38:11 +02:00
|
|
|
$translate('Do you really want to delete this person?').then(function (translation) {
|
2015-05-16 13:30:18 +02:00
|
|
|
$scope.confirm_delete = translation;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-05-02 09:58:53 +02:00
|
|
|
$scope.updateOrded = function(key) {
|
|
|
|
var new_order = [key];
|
|
|
|
var inv_key;
|
|
|
|
if (key && key[0] === '-') {
|
|
|
|
inv_key = key.substring(1);
|
|
|
|
} else {
|
|
|
|
inv_key = '-' + key;
|
|
|
|
}
|
|
|
|
angular.forEach($scope.personsOrder,
|
|
|
|
function(value, idx) {
|
|
|
|
if (value !== key && value !== inv_key) {
|
2016-04-24 16:31:07 +02:00
|
|
|
new_order.push(value);
|
2015-05-02 09:58:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
$scope.personsOrder = new_order;
|
|
|
|
};
|
|
|
|
|
2015-04-18 17:33:42 +02:00
|
|
|
$scope.setAttribute = function(person, key, value) {
|
|
|
|
var data = {_id: person._id};
|
|
|
|
data[key] = value;
|
|
|
|
Person.update(data, function() {
|
|
|
|
$scope.persons = Person.all();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-22 17:08:25 +01:00
|
|
|
$scope.remove = function(_id) {
|
2016-07-02 00:05:50 +02:00
|
|
|
var modalInstance = $uibModal.open({
|
2015-05-03 17:33:52 +02:00
|
|
|
scope: $scope,
|
|
|
|
templateUrl: 'modal-confirm-action.html',
|
|
|
|
controller: 'ModalConfirmInstanceCtrl',
|
|
|
|
resolve: {
|
2015-05-16 13:30:18 +02:00
|
|
|
message: function() { return $scope.confirm_delete; }
|
2015-05-03 17:33:52 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
modalInstance.result.then(function() {
|
|
|
|
Person.remove({'id': _id}, function() {
|
|
|
|
$scope.persons = Person.all();
|
|
|
|
}
|
|
|
|
);
|
2015-03-22 17:08:25 +01:00
|
|
|
});
|
|
|
|
};
|
2015-03-14 17:32:16 +01:00
|
|
|
}]
|
|
|
|
);
|
|
|
|
|
2015-03-15 23:05:59 +01:00
|
|
|
|
2016-07-02 14:49:39 +02:00
|
|
|
eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$state', 'Person', 'Event', 'Setting', '$log',
|
|
|
|
function ($scope, $state, Person, Event, Setting, $log) {
|
2015-04-06 12:48:41 +02:00
|
|
|
$scope.personsOrderProp = 'name';
|
2016-04-25 13:40:03 +02:00
|
|
|
$scope.eventsOrderProp = '-begin_date';
|
2015-04-06 21:08:52 +02:00
|
|
|
$scope.addToEvent = '';
|
2015-04-19 00:49:11 +02:00
|
|
|
$scope.customFields = Setting.query({setting: 'person_custom_field',
|
|
|
|
in_persons_list: true});
|
2015-04-06 21:08:52 +02:00
|
|
|
|
2016-07-02 14:49:39 +02:00
|
|
|
if ($state.params.id) {
|
|
|
|
$scope.person = Person.get($state.params);
|
|
|
|
$scope.events = Person.getEvents({_id: $state.arams.id, all: true});
|
2015-04-06 22:55:16 +02:00
|
|
|
} else {
|
|
|
|
$scope.events = Event.all();
|
2015-03-21 16:48:00 +01:00
|
|
|
}
|
2015-05-04 22:36:27 +02: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() {
|
2016-06-01 19:33:27 +02:00
|
|
|
if ($scope.person._id === undefined) {
|
2015-04-06 22:55:16 +02:00
|
|
|
$scope.person = new Person($scope.person);
|
|
|
|
$scope.person.$save(function(person) {
|
|
|
|
if ($scope.addToEvent) {
|
|
|
|
var data = angular.copy(person);
|
|
|
|
data.person_id = data._id;
|
|
|
|
data._id = $scope.addToEvent;
|
|
|
|
data.attended = false;
|
2015-04-18 19:58:15 +02:00
|
|
|
Event.addPerson(data);
|
2015-04-06 22:55:16 +02:00
|
|
|
}
|
|
|
|
});
|
2015-04-05 00:55:59 +02:00
|
|
|
} else {
|
2015-04-06 22:55:16 +02:00
|
|
|
$scope.person = Person.update($scope.person, function(data) {
|
|
|
|
if ($scope.addToEvent) {
|
|
|
|
var data = angular.copy($scope.person);
|
|
|
|
data._id = $scope.addToEvent;
|
|
|
|
data.person_id = $scope.person._id;
|
|
|
|
data.attended = false;
|
2015-04-18 19:58:15 +02:00
|
|
|
Event.addPerson(data);
|
2015-04-06 22:55:16 +02:00
|
|
|
}
|
|
|
|
});
|
2015-04-06 21:08:52 +02:00
|
|
|
}
|
2015-05-05 21:31:37 +02:00
|
|
|
$scope.personForm.$setPristine(false);
|
2015-03-21 16:48:00 +01:00
|
|
|
};
|
2015-04-06 17:19:20 +02:00
|
|
|
|
2015-04-18 19:56:00 +02:00
|
|
|
$scope.setPersonAttributeAtEvent = function(evnt, key, value) {
|
2016-07-02 14:49:39 +02:00
|
|
|
var attrs = {_id: evnt._id, person_id: $state.params.id};
|
2015-04-18 19:56:00 +02:00
|
|
|
attrs[key] = value;
|
|
|
|
Event.updatePerson(attrs,
|
2015-04-05 00:55:59 +02:00
|
|
|
function(data) {
|
2016-07-02 14:49:39 +02:00
|
|
|
$scope.events = Person.getEvents({_id: $state.params.id, all: true});
|
2015-04-05 00:55:59 +02:00
|
|
|
}
|
|
|
|
);
|
2015-04-06 17:19:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.switchRegistered = function(evnt, person, add) {
|
|
|
|
$log.debug('PersonDetailsCtrl.switchRegistered.event_id: ' + evnt._id);
|
|
|
|
$log.debug('PersonDetailsCtrl.switchRegistered.person_id: ' + person._id);
|
|
|
|
$log.debug('PersonDetailsCtrl.switchRegistered.add: ' + add);
|
|
|
|
if (add) {
|
|
|
|
var data = angular.copy(person);
|
|
|
|
data._id = evnt._id;
|
|
|
|
data.person_id = person._id;
|
2015-04-12 21:21:57 +02:00
|
|
|
data.attended = false;
|
2015-04-18 19:58:15 +02:00
|
|
|
Event.addPerson(data,
|
2015-04-06 17:19:20 +02:00
|
|
|
function(data) {
|
2016-07-02 14:49:39 +02:00
|
|
|
$scope.events = Person.getEvents({_id: $state.params.id, all: true});
|
2015-04-06 17:19:20 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
2015-04-18 19:58:15 +02:00
|
|
|
Event.deletePerson({_id: evnt._id, person_id: person._id},
|
2015-04-06 17:19:20 +02:00
|
|
|
function(data) {
|
2016-07-02 14:49:39 +02:00
|
|
|
$scope.events = Person.getEvents({_id: $state.params.id, all: true});
|
2015-04-06 17:19:20 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2015-03-15 23:05:59 +01:00
|
|
|
}]
|
|
|
|
);
|
|
|
|
|
2016-07-02 19:05:28 +02:00
|
|
|
|
2016-06-12 16:04:46 +02:00
|
|
|
eventManControllers.controller('LoginCtrl', ['$scope', '$rootScope', '$state', '$log', 'User',
|
|
|
|
function ($scope, $rootScope, $state, $log, User) {
|
|
|
|
$scope.loginData = {};
|
|
|
|
|
2016-06-12 23:44:48 +02:00
|
|
|
$scope.register = function() {
|
|
|
|
User.add($scope.newUser, function(data) {
|
|
|
|
$scope.login($scope.newUser);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.login = function(loginData) {
|
|
|
|
if (!loginData) {
|
|
|
|
loginData = $scope.loginData;
|
|
|
|
}
|
|
|
|
User.login(loginData, function(data) {
|
2016-06-12 16:04:46 +02:00
|
|
|
if (!data.error) {
|
|
|
|
$rootScope.readInfo(function() {
|
2016-06-12 23:44:48 +02:00
|
|
|
$rootScope.clearError();
|
2016-06-12 16:04:46 +02:00
|
|
|
$state.go('events');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.logout = function() {
|
|
|
|
User.logout({}, function(data) {
|
|
|
|
if (!data.error) {
|
|
|
|
$rootScope.readInfo(function() {
|
|
|
|
$state.go('events');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}]
|
|
|
|
);
|
2015-03-29 00:46:42 +01:00
|
|
|
|
2016-07-02 20:40:18 +02:00
|
|
|
|
2015-03-29 15:50:36 +02:00
|
|
|
eventManControllers.controller('FileUploadCtrl', ['$scope', '$log', '$upload', 'Event',
|
|
|
|
function ($scope, $log, $upload, Event) {
|
2016-06-12 16:04:46 +02:00
|
|
|
$scope.file = null;
|
|
|
|
$scope.reply = {};
|
|
|
|
$scope.events = Event.all();
|
|
|
|
$scope.upload = function(file, url) {
|
|
|
|
$log.debug("FileUploadCtrl.upload");
|
|
|
|
$upload.upload({
|
|
|
|
url: url,
|
|
|
|
file: file,
|
|
|
|
fields: {targetEvent: $scope.targetEvent}
|
|
|
|
}).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
|
|
|
}]
|
|
|
|
);
|
|
|
|
|