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

Contents of /processor-yui.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: 3595 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 Yahoo User Interface Library
15 ;;; ( http://developer.yahoo.com/yui/ )
16
17
18 (defclass yui-ajax-processor (library-ajax-processor)
19 ())
20
21 (defmethod default-library-file-names ((processor yui-ajax-processor))
22 (declare (ignore processor))
23
24 '("yahoo.js" "connection.js"))
25
26 ;;
27
28
29 (defun prepare-js-yui-ajax-preamble (server-uri)
30 "Output a string containing the call function."
31 (concatenate 'string
32 "
33
34 var ajax_server_uri = '" server-uri "';
35
36
37
38 function ajax_call_uri(func, callback_spec, args) {
39 var uri = ajax_server_uri;
40 var i;
41
42 if (uri.indexOf('?') == -1)
43 uri = uri + '?';
44 else
45 uri = uri + '&';
46
47 uri = uri + ajax_encode_args(func, args);
48 var callbacks = ajax_parse_callbacks(callback_spec);
49
50 var transaction = YAHOO.util.Connect.asyncRequest('GET',
51 uri,
52 { success: function (response) {
53 var data = response.responseText;
54 ajax_call_maybe_evaluate_json(callbacks[0],
55 data,
56 response.getResponseHeader['Content-Type']);
57 },
58 failure: function (response) {
59 if(callbacks[1]) {
60 callbacks[1](response.statusText);
61 }
62 else {
63 debug_alert(response.statusText);
64 }
65 }
66 },
67 null);
68 }
69
70
71 function ajax_post_uri(func, callback_spec, args) {
72 var params = ajax_encode_args(func, args);
73 var callbacks = ajax_parse_callbacks(callback_spec);
74
75 var transaction = YAHOO.util.Connect.asyncRequest('POST',
76 ajax_server_uri,
77 { success: function (response) {
78 var data = response.responseText;
79 ajax_call_maybe_evaluate_json(callbacks[0],
80 data,
81 response.getResponseHeader['Content-Type']);
82 },
83 failure: function (response) {
84 if(callbacks[1]) {
85 callbacks[1](response.statusText);
86 }
87 else {
88 debug_alert(response.statusText);
89 }
90 }
91 },
92 params);
93 }"))
94
95
96
97
98 (defmethod %generate-js-code ((processor yui-ajax-processor))
99 (concatenate 'string
100 (apply #'concatenate 'string
101 (prepare-js-debug-function processor)
102 (prepare-js-ajax-encode-args)
103 (prepare-js-parse-callbacks)
104 (prepare-js-ajax-is-json)
105 (prepare-js-ajax-call-maybe-evaluate-json)
106 (prepare-js-yui-ajax-preamble (maybe-rewrite-url-for-session
107 (server-uri processor)))
108
109
110 (loop
111 for fun-name being the hash-keys
112 in (exported-funcs processor)
113 collect (apply #'prepare-js-ajax-function
114 processor
115 fun-name
116 (js-function-name processor fun-name)
117 (gethash fun-name (exported-funcs processor))))
118 )))

  ViewVC Help
Powered by ViewVC 1.1.5