Part of ACREP-30.
[mkws-moved-to-github.git] / src / mkws-team.js
index cbac794..17f0f1f 100644 (file)
@@ -73,11 +73,11 @@ mkws.makeTeam = function($, teamName) {
   delete m_default.filters;
   $.extend(m_default, tmp.fragmentItems());
 
-  that.urlFragment = function () {
+  that.urlFragment = function(overrides) {
     var s;
 
     // Expand the filterSet into a set of key=value properties 
-    var state = $.extend(true, {}, m_state);
+    var state = $.extend(true, {}, m_state, overrides ? overrides : {});
     var tmp = state.filters;
     delete state.filters;
     $.extend(state, tmp.fragmentItems());
@@ -101,6 +101,49 @@ mkws.makeTeam = function($, teamName) {
     return s;
   }
 
+  // ### what quoting do we need to undo? Complement of previous function
+  that.parseFragment = function(s) {
+    var x = {};
+
+    var list = s.split('@');
+    for (var i in list) {
+      var a = list[i].split('=');
+      x[a[0]] = a[1];
+    }
+
+    return x;
+  }
+
+  that.handleChanges = function(oldState, newState) {
+    for (var key in newState) {
+      var val = newState[key];
+      if (newState.hasOwnProperty(key) &&
+          (!oldState || val != oldState[key])) {
+        that.warn("changed property " + key + ": " + 
+                  (oldState ? ("'" + oldState[key] + "'") : "undefined") +
+                  " -> '" + val + "'");
+        if (key === 'page') {
+          that.showPage(parseInt(val));
+        } else if (key === 'sort') {
+          that.set_sortOrder(val);
+          if (that.submitted()) {
+            that.reShow();
+          }
+        } else if (key === 'size') {
+          that.set_perpage(val);
+          if (that.submitted()) {
+            that.reShow();
+          }
+        } else if (key.indexOf('xt-') == 0) {
+          that.limitTarget(key.substring(3), val);
+        } else if (key.indexOf('xf-') == 0) {
+          var a = key.split('-');
+          that.limitQuery(a[1], a[2]);
+        }
+      }
+    }
+  };
+
 
   // The following PubSub code is modified from the jQuery manual:
   // http://api.jquery.com/jQuery.Callbacks/
@@ -299,6 +342,7 @@ mkws.makeTeam = function($, teamName) {
   that.showPage = function(pageNum) {
     m_state.page = pageNum;
     m_paz.showPage(m_state.page - 1);
+    that.warn("fragment: " + that.urlFragment());
   };
 
 
@@ -306,13 +350,16 @@ mkws.makeTeam = function($, teamName) {
     if (m_totalRecordCount - m_state.size * m_state.page > 0) {
       m_paz.showNext();
       m_state.page++;
+      that.warn("fragment: " + that.urlFragment());
     }
   };
 
 
   that.pagerPrev = function() {
-    if (m_paz.showPrev() != false)
+    if (m_paz.showPrev() != false) {
       m_state.page--;
+      that.warn("fragment: " + that.urlFragment());
+    }
   };
 
 
@@ -387,6 +434,7 @@ mkws.makeTeam = function($, teamName) {
   that.fetchDetails = function(recId) {
     that.info("fetchDetails() requesting record '" + recId + "'");
     m_paz.record(recId);
+    that.warn("fragment: " + that.urlFragment());
   };