Merge pull request #4836 from TheHollidayInn/fix-max-value-0-challenges

Added hide and error message when a user tries to create a challenge for...
This commit is contained in:
Alys
2015-03-27 19:21:51 +10:00
3 changed files with 12 additions and 4 deletions

View File

@@ -46,5 +46,6 @@
"removeTasks": "Remove Tasks",
"keepTasks": "Keep Tasks",
"closeCha": "Close challenge and...",
"leaveCha": "Leave challenge and..."
"leaveCha": "Leave challenge and...",
"challengeNotEnoughGems": "You do not have enough gems to post this challenge."
}

View File

@@ -45,6 +45,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
*/
$scope.save = function(challenge) {
if (!challenge.group) return alert(window.env.t('selectGroup'));
if (!$scope.enoughGems) return alert(window.env.t('challengeNotEnoughGems'));
var isNew = !challenge._id;
challenge.$save(function(_challenge){
if (isNew) {
@@ -218,7 +219,11 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
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;
$scope.enoughGems = true;
if (gid == 'habitrpg') {
$scope.newChallenge.prize = 1;
if ( $scope.maxPrize <= 0 ) $scope.enoughGems = false;
}
})
$scope.selectAll = function(){

View File

@@ -116,9 +116,11 @@ script(type='text/ng-template', id='partials/options.social.challenges.html')
//- what's going on here?
br
br
div.alert.alert-warning(ng-hide="enoughGems")
=env.t('challengeNotEnoughGems')
.form-group
input.form-control(type='number', min="{{newChallenge.group=='habitrpg' ? 1 : 0}}", max="{{maxPrize}}", ng-model='newChallenge.prize', placeholder=env.t('prize'))
input.form-control(type='number', min="{{newChallenge.group=='habitrpg' ? 1 : 0}}", max="{{enoughGems ? maxPrize : null}}", ng-model='newChallenge.prize', placeholder=env.t('prize'), ng-show="enoughGems")
span.input-suffix.Pet_Currency_Gem1x.inline-gems
|&nbsp;
span.hint.vertical-20(popover=env.t('prizePop'), popover-trigger='mouseenter', popover-placement='right')