Prevent tooltips from displaying when the mouse is over the search or paging controllers.
[quanweb.git] / js / BooksModel.js
index 0c0b915769e0cfcd29501ccceef7740a31ec9eec..75e065194ccdc49602033971208598b9bcde7c64 100644 (file)
@@ -24,6 +24,35 @@ var BooksModel = (function() {
     // ==============
     // Public methods
     
+    my.adjustPos = function(setting) {
+
+        var value = parseInt(setting);
+
+        var prev = {
+            first: my.first,
+            last: my.last,
+        };
+        
+        var maxFirst = Math.max(0, my.count - my.pageSize);
+        
+        if (value < 0) {
+            my.first = 0;
+        } else if (value > maxFirst) {
+            my.first = maxFirst;
+        } else {
+            my.first = value;
+        }
+    
+        my.last = my.first + my.pageSize - 1;
+        if (my.last >= my.count) {
+            my.last = my.count - 1;
+        }
+        
+        if (prev.first !== my.first || prev.last !== my.last) {
+            my.refreshData();
+        }
+    };
+    
     my.listen = function(subscriber) {
         listeners.push(subscriber);
     };
@@ -42,13 +71,12 @@ var BooksModel = (function() {
         }
 
         fetch(url, {method:'GET', cache:'default'})
-            .then(response => response.json())
-            .then((jsonValue) => {
-                console.log('JSON response for info:  ', jsonValue);
+            .then(function(response) {return response.json();})
+            .then(function(jsonValue) {
                 my.cache = jsonValue;
                 notifyAll();    // inform all subscribers that the model has been updated
             })
-            .catch(err => {
+            .catch(function(err) {
                 var msg = 'Error fetching book details via URL:  ' + url + ': ' + err;
                 console.log(msg, err.stack);
                 report(msg);