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

Contents of /processor-lokris.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations)
Fri Nov 14 21:17:43 2008 UTC (5 years, 5 months ago) by xlopez
File size: 3452 byte(s)
Initial commit, version 0.0.7.
1 xlopez 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 Lokris library
15     ;;; ( http://www.ajaxbuch.de/lokris/ )
16    
17    
18     (defclass lokris-ajax-processor (library-ajax-processor)
19     ())
20    
21     (defmethod default-library-file-names ((processor lokris-ajax-processor))
22     (declare (ignore processor))
23    
24     '("lokris.js"))
25    
26     ;;
27    
28    
29    
30     (defun prepare-js-lokris-ajax-preamble (server-uri)
31     "Output a string containing the call functions."
32     (concatenate 'string "
33     var ajax_server_uri = '" server-uri "';
34    
35     function ajax_call_uri(func, callback_spec, args) {
36     var uri = ajax_server_uri;
37     var i;
38    
39     if (uri.indexOf('?') == -1)
40     uri = uri + '?';
41     else
42     uri = uri + '&';
43    
44     uri = uri + ajax_encode_args(func, args);
45     var callbacks = ajax_parse_callbacks(callback_spec);
46    
47     var error_cb = function (req) {
48     if(callbacks[1]) {
49     callbacks[1](req.status + ' ' + req.statusText)
50     }
51     else {
52     debug_alert(req.status + ' ' + req.statusText);
53     }
54     }
55    
56     var request = Lokris.AjaxCall(uri,
57     function (response) {
58     var data = response.responseText;
59     ajax_call_maybe_evaluate_json(callbacks[0],
60     data,
61     response.getResponseHeader('Content-Type'));
62     },
63     {
64     errorHandler: error_cb,
65     rawResponse:true
66     }
67     );
68     }
69    
70     function ajax_post_uri(func, callback_spec, args) {
71     var params = ajax_encode_args(func, args);
72     var callbacks = ajax_parse_callbacks(callback_spec);
73    
74     var error_cb = function (req) {
75     if(callbacks[1]) {
76     callbacks[1](req.status + ' ' + req.statusText)
77     }
78     else {
79     debug_alert(req.status + ' ' + req.statusText);
80     }
81     }
82    
83     var request = Lokris.AjaxCall(ajax_server_uri,
84     function (response) {
85     var data = response.responseText;
86     ajax_call_maybe_evaluate_json(callbacks[0],
87     data,
88     response.getResponseHeader('Content-Type'));
89     },
90    
91     {postBody: params,
92     method: 'POST',
93     errorHandler: error_cb,
94     rawResponse:true
95     });
96     }"
97     ))
98    
99    
100    
101    
102     (defmethod %generate-js-code ((processor lokris-ajax-processor))
103     (concatenate 'string
104     (apply #'concatenate 'string
105     (prepare-js-debug-function processor)
106     (prepare-js-ajax-encode-args)
107     (prepare-js-parse-callbacks)
108     (prepare-js-ajax-is-json)
109     (prepare-js-ajax-call-maybe-evaluate-json)
110     (prepare-js-lokris-ajax-preamble (maybe-rewrite-url-for-session
111     (server-uri processor)))
112    
113    
114     (loop
115     for fun-name being the hash-keys
116     in (exported-funcs processor)
117     collect (apply #'prepare-js-ajax-function
118     processor
119     fun-name
120     (js-function-name processor fun-name)
121     (gethash fun-name (exported-funcs processor))))
122     )))

  ViewVC Help
Powered by ViewVC 1.1.5