eventman/angular_app/js/app.js

182 lines
6 KiB
JavaScript
Raw Normal View History

2015-03-22 08:57:57 +01:00
'use strict';
2015-03-22 09:36:32 +01:00
/*
Copyright 2015 Davide Alberani <da@erlug.linux.it>
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',
'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',
'angularFileUpload',
'angular-websocket'
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) {
$rootScope.app_uuid = guid();
$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 || {};
if (callback) {
callback();
}
});
};
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
/* Check GUI privileges. */
$rootScope.hasPermission = function(permission) {
2016-06-06 21:44:04 +02:00
if (!($rootScope.info && $rootScope.info.user && $rootScope.info.user.permissions)) {
2016-05-29 11:59:09 +02:00
return false;
}
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';
angular.forEach($rootScope.info.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) {
granted = true;
2016-05-29 11:59:09 +02:00
return;
}
}
);
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'
})
.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
})
.state('event.info', {
url: '/:id',
templateUrl: 'event-info.html',
2015-03-21 15:45:40 +01:00
controller: 'EventDetailsCtrl'
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'
})
2015-04-05 17:36:29 +02:00
.state('persons', {
2015-04-05 16:57:21 +02:00
url: '/persons',
templateUrl: 'persons-list.html',
controller: 'PersonsListCtrl'
})
2015-04-05 17:36:29 +02:00
.state('person', {
url: '/person',
2016-04-24 16:31:07 +02:00
templateUrl: 'person-main.html'
2015-04-05 17:36:29 +02:00
})
.state('person.new', {
2015-04-05 17:58:39 +02:00
url: '/new',
2015-04-05 17:36:29 +02:00
templateUrl: 'person-edit.html',
controller: 'PersonDetailsCtrl'
})
.state('person.edit', {
2015-04-05 17:58:39 +02:00
url: '/:id/edit',
2015-04-05 17:36:29 +02:00
templateUrl: 'person-edit.html',
2015-04-05 16:57:21 +02:00
controller: 'PersonDetailsCtrl'
})
2015-04-05 17:36:29 +02:00
.state('person.info', {
2015-04-05 17:58:39 +02:00
url: '/:id',
2015-04-05 17:36:29 +02:00
templateUrl: 'person-info.html',
2015-03-21 15:45:40 +01:00
controller: 'PersonDetailsCtrl'
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',
controller: 'FileUploadCtrl'
2016-06-12 16:04:46 +02:00
})
.state('login', {
url: '/login',
templateUrl: 'login.html',
controller: 'LoginCtrl'
2015-04-05 18:10:26 +02:00
});
2015-03-22 09:19:30 +01:00
}
]);
2015-03-15 18:00:08 +01:00