ganelon.web.actions documentation

This namespace contains actions support functions and macros.

*widget-id*

Id of a current widget, for example provided as a 'widget-id' GET/POST parameter.

ACTION

macro

(ACTION name params & body)
Define and register basic action, by adding: logging and exception handling to compojure.core/ANY handler with path
composed from '/a/' prefix and action name.

Example:

(ACTION "sample4" [x y]
  (noir.response/json {:x x :y y :z "!"}))

This macro does not register handler with ganelon.web.dyna-routes.

JSONACTION

macro

(JSONACTION name params & body)
Define and register JSON action, by adding: logging and exception handling to compojure.core/ANY handler with path
composed from '/a/' prefix and action name.

If the body result is a not collection or is a map, it is wrapped in a vector. The final result is passed to
noir.response/json function.

Example:

(JSONACTION "sample4" [x y]
  {:x x :y y :z "!"})

This macro does not register handler with ganelon.web.dyna-routes.

WIDGETACTION

macro

(WIDGETACTION name params & body)
Define and register widget action, by adding: logging and exception handling to compojure.core/ANY handler with path
composed from '/a/' prefix and action name.

The result of body is used as a value for ganelon.web.ui-operations/replace-with. The id is taken from *widget-id*
special variable. The operation is wrapped with JSONACTION macro.

If ~body returns nil, the widget is not updated.

Example:

(WIDGETACTION "sample4" [x y]
  (str "<p>Test!" (int x) "</p>"))

This macro does not register handler with ganelon.web.dyna-routes.

defaction

macro

(defaction name params & body)
This macro wraps ACTION with ganelon.web.dyna-routes/setroute! function, registering action for a default
dyna-routes handler.

Example:

(defaction "sample4" [x y]
  (noir.response/json {:x x :y y :z "!"}))

defjsonaction

macro

(defjsonaction name params & body)
This macro wraps JSONACTION with ganelon.web.dyna-routes/setroute! function, registering action for a default
dyna-routes handler.

Example:

(defjsonaction "sample4" [x y]
  {:x x :y y :z "!"})

defwidgetaction

macro

(defwidgetaction name params & body)
This macro wraps JSONACTION with ganelon.web.dyna-routes/setroute! function, registering action for a default
dyna-routes handler.

Example:

(defwidgetaction "sample4" [x y]
  (str "<p>Test!" (int x) "</p>"))

javascript-action-interface

(javascript-action-interface [name params])
Generate action interface for JavaScript. Dash (-) and slash (/) characters are translated to an underscore (_).
If the action does not use widget-id parameter, it will be added implicitly at the end of params.

Example:

(javascript-action-interface ['test-action ['widget-id 'x 'y]])
;=> "GanelonAction.test_action=function(widget_id,x,y, onSuccess, onError){Ganelon.performAction('test-action','widget-id='+encodeURIComponent(widget_id)+'&x='+encodeURIComponent(x)+'&y='+encodeURIComponent(y)+'',onSuccess,onError);};"
(javascript-action-interface ['test-action ['x 'y 'z]])
;=> "GanelonAction.test_action=function(x,y,z,widget_id, onSuccess, onError){Ganelon.performAction('test-action','x='+encodeURIComponent(x)+'&y='+encodeURIComponent(y)+'&z='+encodeURIComponent(z)+'&widget-id='+encodeURIComponent(widget_id)+'',onSuccess,onError);};"

javascript-actions-handler

(javascript-actions-handler)
Ring handler that returns a JavaScript file containing action interfaces for all registered actions.
Usually, it is more convienient to use ganelon.web.app/javascript-actions-handler, which provides a route
to this handler for GET on /ganelon/actions.js.

Example use:

(compojure/GET "/ganelon/actions.js" []
    (actions/javascript-actions-handler))

put-operation!

(put-operation! & operations)
Register operation to be returned as a part of the action response. Returns nil in case the put-operation!
is used at the end of an action body.

Example:

(actions/put-operation! (ui/notification "Success"
  (h/html "Message set to: " [:b (hiccup.util/escape-html msg)])))

wrap-set-widget-id

(wrap-set-widget-id app)
Bind 'widget-id' req parameter to a special variable *widget-id*.

This middleware requires wrap-keyword-params.