diff --git a/website/public/js/app.js b/website/public/js/app.js index 0450302389..2f8e2fd512 100644 --- a/website/public/js/app.js +++ b/website/public/js/app.js @@ -146,6 +146,16 @@ window.habitrpg = angular.module('habitrpg', }); }] }) + .state('options.social.challenges.edit', { + url: '/:cid/edit', + templateUrl: 'partials/options.social.challenges.detail.html', + controller: ['$scope', 'Challenges', '$stateParams', + function($scope, Challenges, $stateParams){ + $scope.obj = $scope.challenge = Challenges.Challenge.get({cid:$stateParams.cid}, function(){ + $scope.challenge._locked = false; + }); + }] + }) .state('options.social.challenges.detail.member', { url: '/:uid', templateUrl: 'partials/options.social.challenges.detail.member.html', diff --git a/website/public/js/controllers/challengesCtrl.js b/website/public/js/controllers/challengesCtrl.js index eec3e3c4df..14925b2ac1 100644 --- a/website/public/js/controllers/challengesCtrl.js +++ b/website/public/js/controllers/challengesCtrl.js @@ -1,7 +1,7 @@ "use strict"; -habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state', - function($rootScope, $scope, Shared, User, Challenges, Notification, $compile, Groups, $state) { +habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state', '$stateParams', + function($rootScope, $scope, Shared, User, Challenges, Notification, $compile, Groups, $state, $stateParams) { // Use presence of cid to determine whether to show a list or a single // challenge @@ -40,6 +40,13 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', // Challenge //------------------------------------------------------------ + // Use this to force the top view to change, not just the nested view. + $scope.edit = function(challenge) { + $state.transitionTo('options.social.challenges.edit', {cid: challenge._id}, { + reload: true, inherit: false, notify: true + }); + }; + /** * Create */ @@ -95,6 +102,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', // TODO figure out a more elegant way about this //challenge._editing = false; challenge._locked = true; + getChallenges(); } }); }; diff --git a/website/views/options/social/challenges.jade b/website/views/options/social/challenges.jade index a2115db07c..e01d31f76d 100644 --- a/website/views/options/social/challenges.jade +++ b/website/views/options/social/challenges.jade @@ -24,7 +24,7 @@ script(type='text/ng-template', id='partials/options.social.challenges.detail.ht // Edit button div(bindonce='challenge', ng-if='challenge.leader==user._id') div(ng-hide='challenge._locked==false') - button.btn.btn-sm.btn-default(ng-click='challenge._locked = false')=env.t('edit') + button.btn.btn-sm.btn-default(ng-click='edit(challenge)')=env.t('edit') button.btn.btn-sm.btn-warning(ng-click='close(challenge, $event)', tooltip=env.t('deleteOrSelect'))=env.t('endChallenge') form(ng-show='challenge._locked==false')