app.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. ]);
  24. /* Add some utilities to the global scope. */
  25. eventManApp.run(['$rootScope', '$state', '$stateParams',
  26. function($rootScope, $state, $stateParams) {
  27. $rootScope.$state = $state;
  28. $rootScope.$stateParams = $stateParams;
  29. }]
  30. );
  31. /* Filter that handles splitted words. */
  32. eventManApp.filter('splittedFilter', ['$filter',
  33. function($filter) {
  34. return function(inputArray, searchText) {
  35. var wordArray = searchText ? searchText.toLowerCase().split(/\s+/) : [];
  36. for (var x=0; x < wordArray.length; x++) {
  37. inputArray = $filter('filter')(inputArray, wordArray[x]);
  38. }
  39. return inputArray;
  40. };
  41. }]
  42. );
  43. /* Filter for events that have (or not) information about a registered person. */
  44. eventManApp.filter('eventWithPersonData', ['$filter',
  45. function($filter) {
  46. return function(inputArray, mustBePresent) {
  47. if (mustBePresent === undefined) {
  48. mustBePresent = true;
  49. }
  50. inputArray = inputArray || [];
  51. var returnArray = [];
  52. for (var x=0; x < inputArray.length; x++) {
  53. var found = inputArray[x].person_data && inputArray[x].person_data.person_id;
  54. if ((found && mustBePresent) || (!found && !mustBePresent)) {
  55. returnArray.push(inputArray[x]);
  56. }
  57. }
  58. return returnArray;
  59. };
  60. }]
  61. );
  62. eventManApp.filter('personRegistered', ['$filter',
  63. function($filter) {
  64. return function(inputArray, data) {
  65. if (data.present === undefined) {
  66. data.present = true;
  67. }
  68. inputArray = inputArray || [];
  69. var returnArray = [];
  70. var registeredIDs = [];
  71. if (!(data.event && data.event.persons && data.event.persons.length)) {
  72. return inputArray;
  73. }
  74. for (var x=0; x < data.event.persons.length; x++) {
  75. registeredIDs.push(data.event.persons[x].person_id);
  76. }
  77. for (var x=0; x < inputArray.length; x++) {
  78. var found = registeredIDs.indexOf(inputArray[x]._id) != -1;
  79. if ((found && data.present) || (!found && !data.present)) {
  80. returnArray.push(inputArray[x]);
  81. }
  82. }
  83. return returnArray;
  84. }
  85. }]
  86. );
  87. /* Directive that can be used to make an input field react to the press of Enter. */
  88. eventManApp.directive('ngEnter', function () {
  89. return function (scope, element, attrs) {
  90. element.bind("keydown keypress", function (event) {
  91. if(event.which === 13) {
  92. scope.$apply(function (){
  93. scope.$eval(attrs.ngEnter);
  94. });
  95. event.preventDefault();
  96. }
  97. });
  98. };
  99. });
  100. /* Configure the states. */
  101. eventManApp.config(['$stateProvider', '$urlRouterProvider',
  102. function($stateProvider, $urlRouterProvider) {
  103. $urlRouterProvider.otherwise("/events");
  104. $stateProvider
  105. .state('events', {
  106. url: '/events',
  107. templateUrl: 'events-list.html',
  108. controller: 'EventsListCtrl'
  109. })
  110. .state('event', {
  111. url: '/event',
  112. templateUrl: 'event-main.html',
  113. })
  114. .state('event.new', {
  115. url: '/new',
  116. templateUrl: 'event-edit.html',
  117. controller: 'EventDetailsCtrl'
  118. })
  119. .state('event.edit', {
  120. url: '/:id/edit',
  121. templateUrl: 'event-edit.html',
  122. controller: 'EventDetailsCtrl'
  123. })
  124. .state('event.info', {
  125. url: '/:id',
  126. templateUrl: 'event-info.html',
  127. controller: 'EventDetailsCtrl'
  128. })
  129. .state('persons', {
  130. url: '/persons',
  131. templateUrl: 'persons-list.html',
  132. controller: 'PersonsListCtrl'
  133. })
  134. .state('person', {
  135. url: '/person',
  136. templateUrl: 'person-main.html',
  137. })
  138. .state('person.new', {
  139. url: '/new',
  140. templateUrl: 'person-edit.html',
  141. controller: 'PersonDetailsCtrl'
  142. })
  143. .state('person.edit', {
  144. url: '/:id/edit',
  145. templateUrl: 'person-edit.html',
  146. controller: 'PersonDetailsCtrl'
  147. })
  148. .state('person.info', {
  149. url: '/:id',
  150. templateUrl: 'person-info.html',
  151. controller: 'PersonDetailsCtrl'
  152. })
  153. .state('import', {
  154. url: '/import',
  155. templateUrl: 'import-main.html',
  156. })
  157. .state('import.persons', {
  158. url: '/persons',
  159. templateUrl: 'import-persons.html',
  160. controller: 'FileUploadCtrl'
  161. });
  162. }
  163. ]);