Refactor search into its own controller.
[quanweb.git] / js / BooksModel.js
index 0c0b915769e0cfcd29501ccceef7740a31ec9eec..984519d137409329027f20ca894beeeb18409ab0 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);
     };