// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem // throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem // to avoid the entire page breaking, without having to do a check at each usage of Storage. if (typeof localStorage === 'object') { try { localStorage.setItem('localStorage', 1); localStorage.removeItem('localStorage'); } catch (e) { Storage.prototype._setItem = Storage.prototype.setItem; Storage.prototype.setItem = function() {}; alert('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some settings may not save or some features may not work properly for you.'); } } var sesf = angular.module('sesf',[ 'ngRoute', 'sesfControllers', 'sesfDirectives', 'angularFileUpload', 'ui.bootstrap', 'ngResource', 'ngAnimate', 'appStorage', 'angular-carousel', 'AngularGM']); sesf.config(['$routeProvider', '$provide', function($routeProvider, $provide) { $routeProvider. when('/forum', { templateUrl: '/template/forum', controller: 'emptyController' }). when('/privacy-policy', { templateUrl: '/template/privacy_policy', controller: 'emptyController' }). when('/about-us', { templateUrl: '/template/about_us', controller: 'emptyController' }). when('/login', { templateUrl: '/template/login', controller: 'loginController' }). when('/forgot-password', { templateUrl: '/template/forgot_password', controller: 'forgotPasswordController' }). when('/reset-password', { templateUrl: '/template/reset_password', controller: 'resetPasswordController' }). when('/register', { templateUrl: '/template/register', controller: 'registerController' }). when('/admin/register-user/:userId', { templateUrl: '/template/admin_register_user', controller: 'adminRegisterUserController', min_user_level: 3, resolve: { events: function(EventsService) { return EventsService.Events().query().$promise; } } }). when('/members', { templateUrl: '/template/members', controller: 'membersController', eventPage: false }). when('/cars', { templateUrl: '/template/cars', controller: 'carsController', eventPage: false }). when('/gallery', { templateUrl: '/template/gallery?page=event_list', controller: 'galleryEventListController', resolve: { events: function(GalleryService) { return GalleryService.EventList().query().$promise; } } }). when('/gallery/create/:eventId/:galleryId?', { templateUrl: '/template/gallery?page=create', controller: 'galleryCreateController', min_user_level: 3, resolve: { event: function(EventService) { return EventService.EventInfo().get().$promise; }, gallery: function(GalleryService) { return GalleryService.Gallery().get().$promise; } } }). when('/gallery/e:eventId/:galleryId?', { templateUrl: '/template/gallery?page=list', controller: 'galleryListController', resolve: { breadcrumb: function(GalleryService) { return GalleryService.Breadcrumb().get().$promise; }, galleries: function(GalleryService) { return GalleryService.GalleryList().query().$promise; }, galleryInfo: function(GalleryService) { return GalleryService.Gallery().get().$promise; }, galleryItems: function(GalleryService) { return GalleryService.Items(true).get().$promise; } } }). when('/gallery/manage/:galleryId', { templateUrl: '/template/gallery?page=manage', controller: 'galleryManageController', min_user_level: 3, resolve: { gallery: function(GalleryService) { return GalleryService.Gallery().get().$promise; }, galleryItems: function(GalleryService) { return GalleryService.Items().get().$promise; } } }). when('/:memberName/u:memberId', { templateUrl: '/template/member', controller: 'memberController' }). when('/:memberName/u:memberId/settings', { templateUrl: '/template/member_settings', controller: 'memberController', private_profile_section: true, min_user_level: 1 }). when('/:memberName/u:memberId/cars', { templateUrl: '/template/member?page=cars', controller: 'memberCarsController', resolve: { cars: function(MemberService) { return MemberService.Cars().query().$promise; } } }). when('/:memberName/u:memberId/billing/:registrationId?', { templateUrl: '/template/member?page=billing', controller: 'memberBillingController', private_profile_section: true, min_user_level: 1, resolve: { invoiceList: function(MemberService) { return MemberService.InvoiceList().query().$promise; } } }). when('/car/new', { templateUrl: '/template/car_profile?page=new', controller: 'carNewController', min_user_level: 1 }). when('/car/:carId/new-image', { templateUrl: '/template/car_profile?page=new_image', controller: 'carNewImageController', min_user_level: 1 }). when('/car/:carId', { templateUrl: '/template/car_profile', controller: 'carController' }). when('/car/:carId/settings', { templateUrl: '/template/car_profile?page=settings', controller: 'carController', min_user_level: 1 }). when('/events', { templateUrl: '/template/events', controller: 'eventsController' }). when('/:eventName/e:eventId', { templateUrl: '/template/event?page=agenda', controller: 'eventAgendaController', resolve: { agenda: function(EventService) { return EventService.Agenda().query().$promise; }, sponsors: function(EventService) { return EventService.Sponsors().get(); } } }). when('/:eventName/e:eventId/judging', { templateUrl: '/template/event?page=agenda', controller: 'eventJudgingController', resolve: { agenda: function(EventService) { return EventService.Agenda().query({type_id: 2}); } } }). when('/:eventName/e:eventId/directions', { templateUrl: '/template/event?page=directions', controller: 'eventDirectionsController', resolve: { locations: function(EventService){ return EventService.Locations().query().$promise;; } } }). when('/:eventName/e:eventId/schedule', { templateUrl: '/template/event?page=schedule', controller: 'eventScheduleController' }). when('/:eventName/e:eventId/sponsors', { templateUrl: '/template/event?page=sponsors', controller: 'eventSponsorController', resolve: { sponsors: function(EventService) { return EventService.Sponsors().get(); } } }). when('/:eventName/e:eventId/news', { templateUrl: '/template/event?page=news', controller: 'eventController' }). when('/:eventName/e:eventId/register', { templateUrl: '/template/event?page=register', controller: 'eventRegisterController', min_user_level: 1, resolve: { 'registration': function(EventService) { return EventService.Registration().get(); }, 'cars': function(EventService) { return EventService.Cars().query().$promise; } } }). when('/:eventName/e:eventId/extra/:extraId', { templateUrl: '/template/event?page=extra', controller: 'eventExtraController', min_user_level: 1, resolve: { 'registration': function(EventService) { return EventService.Extra().get(); } } }). when('/:eventName/e:eventId/members', { templateUrl: '/template/event?page=members', controller: 'eventController', eventPage: true }). when('/:eventName/e:eventId/cars', { templateUrl: '/template/event?page=cars', controller: 'eventController', eventPage: true }). when('/:carName/c:carId', { templateUrl: '/template/car?public', controller: 'carController' }). otherwise({ templateUrl: '/template/home', controller: 'homeController' }); var logs = []; $provide.decorator( '$log', [ "$delegate", function( $delegate){ // Save the original $log.debug() var log = function(logFn, type, args) { var now = Date(); var args = [ '[' + type + '] ' + now + ' - ' + [].slice.call(args)]; logs.push(args[0]); logFn.apply(null, args); }; var _debug = $delegate.debug; $delegate.debug = function( ) { log(_debug, 'DEBUG', arguments); }; var _error = $delegate.error; $delegate.error = function( ) { log(_error, 'ERROR', arguments); }; var _info = $delegate.info; $delegate.info = function( ) { log(_info, 'INFO', arguments); }; var _log = $delegate.log; $delegate.log = function( ) { log(_log, 'LOG', arguments); }; var _warn = $delegate.warn; $delegate.warn = function( ) { log(_warn, 'WARN', arguments); }; $delegate.exportLogs = function(args) { return logs; }; return $delegate; }]); }]); sesf.filter('trustHtml', ['$sce', function($sce) { return function(html) { return $sce.trustAsHtml(html); }; }]); sesf.filter('iif', function () { return function(input, trueValue, falseValue) { return input ? trueValue : falseValue; }; }); sesf.run(function($rootScope, $location, $anchorScroll, $routeParams, LoginService, $route, $log) { $rootScope.$on('$routeChangeStart', function(e, curr, prev) { $log.info('loading new page, url: ', $location.path() + ' | path: ' + JSON.stringify(curr.$$route)); if (curr.$$route && curr.$$route.resolve) { /* Show a loading message until promises are not resolved */ $rootScope.loadingView = true; } }); $rootScope.$on('$routeChangeSuccess', function(e, curr, prev) { $rootScope.loadingView = false; }); $rootScope.$on('$routeChangeError', function(e, curr, prev, rejection) { $rootScope.loadingView = false; $log.error('Route change failed: ' + JSON.stringify(rejection)); }); $rootScope.$on('$locationChangeSuccess', function(event, newLocation, oldLocation) { $rootScope.log('$locationChangeSuccess', oldLocation, newLocation); }); $rootScope.$on('$routeChangeStart', function(event, newRoute, oldRoute) { $rootScope.log('$routeChangeStart', oldRoute, newRoute); if($location.path() != '/login' && $location.path() != '/logout' && $location.path() != '/reset-password') { $rootScope.log('updating login nextUrl', $location.path()); LoginService.nextUrl = $location.path(); } try { var routeInfo = newRoute; $rootScope.log('route info', routeInfo); if(typeof(routeInfo.min_user_level) != 'undefined' && routeInfo.min_user_level > 0) { $rootScope.log('requiring auth', routeInfo.min_user_level); if(!LoginService.auth_resolved) { $rootScope.log('auth not yet resolved, deferring check'); return; } if(LoginService.is_logged_in !== true || LoginService.user_level < routeInfo.min_user_level) { $rootScope.log('login required'); event.preventDefault(); $location.path('/login'); return; } } if(routeInfo.private_profile_section == true) { if(!LoginService.auth_resolved) { $rootScope.log('auth not yet resolved, deferring check'); return; } if(newRoute.params.memberId != LoginService.user_id) { $rootScope.log('not authorized to view this page', $route, $routeParams, LoginService.user_id); event.preventDefault(); $location.path('/'); return; } } } catch(err) { $rootScope.log('route change error', err); } }); $rootScope.$on('login.update', function() { var current = $route.current; if(!current || !current.$$route) return; var routeInfo = current.$$route; if(typeof(routeInfo.min_user_level) != 'undefined' && routeInfo.min_user_level > 0 && (LoginService.is_logged_in !== true || LoginService.user_level < routeInfo.min_user_level)) { $location.path('/login'); return; } if(routeInfo.private_profile_section == true && current.params.memberId != LoginService.user_id) { $location.path('/'); } }); $rootScope.href = function(url) { $location.path(url); } }); sesf.run(function($rootScope){ $rootScope.log = function(){ /* console.log(arguments);*/ }; }); angular.module('appStorage', []) .factory('appStorage', ['$window', '$rootScope', function($window, $rootScope) { var appStorages = {}; var api = undefined; if ($window.localStorage) { api = { set : function(name, value) { $window.localStorage.setItem(name, JSON.stringify(value)); }, get : function(name) { var str = $window.localStorage.getItem(name); var val = {}; try { val = str ? JSON.parse(str) : {}; } catch (e) { $rootScope.log('Parse error for localStorage ' + name); } return val; }, clear : function() { $window.localStorage.clear(); } }; } /* possibly support other */ if (!api) { throw new Error('Could not find suitable storage'); } return function(appName, property, scope) { if (appName === undefined) { throw new Error('appName is required'); } var appStorage = appStorages[appName]; var update = function() { api.set(appName, appStorage); }; var clear = function() { api.clear(appName); }; if (!appStorage) { appStorage = api.get(appName); appStorages[appName] = appStorage; update(); } var bind = function(property, scope) { scope[property] = appStorage; scope.$watch(property, function() { update(); }, true); }; if (property !== undefined && scope !== undefined) { bind(property, scope); } return { get : function(name) { return appStorage[name]; }, set : function(name, value) { appStorage[name] = value; update(); }, clear : clear }; }; }]);