2015-03-22 08:57:57 +01:00
|
|
|
'use strict';
|
2015-03-22 09:36:32 +01:00
|
|
|
/*
|
2017-04-01 18:43:42 +02:00
|
|
|
Copyright 2015-2017 Davide Alberani <da@erlug.linux.it>
|
2016-06-19 15:12:40 +02:00
|
|
|
RaspiBO <info@raspibo.org>
|
2015-03-22 08:57:57 +01:00
|
|
|
|
2015-03-22 09:36:32 +01:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Register our fantastic app. */
|
2015-03-15 18:00:08 +01:00
|
|
|
var eventManApp = angular.module('eventManApp', [
|
2015-03-21 15:45:40 +01:00
|
|
|
'ngRoute',
|
2017-04-15 13:35:15 +02:00
|
|
|
'ngAnimate',
|
2015-03-21 15:45:40 +01:00
|
|
|
'eventManServices',
|
2015-03-24 22:37:46 +01:00
|
|
|
'eventManControllers',
|
2015-03-28 20:06:33 +01:00
|
|
|
'ui.bootstrap',
|
2015-04-05 16:57:21 +02:00
|
|
|
'ui.router',
|
2015-03-29 09:58:52 +02:00
|
|
|
'pascalprecht.translate',
|
2015-04-26 01:10:58 +02:00
|
|
|
'angularFileUpload',
|
2016-06-18 20:01:17 +02:00
|
|
|
'angular-websocket',
|
2016-06-19 15:12:40 +02:00
|
|
|
'eda.easyFormViewer',
|
2016-06-26 16:54:08 +02:00
|
|
|
'eda.easyformGen.stepway'
|
2015-03-15 18:00:08 +01:00
|
|
|
]);
|
|
|
|
|
2015-03-21 15:45:40 +01:00
|
|
|
|
2015-04-05 16:57:21 +02:00
|
|
|
/* Add some utilities to the global scope. */
|
2016-05-29 11:59:09 +02:00
|
|
|
eventManApp.run(['$rootScope', '$state', '$stateParams', '$log', 'Info',
|
|
|
|
function($rootScope, $state, $stateParams, $log, Info) {
|
2016-04-24 16:03:49 +02:00
|
|
|
$rootScope.app_uuid = guid();
|
2016-07-09 17:18:07 +02:00
|
|
|
$rootScope.info = {};
|
2016-04-24 16:03:49 +02:00
|
|
|
$log.debug('App UUID: ' + $rootScope.app_uuid);
|
2015-04-06 11:58:44 +02:00
|
|
|
$rootScope.$state = $state;
|
|
|
|
$rootScope.$stateParams = $stateParams;
|
2016-05-29 11:34:39 +02:00
|
|
|
|
2016-06-12 23:44:48 +02:00
|
|
|
$rootScope.error = {error: false, message: '', code: 0};
|
2016-05-29 11:34:39 +02:00
|
|
|
|
2016-06-12 16:04:46 +02:00
|
|
|
$rootScope.readInfo = function(callback) {
|
|
|
|
Info.get({}, function(data) {
|
|
|
|
$rootScope.info = data || {};
|
2016-07-09 17:18:07 +02:00
|
|
|
if (data.authentication_required && !(data.user && data.user._id)) {
|
|
|
|
$state.go('login');
|
|
|
|
} else if (callback) {
|
2016-07-08 21:29:09 +02:00
|
|
|
callback(data);
|
2016-06-12 16:04:46 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2016-05-29 11:59:09 +02:00
|
|
|
|
2016-06-12 23:44:48 +02:00
|
|
|
$rootScope.showError = function(error) {
|
|
|
|
$rootScope.error.code = error.code;
|
|
|
|
$rootScope.error.message = error.message;
|
|
|
|
$rootScope.error.error = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
$rootScope.clearError = function() {
|
|
|
|
$rootScope.error.code = null;
|
|
|
|
$rootScope.error.message = '';
|
|
|
|
$rootScope.error.error = false;
|
|
|
|
};
|
|
|
|
|
2016-05-29 11:34:39 +02:00
|
|
|
$rootScope.errorHandler = function(response) {
|
|
|
|
$log.debug('Handling error message:');
|
|
|
|
$log.debug(response);
|
|
|
|
$rootScope.error.status = response.status;
|
|
|
|
$rootScope.error.statusText = response.statusText;
|
|
|
|
if (response.data && response.data.error) {
|
2016-06-12 23:44:48 +02:00
|
|
|
$rootScope.showError(response.data);
|
2016-05-29 11:34:39 +02:00
|
|
|
} else {
|
2016-06-12 23:44:48 +02:00
|
|
|
$rootScope.clearError();
|
2016-05-29 11:34:39 +02:00
|
|
|
}
|
|
|
|
};
|
2016-05-29 11:59:09 +02:00
|
|
|
|
2017-04-03 21:39:26 +02:00
|
|
|
/* Check privileges of the currently logged in user or of the one specified with the second parameter. */
|
|
|
|
$rootScope.hasPermission = function(permission, user) {
|
|
|
|
if (!(user || ($rootScope.info && $rootScope.info.user && $rootScope.info.user.permissions))) {
|
2016-05-29 11:59:09 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-04-03 21:39:26 +02:00
|
|
|
if (!user) {
|
|
|
|
user = $rootScope.info.user;
|
|
|
|
}
|
2016-05-29 14:06:34 +02:00
|
|
|
var granted = false;
|
2016-05-31 22:26:38 +02:00
|
|
|
var splitted_permission = permission.split('|');
|
2016-06-06 21:44:04 +02:00
|
|
|
var global_permission = splitted_permission[0] + '|all';
|
2016-05-29 14:06:34 +02:00
|
|
|
|
2017-04-03 21:39:26 +02:00
|
|
|
angular.forEach(user.permissions || [],
|
2016-05-29 11:59:09 +02:00
|
|
|
function(value, idx) {
|
2016-05-31 22:26:38 +02:00
|
|
|
if (value === 'admin|all' || value === global_permission || value === permission) {
|
2016-05-29 14:06:34 +02:00
|
|
|
granted = true;
|
2016-05-29 11:59:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2016-05-29 14:06:34 +02:00
|
|
|
return granted;
|
2016-05-29 11:59:09 +02:00
|
|
|
};
|
2016-06-12 16:04:46 +02:00
|
|
|
|
|
|
|
$rootScope.readInfo();
|
2015-04-06 11:58:44 +02:00
|
|
|
}]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2015-04-05 16:57:21 +02:00
|
|
|
/* Configure the states. */
|
|
|
|
eventManApp.config(['$stateProvider', '$urlRouterProvider',
|
|
|
|
function($stateProvider, $urlRouterProvider) {
|
2016-04-24 16:31:07 +02:00
|
|
|
$urlRouterProvider.otherwise('/events');
|
2015-04-05 16:57:21 +02:00
|
|
|
$stateProvider
|
|
|
|
.state('events', {
|
|
|
|
url: '/events',
|
2015-03-21 15:45:40 +01:00
|
|
|
templateUrl: 'events-list.html',
|
|
|
|
controller: 'EventsListCtrl'
|
2015-04-05 16:57:21 +02:00
|
|
|
})
|
|
|
|
.state('event', {
|
|
|
|
url: '/event',
|
2016-04-24 16:31:07 +02:00
|
|
|
templateUrl: 'event-main.html'
|
2015-04-05 16:57:21 +02:00
|
|
|
})
|
|
|
|
.state('event.new', {
|
|
|
|
url: '/new',
|
|
|
|
templateUrl: 'event-edit.html',
|
|
|
|
controller: 'EventDetailsCtrl'
|
|
|
|
})
|
2016-06-24 23:11:57 +02:00
|
|
|
.state('event.view', {
|
|
|
|
url: '/:id/view',
|
|
|
|
templateUrl: 'event-edit.html',
|
|
|
|
controller: 'EventDetailsCtrl'
|
|
|
|
})
|
2015-04-05 16:57:21 +02:00
|
|
|
.state('event.edit', {
|
|
|
|
url: '/:id/edit',
|
|
|
|
templateUrl: 'event-edit.html',
|
2015-03-21 15:45:40 +01:00
|
|
|
controller: 'EventDetailsCtrl'
|
2015-04-05 16:57:21 +02:00
|
|
|
})
|
2016-06-19 16:58:38 +02:00
|
|
|
.state('event.tickets', {
|
|
|
|
url: '/:id/tickets',
|
|
|
|
templateUrl: 'event-tickets.html',
|
2016-07-02 14:49:39 +02:00
|
|
|
controller: 'EventTicketsCtrl'
|
2015-04-05 16:57:21 +02:00
|
|
|
})
|
2016-06-08 23:05:16 +02:00
|
|
|
.state('event.ticket', {
|
|
|
|
url: '/:id/ticket',
|
|
|
|
templateUrl: 'ticket-main.html'
|
|
|
|
})
|
|
|
|
.state('event.ticket.new', {
|
|
|
|
url: '/new',
|
|
|
|
templateUrl: 'ticket-edit.html',
|
|
|
|
controller: 'EventTicketsCtrl'
|
|
|
|
})
|
|
|
|
.state('event.ticket.edit', {
|
|
|
|
url: '/:ticket_id/edit',
|
|
|
|
templateUrl: 'ticket-edit.html',
|
|
|
|
controller: 'EventTicketsCtrl'
|
|
|
|
})
|
2016-07-05 21:30:12 +02:00
|
|
|
.state('tickets', {
|
|
|
|
url: '/tickets',
|
|
|
|
templateUrl: 'tickets-list.html',
|
2016-07-07 22:18:30 +02:00
|
|
|
controller: 'EventsListCtrl'
|
2015-04-05 16:57:21 +02:00
|
|
|
})
|
2015-04-05 18:10:26 +02:00
|
|
|
.state('import', {
|
2015-04-05 17:58:39 +02:00
|
|
|
url: '/import',
|
2016-04-24 16:31:07 +02:00
|
|
|
templateUrl: 'import-main.html'
|
2015-04-05 18:10:26 +02:00
|
|
|
})
|
|
|
|
.state('import.persons', {
|
|
|
|
url: '/persons',
|
2015-03-29 00:46:42 +01:00
|
|
|
templateUrl: 'import-persons.html',
|
2015-04-06 21:08:52 +02:00
|
|
|
controller: 'FileUploadCtrl'
|
2016-06-12 16:04:46 +02:00
|
|
|
})
|
2016-07-08 22:10:42 +02:00
|
|
|
.state('users', {
|
|
|
|
url: '/users',
|
|
|
|
templateUrl: 'users-list.html',
|
|
|
|
controller: 'UsersCtrl'
|
|
|
|
})
|
2016-07-09 13:34:36 +02:00
|
|
|
.state('user', {
|
|
|
|
url: '/user',
|
|
|
|
templateUrl: 'user-main.html'
|
|
|
|
})
|
|
|
|
.state('user.edit', {
|
2016-07-10 15:37:56 +02:00
|
|
|
url: ':id/edit',
|
2016-07-09 13:34:36 +02:00
|
|
|
templateUrl: 'user-edit.html',
|
|
|
|
controller: 'UsersCtrl'
|
|
|
|
})
|
2016-06-12 16:04:46 +02:00
|
|
|
.state('login', {
|
|
|
|
url: '/login',
|
|
|
|
templateUrl: 'login.html',
|
2016-07-08 22:10:42 +02:00
|
|
|
controller: 'UsersCtrl'
|
2015-04-05 18:10:26 +02:00
|
|
|
});
|
2015-03-22 09:19:30 +01:00
|
|
|
}
|
|
|
|
]);
|
2015-03-15 18:00:08 +01:00
|
|
|
|