src/view/admin/components/editor.lisp

DOWNLOAD
(defpackage murja.view.admin.components.editor
  (:use :cl :binding-arrows :spinneret )
  (:export :editor)
  (:import-from :murja.view.admin.components.tag-script :tags-component-frontend)
  (:import-from :murja.model.post :tags :article :post-title :post-hidden? :post-unlisted?))

(in-package :murja.view.admin.components.editor)

(defun tag-component (post)
  (with-html
    (:div.tag-component
     (:select :multiple t :class "tag-select" :id "tag-select"
       (dolist (tag (tags post))
	 (:option :value tag tag)))
     (:button :id "add-tag" "Add tag")
     (:button :id "remove-tag" "Remove tag")

     (:script
      (:raw (tags-component-frontend))))))

(defun post-meta (post)
  (with-html
    (:div 
     (:label "Title: "
	     (:input :id "title" :name "title" :value (post-title post) :type "text"))
     (:label "Hidden: "
	     (:input :id "hidden" :name "hidden" :checked (post-hidden? post) :type "checkbox"))
     (:label "Unlisted: "
	     (:input :id "unlisted" :name "unlisted" :checked (post-unlisted? post) :type "checkbox")))))

(defun header (post)
  (with-html
    (:div.editor-top 
     (post-meta post)
     (tag-component post))))

(defun editor (post)
  (with-html
    ;; TODO: throw this into parenscript?
    (:script (:raw
	      (format nil "
document.addEventListener('DOMContentLoaded', _ => {
    var editor = ace.edit('editor-post-content',
{theme: 'ace/theme/monokai',
 mode: 'ace/mode/html'});

    editor.setKeyboardHandler('ace/keyboard/emacs');

    editor.setValue(~s);
});" (article post))))

    (header post)
    (:div 
     (:div :id "editor-post-content"))))