forked from maccman/holla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.juggernaut.js
More file actions
66 lines (52 loc) · 1.46 KB
/
Copy pathapplication.juggernaut.js
File metadata and controls
66 lines (52 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
jQuery(function($){
if (typeof Juggernaut == "undefined") return;
var user_id = App.user_id;
if ( !user_id || user_id == "" ) return;
var process = function(msg){
App.log("Juggernaut -", msg);
var klass = eval(msg.klass);
switch(msg.type) {
case "create":
if ( !klass.exists(msg.record.id) )
klass.create(msg.record);
break;
case "update":
klass.update(msg.id, msg.record);
break;
case "destroy":
klass.destroy(msg.id);
break;
default:
throw("Unknown type:" + type);
}
};
var jug = new Juggernaut;
jug.meta = {user_id:user_id};
var offline = $("<div></div>")
.html("The connection has been disconnected! <br /> " +
"Please go back online to use this service.")
.dialog({
autoOpen: false,
modal: true,
width: 330,
resizable: false,
closeOnEscape: false,
title: "Connection"
});
jug.on("connect", function(){
App.log("Jug connected");
offline.dialog("close");
});
jug.on("disconnect", function(){
offline.dialog("open");
App.log("Jug disconnected")
});
jug.on("reconnect", function(){ App.log("Jug reconnecting") });
SuperRPC.bind("beforeSend", function(xhr){
xhr.setRequestHeader("X-Session-ID", jug.sessionID);
});
App.log("Jug subscribing to: ", "/observer/" + user_id);
jug.subscribe("/observer/" + user_id, process);
// Expose
App.jug = jug;
});