Created
August 7, 2014 02:10
-
-
Save brianherman/ec843cd93bb497b198f6 to your computer and use it in GitHub Desktop.
callbacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
etherpad.createAuthorIfNotExistsFor(author_args, function(error, a) { | |
if (error) console.error('error creating author' + error.message) | |
else { | |
console.log("author created with ID: " + a.authorID) | |
var group_args = { | |
groupMapper: req.user.id | |
} | |
// Create an group if it doesnt exist or get an author from the etherpad instance | |
etherpad.createGroupIfNotExistsFor(group_args, function(error, g) { | |
if (error) console.error('error creating group' + error.message) | |
else { | |
console.log("groupid " + g.groupID) | |
var pad_args = { | |
authorID: a.authorID, | |
groupID: g.groupID, | |
padName: req.param('pad_name') | |
} | |
// Create a group pad based on the groupID recieved from the etherpad instance and authorID | |
etherpad.createGroupPad(pad_args, function(error, data) { | |
if (error) { | |
console.error('error creating pad' + error.message) | |
if (error.message === 'padName does already exist') { | |
res.render('error', { | |
message: 'pad already exists with that name' | |
}) | |
} | |
} else { | |
//set the password on the pad based on the request | |
var password_args = { | |
padID: g.groupID + '$' + req.param('pad_name'), | |
password: req.param('password') | |
} | |
etherpad.setPassword(password_args, function(error, data) { | |
if (error) { | |
console.error('error creating password' + error.message) | |
} | |
}) | |
console.log("created pad with name" + req.param('pad_name')) | |
// create a session so the etherpad instance will pick it up using the jquery code in the view | |
var session_args = { | |
authorID: a.authorID, | |
groupID: g.groupID, | |
validUntil: (Date.now() + (1800)) //create a session for 30 minutes | |
} | |
etherpad.createSession(session_args, function(error, data) { | |
if (error) console.error('error creating session' + error.message) | |
else { | |
//create a database record based on the pad | |
db.Pad.create({ | |
name: req.param('pad_name'), | |
group: g.groupID, | |
author: a.authorID, | |
password: req.param('password') | |
}).success(function(pads) { | |
console.log("database record created" + pads.values) | |
}) | |
//set the session cookie | |
res.cookie('sessionID', data.sessionID, { | |
domain: '.mooo.com', | |
path: '/' | |
}) | |
// show the view | |
res.redirect('/pad/' + req.param('pad_name') + '/view') | |
console.log("session created" + data.sessionID) | |
} | |
}) | |
} | |
}) | |
} | |
}) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment