Blame view
resources/js/predictor/PredictorController.js
1.51 KB
e77200db5 Initial commit |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
angular.module('footyroom') .controller('PredictorController', ['$scope', '$route', '$sce', 'predictService', '$location', function ($scope, $route, $sce, predictService, $location) { $scope.$route = $route; $scope.predictor = DataStore.predictor; $scope.predictor.prizeHtml = $sce.trustAsHtml($scope.predictor.prizeHtml); $scope.loadPlayer = () => { predictService.getPlayer().then((player) => { $scope.player = player; }); }; /** * Request to load player only if we are not a guest. */ if (!DataStore.isGuest) { $scope.loadPlayer(); } /** * We will ask playing guests to sign up. */ if (DataStore.isGuest) { $scope.showSignUp = true; } /** * Handle loading of player for "viewAs" situations. */ $scope.$on('$routeChangeStart', function (event, next) { if (next) { predictService.loadViewAs(parseInt($location.search().viewAs, 10)).then(() => { $scope.viewAs = predictService.getViewAs(); }).catch(() => { /** * In case we can't fetch a viewAs player then redirect to predictor home page. * TODO: What we really need is a proper 404 and a general error handler within * angular. This is important for SEO also. * * https://stackoverflow.com/questions/14779190 */ $location.url('/predictor'); }); } }); }]); |