blob: c8b8ae0e946665e5324c20e91767b4565e7f164c [file] [log] [blame]
Zhenkai Zhu5c2475b2013-02-26 22:57:31 -08001
Alexander Afanasyevfd5e6272013-02-27 20:25:20 -08002$.Class ("FilesClosure", {}, {
3 upcall: function(kind, upcallInfo) {
4 $("#loader").fadeOut (500); // ("hidden");
5 if (kind == Closure.UPCALL_CONTENT) {
6 convertedData = DataUtils.toString (upcallInfo.contentObject.content);
7 $("#json").text (convertedData);
8 $("#json").removeClass ("hidden");
9 data = JSON.parse (convertedData);
Zhenkai Zhu5c2475b2013-02-26 22:57:31 -080010
Alexander Afanasyevfd5e6272013-02-27 20:25:20 -080011 // error handling?
12 // if (data.files instanceof Array) {
13 // alert (data.files);
14 // }
Zhenkai Zhu5c2475b2013-02-26 22:57:31 -080015
Alexander Afanasyevfd5e6272013-02-27 20:25:20 -080016 var html = $("tbody#files");
17 for (var i = 0; i < data.files.length; i++) {
18 file = data.files[i];
19 html = html.append ([
20 "<tr"+(i%2?" class=\"odd\"":"")+">",
21 "<td class=\"border-left\">" + file.filename + "</td>",
22 "<td>" + file.version + "</td>",
23 "<td>" + file.timestamp + "</td>",
24 "<td class=\"border-right\">" + "</td>",
25 "</tr>"
26 ].join());
27 }
28 }
29 else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
30 $("#error").html ("Interest timed out");
31 $("#error").removeClass ("hidden");
32 }
33 else {
34 $("#error").html ("Unknown error happened");
35 $("#error").removeClass ("hidden");
36 // some kind of error
37 }
Zhenkai Zhu5c2475b2013-02-26 22:57:31 -080038 }
Alexander Afanasyevfd5e6272013-02-27 20:25:20 -080039});
Zhenkai Zhu5c2475b2013-02-26 22:57:31 -080040
Alexander Afanasyevfd5e6272013-02-27 20:25:20 -080041
42$.Class ("ChronoShare", { },
43 {
44 init: function (username, foldername) {
45 this.username = new Name (username);
46 this.files = new Name ("/localhost").add (this.username).add ("chronoshare").add (foldername).add ("info").add ("files").add ("folder");
47
48 this.actions = new Name ("/localhost").add (this.username).add ("chronoshare").add (foldername).add ("info").add ("actions").add ("folder");
49
50 this.restore = new Name ("/localhost").add (this.username).add ("chronoshare").add (foldername).add ("cmd").add ("restore").add ("file");
51
52 this.ndn = new NDN ({host:"127.0.0.1", getHostAndPort: function() { return {host: "127.0.0.1", port: 9696}}});
53 // this.ndn.transport.connect (this.ndn);
54 },
55
56 run: function () {
57 request = new Name ().add (this.files)./*add (folder_in_question).*/add ("nonce").addSegment (0);
58 console.log (request.to_uri ());
59 $("#files").empty ();
60 // $("#loader").removeClass ("hidden");
61 $("#loader").fadeIn (500);
62 this.ndn.expressInterest (request, new FilesClosure ());
63 }
64// ,
65
66 // sendRequest: function () {
67 // alert ('bla');
68 // }
69 });
70
71
72// $.Class ("onFiles",
73// {
74// },
75
76// {
77// upcall: function(kind, upcallInfo, tmp) {
78// if (kind
79// }
80// });
81
82// var AsyncGetClosure = function AsyncGetClosure() {
83// Closure.call(this);
84// };
85
86// AsyncGetClosure.prototype.upcall = function(kind, upcallInfo, tmp) {
87// if (kind == Closure.UPCALL_FINAL) {
88// // Do nothing.
89// } else if (kind == Closure.UPCALL_CONTENT) {
90// var content = upcallInfo.contentObject;
91// var nameStr = content.name.getName().split("/").slice(5,6);
92
93// if (nameStr == "prefix") {
94// document.getElementById('prefixcontent').innerHTML = DataUtils.toString(content.content);
95// prefix();
96// } else if (nameStr == "link") {
97// document.getElementById('linkcontent').innerHTML = DataUtils.toString(content.content);
98// link();
99// } else {
100// var data = DataUtils.toString(content.content);
101// var obj = jQuery.parseJSON(data);
102// document.getElementById("lastupdated").innerHTML = obj.lastupdated;
103// document.getElementById("lastlog").innerHTML = obj.lastlog;
104// document.getElementById("lasttimestamp").innerHTML = obj.lasttimestamp;
105// }
106// } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
107// console.log("Closure.upcall called with interest time out.");
108// }
109// return Closure.RESULT_OK;
110// };
111
112// function getStatus(name) {
113// // Template interest to get the latest content.
114// var interest = new Interest("/tmp/");
115// interest.childSelector = 1;
116// interest.interestLifetime = 4000;
117
118// ndn.expressInterest(new Name("/ndn/memphis.edu/netlab/status/" + name), new AsyncGetClosure(), interest);
119// }
120
121// // Calls to get the content data.
122// function begin() {
123// getStatus("metadata");
124// getStatus("prefix");
125// getStatus("link");
126// }
127
128// var ndn;
129// $(document).ready(function() {
130// $("#all").fadeIn(500);
131// var res = detect();
132
133// if (!res) {
134// $("#base").fadeOut(50);
135// $("#nosupport").fadeIn(500);
136// } else {
137// //$("#all").fadeIn(500);
138
139// $.get("test.php", function() {
140// openHandle = function() { begin() };
141// ndn = new NDN({host:hostip, onopen:openHandle});
142// ndn.transport.connectWebSocket(ndn);
143// $("#base").fadeOut(500, function () {
144// $("#status").fadeIn(1000);
145// });
146// });
147// }
148// });
149
150// $("#continue").click(function() {
151// $("#nosupport").fadeOut(50);
152// $("#base").fadeIn(500);
153// $.get("test.php", function() {
154// openHandle = function() { begin() };
155// ndn = new NDN({host:hostip, onopen:openHandle});
156// ndn.transport.connectWebSocket(ndn);
157// $("#base").fadeOut(500, function () {
158// $("#status").fadeIn(1000);
159// });
160// });
161// });