Merge "gui/html: Request up to 5 content objects, display More/Less buttons if necessary"
diff --git a/gui/html/chronoshare-helpers.js b/gui/html/chronoshare-helpers.js
index 4f59563..60702a8 100644
--- a/gui/html/chronoshare-helpers.js
+++ b/gui/html/chronoshare-helpers.js
@@ -87,54 +87,44 @@
document.location = url;
};
-// No need anymore (displaying the whole data set at once)
+displayContent = function (newcontent, more, baseUrl) {
-// displayContent = function (newcontent, more, baseUrl) {
+ $("#content").fadeOut ("fast", function () {
+ $(this).replaceWith (newcontent);
+ $("#content").fadeIn ("fast");
+ });
-// // if (!PARAMS.offset || PARAMS.offset==0)
-// // {
-// $("#content").fadeOut ("fast", function () {
-// $(this).replaceWith (newcontent);
-// $("#content").fadeIn ("fast");
-// });
+ $("#content-nav").fadeOut ("fast", function () {
+ $("#content-nav a").hide ();
-// $("#content-nav").fadeOut ("fast", function () {
-// $("#content-nav a").hide ();
+ if (PARAMS.offset !== undefined || more !== undefined) {
+ $("#content-nav").fadeIn ("fast");
-// if (PARAMS.offset !== undefined || more !== undefined) {
-// $("#content-nav").fadeIn ("fast");
+ if (more !== undefined) {
+ $("#get-more").show ();
-// if (more !== undefined) {
-// $("#get-more").show ();
+ $("#get-more").unbind ('click').click (function () {
+ url = baseUrl;
+ url += "&offset="+more;
-// $("#get-more").unbind ('click').click (function () {
-// url = baseUrl;
-// url += "&offset="+more;
+ document.location = url;
+ });
+ }
+ if (PARAMS.offset > 0) {
+ $("#get-less").show ();
-// document.location = url;
-// });
-// }
-// if (PARAMS.offset > 0) {
-// $("#get-less").show ();
+ $("#get-less").unbind ('click').click (function () {
+ url = baseUrl;
+ if (PARAMS.offset > 5) {
+ url += "&offset="+(PARAMS.offset - 5);
+ }
-// $("#get-less").unbind ('click').click (function () {
-// url = baseUrl;
-// if (PARAMS.offset > 1) {
-// url += "&offset="+(PARAMS.offset - 1);
-// }
-
-// document.location = url;
-// });
-// }
-// }
-// });
-// // }
-// // else {
-// // tbody.children ().each (function (index, row) {
-// // $("#history-list-actions").append (row);
-// // });
-// // }
-// };
+ document.location = url;
+ });
+ }
+ }
+ });
+};
function custom_alert (output_msg, title_msg)
{
diff --git a/gui/html/chronoshare.js b/gui/html/chronoshare.js
index 2e4abd4..ea6a6b8 100644
--- a/gui/html/chronoshare.js
+++ b/gui/html/chronoshare.js
@@ -102,6 +102,7 @@
$("#json").empty ();
this.collection = [];
+ this.counter = 0;
},
upcall: function(kind, upcallInfo) {
@@ -117,12 +118,20 @@
this.collection = this.collection.concat (data[this.collectionName]);
if (data[this.moreName] !== undefined) {
nextSegment = upcallInfo.interest.name.cut (1).addSegment (data[this.moreName]);
- console.log ("MORE: " +nextSegment.to_uri ());
- CHRONOSHARE.ndn.expressInterest (nextSegment, this);
+ this.counter ++;
+
+ if (this.counter < 5) {
+ console.log ("MORE: " +nextSegment.to_uri ());
+ CHRONOSHARE.ndn.expressInterest (nextSegment, this);
+ }
+ else {
+ $("#loader").fadeOut (500); // ("hidden");
+ this.onData (this.collection, data[this.moreName]);
+ }
}
else {
$("#loader").fadeOut (500); // ("hidden");
- this.onData (this.collection);
+ this.onData (this.collection, undefined);
}
}
else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
@@ -137,7 +146,7 @@
return Closure.RESULT_OK; // make sure we never re-express the interest
},
- onData: function(data) {
+ onData: function(data, more) {
},
onTimeout: function () {
@@ -158,7 +167,7 @@
this.chronoshare = chronoshare;
},
- onData: function(data) {
+ onData: function(data, more) {
tbody = $("<tbody />", { "id": "file-list-files" });
/// @todo Eventually set title for other pages
@@ -207,10 +216,7 @@
tbody = tbody.append (row);
}
- $("#content").fadeOut ("fast", function () {
- $(this).replaceWith (newcontent);
- $("#content").fadeIn ("fast");
- });
+ displayContent (newcontent, more, this.base_url ());
$.contextMenu( 'destroy', ".with-context-menu" ); // cleanup
$.contextMenu({
@@ -245,7 +251,7 @@
this.chronoshare = chronoshare;
},
- onData: function(data) {
+ onData: function(data, more) {
tbody = $("<tbody />", { "id": "history-list-actions" });
/// @todo Eventually set title for other pages
@@ -301,10 +307,7 @@
tbody = tbody.append (row);
}
- $("#content").fadeOut ("fast", function () {
- $(this).replaceWith (newcontent);
- $("#content").fadeIn ("fast");
- });
+ displayContent (newcontent, more, this.base_url (PAGE));
$.contextMenu( 'destroy', ".with-context-menu" ); // cleanup
$.contextMenu({