Add a preview function and an help on the edit note page.
This commit is contained in:
parent
86e10b3c03
commit
ab80cf5ef9
|
@ -13,7 +13,7 @@
|
|||
; Operations
|
||||
new-note update-note remove-note
|
||||
get-note-by-name get-all-notes get-public-notes
|
||||
format-note
|
||||
format-note format-note-content
|
||||
; Init repo
|
||||
note-init-repository
|
||||
)
|
||||
|
@ -119,6 +119,9 @@
|
|||
|
||||
; Format a note
|
||||
(define (format-note nt)
|
||||
(format-note-content (notepadnote-content nt)))
|
||||
; Format a note content
|
||||
(define (format-note-content cnt)
|
||||
; Recursive parsing function
|
||||
(define (collect parsed)
|
||||
; Recursively apply the parsing:
|
||||
|
@ -188,6 +191,9 @@
|
|||
))))
|
||||
;
|
||||
(collect
|
||||
(scrib:read-inside
|
||||
(open-input-string
|
||||
(notepadnote-content nt)))))
|
||||
(with-handlers
|
||||
(( exn:fail?
|
||||
(lambda (e) (list (exn-message e))) ))
|
||||
(scrib:read-inside
|
||||
(open-input-string
|
||||
cnt)))))
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
pages:notepad:page-show
|
||||
pages:notepad:page-edit
|
||||
pages:notepad:page-delete
|
||||
pages:notepad:preview
|
||||
pages:notepad:media-list
|
||||
pages:notepad:media-show
|
||||
pages:notepad:media-new
|
||||
|
@ -178,6 +179,7 @@
|
|||
( (pages:template
|
||||
#:title (string-append "Édition de la note '" page-name "'")
|
||||
#:author (user-name connected-usr)
|
||||
#:scripts '("/scripts/notepad.js")
|
||||
#:content
|
||||
; Display the page as a form
|
||||
`(article
|
||||
|
@ -186,21 +188,53 @@
|
|||
"")
|
||||
(form ((action ,(note-link 'edit page-name))
|
||||
(method "post"))
|
||||
(label ((for "pagename")) "Nom de la note") (br)
|
||||
(input ((id "pagename")(name "pagename")(type "text")(value ,page-name))) (br)
|
||||
(label ((for "pagetitle")) "Titre de la note") (br)
|
||||
(input ((id "pagetitle")(name "pagetitle")(type "text")(value ,title))) (br)
|
||||
(input ((id "pagepublic")(name "pagepublic")(type "checkbox")(value "on")
|
||||
,@(if public? '((checked "true")) '())))
|
||||
(label ((for "pagepublic")) "Note publique") (br)
|
||||
(label ((for "pagecontent")) "Contenu de la note") (br)
|
||||
(textarea ((rows "10")(cols "80")(id "pagecontent")(name "pagecontent"))
|
||||
,content) (br)
|
||||
(input ((type "submit")
|
||||
(value "Sauver et quitter l'édition")))
|
||||
(input ((type "submit")(formaction ,(note-link 'edit page-name "?continue=t"))
|
||||
(value "Sauver et continuer l'édition")))
|
||||
)))
|
||||
(label ((for "pagename")) "Nom (URL)") " "
|
||||
(input ((id "pagename")(name "pagename")(type "text")(value ,page-name))) (br)
|
||||
(label ((for "pagetitle")) "Titre") " "
|
||||
(input ((id "pagetitle")(name "pagetitle")(type "text")(value ,title))) (br)
|
||||
(label ((for "pagepublic")) "Publique")
|
||||
(input ((id "pagepublic")(name "pagepublic")(type "checkbox")(value "on")
|
||||
,@(if public? '((checked "true")) '()))) (br)
|
||||
(textarea ((rows "10")(cols "80")(id "pagecontent")(name "pagecontent"))
|
||||
,content) (br)
|
||||
(input ((type "submit")
|
||||
(value "Sauver et quitter l'édition")))
|
||||
(input ((type "submit")(formaction ,(note-link 'edit page-name "?continue=t"))
|
||||
(value "Sauver et continuer l'édition")))
|
||||
(input ((type "button")(onclick ,(string-append "window.location.href='" (note-link 'show page-name) "';"))
|
||||
(value "Annuler les modifications")))
|
||||
)
|
||||
(hr)
|
||||
(section
|
||||
(h2 "Aperçu")
|
||||
(button ((onclick "notepadPreview();")) "Afficher l'aperçu")
|
||||
(button ((onclick "notepadClearPreview();")) "Effacer l'aperçu")
|
||||
(hr)
|
||||
(div ((id "preview")) ))
|
||||
(hr)
|
||||
(section
|
||||
(h2 "Syntaxe")
|
||||
"Le bloc-note utilise une syntaxe proche de celle de " (a ((href "https://docs.racket-lang.org/scribble/index.html")) "Scribble") ". " (br)
|
||||
"Pour introduire un passage à la ligne, il faut sauter une ligne. " (br)
|
||||
,@(map
|
||||
(lambda (x)
|
||||
`(div (code "@" ,(car x) ,(if (cadr x) (string-append "[" (cadr x) "]") "")
|
||||
"{" ,(caddr x) "}") " " ,@(cadddr x)))
|
||||
'(("link" "to" "desc" ("Un lien vers l'addresse " (code "to") " intitulé " (code "desc") "."))
|
||||
("image" "path" "alt" ("Une image située à l'addresse " (code "path") " avec le texte alternatif " (code "alt") "."))
|
||||
("strong" #f "text" ("Affiche le texte " (code "text") " en gras."))
|
||||
("str" #f "text" ("Synonyme de " (code "strong") "."))
|
||||
("emphase" #f "text" ("Affiche le texte " (code "text") " en italique."))
|
||||
("emp" #f "text" ("Synonyme de " (code "emphase") "."))
|
||||
("section" #f "title" ("Démarre une nouvelle section de niveau 1 intitulée " (code "title") "."))
|
||||
("subsection" #f "title" ("Démarre une nouvelle section de niveau 2 intitulée " (code "title") "."))
|
||||
("subsubsection" #f "title" ("Démarre une nouvelle section de niveau 3 intitulée " (code "title") "."))
|
||||
("paragraph" "justify" "text" ("Démarre un paragraphe contenant " (code "text") " avec la justification " (code "justify")
|
||||
" (optionnelle, valeurs possibles: " (code "left") ", " (code "right") " ou " (code "center") "). "))
|
||||
("para" #f "text" ("Synonyme de " (code "paragraph") "."))
|
||||
))
|
||||
)
|
||||
))
|
||||
param))
|
||||
( (and page connected-usr secured? (eq? method 'post))
|
||||
(define continue? (equal? "t" (weblet-parameter-ref param 'continue #f)))
|
||||
|
@ -278,6 +312,24 @@
|
|||
; No such page
|
||||
(pages:notepad:error param 'not-found))))
|
||||
|
||||
; /notes/preview
|
||||
; Format and return the content
|
||||
; Used on the edition page to preview the content before saving it.
|
||||
(define pages:notepad:preview
|
||||
(html-page-weblet
|
||||
#:error-code 200
|
||||
#:body
|
||||
(lambda (param)
|
||||
(define connected-usr (get-user param))
|
||||
(define secured? (check-secured? param))
|
||||
(define can-edit? (and connected-usr secured?))
|
||||
(define content (weblet-parameter-ref param 'pagecontent #f))
|
||||
(if (and can-edit? content)
|
||||
`(article
|
||||
,@(format-note-content content))
|
||||
""))))
|
||||
|
||||
|
||||
; Media
|
||||
|
||||
; Link to a media with a given name
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
function notepadPreview() {
|
||||
notepadClearPreview()
|
||||
var content = document.getElementById('pagecontent').value
|
||||
var request = new XMLHttpRequest();
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState == XMLHttpRequest.DONE && request.status == 200) {
|
||||
document.getElementById('preview').innerHTML = request.responseText;
|
||||
}
|
||||
};
|
||||
request.open('POST', '/notes/preview');
|
||||
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
var params = new URLSearchParams()
|
||||
params.append('pagecontent', content)
|
||||
request.send(params.toString());
|
||||
}
|
||||
|
||||
function notepadClearPreview() {
|
||||
document.getElementById('preview').innerHTML = '';
|
||||
}
|
Loading…
Reference in New Issue