;;; -*- mode: Lisp; Syntax: Common-Lisp; -*-
;;;
;;; Copyright (c) 2009 by the authors.
;;;
;;; See LICENCE for details.
(in-package :hu.dwim.presentation)
;;;;;;
;;; Checkbox field
(def (function e) render-checkbox-field (value &key checked-image unchecked-image (id (unique-js-name "_chkb"))
checked-tooltip unchecked-tooltip
checked-class unchecked-class
on-change name value-sink (preprocess-value #t) (disabled #f))
"PREPROCESS-VALUE means that the js value is turned into a lisp value using STRING-TO-LISP-BOOLEAN."
(check-type disabled boolean)
(assert (or (and (null checked-image) (null unchecked-image))
(and checked-image unchecked-image)))
(assert (not (and name value-sink)))
(assert (or disabled name value-sink) () "you must provide either a NAME or a VALUE-SINK argument to ~S unless it's a DISABLED one" 'render-checkbox-field)
(when (typep name 'client-state-sink)
(setf name (id-of name)))
(bind ((name (unless disabled
(if name
(etypecase name
(client-state-sink (id-of name))
(string name))
(progn
(assert (functionp value-sink))
(id-of (if preprocess-value
(client-state-sink (client-value)
(funcall value-sink (string-to-lisp-boolean client-value)))
(client-state-sink (client-value)
(funcall value-sink client-value))))))))
(custom (or checked-image checked-class))
(hidden-id (string+ id "_hidden"))
(checked (when value "")))
(unless disabled
)
(if custom
;; FIXME i think it's completely bitrotten...
(progn
;; TODO :tabindex (tabindex field)
;; :class (style-class field)
;; handle :disabled
tags are not allowed without an alt, but this is pure confusion here...
)>
`js-onload(hdp.field.setup-custom-checkbox ,id ,disabled ,checked-image ,unchecked-image ,checked-tooltip ,unchecked-tooltip ,checked-class ,unchecked-class))
(progn
;; TODO :accesskey (accesskey field)
;; :title (or (tooltip field) (if value
;; (enabled-tooltip-of field)
;; (disabled-tooltip-of field)))
;; :tabindex (tabindex field)
;; :class (style-class field)
;; :style (style field)
`js-onload(hdp.field.setup-simple-checkbox ,id ,disabled ,checked-tooltip ,unchecked-tooltip))))
(values))
;;;;;;
;;; String field
(def function render-string-field (type value client-state-sink &key (id (generate-unique-component-id "_stw")) on-change on-key-down on-key-up)
;; TODO dojoRows 3
(render-dojo-widget (+dijit/text-box+ () :id id)
))
;;;;;;
;;; Number field
(def function render-number-field (value client-state-sink &key (id (generate-unique-component-id "_nrw")) on-change on-key-down on-key-up)
(render-dojo-widget (+dijit/number-text-box+ () :id id)
))
;;;;;;
;;; Combo box
(def function render-combo-box-field (value possible-values &key (id (generate-unique-component-id "_w")) name
(key #'identity) (test #'equal) (client-name-generator #'princ-to-string))