api: createGroup

This commit is contained in:
Tyler Renelle
2013-09-01 20:50:36 -04:00
parent ac992ea865
commit 010995b38b
4 changed files with 49 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
"use strict"; "use strict";
habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'API_URL', '$q', habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'API_URL', '$q', 'User',
function($scope, $rootScope, Groups, $http, API_URL, $q) { function($scope, $rootScope, Groups, $http, API_URL, $q, User) {
$scope.isMember = function(user, group){ $scope.isMember = function(user, group){
return ~(group.members.indexOf(user._id)); return ~(group.members.indexOf(user._id));
@@ -53,6 +53,36 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
alert("User invited to group"); alert("User invited to group");
}); });
} }
$scope.create = function(group){
group.leader = User.user._id;
group.members = [User.user._id];
if (group.type === 'party') {
group.$save(function(){
location.reload();
});
}
if (User.user.balance >= 1) {
$rootScope.modals.moreGems = true;
// $('#more-gems-modal').modal('show');
}
if (confirm("Create Guild for 4 Gems?")) {
if (group.type === 'guild') {
group.privacy = group.privacy || 'public';
}
group.balance = 1;
group.$save(function(){
User.user.balance--;
User.log({op:'set', data:{'balance':user.balance}});
window.setTimeout(function(){window.location.href='/';}, 500)
})
}
}
} }
]) ])
@@ -74,6 +104,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
function($scope, Groups) { function($scope, Groups) {
$scope.type = 'guild'; $scope.type = 'guild';
$scope.text = 'Guild'; $scope.text = 'Guild';
$scope.newGroup = new Groups({type:'guild', privacy:'private'});
$scope.join = function(group){ $scope.join = function(group){
group.$join(function(saved){ group.$join(function(saved){
@@ -95,6 +126,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
function($scope, Groups, User) { function($scope, Groups, User) {
$scope.type = 'party'; $scope.type = 'party';
$scope.text = 'Party'; $scope.text = 'Party';
$scope.newGroup = new Groups({type:'party'});
$scope.group = $scope.groups.party; $scope.group = $scope.groups.party;
$scope.join = function(party){ $scope.join = function(party){
// workaround since group isn't currently a resource, this won't get saved to the server // workaround since group isn't currently a resource, this won't get saved to the server

View File

@@ -83,6 +83,14 @@ api.getGroups = function(req, res, next) {
}) })
}; };
api.createGroup = function(req, res, next) {
var group = new Group(req.body);
group.save(function(err, saved){
if (err) return res.json(500,{err:err});
res.json(saved);
})
}
api.attachGroup = function(req, res, next) { api.attachGroup = function(req, res, next) {
Group.findById(req.params.gid, function(err, group){ Group.findById(req.params.gid, function(err, group){
if(err) return res.json(500, {err:err}); if(err) return res.json(500, {err:err});

View File

@@ -55,9 +55,9 @@ router.post('/user/buy-gems', auth, user.buyGems);
/* Groups*/ /* Groups*/
router.get('/groups', auth, groups.getGroups); router.get('/groups', auth, groups.getGroups);
router.post('/groups', auth, groups.createGroup);
//TODO: //TODO:
//GET /groups/:gid (get group) //GET /groups/:gid (get group)
//POST /groups/:gid (create group)
//PUT /groups/:gid (edit group) //PUT /groups/:gid (edit group)
//DELETE /groups/:gid //DELETE /groups/:gid

View File

@@ -1,23 +1,22 @@
form.form-horizontal(x-bind='submit:groupCreate', data-type='{{type}}') form.form-horizontal(ng-submit='create(newGroup)')
.alert.alert-danger(ng-show='_groupError') {{_groupError}}
.control-group.whatever-options .control-group.whatever-options
.control-group .control-group
label.control-label(for='new-group-name') {{text}} Name label.control-label(for='new-group-name') {{text}} Name
.controls .controls
input#new-group-name.input-medium.option-content(required, type='text', placeholder='{{text}} Name', value='{{_new.group.name}}') input#new-group-name.input-medium.option-content(required, type='text', placeholder='{{text}} Name', ng-model='newGroup.name')
.control-group .control-group
label.control-label(for='new-group-description') Description label.control-label(for='new-group-description') Description
.controls .controls
textarea#new-group-description.option-content(cols='3', placeholder='Description') {{_new.group.description}} textarea#new-group-description.option-content(cols='3', placeholder='Description', ng-model='newGroup.description')
.control-group(ng-show='type=="guild"') .control-group(ng-show='type=="guild"')
.controls .controls
label.radio label.radio
input(type='radio', name='new-group-privacy', checked='{{"public"==_new.group.privacy}}') input(type='radio', name='new-group-privacy', value='public', ng-model='newGroup.privacy')
| Public | Public
label.radio label.radio
input(type='radio', name='new-group-privacy', checked='{{"private"==_new.group.privacy}}') input(type='radio', name='new-group-privacy', value='private', ng-model='newGroup.privacy')
| Invite Only | Invite Only
input.btn(type='submit', ng-disabled='!_new.group.privacy && !_new.group.name', value='Create') input.btn(type='submit', ng-disabled='!newGroup.privacy && !newGroup.name', value='Create')
span.gem-cost 4 Gems span.gem-cost 4 Gems
p p
small small