Browse Source

/edit page implemented

master
Christian Müller 10 years ago
parent
commit
b078891190
  1. 5
      resources/edit.html
  2. 4
      resources/public/js/publishing.js
  3. 6
      server.js
  4. 12
      src/page.js

5
resources/new.html → resources/edit.html

@ -15,11 +15,12 @@ @@ -15,11 +15,12 @@
<article id="preview" style="flex: none; -webkit-flex: none"></article>
<div class="hidden" id="dashed-line"></div>
<div class="central-element helvetica" style="margin-bottom: 3em">
<form action="/note" autocomplete="off" method="%METHOD%">
<form action="/note" autocomplete="off" method="POST">
<input id="action" value="%METHOD%" type="hidden">
<input id="password" name="password" type="hidden">
<input id="session" name="session" type="hidden" value="%SESSION%" />
<input id="signature" name="signature" type="hidden" />
<textarea id="note" name="note">Loading...</textarea>
<textarea id="note" name="note">%CONTENT%</textarea>
<fieldset class="hidden" id="input-elems">
<input class="ui-elem" id="plain-password" name="plain-password" placeholder="Password for editing" type="text">&nbsp;
<input class="button ui-elem" id="publish-button" type="submit" value="Publish">

4
resources/public/js/publishing.js

@ -16,7 +16,7 @@ function md2html(input) { @@ -16,7 +16,7 @@ function md2html(input) {
function onLoad() {
$note = $("note");
$action = document.getElementsByTagName("form")[0].method;
$action = $("action").value;
$preview = $("preview");
$plain_password = $("plain-password");
$proposed_title = $("proposed-title");
@ -32,7 +32,7 @@ function onLoad() { @@ -32,7 +32,7 @@ function onLoad() {
$preview.innerHTML = md2html(content);
}, delay);
};
if ($action.value == "update") updatePreview();
if ($action == "UPDATE") updatePreview();
else $note.value = "";
$note.onkeyup = updatePreview;
$("publish-button").onclick = function(e) {

6
server.js

@ -39,6 +39,12 @@ app.get("/:year/:month/:day/:title", function (req, res) { @@ -39,6 +39,12 @@ app.get("/:year/:month/:day/:title", function (req, res) {
.then(id => res.redirect("/" + id));
});
app.get(/\/([a-z0-9]+\/edit)/, function (req, res) {
var link = req.params["0"].replace("/edit", "");
storage.getNote(link).then(note =>
res.send(page.editNotePage(getTimeStamp() + md5(Math.random()), note)));
});
app.get(/\/([a-z0-9]+\/export)/, function (req, res) {
var link = req.params["0"].replace("/export", "");
res.set({ 'Content-Type': 'text/plain', 'Charset': 'utf-8' });

12
src/page.js

@ -2,7 +2,7 @@ var marked = require("marked"); @@ -2,7 +2,7 @@ var marked = require("marked");
var fs = require("fs");
var pageTemplate = fs.readFileSync("resources/template.html", "utf-8");
var newNoteTemplate = fs.readFileSync("resources/new.html", "utf-8");
var editTemplate = fs.readFileSync("resources/edit.html", "utf-8");
var buildPage = (id, title, content) => pageTemplate
.replace("%TITLE%", title)
.replace(/%LINK%/g, id)
@ -10,6 +10,12 @@ var buildPage = (id, title, content) => pageTemplate @@ -10,6 +10,12 @@ var buildPage = (id, title, content) => pageTemplate
module.exports.buildNote = note => buildPage(note.id, note.title, marked(note.text));
module.exports.newNotePage = session => newNoteTemplate
module.exports.newNotePage = session => editTemplate
.replace("%METHOD%", "POST")
.replace("%SESSION%", session);
.replace("%SESSION%", session)
.replace("%CONTENT%", "Loading...");
module.exports.editNotePage = (session, note) => editTemplate
.replace("%METHOD%", "UPDATE")
.replace("%SESSION%", session)
.replace("%CONTENT%", note.text);
Loading…
Cancel
Save