aboutsummaryrefslogtreecommitdiffstats
path: root/src/Server.js
diff options
context:
space:
mode:
authorMisko Hevery2010-01-25 20:02:24 -0800
committerMisko Hevery2010-01-25 20:02:24 -0800
commit0b630972b15676b1c1b6c59edd564e4ee331ec70 (patch)
treebd31ca5b69b6ea03d906a3107dfe38a8c1adcb8e /src/Server.js
parent19bbee030ba012b8fc4835c1d17e039804b2b94b (diff)
parent473e57e22532f9b85fc9dcc1bcc53e12a10154c2 (diff)
downloadangular.js-0b630972b15676b1c1b6c59edd564e4ee331ec70.tar.bz2
merge
Diffstat (limited to 'src/Server.js')
-rw-r--r--src/Server.js57
1 files changed, 28 insertions, 29 deletions
diff --git a/src/Server.js b/src/Server.js
index 94b0cc10..5c4ec3c6 100644
--- a/src/Server.js
+++ b/src/Server.js
@@ -1,6 +1,4 @@
-// Copyright (C) 2008,2009 BRAT Tech LLC
-
-nglr.Server = function(url, getScript) {
+function Server(url, getScript) {
this.url = url;
this.nextId = 0;
this.getScript = getScript;
@@ -8,51 +6,52 @@ nglr.Server = function(url, getScript) {
this.maxSize = 1800;
};
-nglr.Server.prototype.base64url = function(txt) {
- return Base64.encode(txt);
-};
-
-nglr.Server.prototype.request = function(method, url, request, callback) {
- var requestId = this.uuid + (this.nextId++);
- nglr[requestId] = function(response) {
- delete nglr[requestId];
- callback(200, response);
- };
- var payload = {u:url, m:method, p:request};
- payload = this.base64url(nglr.toJson(payload));
- var totalPockets = Math.ceil(payload.length / this.maxSize);
- var baseUrl = this.url + "/$/" + requestId + "/" + totalPockets + "/";
- for ( var pocketNo = 0; pocketNo < totalPockets; pocketNo++) {
- var pocket = payload.substr(pocketNo * this.maxSize, this.maxSize);
- this.getScript(baseUrl + (pocketNo+1) + "?h=" + pocket, nglr.noop);
+Server.prototype = {
+ base64url: function(txt) {
+ return Base64.encode(txt);
+ },
+
+ request: function(method, url, request, callback) {
+ var requestId = this.uuid + (this.nextId++);
+ var payload = this.base64url(toJson({'u':url, 'm':method, 'p':request}));
+ var totalPockets = Math.ceil(payload.length / this.maxSize);
+ var baseUrl = this.url + "/$/" + requestId + "/" + totalPockets + "/";
+ angularCallbacks[requestId] = function(response) {
+ delete angularCallbacks[requestId];
+ callback(200, response);
+ };
+ for ( var pocketNo = 0; pocketNo < totalPockets; pocketNo++) {
+ var pocket = payload.substr(pocketNo * this.maxSize, this.maxSize);
+ this.getScript(baseUrl + (pocketNo+1) + "?h=" + pocket, noop);
+ }
}
};
-nglr.FrameServer = function(frame) {
+function FrameServer(frame) {
this.frame = frame;
};
-nglr.FrameServer.PREFIX = "$DATASET:";
+FrameServer.PREFIX = "$DATASET:";
-nglr.FrameServer.prototype = {
+FrameServer.prototype = {
read:function(){
- this.data = nglr.fromJson(this.frame.name.substr(nglr.FrameServer.PREFIX.length));
+ this.data = fromJson(this.frame.name.substr(FrameServer.PREFIX.length));
},
write:function(){
- this.frame.name = nglr.FrameServer.PREFIX + nglr.toJson(this.data);
+ this.frame.name = FrameServer.PREFIX + toJson(this.data);
},
request: function(method, url, request, callback) {
- //alert(method + " " + url + " " + nglr.toJson(request) + " " + nglr.toJson(callback));
+ //alert(method + " " + url + " " + toJson(request) + " " + toJson(callback));
}
};
-nglr.VisualServer = function(delegate, status, update) {
+function VisualServer(delegate, status, update) {
this.delegate = delegate;
this.update = update;
this.status = status;
};
-nglr.VisualServer.prototype = {
+VisualServer.prototype = {
request:function(method, url, request, callback) {
var self = this;
this.status.beginRequest(request);
@@ -61,7 +60,7 @@ nglr.VisualServer.prototype = {
try {
callback.apply(this, arguments);
} catch (e) {
- nglr.alert(nglr.toJson(e));
+ alert(toJson(e));
}
self.update();
});