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
+34 -2
View File
@@ -1,7 +1,7 @@
"use strict";
habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'API_URL', '$q',
function($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, User) {
$scope.isMember = function(user, group){
return ~(group.members.indexOf(user._id));
@@ -53,6 +53,36 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
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) {
$scope.type = 'guild';
$scope.text = 'Guild';
$scope.newGroup = new Groups({type:'guild', privacy:'private'});
$scope.join = function(group){
group.$join(function(saved){
@@ -95,6 +126,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
function($scope, Groups, User) {
$scope.type = 'party';
$scope.text = 'Party';
$scope.newGroup = new Groups({type:'party'});
$scope.group = $scope.groups.party;
$scope.join = function(party){
// workaround since group isn't currently a resource, this won't get saved to the server
+8
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) {
Group.findById(req.params.gid, function(err, group){
if(err) return res.json(500, {err:err});
+1 -1
View File
@@ -55,9 +55,9 @@ router.post('/user/buy-gems', auth, user.buyGems);
/* Groups*/
router.get('/groups', auth, groups.getGroups);
router.post('/groups', auth, groups.createGroup);
//TODO:
//GET /groups/:gid (get group)
//POST /groups/:gid (create group)
//PUT /groups/:gid (edit group)
//DELETE /groups/:gid
+6 -7
View File
@@ -1,23 +1,22 @@
form.form-horizontal(x-bind='submit:groupCreate', data-type='{{type}}')
.alert.alert-danger(ng-show='_groupError') {{_groupError}}
form.form-horizontal(ng-submit='create(newGroup)')
.control-group.whatever-options
.control-group
label.control-label(for='new-group-name') {{text}} Name
.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
label.control-label(for='new-group-description') Description
.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"')
.controls
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
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
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
p
small