Added previous state tracker and a filter for challenges by a guild if the user has clicked that guild's challenge link.

This commit is contained in:
kholliday
2015-03-15 12:24:48 -05:00
parent 5752f75c46
commit c54794fd2a

View File

@@ -138,10 +138,16 @@ window.habitrpg = angular.module('habitrpg',
.state('options.social.challenges.detail', {
url: '/:cid',
templateUrl: 'partials/options.social.challenges.detail.html',
controller: ['$scope', 'Challenges', '$stateParams',
function($scope, Challenges, $stateParams){
controller: ['$scope', 'Challenges', '$stateParams', '$rootScope',
function($scope, Challenges, $stateParams, $rootScope){
$scope.obj = $scope.challenge = Challenges.Challenge.get({cid:$stateParams.cid}, function(){
$scope.challenge._locked = true;
//If the user came from a guild page, then we want to filter challenges by the user's guild
if ( $rootScope.$state.previousState.url == "/:gid" ) {
$scope.search.group = [];
$scope.search.group[$scope.challenge.group] = true;
}
});
}]
})
@@ -225,3 +231,9 @@ window.habitrpg = angular.module('habitrpg',
$httpProvider.defaults.headers.common['x-api-key'] = settings.auth.apiToken;
}
}])
.run(function ($rootScope, $state) {
$rootScope.$state = $state;
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState) {
$state.previousState = fromState;
});
});