X-Git-Url: http://git.indexdata.com/?p=mkws-moved-to-github.git;a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=c506ccfe645b658ac0307e082bf781cef59cc3ef;hp=3f8c84c946dbd90eb85a633d0dade86905ab506f;hb=db352294db725a7576d7f867b15a5cded97e248e;hpb=6e074b7f3e1fea1ef7c58c4d76966d8209e0816f
diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js
index 3f8c84c..c506ccf 100644
--- a/tools/htdocs/mkws.js
+++ b/tools/htdocs/mkws.js
@@ -160,15 +160,24 @@ function widget($, team, type, node) {
if (type === 'Targets') {
promoteTargets();
+ team.debug("made targets widget(node=" + node + ")");
} else if (type === 'Stat') {
promoteStat();
+ team.debug("made stat widget(node=" + node + ")");
} else if (type === 'Termlists') {
promoteTermlists();
+ team.debug("made termlists widget(node=" + node + ")");
+ } else if (type === 'Pager') {
+ promotePager();
+ team.debug("made pager widget(node=" + node + ")");
+ } else if (type === 'Records') {
+ promoteRecords();
+ team.debug("made records widget(node=" + node + ")");
} else {
// ### Handle other types here
+ team.debug("made unencapsulated widget(type=" + type + ", node=" + node + ")");
}
- mkws.debug("made widget(team=" + team + ", type=" + type + ", node=" + node);
return that;
@@ -276,6 +285,95 @@ function widget($, team, type, node) {
}
});
}
+
+
+ function promotePager() {
+ team.queue("pager").subscribe(function(data) {
+ $(node).html(drawPager(data))
+
+ function drawPager(data) {
+ var s = '
' + M('Displaying') + ': '
+ + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) +
+ ' ' + M('of') + ' ' + data.merged + ' (' + M('found') + ': '
+ + data.total + ')
';
+
+ //client indexes pages from 1 but pz2 from 0
+ var onsides = 6;
+ var pages = Math.ceil(team.totalRecordCount() / team.perpage());
+ var currentPage = team.currentPage();
+
+ var firstClkbl = (currentPage - onsides > 0)
+ ? currentPage - onsides
+ : 1;
+
+ var lastClkbl = firstClkbl + 2*onsides < pages
+ ? firstClkbl + 2*onsides
+ : pages;
+
+ var prev = '<< ' + M('Prev') + ' | ';
+ if (currentPage > 1)
+ prev = ''
+ +'<< ' + M('Prev') + ' | ';
+
+ var middle = '';
+ for(var i = firstClkbl; i <= lastClkbl; i++) {
+ var numLabel = i;
+ if(i == currentPage)
+ numLabel = '' + i + '';
+
+ middle += ' '
+ + numLabel + ' ';
+ }
+
+ var next = ' | ' + M('Next') + ' >>';
+ if (pages - currentPage > 0)
+ next = ' | '
+ + M('Next') + ' >>';
+
+ var predots = '';
+ if (firstClkbl > 1)
+ predots = '...';
+
+ var postdots = '';
+ if (lastClkbl < pages)
+ postdots = '...';
+
+ s += ''
+ + prev + predots + middle + postdots + next + '
';
+
+ return s;
+ }
+ });
+ }
+
+
+ function promoteRecords() {
+ team.queue("records").subscribe(function(data) {
+ var html = [];
+ for (var i = 0; i < data.hits.length; i++) {
+ var hit = data.hits[i];
+ 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.
+ if (hit.recid == team.currentRecordId()) {
+ if (team.currentRecordData())
+ html.push(renderDetails(team.currentRecordData()));
+ }
+ }
+ $(node).html(html.join(''));
+
+ function renderSummary(hit)
+ {
+ var template = team.loadTemplate("Summary");
+ hit._id = "mkwsRec_" + hit.recid;
+ hit._onclick = "mkws.showDetails('" + team.name() + "', this.id);return false;"
+ return template(hit);
+ }
+ });
+ }
}
@@ -290,7 +388,6 @@ function widget($, team, type, node) {
function team($, teamName) {
var that = {};
var m_teamName = teamName;
- that.name = function() { return m_teamName; }
var m_submitted = false;
var m_query; // initially undefined
var m_sortOrder; // will be set below
@@ -308,6 +405,12 @@ function team($, teamName) {
var m_paz; // will be initialised below
var m_template = {};
+ that.name = function() { return m_teamName; }
+ that.perpage = function() { return m_perpage; }
+ that.totalRecordCount = function() { return m_totalRecordCount; }
+ that.currentPage = function() { return m_currentPage; }
+ that.currentRecordId = function() { return m_currentRecordId; }
+ that.currentRecordData = function() { return m_currentRecordData; }
var debug = function (s) {
var now = $.now();
@@ -316,6 +419,7 @@ function team($, teamName) {
mkws.debug(m_teamName + ": " + timestamp + s);
}
+ that.debug = debug;
debug("start running MKWS");
@@ -371,28 +475,8 @@ function team($, teamName) {
function onShow(data, teamName) {
debug("show");
m_totalRecordCount = data.merged;
-
- var pager = findnode(".mkwsPager");
- if (pager.length) {
- pager.html(drawPager(data))
- }
-
- var results = findnode(".mkwsRecords");
- if (!results.length)
- return;
-
- var html = [];
- for (var i = 0; i < data.hits.length; i++) {
- var hit = data.hits[i];
- html.push('',
- renderSummary(hit),
- '
');
- if (hit.recid == m_currentRecordId) {
- if (m_currentRecordData)
- html.push(renderDetails(m_currentRecordData));
- }
- }
- results.html(html.join(''));
+ queue("pager").publish(data);
+ queue("records").publish(data);
}
@@ -422,60 +506,6 @@ function team($, teamName) {
}
- function drawPager (data)
- {
- var s = '' + M('Displaying') + ': '
- + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) +
- ' ' + M('of') + ' ' + data.merged + ' (' + M('found') + ': '
- + data.total + ')
';
-
- //client indexes pages from 1 but pz2 from 0
- var onsides = 6;
- var pages = Math.ceil(m_totalRecordCount / m_perpage);
-
- var firstClkbl = (m_currentPage - onsides > 0)
- ? m_currentPage - onsides
- : 1;
-
- var lastClkbl = firstClkbl + 2*onsides < pages
- ? firstClkbl + 2*onsides
- : pages;
-
- var prev = '<< ' + M('Prev') + ' | ';
- if (m_currentPage > 1)
- prev = ''
- +'<< ' + M('Prev') + ' | ';
-
- var middle = '';
- for(var i = firstClkbl; i <= lastClkbl; i++) {
- var numLabel = i;
- if(i == m_currentPage)
- numLabel = '' + i + '';
-
- middle += ' '
- + numLabel + ' ';
- }
-
- var next = ' | ' + M('Next') + ' >>';
- if (pages - m_currentPage > 0)
- next = ' | '
- + M('Next') + ' >>';
-
- var predots = '';
- if (firstClkbl > 1)
- predots = '...';
-
- var postdots = '';
- if (lastClkbl < pages)
- postdots = '...';
-
- s += ''
- + prev + predots + middle + postdots + next + '
';
-
- return s;
- }
-
-
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -1038,15 +1068,6 @@ function team($, teamName) {
}
- function renderSummary(hit)
- {
- var template = loadTemplate("Summary");
- hit._id = "mkwsRec_" + hit.recid;
- hit._onclick = "mkws.showDetails('" + m_teamName + "', this.id);return false;"
- return template(hit);
- }
-
-
function renderDetails(data, marker)
{
var template = loadTemplate("Record");
@@ -1078,6 +1099,7 @@ function team($, teamName) {
return template;
}
+ that.loadTemplate = loadTemplate;
// The following PubSub code is modified from the jQuery manual: