!7 static S text, title; concept Text { S conceptID; S title; S text; S by; } p { db(); indexConceptField(Text, 'conceptID); indexConceptField(Text, 'by); load("text"); load("title"); if (isMainProgram()) serveHttpAndOpenBrowser(); } synchronized html { uri = dropPrefix("/", uri); if (possibleGlobalID(uri)) { S id = uri; Text t = findConcept(Text, conceptID := id); ret t == null ? "Text with ID " + id + " not found" : p(ahref(botLink(), "<< back")) + h3(t.conceptID + " - " + dynamize(or2(t.title, "Untitled"))) + textFormat(t.text) + p("by " + t.by); } S newTitle = params.get("title"); if (newTitle != null) { title = newTitle; save("title"); } S newText = params.get("text"); if (newText != null) { text = newText; save("text"); } S user = cookieConcept(); S msg = ""; if (nempty(params.get("publish"))) { Text t = uniq_sync(Text, +title, +text, by := user); if (empty(t.conceptID)) cset(t, conceptID := aGlobalID()); msg = "Published as: " + t.conceptID; } S list = p("Published texts: " + join(", ", map(func(Text t) { ahref(selfLink(t.conceptID), t.conceptID) }, list(Text)))); ret (empty(msg) ? "" : p(msg)) + list + p("You are: " + or2(user, "?")) + hpostform([[ Title:
#TEXT#<>


]].replace("#TITLE#<>", htmlencode(title)) .replace("#TEXT#<>", htmlencode(text)), onSubmit := "if (editor) text.value = editor.getValue(); return true;"); } sS textFormat(S text) { ret div(pre(dynamize(text)), style := "padding-left: 1em; padding-top: 0.5em; padding-bottom: 0.5em; background-color: #EEEEEE; border-style: solid; border-color: #666666; border-width: 1px 0px 1px 0px;"); }