Skip to content

Commit

Permalink
'Create pad' page
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmehall committed Oct 13, 2010
1 parent 69b2ab0 commit 18ebd8a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
21 changes: 21 additions & 0 deletions create_pad.html
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form id='createform' method='POST' action='?'>
<p><strong>Pad name:</strong><br/> http://<span id='hostname'>&lt;host&gt;</span>/<input id='padname' type='text' name='padname' /><input type='submit' name='create' value='Create' /> </p>
</form>
<script>
document.getElementById('hostname').innerHTML = document.location.host
var docid = document.location.pathname.slice(1)
if (docid == ''){
docid = new Date().getTime()
}
document.getElementById('padname').value = docid
document.getElementById('createform').onsubmit = function(){
this.action = '/'+document.getElementById('padname').value
}
</script>
</body>
</html>
22 changes: 18 additions & 4 deletions server.coffee
Expand Up @@ -11,7 +11,8 @@ common = require('./servercommon')
servercore = require('./servercore')
[debug, warn, error] = [common.debug, common.warn, common.error]

serveStaticFile = (res, path, contentType) ->
serveStaticFile = (res, path, contentType, code) ->
code ?= 200
fs.readFile __dirname + path, (err, data) ->
if (err)
serve404(res, path, err)
Expand All @@ -36,8 +37,21 @@ server = http.createServer (req, res) ->
serve404(res, path, "Invalid file")
else if path.indexOf('.js') != -1
serveStaticFile(res, path, 'text/javascript')
else if path == '/'
serveStaticFile(res, '/create_pad.html', 'text/html')
else
serveStaticFile(res, '/pad.html', 'text/html')
getDocument path, (doc) ->
if req.method == 'POST'
if not doc
createDocument(path)
# Redirect back to GET version
res.writeHead(302, {'Location': path})
res.write("Creating...", 'utf8')
res.end()
else if doc
serveStaticFile(res, '/pad.html', 'text/html')
else
serveStaticFile(res, '/create_pad.html', 'text/html', 404)



Expand All @@ -61,12 +75,12 @@ getDocument = (docid, callback) ->
if doc
callback(doc)
else
callback(createDocument(docid))
callback(false)

persistDir = 'db'

checkDocName = (name) ->
(/^\/[a-zA-Z0-9-_.]+$/).test(name)
(/^\/[a-zA-Z0-9-_.]*$/).test(name)

saveDocument = (doc, callback) ->
if not checkDocName(doc.id)
Expand Down

0 comments on commit 18ebd8a

Please sign in to comment.