/[ht-ajax]/processor-dojo.lisp
ViewVC logotype

Contents of /processor-dojo.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Fri Nov 14 21:17:43 2008 UTC (5 years, 5 months ago) by xlopez
File size: 3700 byte(s)
Initial commit, version 0.0.7.
1 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Base: 10 -*-
2 ;;;
3 ;;; Copyright (c) 2007, Ury Marshak
4 ;;; The code comes with a BSD-style license, so you can basically do
5 ;;; with it whatever you want. See the file LICENSE for details.
6 ;;;
7
8 (in-package #:ht-ajax)
9
10 (declaim #.*optimization*)
11 ;;
12
13
14 ;;; This is the AJAX processor interfacing to the Dojo Toolkit
15 ;;; ( http://dojotoolkit.org/ )
16
17
18 (defclass dojo-ajax-processor (library-ajax-processor)
19 ())
20
21 (defmethod default-library-file-names ((processor dojo-ajax-processor))
22 (declare (ignore processor))
23
24 '("dojo.js"))
25
26 ;;
27
28
29 (defun prepare-js-dojo-ajax-preamble (server-uri)
30 "Output a string containing the call function."
31 (concatenate 'string
32 "
33 dojo.require('dojo.io.*');
34
35 var ajax_server_uri = '" server-uri "';
36
37 function ajax_call_uri(func, callback_spec, args) {
38 var uri = ajax_server_uri;
39 var i;
40
41 if (uri.indexOf('?') == -1)
42 uri = uri + '?';
43 else
44 uri = uri + '&';
45
46 uri = uri + ajax_encode_args(func, args);
47 var callbacks = ajax_parse_callbacks(callback_spec);
48
49 dojo.io.bind({ url: uri,
50 transport: 'XMLHTTPTransport',
51 load: function (type, data, evt) {
52 ajax_call_maybe_evaluate_json(callbacks[0],
53 data,
54 evt.getResponseHeader('Content-Type'));
55
56 },
57 error: function (type, errorObject) {
58 if(callbacks[1]) {
59 callbacks[1](dojo.errorToString(errorObject));
60 }
61 else {
62 debug_alert(dojo.errorToString(errorObject));
63 }
64 }
65 });
66 }
67
68
69 function ajax_post_uri(func, callback_spec, args) {
70 var params = ajax_encode_args(func, args);
71 var callbacks = ajax_parse_callbacks(callback_spec);
72
73 dojo.io.bind({ url: ajax_server_uri,
74 transport: 'XMLHTTPTransport',
75 method: 'POST',
76 load: function (type, data, evt) {
77 ajax_call_maybe_evaluate_json(callbacks[0],
78 data,
79 evt.getResponseHeader('Content-Type'));
80
81 },
82 error: function (type, errorObject) {
83 if(callbacks[1]) {
84 callbacks[1](dojo.errorToString(errorObject));
85 }
86 else {
87 debug_alert(dojo.errorToString(errorObject));
88 }
89 },
90 postContent: params
91 });
92 }"))
93
94
95
96
97 (defmethod %generate-js-code ((processor dojo-ajax-processor))
98 (concatenate 'string
99 (apply #'concatenate 'string
100 (prepare-js-debug-function processor)
101 (prepare-js-ajax-encode-args)
102 (prepare-js-parse-callbacks)
103 (prepare-js-ajax-is-json)
104 (prepare-js-ajax-call-maybe-evaluate-json)
105 (prepare-js-dojo-ajax-preamble (maybe-rewrite-url-for-session
106 (server-uri processor)))
107
108
109 (loop
110 for fun-name being the hash-keys
111 in (exported-funcs processor)
112 collect (apply #'prepare-js-ajax-function
113 processor
114 fun-name
115 (js-function-name processor fun-name)
116 (gethash fun-name (exported-funcs processor))))
117 )))

  ViewVC Help
Powered by ViewVC 1.1.5