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

Contents of /processor-prototype.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: 3303 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 Prototype library
15 ;;; ( http://prototypejs.org )
16
17
18 (defclass prototype-ajax-processor (library-ajax-processor)
19 ())
20
21 (defmethod default-library-file-names ((processor prototype-ajax-processor))
22 (declare (ignore processor))
23
24 '("prototype.js"))
25
26 ;;
27
28
29 (defun prepare-js-prototype-ajax-preamble (server-uri)
30 "Output a string containing the call functions."
31 (concatenate 'string
32 "
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 new Ajax.Request(uri,
48 {
49 method:'get',
50 onSuccess: function(transport){
51 var data = transport.responseText;
52 ajax_call_maybe_evaluate_json(callbacks[0],
53 data,
54 transport.getResponseHeader('Content-Type'));
55 },
56 onFailure: function(){
57 if(callbacks[1]) {
58 callbacks[1]('URI: '+uri);
59 }
60 else {
61 debug_alert('Error for URI: '+uri);
62 }
63 }
64 });
65 }
66
67 function ajax_post_uri(func, callback_spec, args) {
68 var params = ajax_encode_args(func, args);
69 var callbacks = ajax_parse_callbacks(callback_spec);
70
71 new Ajax.Request(ajax_server_uri,
72 {
73 method:'post',
74 parameters: params,
75 onSuccess: function(transport){
76 var data = transport.responseText;
77 ajax_call_maybe_evaluate_json(callbacks[0],
78 data,
79 transport.getResponseHeader('Content-Type'));
80 },
81 onFailure: function(){
82 if(callbacks[1]) {
83 callbacks[1]('URI: '+uri);
84 }
85 else {
86 debug_alert('Error for URI: '+uri);
87 }
88 }
89 });
90 }"))
91
92
93
94 (defmethod %generate-js-code ((processor prototype-ajax-processor))
95 (concatenate 'string
96 (apply #'concatenate 'string
97 (prepare-js-debug-function processor)
98 (prepare-js-ajax-encode-args)
99 (prepare-js-parse-callbacks)
100 (prepare-js-ajax-is-json)
101 (prepare-js-ajax-call-maybe-evaluate-json)
102 (prepare-js-prototype-ajax-preamble (maybe-rewrite-url-for-session
103 (server-uri processor)))
104
105
106 (loop
107 for fun-name being the hash-keys
108 in (exported-funcs processor)
109 collect (apply #'prepare-js-ajax-function
110 processor
111 fun-name
112 (js-function-name processor fun-name)
113 (gethash fun-name (exported-funcs processor))))
114 )))
115
116
117
118

  ViewVC Help
Powered by ViewVC 1.1.5