Team object now carries a copy of its initial state.
authorMike Taylor <mike@indexdata.com>
Thu, 30 Apr 2015 16:02:55 +0000 (17:02 +0100)
committerMike Taylor <mike@indexdata.com>
Thu, 30 Apr 2015 16:02:55 +0000 (17:02 +0100)
This is used by team.urlFragment to generate a fragment representing state diff.
FOR NOW, this fragment is emitted as a warning when doing search or show.
Currently, facets don't work at all, as they are stored in a non-string object.

src/mkws-team.js

index 4d63ca2..bae55cf 100644 (file)
@@ -65,6 +65,31 @@ mkws.makeTeam = function($, teamName) {
   that.set_sortOrder = function(val) { m_state.sort = val };
   that.set_perpage = function(val) { m_state.size = val };
 
+  m_state.sort = config.sort_default;
+  m_state.size = config.perpage_default;
+  var m_default = $.extend(true, {}, m_state);
+
+  that.urlFragment = function () {
+    var s;
+
+    for (var key in m_state) {
+      if (m_state.hasOwnProperty(key) &&
+          m_state[key] != m_default[key]) {
+        if (!s) {
+          var s = 'mkws';
+          if (m_teamName !== 'AUTO') s += m_teamName;
+          s += '=';
+        } else {
+          s += "@";
+        }
+
+        s += key + '=' + m_state[key];
+      }
+    }
+
+    return s;
+  }
+
 
   // The following PubSub code is modified from the jQuery manual:
   // http://api.jquery.com/jQuery.Callbacks/
@@ -106,9 +131,6 @@ mkws.makeTeam = function($, teamName) {
 
   that.info("making new widget team");
 
-  m_state.sort = config.sort_default;
-  m_state.size = config.perpage_default;
   // pz2.js event handlers:
   function onInit() {
     that.info("init");
@@ -286,6 +308,8 @@ mkws.makeTeam = function($, teamName) {
   that.reShow = function() {
     resetPage();
     m_paz.show(0, m_state.size, m_state.sort);
+    // ### not really the right place for this but it will do for now.
+    that.warn("fragment: " + that.urlFragment());
   };
 
 
@@ -343,6 +367,9 @@ mkws.makeTeam = function($, teamName) {
 
     m_paz.search(m_state.query, m_state.size, m_state.sort, pp2filter, undefined, params);
     queue("searchtriggered").publish();
+
+    // ### not really the right place for this but it will do for now.
+    that.warn("fragment: " + that.urlFragment());
   }
 
   // fetch record details to be retrieved from the record queue