X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=02b0b550e94d61379b49b936a7dac7e6627020b5;hb=5b0f2c074c1fee794cdec4bca1612f704ec9bca3;hp=1b45c79a3a3e7164abc77476c7faca36a53adc6f;hpb=eefc90ceb608fec8b276e06b0218f1e717854159;p=mkws-moved-to-github.git
diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js
index 1b45c79..02b0b55 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];
@@ -222,7 +224,6 @@ function widget($, team, type, node) {
function promoteTermlists() {
team.queue("termlists").subscribe(function(data) {
- mkws.debug("in termlist consumer");
if (!node) {
alert("termlists event when there are no termlists");
return;
@@ -347,9 +348,8 @@ function widget($, team, type, node) {
var html = [];
for (var i = 0; i < data.hits.length; i++) {
var hit = data.hits[i];
- html.push('
',
- renderSummary(hit),
- '
');
+ var divId = team.recordElementId(hit.recid[0]);
+ html.push('', renderSummary(hit), '
');
// ### At some point, we may be able to move the
// m_currentRecordId and m_currentRecordData members
// from the team object into this widget.
@@ -394,6 +394,33 @@ function widget($, team, type, node) {
$(node).html(text);
});
}
+
+
+ function promoteSort() {
+ // It seems this and the Perpage widget doen't need to
+ // subscribe to anything, since they produce events rather
+ // than consuming them.
+ $(node).change(function () {
+ team.set_sortOrder($(node).val());
+ if (team.submitted()) {
+ team.resetPage();
+ team.reShow();
+ }
+ return false;
+ });
+ }
+
+
+ function promotePerpage() {
+ $(node).change(function() {
+ team.set_perpage($(node).val());
+ if (team.submitted()) {
+ team.resetPage();
+ team.reShow();
+ }
+ return false;
+ });
+ }
}
@@ -426,6 +453,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 +461,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) + ") "
@@ -509,13 +541,19 @@ function team($, teamName) {
var detRecordDiv = document.getElementById('mkwsDet_' + teamName + '_' + data.recid);
if (detRecordDiv) return;
m_currentRecordData = data;
- // Can't use jQuery's $('#x') syntax to find this ID, because it contains spaces.
- var recordDiv = document.getElementById('mkwsRecdiv_' + teamName + '_' + m_currentRecordData.recid);
+ var recordDiv = findnode(recordElementId(m_currentRecordData.recid[0]));
var html = renderDetails(m_currentRecordData);
$(recordDiv).append(html);
}
+ // Used by promoteRecords() and onRecord()
+ function recordElementId(s) {
+ return 'mkwsRec_' + s.replace(/[^a-z0-9]/ig, '_');
+ }
+ that.recordElementId = recordElementId;
+
+
that.targetFiltered = function(id) {
for (var i = 0; i < m_filters.length; i++) {
if (m_filters[i].id === id ||
@@ -556,26 +594,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 +661,7 @@ function team($, teamName) {
m_currentPage = 1;
m_totalRecordCount = 0;
}
+ that.resetPage = resetPage;
function triggerSearch (query, sortOrder, targets)
@@ -695,6 +714,12 @@ function team($, teamName) {
}
+ that.reShow = function() {
+ m_paz.show(0, m_perpage, m_sortOrder);
+ }
+
+
+
that.showPage = function (pageNum)
{
m_currentPage = pageNum;
@@ -836,8 +861,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(); });