/[drupal]/contributions/modules/json_server/json_server.js
ViewVC logotype

Contents of /contributions/modules/json_server/json_server.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sun Jan 13 15:48:11 2008 UTC (22 months, 2 weeks ago) by dmitrig01
Branch: MAIN
CVS Tags: DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5
Changes since 1.1: +44 -28 lines
File MIME type: text/javascript
First try at porting to Drupal 6
1 // $Id: json_server.js,v 1.1 2007/11/09 17:34:57 dmitrig01 Exp $
2 Drupal.service = function(method, parameters, success) {
3 if (!this.servicesClient) {
4 return new Drupal.service(method, parameters, success);
5 }
6 parameters.method = method;
7 parsed = this.parse(parameters);
8 this.ajax(parsed, success);
9 }
10 Drupal.service.prototype = {
11 servicesClient: true,
12 parse: function(parameters) {
13 return $.param(this._parse([], [], parameters));
14 },
15 _parse: function(currentData, currentNesting, parameters) {
16 for (index in parameters) {
17 data = parameters[index];
18 currentNesting.push(encodeURIComponent(index));
19 if (typeof data == 'object') {
20 currentData = this._parse(currentData, currentNesting, data);
21 }
22 else {
23 currentData.push({name: this._makeURI(currentNesting), value: encodeURIComponent(data) });
24 }
25 currentNesting.pop();
26 }
27 return currentData;
28 },
29 _makeURI: function(data) {
30 output = data.shift();
31 for (i in data) {
32 output += '['+ data[i] +']';
33 }
34 return output;
35 },
36 ajax: function(data, success) {
37 $.ajax({
38 url: Drupal.settings.basePath +"?q=services/json",
39 type: "POST",
40 data: data,
41 success: function(data) {
42 parsed = Drupal.parseJson(data);
43 success(parsed['status'], parsed['data']);
44 },
45 });
46 }
47 };

  ViewVC Help
Powered by ViewVC 1.1.2