2013-08-29 02:08:59 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
2013-09-01 23:23:16 +00:00
|
|
|
habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'API_URL', '$q',
|
|
|
|
|
function($scope, $rootScope, Groups, $http, API_URL, $q) {
|
2013-09-01 02:59:35 +00:00
|
|
|
|
2013-09-01 03:35:53 +00:00
|
|
|
$scope.isMember = function(user, group){
|
2013-09-01 23:23:16 +00:00
|
|
|
return ~(group.members.indexOf(user._id));
|
2013-09-01 03:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
2013-09-01 02:59:35 +00:00
|
|
|
// The user may not visit the public guilds, personal guilds, and tavern pages. So
|
|
|
|
|
// we defer loading them to the html until they've clicked the tabs
|
|
|
|
|
var partyQ = $q.defer(),
|
|
|
|
|
guildsQ = $q.defer(),
|
|
|
|
|
publicQ = $q.defer(),
|
|
|
|
|
tavernQ = $q.defer();
|
|
|
|
|
|
|
|
|
|
$scope.groups = {
|
|
|
|
|
party: partyQ.promise,
|
|
|
|
|
guilds: guildsQ.promise,
|
|
|
|
|
public: publicQ.promise,
|
|
|
|
|
tavern: tavernQ.promise
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// But we don't defer triggering Party, since we always need it for the header if nothing else
|
|
|
|
|
Groups.query({type:'party'}, function(_groups){
|
|
|
|
|
partyQ.resolve(_groups[0]);
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Note the _.once() to make sure it can never be called again
|
|
|
|
|
$scope.fetchGuilds = _.once(function(){
|
|
|
|
|
$('#loading-indicator').show();
|
|
|
|
|
Groups.query({type:'guilds'}, function(_groups){
|
|
|
|
|
guildsQ.resolve(_groups);
|
|
|
|
|
$('#loading-indicator').hide();
|
|
|
|
|
})
|
|
|
|
|
Groups.query({type:'public'}, function(_groups){
|
|
|
|
|
publicQ.resolve(_groups);
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$scope.fetchTavern = _.once(function(){
|
|
|
|
|
$('#loading-indicator').show();
|
|
|
|
|
Groups.query({type:'tavern'}, function(_groups){
|
|
|
|
|
$('#loading-indicator').hide();
|
|
|
|
|
tavernQ.resolve(_groups[0]);
|
|
|
|
|
})
|
2013-08-31 21:47:03 +00:00
|
|
|
});
|
2013-09-01 02:59:35 +00:00
|
|
|
|
2013-09-01 15:33:39 +00:00
|
|
|
$scope.invitee = '';
|
|
|
|
|
$scope.invite = function(group, uuid){
|
|
|
|
|
group.$invite({uuid:uuid}, function(){
|
|
|
|
|
$scope.invitee = '';
|
2013-09-02 00:24:44 +00:00
|
|
|
alert("User invited to group");
|
2013-09-01 15:33:39 +00:00
|
|
|
});
|
|
|
|
|
}
|
2013-08-30 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
|
2013-09-01 23:23:16 +00:00
|
|
|
.controller('ChatCtrl', ['$scope', 'Groups', function($scope, Groups){
|
|
|
|
|
$scope._chatMessage = '';
|
|
|
|
|
$scope.postChat = function(group, message){
|
|
|
|
|
if (_.isEmpty(message)) return
|
|
|
|
|
$('.chat-btn').addClass('disabled');
|
|
|
|
|
group.$postChat({message:message}, function(data){
|
|
|
|
|
$scope._chatMessage = '';
|
|
|
|
|
group.chat = data.chat;
|
|
|
|
|
$('.chat-btn').removeClass('disabled');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}])
|
|
|
|
|
|
2013-08-30 00:18:39 +00:00
|
|
|
.controller("GuildsCtrl", ['$scope', 'Groups',
|
|
|
|
|
function($scope, Groups) {
|
|
|
|
|
$scope.type = 'guild';
|
|
|
|
|
$scope.text = 'Guild';
|
2013-09-01 03:35:53 +00:00
|
|
|
|
2013-09-01 02:59:35 +00:00
|
|
|
$scope.join = function(group){
|
2013-09-01 03:35:53 +00:00
|
|
|
group.$join(function(saved){
|
|
|
|
|
//$scope.groups.guilds.push(saved);
|
|
|
|
|
alert('Joined guild, refresh page to see changes')
|
|
|
|
|
})
|
|
|
|
|
}
|
2013-09-01 02:59:35 +00:00
|
|
|
|
2013-09-01 03:35:53 +00:00
|
|
|
$scope.leave = function(group){
|
|
|
|
|
group.$leave();
|
|
|
|
|
// var i = _.find($scope.groups.guilds, {_id:group._id});
|
|
|
|
|
// if (~i) $scope.groups.guilds.splice(i, 1);
|
|
|
|
|
alert('Left guild, refresh page to see changes')
|
2013-09-01 02:59:35 +00:00
|
|
|
}
|
2013-08-30 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
|
2013-09-02 00:24:44 +00:00
|
|
|
.controller("PartyCtrl", ['$scope', 'Groups', 'User',
|
|
|
|
|
function($scope, Groups, User) {
|
2013-08-30 00:18:39 +00:00
|
|
|
$scope.type = 'party';
|
|
|
|
|
$scope.text = 'Party';
|
2013-09-01 02:59:35 +00:00
|
|
|
$scope.group = $scope.groups.party;
|
2013-09-01 15:33:39 +00:00
|
|
|
$scope.join = function(party){
|
|
|
|
|
// workaround since group isn't currently a resource, this won't get saved to the server
|
|
|
|
|
var group = new Groups({_id: party.id, name: party.name});
|
|
|
|
|
group.$join();
|
|
|
|
|
}
|
2013-09-02 00:24:44 +00:00
|
|
|
$scope.leave = function(group){
|
|
|
|
|
group.$leave(function(){
|
|
|
|
|
$parent.groups.party = {}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
$scope.reject = function(){
|
|
|
|
|
User.user.invitations.party = undefined;
|
|
|
|
|
User.log({op:'set',data:{'invitations.party':{}}});
|
|
|
|
|
}
|
2013-08-30 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
.controller("TavernCtrl", ['$scope', 'Groups',
|
|
|
|
|
function($scope, Groups) {
|
2013-09-01 02:59:35 +00:00
|
|
|
$scope.group = $scope.groups.tavern;
|
2013-08-30 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
])
|