From: Mike Taylor Date: Thu, 30 Apr 2015 16:02:55 +0000 (+0100) Subject: Team object now carries a copy of its initial state. X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=61e95cf874362f311c783de8dcd736d375aac714;p=mkws-moved-to-github.git 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. --- 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