mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Create new function to check for enough gems, added @crookedneighbor 's tests, and added tests to check for enoughGems when user creates a habitrpg challenge
This commit is contained in:
committed by
Blade Barringer
parent
53c21b07a3
commit
ef9dfac087
@@ -133,6 +133,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
$scope.save = function(challenge) {
|
||||
if (!challenge.group) return alert(window.env.t('selectGroup'));
|
||||
var isNew = !challenge._id;
|
||||
$scope.hasEnoughGems(challenge.group);
|
||||
if (!$scope.enoughGems && isNew ) return alert(window.env.t('challengeNotEnoughGems'));
|
||||
challenge.$save(function(_challenge){
|
||||
if (isNew) {
|
||||
@@ -304,17 +305,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
}
|
||||
|
||||
$scope.$watch('newChallenge.group', function(gid){
|
||||
if (!gid) return;
|
||||
var group = _.find($scope.groups, {_id:gid});
|
||||
$scope.maxPrize = User.user.balance*4 + ((group && group.balance && group.leader==User.user._id) ? group.balance*4 : 0);
|
||||
if (gid == 'habitrpg') {
|
||||
$scope.newChallenge.prize = 1;
|
||||
//If the usere does not have enough gems for the Habitrpg group, the set our enoughGems var to false
|
||||
if ( $scope.maxPrize <= 0 ) $scope.enoughGems = false;
|
||||
} else {
|
||||
//Reset our enoughGems variable incase the user tried to create a challenge for habitrpg and was unable to
|
||||
$scope.enoughGems = true;
|
||||
}
|
||||
$scope.hasEnoughGems(gid);
|
||||
})
|
||||
|
||||
$scope.selectAll = function(){
|
||||
@@ -325,6 +316,28 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
$scope.search.group = _.transform($scope.groups, function(m,g){m[g._id] = false});
|
||||
}
|
||||
|
||||
$scope.shouldShow = function(task, list, prefs){
|
||||
return true;
|
||||
};
|
||||
|
||||
//A helper function to dermine if the user has enough gems to create a Habitrpg challenge
|
||||
$scope.hasEnoughGems = function(gid) {
|
||||
if (!gid) return;
|
||||
var groupBalance = 0;
|
||||
var group = _.find($scope.groups, {_id:gid});
|
||||
if (group) { groupBalance = group.balance; }
|
||||
var userBalance = User.user.balance || 0;
|
||||
$scope.maxPrize = userBalance * 4 + ((group && groupBalance && group.leader==User.user._id) ? groupBalance*4 : 0);
|
||||
if (gid == 'habitrpg') {
|
||||
$scope.newChallenge.prize = 1;
|
||||
//If the user does not have enough gems for the Habitrpg group, the set our enoughGems var to false
|
||||
if ( $scope.maxPrize <= 0 ) $scope.enoughGems = false;
|
||||
} else {
|
||||
//Reset our enoughGems variable incase the user tried to create a challenge for habitrpg and was unable to
|
||||
$scope.enoughGems = true;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.shouldShow = function(task, list, prefs){
|
||||
return true;
|
||||
};
|
||||
@@ -340,4 +353,5 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
|
||||
return groupSelected && checkOwner && checkMember;
|
||||
}
|
||||
|
||||
}]);
|
||||
|
||||
Reference in New Issue
Block a user