Copy leave and clickLeave function for party to fix #2304. TODO: Refactor into one function?

This commit is contained in:
Cole Gleason
2014-01-08 15:09:08 -06:00
parent 039bdabb49
commit cdd80f11e8

View File

@@ -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(
'<a ng-controller="GroupsCtrl" ng-click="leave(\'remove-all\')">Remove Tasks</a><br/>\n<a ng-click="leave(\'keep-all\')">Keep Tasks</a><br/>\n<a ng-click="leave(\'cancel\')">Cancel</a><br/>'
)($scope);
title = "Leave party challenges and...";
} else {
html = $compile(
'<a ng-controller="GroupsCtrl" ng-click="leave(\'keep-all\')">Confirm</a><br/>\n<a ng-click="leave(\'cancel\')">Cancel</a><br/>'
)($scope);
title = "Leave party?";
}
$scope.popoverEl.popover('destroy').popover({
html: true,
placement: 'top',
trigger: 'manual',
title: title,
content: html
}).popover('show');
});
}
$scope.reject = function(){