mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
Copy leave and clickLeave function for party to fix #2304. TODO: Refactor into one function?
This commit is contained in:
@@ -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(){
|
||||
|
||||
Reference in New Issue
Block a user