From 01237df2132dc6fc451f4bfec014a7cd835d66b1 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Mon, 3 Aug 2015 08:32:35 -0500 Subject: [PATCH] Add buttons to challenge participant modal --- test/spec/controllers/challengesCtrlSpec.js | 41 +++++++++++++++++-- .../public/js/controllers/challengesCtrl.js | 16 +++++++- website/views/options/social/challenges.jade | 7 ++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/test/spec/controllers/challengesCtrlSpec.js b/test/spec/controllers/challengesCtrlSpec.js index 9cb1ba29cd..589aa87b59 100644 --- a/test/spec/controllers/challengesCtrlSpec.js +++ b/test/spec/controllers/challengesCtrlSpec.js @@ -1,7 +1,7 @@ 'use strict'; describe('Challenges Controller', function() { - var $rootScope, scope, user, User, ctrl, groups, notification, state; + var rootScope, scope, user, User, ctrl, groups, members, notification, state; beforeEach(function() { module(function($provide) { @@ -15,11 +15,12 @@ describe('Challenges Controller', function() { $provide.value('User', User); }); - inject(function($rootScope, $controller, _$state_, _Groups_, _Notification_){ + inject(function($rootScope, $controller, _$state_, _Groups_, _Members_, _Notification_){ user = specHelper.newUser(); user._id = "unique-user-id"; scope = $rootScope.$new(); + rootScope = $rootScope; // Load RootCtrl to ensure shared behaviors are loaded $controller('RootCtrl', {$scope: scope, User: User}); @@ -27,6 +28,7 @@ describe('Challenges Controller', function() { ctrl = $controller('ChallengesCtrl', {$scope: scope, User: User}); groups = _Groups_; + members = _Members_; notification = _Notification_; state = _$state_; }); @@ -614,7 +616,7 @@ describe('Challenges Controller', function() { }); }); - describe('User interactions', function() { + context('User interactions', function() { describe('join', function() { it('calls challenge.$join', function(){ var challenge = specHelper.newChallenge({ @@ -682,4 +684,37 @@ describe('Challenges Controller', function() { }); }); }); + + context('modal actions', function() { + beforeEach(function() { + sandbox.stub(members, 'selectMember'); + sandbox.stub(rootScope, 'openModal'); + }); + + describe('sendMessageToChallengeParticipant', function() { + it('opens private-message modal', function() { + members.selectMember.yields(); + scope.sendMessageToChallengeParticipant(user._id); + + expect(rootScope.openModal).to.be.calledOnce; + expect(rootScope.openModal).to.be.calledWith( + 'private-message', + { controller: 'MemberModalCtrl' } + ); + }); + }); + + describe('sendGiftToChallengeParticipant', function() { + it('opens send-gift modal', function() { + members.selectMember.yields(); + scope.sendGiftToChallengeParticipant(user._id); + + expect(rootScope.openModal).to.be.calledOnce; + expect(rootScope.openModal).to.be.calledWith( + 'send-gift', + { controller: 'MemberModalCtrl' } + ); + }); + }); + }); }); diff --git a/website/public/js/controllers/challengesCtrl.js b/website/public/js/controllers/challengesCtrl.js index 8c1d2e8d37..d60c15bd00 100644 --- a/website/public/js/controllers/challengesCtrl.js +++ b/website/public/js/controllers/challengesCtrl.js @@ -1,5 +1,5 @@ -habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state', '$stateParams', 'Tasks', - function($rootScope, $scope, Shared, User, Challenges, Notification, $compile, Groups, $state, $stateParams, Tasks) { +habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', 'Challenges', 'Notification', '$compile', 'Groups', '$state', '$stateParams', 'Members', 'Tasks', + function($rootScope, $scope, Shared, User, Challenges, Notification, $compile, Groups, $state, $stateParams, Members, Tasks) { // Use presence of cid to determine whether to show a list or a single // challenge @@ -313,6 +313,18 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', } } + $scope.sendMessageToChallengeParticipant = function(uid) { + Members.selectMember(uid, function(){ + $rootScope.openModal('private-message',{controller:'MemberModalCtrl'}); + }); + }; + + $scope.sendGiftToChallengeParticipant = function(uid) { + Members.selectMember(uid, function(){ + $rootScope.openModal('send-gift',{controller:'MemberModalCtrl'}) + }); + }; + function _calculateMaxPrize(gid) { var userBalance = User.getBalanceInGems() || 0; diff --git a/website/views/options/social/challenges.jade b/website/views/options/social/challenges.jade index 6df715fa57..9a78e79dcc 100644 --- a/website/views/options/social/challenges.jade +++ b/website/views/options/social/challenges.jade @@ -19,6 +19,13 @@ script(type='text/ng-template', id='partials/options.social.challenges.detail.me .modal-body habitrpg-tasks(main=false, modal='true') .modal-footer + .btn-group.pull-left(role="group") + button.btn.btn-default(ng-click='clickMember(obj._id, true)') + .glyphicon.glyphicon-user + button.btn.btn-default(ng-click='sendMessageToChallengeParticipant(obj._id)') + .glyphicon.glyphicon-envelope + button.btn.btn-default(ng-click='sendGiftToChallengeParticipant(obj._id)') + .glyphicon.glyphicon-gift a.btn.btn-default(ng-click='$state.go("^")')=env.t('close') script(type='text/ng-template', id='partials/options.social.challenges.detail.html')