2013-08-29 02:08:59 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
2013-08-30 00:18:39 +00:00
|
|
|
habitrpg
|
|
|
|
|
|
2013-09-01 02:59:35 +00:00
|
|
|
.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'API_URL', '$q',
|
|
|
|
|
function($scope, $rootScope, Groups, $http, API_URL, $q) {
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
//$scope._chatMessage = '';
|
2013-08-31 23:14:58 +00:00
|
|
|
$scope.postChat = function(group, message){
|
2013-09-01 00:52:41 +00:00
|
|
|
//FIXME ng-model makes this painfully slow! using jquery for now, which is really non-angular-like
|
|
|
|
|
message = $('.chat-textarea').val();
|
2013-08-31 23:14:58 +00:00
|
|
|
if (_.isEmpty(message)) return
|
|
|
|
|
$('.chat-btn').addClass('disabled');
|
2013-09-01 02:59:35 +00:00
|
|
|
group.$postChat({message:message}, function(data){
|
|
|
|
|
//$scope._chatMessage = '';
|
|
|
|
|
$('.chat-textarea').val('');
|
|
|
|
|
group.chat = data.chat;
|
|
|
|
|
$('.chat-btn').removeClass('disabled');
|
|
|
|
|
});
|
2013-08-31 23:14:58 +00:00
|
|
|
}
|
2013-08-30 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
.controller("GuildsCtrl", ['$scope', 'Groups',
|
|
|
|
|
function($scope, Groups) {
|
|
|
|
|
$scope.type = 'guild';
|
|
|
|
|
$scope.text = 'Guild';
|
2013-09-01 02:59:35 +00:00
|
|
|
$scope.join = function(group){
|
|
|
|
|
|
|
|
|
|
}
|
2013-08-30 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
.controller("PartyCtrl", ['$scope', 'Groups',
|
|
|
|
|
function($scope, Groups) {
|
|
|
|
|
$scope.type = 'party';
|
|
|
|
|
$scope.text = 'Party';
|
2013-09-01 02:59:35 +00:00
|
|
|
$scope.group = $scope.groups.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
|
|
|
}
|
|
|
|
|
])
|