2013-08-29 02:08:59 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
2013-10-30 21:34:59 +00:00
|
|
|
habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'API_URL', '$q', 'User', 'Members', '$state',
|
|
|
|
|
function($scope, $rootScope, Groups, $http, API_URL, $q, User, Members, $state) {
|
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-09 20:15:57 +00:00
|
|
|
$scope.Members = Members;
|
|
|
|
|
$scope._editing = {group:false};
|
|
|
|
|
|
2013-09-09 21:09:45 +00:00
|
|
|
$scope.save = function(group){
|
2013-10-28 21:21:18 +00:00
|
|
|
if(group._newLeader && group._newLeader._id) group.leader = group._newLeader._id;
|
2013-09-09 21:09:45 +00:00
|
|
|
group.$save();
|
|
|
|
|
group._editing = false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 20:58:38 +00:00
|
|
|
$scope.addWebsite = function(group){
|
|
|
|
|
group.websites.push(group._newWebsite);
|
|
|
|
|
group._newWebsite = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.removeWebsite = function(group, $index){
|
|
|
|
|
group.websites.splice($index,1);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-07 16:45:39 +00:00
|
|
|
// ------ Modals ------
|
|
|
|
|
|
2013-09-07 17:59:49 +00:00
|
|
|
$scope.clickMember = function(uid, forceShow) {
|
|
|
|
|
if (User.user._id == uid && !forceShow) {
|
2013-10-28 05:27:07 +00:00
|
|
|
if ($state.is('tasks')) {
|
|
|
|
|
$state.go('options');
|
2013-09-07 16:45:39 +00:00
|
|
|
} else {
|
2013-10-28 05:27:07 +00:00
|
|
|
$state.go('tasks');
|
2013-09-07 16:45:39 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// We need the member information up top here, but then we pass it down to the modal controller
|
|
|
|
|
// down below. Better way of handling this?
|
|
|
|
|
Members.selectMember(uid);
|
|
|
|
|
$rootScope.modals.member = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-31 16:35:04 +00:00
|
|
|
$scope.removeMember = function(group, member, isMember){
|
2013-10-28 16:10:29 +00:00
|
|
|
var yes = confirm("Do you really want to remove this member from the party?")
|
|
|
|
|
if(yes){
|
2013-10-31 16:35:04 +00:00
|
|
|
group.$removeMember({uuid: member._id});
|
|
|
|
|
if(isMember){
|
2013-11-02 08:52:48 +00:00
|
|
|
_.pull(group.members, member);
|
2013-10-31 16:35:04 +00:00
|
|
|
}else{
|
2013-11-02 08:52:48 +00:00
|
|
|
_.pull(group.invites, member);
|
2013-10-31 16:35:04 +00:00
|
|
|
}
|
2013-10-28 16:10:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-07 16:45:39 +00:00
|
|
|
// ------ Invites ------
|
|
|
|
|
|
2013-10-29 15:50:28 +00:00
|
|
|
$scope.invite = function(group){
|
|
|
|
|
group.$invite({uuid:group.invitee}, function(){
|
|
|
|
|
group.invitee = '';
|
|
|
|
|
}, function(){
|
|
|
|
|
group.invitee = '';
|
2013-09-01 15:33:39 +00:00
|
|
|
});
|
|
|
|
|
}
|
2013-08-30 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
|
2013-09-07 16:45:39 +00:00
|
|
|
.controller("MemberModalCtrl", ['$scope', '$rootScope', 'Members',
|
|
|
|
|
function($scope, $rootScope, Members) {
|
2013-09-09 22:56:46 +00:00
|
|
|
$scope.timestamp = function(timestamp){
|
|
|
|
|
return moment(timestamp).format('MM/DD/YYYY');
|
|
|
|
|
}
|
2013-09-07 16:45:39 +00:00
|
|
|
// We watch Members.selectedMember because it's asynchronously set, so would be a hassle to handle updates here
|
|
|
|
|
$scope.$watch( function() { return Members.selectedMember; }, function (member) {
|
|
|
|
|
$scope.profile = member;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
|
2013-09-07 01:03:44 +00:00
|
|
|
.controller('ChatCtrl', ['$scope', 'Groups', 'User', function($scope, Groups, User){
|
2013-09-01 23:23:16 +00:00
|
|
|
$scope._chatMessage = '';
|
2013-11-04 14:17:09 +00:00
|
|
|
$scope._sending = false;
|
2013-09-08 15:22:03 +00:00
|
|
|
|
2013-09-01 23:23:16 +00:00
|
|
|
$scope.postChat = function(group, message){
|
2013-11-04 14:17:09 +00:00
|
|
|
if (_.isEmpty(message) || $scope._sending) return;
|
|
|
|
|
$scope._sending = true;
|
2013-09-01 23:23:16 +00:00
|
|
|
group.$postChat({message:message}, function(data){
|
|
|
|
|
group.chat = data.chat;
|
2013-11-04 14:17:09 +00:00
|
|
|
$scope._chatMessage = '';
|
|
|
|
|
$scope._sending = false;
|
2013-11-04 14:21:05 +00:00
|
|
|
}, function(err){
|
|
|
|
|
$scope._sending = false;
|
2013-09-01 23:23:16 +00:00
|
|
|
});
|
|
|
|
|
}
|
2013-09-08 15:22:03 +00:00
|
|
|
|
|
|
|
|
$scope.deleteChatMessage = function(group, message){
|
2013-09-18 13:06:51 +00:00
|
|
|
if(message.uuid === User.user.id || (User.user.backer && User.user.backer.admin)){
|
2013-09-08 15:22:03 +00:00
|
|
|
group.$deleteChatMessage({messageId: message.id}, function(){
|
|
|
|
|
var i = _.indexOf(group.chat, message);
|
|
|
|
|
if(i !== -1) group.chat.splice(i, 1);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-07 01:03:44 +00:00
|
|
|
$scope.sync = function(group){
|
|
|
|
|
group.$get();
|
|
|
|
|
}
|
2013-09-08 15:22:03 +00:00
|
|
|
|
2013-09-07 01:03:44 +00:00
|
|
|
$scope.nameTagClasses = function(message){
|
2013-09-13 19:10:47 +00:00
|
|
|
if (!message) return; // fixme what's triggering this?
|
2013-09-07 01:03:44 +00:00
|
|
|
if (message.contributor) {
|
2013-09-07 19:31:36 +00:00
|
|
|
if (message.contributor.match(/npc/i) || message.contributor.match(/royal/i)) {
|
|
|
|
|
return 'label-royal';
|
2013-09-07 01:03:44 +00:00
|
|
|
} else if (message.contributor.match(/champion/i)) {
|
2013-09-07 19:31:36 +00:00
|
|
|
return 'label-champion';
|
2013-09-07 01:03:44 +00:00
|
|
|
} else if (message.contributor.match(/elite/i)) {
|
|
|
|
|
return 'label-success'; //elite
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (message.uuid == User.user.id) {
|
|
|
|
|
return 'label-inverse'; //self
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-01 23:23:16 +00:00
|
|
|
|
|
|
|
|
}])
|
|
|
|
|
|
2013-10-30 21:34:59 +00:00
|
|
|
.controller("GuildsCtrl", ['$scope', 'Groups', 'User', '$rootScope', '$state', '$location',
|
|
|
|
|
function($scope, Groups, User, $rootScope, $state, $location) {
|
2013-11-02 03:15:04 +00:00
|
|
|
$scope.groups = {
|
|
|
|
|
guilds: Groups.myGuilds(),
|
|
|
|
|
"public": Groups.publicGuilds()
|
|
|
|
|
}
|
2013-08-30 00:18:39 +00:00
|
|
|
$scope.type = 'guild';
|
|
|
|
|
$scope.text = 'Guild';
|
2013-09-02 02:08:01 +00:00
|
|
|
$scope.newGroup = new Groups.Group({type:'guild', privacy:'private', leader: User.user._id, members: [User.user._id]});
|
2013-09-02 00:57:01 +00:00
|
|
|
|
|
|
|
|
$scope.create = function(group){
|
2013-10-27 12:03:03 +00:00
|
|
|
if (User.user.balance < 1) return $rootScope.modals.buyGems = true;
|
2013-09-02 00:57:01 +00:00
|
|
|
|
|
|
|
|
if (confirm("Create Guild for 4 Gems?")) {
|
2013-10-30 21:34:59 +00:00
|
|
|
group.$save(function(saved){
|
2013-11-02 09:04:31 +00:00
|
|
|
User.user.balance--;
|
2013-11-01 20:08:36 +00:00
|
|
|
$scope.groups.guilds.push(saved);
|
|
|
|
|
if(saved.privacy === 'public') $scope.groups.public.push(saved);
|
|
|
|
|
$state.go('options.social.guilds.detail', {gid: saved._id});
|
2013-10-27 12:03:03 +00:00
|
|
|
});
|
2013-09-02 00:57:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-09-01 03:35:53 +00:00
|
|
|
|
2013-09-01 02:59:35 +00:00
|
|
|
$scope.join = function(group){
|
2013-09-11 21:16:23 +00:00
|
|
|
// If we're accepting an invitation, we don't have the actual group object, but a faux group object (for performance
|
|
|
|
|
// purposes) {id, name}. Let's trick ngResource into thinking we have a group, so we can call the same $join
|
|
|
|
|
// function (server calls .attachGroup(), which finds group by _id and handles this properly)
|
|
|
|
|
if (group.id && !group._id) {
|
|
|
|
|
group = new Groups.Group({_id:group.id});
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 20:08:36 +00:00
|
|
|
group.$join(function(joined){
|
|
|
|
|
var i = _.findIndex(User.user.invitations.guilds, {id:joined._id});
|
|
|
|
|
if (~i) User.user.invitations.guilds.splice(i,1);
|
|
|
|
|
$scope.groups.guilds.push(joined);
|
2013-11-03 10:58:42 +00:00
|
|
|
if(joined.privacy == 'public'){
|
|
|
|
|
joined._isMember = true;
|
2013-11-03 11:00:57 +00:00
|
|
|
joined.memberCount++;
|
2013-11-03 10:58:42 +00:00
|
|
|
}
|
2013-11-01 20:08:36 +00:00
|
|
|
$state.go('options.social.guilds.detail', {gid: joined._id});
|
2013-09-01 03:35:53 +00:00
|
|
|
})
|
|
|
|
|
}
|
2013-09-01 02:59:35 +00:00
|
|
|
|
2013-09-01 03:35:53 +00:00
|
|
|
$scope.leave = function(group){
|
2013-09-21 14:14:19 +00:00
|
|
|
if (confirm("Are you sure you want to leave this guild?") !== true) {
|
2013-09-18 18:09:35 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2013-11-03 11:12:43 +00:00
|
|
|
group.$leave(function(){
|
2013-11-01 20:08:36 +00:00
|
|
|
$scope.groups.guilds.splice(_.indexOf($scope.groups.guilds, group), 1);
|
|
|
|
|
// remove user from group members if guild is public so that he can re-join it immediately
|
2013-11-03 11:12:43 +00:00
|
|
|
if(group.privacy == 'public' || !group.privacy){ //public guilds with only some fields fetched
|
2013-11-03 10:58:42 +00:00
|
|
|
var i = _.findIndex($scope.groups.public, {_id: group._id});
|
|
|
|
|
if(~i){
|
|
|
|
|
var guild = $scope.groups.public[i];
|
|
|
|
|
guild.memberCount--;
|
|
|
|
|
guild._isMember = false;
|
|
|
|
|
}
|
2013-11-01 20:08:36 +00:00
|
|
|
}
|
|
|
|
|
$state.go('options.social.guilds');
|
2013-10-30 21:34:59 +00:00
|
|
|
});
|
2013-09-01 02:59:35 +00:00
|
|
|
}
|
2013-09-11 14:28:14 +00:00
|
|
|
|
|
|
|
|
$scope.reject = function(guild){
|
2013-09-11 18:08:53 +00:00
|
|
|
var i = _.findIndex(User.user.invitations.guilds, {id:guild.id});
|
2013-09-11 15:07:38 +00:00
|
|
|
if (~i){
|
|
|
|
|
User.user.invitations.guilds.splice(i, 1);
|
|
|
|
|
User.set('invitations.guilds', User.user.invitations.guilds);
|
|
|
|
|
}
|
2013-09-11 14:28:14 +00:00
|
|
|
}
|
2013-08-30 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
|
2013-11-01 20:08:36 +00:00
|
|
|
.controller("PartyCtrl", ['$scope', 'Groups', 'User', '$state',
|
|
|
|
|
function($scope, Groups, User, $state) {
|
2013-08-30 00:18:39 +00:00
|
|
|
$scope.type = 'party';
|
|
|
|
|
$scope.text = 'Party';
|
2013-11-02 03:15:04 +00:00
|
|
|
$scope.group = Groups.party();
|
2013-09-02 02:08:01 +00:00
|
|
|
$scope.newGroup = new Groups.Group({type:'party', leader: User.user._id, members: [User.user._id]});
|
2013-09-02 00:57:01 +00:00
|
|
|
$scope.create = function(group){
|
2013-10-31 16:35:04 +00:00
|
|
|
group.$save(function(newGroup){
|
2013-11-01 20:08:36 +00:00
|
|
|
$scope.group = newGroup;
|
2013-09-02 00:57:01 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-01 15:33:39 +00:00
|
|
|
$scope.join = function(party){
|
2013-09-02 02:08:01 +00:00
|
|
|
var group = new Groups.Group({_id: party.id, name: party.name});
|
2013-09-02 01:31:38 +00:00
|
|
|
// there a better way to access GroupsCtrl.groups.party?
|
2013-10-31 16:35:04 +00:00
|
|
|
group.$join(function(groupJoined){
|
2013-11-01 20:08:36 +00:00
|
|
|
$scope.group = groupJoined;
|
2013-09-02 01:31:38 +00:00
|
|
|
});
|
2013-09-01 15:33:39 +00:00
|
|
|
}
|
2013-10-31 16:35:04 +00:00
|
|
|
|
2013-09-02 00:24:44 +00:00
|
|
|
$scope.leave = function(group){
|
2013-09-18 18:09:35 +00:00
|
|
|
if (confirm("Are you sure you want to leave this party?") !== true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-09-02 01:31:38 +00:00
|
|
|
group.$leave(function(){
|
2013-11-01 20:08:36 +00:00
|
|
|
$scope.group = undefined;
|
2013-09-02 01:31:38 +00:00
|
|
|
});
|
2013-09-02 00:24:44 +00:00
|
|
|
}
|
2013-10-31 16:35:04 +00:00
|
|
|
|
2013-09-02 00:24:44 +00:00
|
|
|
$scope.reject = function(){
|
|
|
|
|
User.user.invitations.party = undefined;
|
|
|
|
|
User.log({op:'set',data:{'invitations.party':{}}});
|
|
|
|
|
}
|
2013-08-30 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
|
2013-09-02 13:47:44 +00:00
|
|
|
.controller("TavernCtrl", ['$scope', 'Groups', 'User',
|
|
|
|
|
function($scope, Groups, User) {
|
2013-11-02 03:15:04 +00:00
|
|
|
$scope.group = Groups.tavern();
|
2013-09-02 13:47:44 +00:00
|
|
|
$scope.rest = function(){
|
|
|
|
|
User.user.flags.rest = !User.user.flags.rest;
|
|
|
|
|
User.log({op:'set',data:{'flags.rest':User.user.flags.rest}});
|
|
|
|
|
}
|
2013-08-30 00:18:39 +00:00
|
|
|
}
|
2013-11-02 08:37:17 +00:00
|
|
|
])
|