app.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. 'use strict';
  2. /*
  3. Copyright 2015 Davide Alberani <da@erlug.linux.it>
  4. RaspiBO <info@raspibo.org>
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. /* Register our fantastic app. */
  15. var eventManApp = angular.module('eventManApp', [
  16. 'ngRoute',
  17. 'eventManServices',
  18. 'eventManControllers',
  19. 'ui.bootstrap',
  20. 'ui.router',
  21. 'pascalprecht.translate',
  22. 'angularFileUpload',
  23. 'angular-websocket'
  24. ]);
  25. /* Add some utilities to the global scope. */
  26. eventManApp.run(['$rootScope', '$state', '$stateParams', '$log', 'Info',
  27. function($rootScope, $state, $stateParams, $log, Info) {
  28. $rootScope.app_uuid = guid();
  29. $log.debug('App UUID: ' + $rootScope.app_uuid);
  30. $rootScope.$state = $state;
  31. $rootScope.$stateParams = $stateParams;
  32. $rootScope.error = {error: false};
  33. Info.get({}, function(data) {
  34. $rootScope.info = data || {};
  35. });
  36. $rootScope.errorHandler = function(response) {
  37. $log.debug('Handling error message:');
  38. $log.debug(response);
  39. $rootScope.error.status = response.status;
  40. $rootScope.error.statusText = response.statusText;
  41. if (response.data && response.data.error) {
  42. $rootScope.error.code = response.data.code;
  43. $rootScope.error.message = response.data.message;
  44. $rootScope.error.error = true;
  45. } else {
  46. $rootScope.error.code = null;
  47. $rootScope.error.message = '';
  48. $rootScope.error.error = false;
  49. }
  50. };
  51. /* Check GUI privileges. */
  52. $rootScope.hasPermission = function(permission) {
  53. if (!($rootScope.info && $rootScope.info.user &&
  54. $rootScope.info.user.username && $rootScope.info.user.permissions)) {
  55. return false;
  56. }
  57. var granted = false;
  58. var splitted_permission = permission.split('|');
  59. var global_permission = splitted_permission + '|all';
  60. angular.forEach($rootScope.info.user.permissions || [],
  61. function(value, idx) {
  62. if (value === 'admin|all' || value === global_permission || value === permission) {
  63. granted = true;
  64. return;
  65. }
  66. }
  67. );
  68. return granted;
  69. };
  70. }]
  71. );
  72. /* Configure the states. */
  73. eventManApp.config(['$stateProvider', '$urlRouterProvider',
  74. function($stateProvider, $urlRouterProvider) {
  75. $urlRouterProvider.otherwise('/events');
  76. $stateProvider
  77. .state('events', {
  78. url: '/events',
  79. templateUrl: 'events-list.html',
  80. controller: 'EventsListCtrl'
  81. })
  82. .state('event', {
  83. url: '/event',
  84. templateUrl: 'event-main.html'
  85. })
  86. .state('event.new', {
  87. url: '/new',
  88. templateUrl: 'event-edit.html',
  89. controller: 'EventDetailsCtrl'
  90. })
  91. .state('event.edit', {
  92. url: '/:id/edit',
  93. templateUrl: 'event-edit.html',
  94. controller: 'EventDetailsCtrl'
  95. })
  96. .state('event.info', {
  97. url: '/:id',
  98. templateUrl: 'event-info.html',
  99. controller: 'EventDetailsCtrl'
  100. })
  101. .state('persons', {
  102. url: '/persons',
  103. templateUrl: 'persons-list.html',
  104. controller: 'PersonsListCtrl'
  105. })
  106. .state('person', {
  107. url: '/person',
  108. templateUrl: 'person-main.html'
  109. })
  110. .state('person.new', {
  111. url: '/new',
  112. templateUrl: 'person-edit.html',
  113. controller: 'PersonDetailsCtrl'
  114. })
  115. .state('person.edit', {
  116. url: '/:id/edit',
  117. templateUrl: 'person-edit.html',
  118. controller: 'PersonDetailsCtrl'
  119. })
  120. .state('person.info', {
  121. url: '/:id',
  122. templateUrl: 'person-info.html',
  123. controller: 'PersonDetailsCtrl'
  124. })
  125. .state('event.ticket', {
  126. templateUrl: 'ticket-main.html'
  127. })
  128. .state('event.ticket.new', {
  129. url: '/:id/ticket/new',
  130. templateUrl: 'ticket-edit.html',
  131. controller: 'EventDetailsCtrl'
  132. })
  133. .state('event.ticket.edit', {
  134. url: '/:id/ticket/edit',
  135. templateUrl: 'ticket-edit.html',
  136. controller: 'EventDetailsCtrl'
  137. })
  138. .state('import', {
  139. url: '/import',
  140. templateUrl: 'import-main.html'
  141. })
  142. .state('import.persons', {
  143. url: '/persons',
  144. templateUrl: 'import-persons.html',
  145. controller: 'FileUploadCtrl'
  146. });
  147. }
  148. ]);