Termlists: promoteTermlists,
Pager: promotePager,
Records: promoteRecords,
- Navi: promoteNavi
+ Navi: promoteNavi,
+ Sort: promoteSort,
+ Perpage: promotePerpage
};
var promote = type2fn[type];
if (promote) {
promote();
- team.debug("made " + type + " widget(node=" + node + ")");
+ debug("made " + type + " widget(node=" + node + ")");
} else {
- team.debug("made UNENCAPSULATED widget(type=" + type + ", node=" + node + ")");
+ debug("made UNENCAPSULATED widget(type=" + type + ", node=" + node + ")");
}
return that;
+ function debug(s) {
+ team.debug(s);
+ }
+
// Functions follow for promoting the regular widget object into
// widgets of specific types. These could be moved outside of the
// widget object, or even into their own source files.
function promoteTargets() {
team.queue("targets").subscribe(function(data) {
- if (node.length === 0) alert("huh?!");
-
var table ='<table><thead><tr>' +
'<td>' + M('Target ID') + '</td>' +
'<td>' + M('Hits') + '</td>' +
function promoteTermlists() {
team.queue("termlists").subscribe(function(data) {
- mkws.debug("in termlist consumer");
if (!node) {
alert("termlists event when there are no termlists");
return;
var html = [];
for (var i = 0; i < data.hits.length; i++) {
var hit = data.hits[i];
- html.push('<div class="record" id="mkwsRecdiv_' + team.name() + '_' + hit.recid + '" >',
- renderSummary(hit),
- '</div>');
+ var divId = team.recordElementId(hit.recid[0]);
+ html.push('<div class="record mkwsTeam_' + team.name() + ' ' + divId + '">', renderSummary(hit), '</div>');
// ### At some point, we may be able to move the
// m_currentRecordId and m_currentRecordData members
// from the team object into this widget.
function renderSummary(hit)
{
var template = team.loadTemplate("Summary");
- hit._id = "mkwsRec_" + hit.recid;
- hit._onclick = "mkws.showDetails('" + team.name() + "', this.id);return false;"
+ hit._id = team.recordElementId(hit.recid[0]);
+ hit._onclick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"
return template(hit);
}
});
$(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;
+ });
+ }
}
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; }
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) + ") "
debug("record");
// FIXME: record is async!!
clearTimeout(m_paz.recordTimer);
- // in case on_show was faster to redraw element
- var detRecordDiv = document.getElementById('mkwsDet_' + teamName + '_' + data.recid);
- if (detRecordDiv) return;
+ // ##### restrict to current team
+ var detRecordDiv = document.getElementById(recordDetailsId(data.recid[0]));
+ if (detRecordDiv) {
+ // in case on_show was faster to redraw element
+ 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;
+
+ // Used by onRecord(), showDetails() and renderDetails()
+ function recordDetailsId(s) {
+ return 'mkwsDet_' + 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 ||
}
m_filters = []
- redrawNavi();
- resetPage();
- loadSelect();
triggerSearch(query, sortOrder, targets);
switchView('records'); // In case it's configured to start off as hidden
m_submitted = true;
}
- function onSelectDdChange()
+ // limit by target functions
+ that.limitTarget = function (id, name)
{
- if (!m_submitted) return false;
- resetPage();
- loadSelect();
- m_paz.show(0, m_perpage, m_sortOrder);
+ debug("limitTarget(id=" + id + ", name=" + name + ")");
+ m_filters.push({ id: id, name: name });
+ triggerSearch();
return false;
}
- function redrawNavi ()
+ // limit the query after clicking the facet
+ that.limitQuery = function (field, value)
{
- queue("navi").publish();
+ debug("limitQuery(field=" + field + ", value=" + value + ")");
+ m_filters.push({ field: field, value: value });
+ triggerSearch();
+ return false;
}
- function resetPage()
+ that.delimitTarget = function (id)
{
- m_currentPage = 1;
- m_totalRecordCount = 0;
+ debug("delimitTarget(id=" + id + ")");
+ var newFilters = [];
+ for (var i in m_filters) {
+ var filter = m_filters[i];
+ if (filter.id) {
+ debug("delimitTarget() removing filter " + $.toJSON(filter));
+ } else {
+ debug("delimitTarget() keeping filter " + $.toJSON(filter));
+ newFilters.push(filter);
+ }
+ }
+ m_filters = newFilters;
+
+ triggerSearch();
+ return false;
}
- function loadSelect ()
+ that.delimitQuery = function (field, value)
{
- var node = findnode('.mkwsSort');
- if (node.length && node.val() != m_sortOrder) {
- debug("changing m_sortOrder from " + m_sortOrder + " to " + node.val());
- m_sortOrder = node.val();
- }
- node = findnode('.mkwsPerpage');
- if (node.length && node.val() != m_perpage) {
- debug("changing m_perpage from " + m_perpage + " to " + node.val());
- m_perpage = node.val();
+ debug("delimitQuery(field=" + field + ", value=" + value + ")");
+ var newFilters = [];
+ for (var i in m_filters) {
+ var filter = m_filters[i];
+ if (filter.field &&
+ field == filter.field &&
+ value == filter.value) {
+ debug("delimitQuery() removing filter " + $.toJSON(filter));
+ } else {
+ debug("delimitQuery() keeping filter " + $.toJSON(filter));
+ newFilters.push(filter);
+ }
}
+ m_filters = newFilters;
+
+ triggerSearch();
+ return false;
}
+ function resetPage()
+ {
+ m_currentPage = 1;
+ m_totalRecordCount = 0;
+ }
+ that.resetPage = resetPage;
+
+
function triggerSearch (query, sortOrder, targets)
{
+ resetPage();
+ queue("navi").publish();
+
var pp2filter = "";
var pp2limit = "";
}
- // limit by target functions
- that.limitTarget = function (id, name)
- {
- debug("limitTarget(id=" + id + ", name=" + name + ")");
- m_filters.push({ id: id, name: name });
- redrawNavi();
- resetPage();
- loadSelect();
- triggerSearch();
- return false;
- }
-
-
- // limit the query after clicking the facet
- that.limitQuery = function (field, value)
- {
- debug("limitQuery(field=" + field + ", value=" + value + ")");
- m_filters.push({ field: field, value: value });
- redrawNavi();
- resetPage();
- loadSelect();
- triggerSearch();
- return false;
- }
-
-
- that.delimitTarget = function (id)
- {
- debug("delimitTarget(id=" + id + ")");
- var newFilters = [];
- for (var i in m_filters) {
- var filter = m_filters[i];
- if (filter.id) {
- debug("delimitTarget() removing filter " + $.toJSON(filter));
- } else {
- debug("delimitTarget() keeping filter " + $.toJSON(filter));
- newFilters.push(filter);
- }
- }
- m_filters = newFilters;
-
- redrawNavi();
- resetPage();
- loadSelect();
- triggerSearch();
- return false;
+ that.reShow = function() {
+ m_paz.show(0, m_perpage, m_sortOrder);
}
- that.delimitQuery = function (field, value)
- {
- debug("delimitQuery(field=" + field + ", value=" + value + ")");
- var newFilters = [];
- for (var i in m_filters) {
- var filter = m_filters[i];
- if (filter.field &&
- field == filter.field &&
- value == filter.value) {
- debug("delimitQuery() removing filter " + $.toJSON(filter));
- } else {
- debug("delimitQuery() keeping filter " + $.toJSON(filter));
- newFilters.push(filter);
- }
- }
- m_filters = newFilters;
-
- redrawNavi();
- resetPage();
- loadSelect();
- triggerSearch();
- return false;
- }
-
that.showPage = function (pageNum)
{
alert("Unknown view '" + view + "'");
}
}
-
-
that.switchView = switchView;
// detailed record drawing
- that.showDetails = function (prefixRecId) {
- var recId = prefixRecId.replace('mkwsRec_', '');
+ that.showDetails = function (recId) {
var oldRecordId = m_currentRecordId;
m_currentRecordId = recId;
// remove current detailed view if any
- var detRecordDiv = document.getElementById('mkwsDet_' + m_teamName + '_' + oldRecordId);
+ // ##### restrict to current team
+ var detRecordDiv = document.getElementById(recordDetailsId(oldRecordId));
// lovin DOM!
if (detRecordDiv)
detRecordDiv.parentNode.removeChild(detRecordDiv);
// .mkwsPager
// .mkwsNavi
// .mkwsRecords
- if (findnode(".mkwsResults").length) {
- findnode(".mkwsResults").html('\
+ findnode(".mkwsResults").html('\
<table width="100%" border="0" cellpadding="6" cellspacing="0">\
<tr>\
<td class="mkwsTermlistContainer1 mkwsTeam_' + m_teamName + '" width="250" valign="top">\
</td>\
</tr>\
</table>');
- }
- var node = findnode(".mkwsRanking");
- if (node.length) {
- var ranking_data = '<form name="mkwsSelect" class="mkwsSelect mkwsTeam_' + m_teamName + '" action="" >';
- if (mkws_config.show_sort) {
- ranking_data += M('Sort by') + ' ' + mkwsHtmlSort() + ' ';
- }
- if (mkws_config.show_perpage) {
- ranking_data += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.';
- }
- ranking_data += '</form>';
-
- node.html(ranking_data);
+ var ranking_data = '<form name="mkwsSelect" class="mkwsSelect mkwsTeam_' + m_teamName + '" action="" >';
+ if (mkws_config.show_sort) {
+ ranking_data += M('Sort by') + ' ' + mkwsHtmlSort() + ' ';
}
+ if (mkws_config.show_perpage) {
+ ranking_data += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.';
+ }
+ ranking_data += '</form>';
+ findnode(".mkwsRanking").html(ranking_data);
mkwsHtmlSwitch();
- var node;
- node = findnode('.mkwsSearchForm');
- if (node.length)
- node.submit(onFormSubmitEventHandler);
- node = findnode('.mkwsSort');
- if (node.length)
- node.change(onSelectDdChange);
- node = findnode('.mkwsPerpage');
- if (node.length)
- node.change(onSelectDdChange);
+ findnode('.mkwsSearchForm').submit(onFormSubmitEventHandler);
// on first page, hide the termlist
$(document).ready(function() { findnode(".mkwsTermlists").hide(); });
- var motd = findnode(".mkwsMOTD");
var container = findnode(".mkwsMOTDContainer");
- if (motd.length && container.length) {
+ if (container.length) {
// Move the MOTD from the provided element down into the container
- motd.appendTo(container);
+ findnode(".mkwsMOTD").appendTo(container);
}
}
{
var template = loadTemplate("Record");
var details = template(data);
- return '<div class="details" id="mkwsDet_' + m_teamName + '_' + data.recid + '">' + details + '</div>';
+ return '<div class="details mkwsTeam_' + m_teamName + '" id="' + recordDetailsId(data.recid[0]) + '">' + details + '</div>';
}
that.renderDetails = renderDetails;
}
return queues[id];
}
-
that.queue = queue;
// Second pass: make the individual widget objects. This has
// to be done separately, and after the team-creation, since
// that sometimes makes new widget nodes (e.g. creating
- // mkwsTermlists instead mkwsResults.
+ // mkwsTermlists inside mkwsResults.
$('[class^="mkws"],[class*=" mkws"]').each(function () {
mkws.handleNodeWithTeam(this, function(tname, type) {
var myTeam = mkws.teams[tname];