summaryrefslogtreecommitdiff
path: root/lisp/service/testimonials-service.lisp
blob: 97133f7a987a6123c4cdf64ee802b6b39e3e9c4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(declaim (optimize (speed 0) (safety 3) (debug 3)))

(in-package :bogenherr)

(defclass testimonials-service (rest-service)
  ((title :initarg :title
          :initform nil
          :accessor title))
  (:documentation ""))

(defun testimonials-json ()
  (with-noauth (instance testimonials-service)
    (setf (title instance) "Testimonials")))

(defclass testimonials/view-service (testimonials-service)
  ((content :initarg :content
            :initform nil
            :accessor content)
   (form :initarg :form
         :initform nil
         :accessor form)
   (admin-p :initarg :admin-p
            :initform t
            :accessor admin-p)
   (location-p :initform nil))
  (:documentation ""))

(defun testimonials-view-json ()
  (with-noauth (instance testimonials/view-service)
    (with-valid-user (user "testimonials-modify")
        (setf (admin-p instance) nil)
      (setf (admin-p instance) t))
    (with-bogenherr-database
      (let* ((general-pkg (make-instance 'general-pkg))
             (testimonials (get-testimonials general-pkg)))
        (when testimonials
          (setf (content instance) (content testimonials)))))))

(defclass testimonials/modify-service (testimonials/view-service auth-service)
  ()
  (:documentation ""))

(defun testimonials-modify-json ()
  (with-auth (instance testimonials/modify-service "testimonials-modify")
    (setf (title instance) "Testimonials - Modify")
    (with-bogenherr-database
      (let* ((general-pkg (make-instance 'general-pkg))
             (testimonials (get-testimonials general-pkg))
             content)
        (when testimonials
          (setf content (content testimonials)))
        (setf (form instance) (make-form "testimonials-modify-form"
                                         nil
                                         nil
                                         `((:name "txt-content" :field-type "textarea" :value ,content)
                                           (:label "Modify" :field-type "button" :onclick "on_testimonials_modify_submit_clicked()"))))))))

(defun testimonials-modify-submit-json (content)
  (with-auth (instance testimonials/modify-service "testimonials-modify")
    (setf (title instance) "Testimonials - Modify")
    (with-bogenherr-database
      (let* ((general-pkg (make-instance 'general-pkg))
             (testimonials (get-testimonials general-pkg)))
        (when testimonials
          (setf (content testimonials) content)
          (update-record general-pkg testimonials))))
    (setf (content instance) content)
    (setf (session-value :message) "Testimonials text saved successfully.")))