From 52099b8e0246b1a8977920a584710a7b6521513d Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Fri, 21 Mar 2014 17:00:19 +0000 Subject: [PATCH] Pub/subify two more widgets: Sort and Perpage. Involves: * adding one new team accessor, submitted * adding two new team setters, set_sortOrder and set_perpage * making team method resetPage externally visible * adding new resetPage externally visible team method reShow --- tools/htdocs/mkws.js | 68 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 1b45c79..aced7e2 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -164,7 +164,9 @@ function widget($, team, type, node) { Termlists: promoteTermlists, Pager: promotePager, Records: promoteRecords, - Navi: promoteNavi + Navi: promoteNavi, + Sort: promoteSort, + Perpage: promotePerpage }; var promote = type2fn[type]; @@ -394,6 +396,36 @@ function widget($, team, type, node) { $(node).html(text); }); } + + + function promoteSort() { + team.queue("navi").subscribe(function() {}) + $(node).change(onSortChange); + + function onSortChange() + { + team.set_sortOrder($(node).val()); + if (!team.submitted()) return false; + team.resetPage(); + team.reShow(); + return false; + } + } + + + function promotePerpage() { + team.queue("navi").subscribe(function() {}) + $(node).change(onPerpageChange); + + function onPerpageChange() + { + team.set_perpage($(node).val()); + if (!team.submitted()) return false; + team.resetPage(); + team.reShow(); + return false; + } + } } @@ -426,6 +458,7 @@ function team($, teamName) { var m_template = {}; that.name = function() { return m_teamName; } + that.submitted = function() { return m_submitted; } that.perpage = function() { return m_perpage; } that.totalRecordCount = function() { return m_totalRecordCount; } that.currentPage = function() { return m_currentPage; } @@ -433,6 +466,10 @@ function team($, teamName) { that.currentRecordData = function() { return m_currentRecordData; } that.filters = function() { return m_filters; } + that.set_sortOrder = function(val) { m_sortOrder = val }; + that.set_perpage = function(val) { m_perpage = val }; + + var debug = function (s) { var now = $.now(); var timestamp = ((now - m_debugTime.start)/1000).toFixed(3) + " (+" + ((now - m_debugTime.last)/1000).toFixed(3) + ") " @@ -556,26 +593,6 @@ function team($, teamName) { } - function onSortChange() - { - m_sortOrder = findnode('.mkwsSort').val(); - if (!m_submitted) return false; - resetPage(); - m_paz.show(0, m_perpage, m_sortOrder); - return false; - } - - - function onPerpageChange() - { - m_perpage = findnode('.mkwsPerpage').val(); - if (!m_submitted) return false; - resetPage(); - m_paz.show(0, m_perpage, m_sortOrder); - return false; - } - - // limit by target functions that.limitTarget = function (id, name) { @@ -643,6 +660,7 @@ function team($, teamName) { m_currentPage = 1; m_totalRecordCount = 0; } + that.resetPage = resetPage; function triggerSearch (query, sortOrder, targets) @@ -695,6 +713,12 @@ function team($, teamName) { } + that.reShow = function() { + m_paz.show(0, m_perpage, m_sortOrder); + } + + + that.showPage = function (pageNum) { m_currentPage = pageNum; @@ -836,8 +860,6 @@ function team($, teamName) { mkwsHtmlSwitch(); findnode('.mkwsSearchForm').submit(onFormSubmitEventHandler); - findnode('.mkwsSort').change(onSortChange); - findnode('.mkwsPerpage').change(onPerpageChange); // on first page, hide the termlist $(document).ready(function() { findnode(".mkwsTermlists").hide(); }); -- 1.7.10.4