From 61e95cf874362f311c783de8dcd736d375aac714 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Thu, 30 Apr 2015 17:02:55 +0100 Subject: [PATCH] Team object now carries a copy of its initial state. 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 | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/mkws-team.js b/src/mkws-team.js index 4d63ca2..bae55cf 100644 --- a/src/mkws-team.js +++ b/src/mkws-team.js @@ -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 -- 1.7.10.4