Made default group for a challenge the selected group filter if there is only one filter selected.

This commit is contained in:
kholliday
2015-03-17 09:34:12 -05:00
parent fcc0b67426
commit 6e7aea991e

View File

@@ -25,6 +25,25 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
* Create
*/
$scope.create = function() {
//If the user has one filter selected, assume that the user wants to default to that group
var defaultGroup;
//Our filters contain all groups, but we only want groups that have atleast one challenge
var groupsWithChallenges = _.uniq(_.pluck($scope.groupsFilter, '_id'));
var len = groupsWithChallenges.length;
var filterCount = 0;
for ( var i = 0; i < len; i += 1 ) {
if ( $scope.search.group[groupsWithChallenges[i]] == true ) {
filterCount += 1;
defaultGroup = groupsWithChallenges[i];
}
if (filterCount > 1) {
defaultGroup = $scope.groups[0]._id
break;
}
}
$scope.obj = $scope.newChallenge = new Challenges.Challenge({
name: '',
description: '',
@@ -33,7 +52,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
todos: [],
rewards: [],
leader: User.user._id,
group: $scope.groups[0]._id,
group: defaultGroup,
timestamp: +(new Date),
members: [],
official: false