From cdd80f11e8bb3163cd7110b919b2f7ab571f47fe Mon Sep 17 00:00:00 2001 From: Cole Gleason Date: Wed, 8 Jan 2014 15:09:08 -0600 Subject: [PATCH] Copy leave and clickLeave function for party to fix #2304. TODO: Refactor into one function? --- public/js/controllers/groupsCtrl.js | 49 ++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/public/js/controllers/groupsCtrl.js b/public/js/controllers/groupsCtrl.js index 8a7eb2243a..23a08bb0dd 100644 --- a/public/js/controllers/groupsCtrl.js +++ b/public/js/controllers/groupsCtrl.js @@ -313,8 +313,8 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A } ]) - .controller("PartyCtrl", ['$rootScope','$scope', 'Groups', 'User', '$state', - function($rootScope,$scope, Groups, User, $state) { + .controller("PartyCtrl", ['$rootScope','$scope', 'Groups', 'User', 'Challenges', '$state', '$compile', + function($rootScope,$scope, Groups, User, Challenges, $state, $compile) { $scope.type = 'party'; $scope.text = 'Party'; $scope.group = $rootScope.party = Groups.party(); @@ -333,13 +333,48 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A }); } - $scope.leave = function(group){ - if (confirm("Are you sure you want to leave this party?") !== true) { - return; - } - Groups.Group.leave({gid: group._id}, undefined, function(){ + // TODO: refactor guild and party leave into one function + $scope.leave = function(keep) { + if (keep == 'cancel') { + $scope.selectedGroup = undefined; + } else { + var group = $scope.selectedGroup; + Groups.Group.leave({gid: group._id, keep:keep}, undefined, function(){ $scope.group = undefined; }); + $state.go('options.social.party'); + }; + $scope.popoverEl.popover('destroy'); + } + + // TODO: refactor guild and party clickLeave into one function + $scope.clickLeave = function(group, $event){ + $scope.selectedGroup = group; + $scope.popoverEl = $($event.target); + var html, title; + Challenges.Challenge.query(function(challenges) { + challenges = _.pluck(_.filter(challenges, function(c) { + return c.group._id == group._id; + }), '_id'); + if (_.intersection(challenges, User.user.challenges).length > 0) { + html = $compile( + 'Remove Tasks
\nKeep Tasks
\nCancel
' + )($scope); + title = "Leave party challenges and..."; + } else { + html = $compile( + 'Confirm
\nCancel
' + )($scope); + title = "Leave party?"; + } + $scope.popoverEl.popover('destroy').popover({ + html: true, + placement: 'top', + trigger: 'manual', + title: title, + content: html + }).popover('show'); + }); } $scope.reject = function(){