"use strict"; terminal.setEcho(false); core.register("onInput", function(input) { if (input == "new page") { editPage("new", ""); } else if (input == "submit") { submitNewPost().then(renderBlog); } else if (input == "home") { renderIndex(); } else if (input.substring(0, 5) == "open:") { var title = input.substring(5); database.get(title).then(function(contents) { editPage(title, contents); }); } else if (input.substring(0, 7) == "delete:") { terminal.clear(); var title = input.substring(7); terminal.print("Are you sure you want to delete page '", title, "'?"); terminal.print({command: "confirmDelete:" + title, value: "delete it"}); terminal.print({command: "home", value: "cancel"}); } else if (input.substring(0, 14) == "confirmDelete:") { var title = input.substring(14); database.remove(title).then(renderIndex); } }); function renderIndex() { terminal.clear(); terminal.print("Editor Test"); if (core.user.credentials.permissions.authenticated) { terminal.print({command: "new page"}); } database.getAll().then(function(entries) { for (var i = 0; i < entries.length; i++) { if (core.user.credentials.permissions.authenticated) { terminal.print( "* ", {style: "font-weight: bold", value: {command: "open:" + entries[i], value: entries[i]}}, " (", {command: "delete:" + entries[i], value: "x"}, ")"); } else { terminal.print( "* ", {style: "font-weight: bold", value: {command: "open:" + entries[i], value: entries[i]}}); } } }); } var gPage = null; core.register("onWindowMessage", function(event) { if (event.message.ready) { terminal.postMessageToIframe("iframe", {title: gPage.title, contents: gPage.contents}); } else if (event.message.index) { renderIndex(); } else { database.set(event.message.title, event.message.contents).then(function() { renderIndex(); }); } }); function editPage(title, contents) { gPage = {title: title, contents: contents}; terminal.clear(); terminal.print({iframe: `
`, name: "iframe", style: "width: 100%; border: 0; height: 600px"}); } renderIndex();