X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=32be2c7bbf51a8943f7f3d1a5c4387ee5be04670;hb=212d3cd70d1379ba08272b97a8414ffaadbb4e72;hp=04dca89fa97f87c725f74f4eabc7a61cf5554b91;hpb=61b3773a2c551e9a7114a2057b2e2fb601db7e4d;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 04dca89..32be2c7 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -158,19 +158,23 @@ function widget($, team, type, node) { var M = mkws.M; - if (type === 'Targets') { - promoteTargets(); - } else if (type === 'Stat') { - promoteStat(); - } else if (type === 'Termlists') { - promoteTermlists(); - } else if (type === 'Pager') { - promotePager(); + var type2fn = { + Targets: promoteTargets, + Stat: promoteStat, + Termlists: promoteTermlists, + Pager: promotePager, + Records: promoteRecords, + Navi: promoteNavi + }; + + var promote = type2fn[type]; + if (promote) { + promote(); + team.debug("made " + type + " 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; @@ -180,8 +184,6 @@ function widget($, team, type, node) { function promoteTargets() { team.queue("targets").subscribe(function(data) { - if (node.length === 0) alert("huh?!"); - var table ='' + '' + '' + @@ -282,9 +284,7 @@ function widget($, team, type, node) { function promotePager() { team.queue("pager").subscribe(function(data) { - if (node) { - $(node).html(drawPager(data)) - } + $(node).html(drawPager(data)) function drawPager(data) { var s = '
' + M('Displaying') + ': ' @@ -340,6 +340,60 @@ function widget($, team, type, node) { } }); } + + + 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(team.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); + } + }); + } + + + function promoteNavi() { + team.queue("navi").subscribe(function() { + var filters = team.filters(); + var text = ""; + + for (var i in filters) { + if (text) { + text += " | "; + } + var filter = filters[i]; + if (filter.id) { + text += M('source') + ': ' + filter.name + ''; + } else { + text += M(filter.field) + ': ' + filter.value + ''; + } + } + + $(node).html(text); + }); + } } @@ -375,6 +429,9 @@ function team($, 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; } + that.filters = function() { return m_filters; } var debug = function (s) { var now = $.now(); @@ -383,6 +440,7 @@ function team($, teamName) { mkws.debug(m_teamName + ": " + timestamp + s); } + that.debug = debug; debug("start running MKWS"); @@ -438,25 +496,8 @@ function team($, teamName) { function onShow(data, teamName) { debug("show"); m_totalRecordCount = data.merged; - queue("pager").publish(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("records").publish(data); } @@ -518,7 +559,7 @@ function team($, teamName) { } - function onSelectDdChange() + function onSortChange() { if (!m_submitted) return false; resetPage(); @@ -528,28 +569,19 @@ function team($, teamName) { } - function redrawNavi () + function onPerpageChange() { - var navi = findnode('.mkwsNavi'); - if (!navi) return; + if (!m_submitted) return false; + resetPage(); + loadSelect(); + m_paz.show(0, m_perpage, m_sortOrder); + return false; + } - var text = ""; - for (var i in m_filters) { - if (text) { - text += " | "; - } - var filter = m_filters[i]; - if (filter.id) { - text += M('source') + ': ' + filter.name + ''; - } else { - text += M(filter.field) + ': ' + filter.value + ''; - } - } - navi.html(text); + function redrawNavi () + { + queue("navi").publish(); } @@ -830,8 +862,7 @@ function team($, teamName) { var node = findnode(".mkwsRanking"); if (node.length) { - var ranking_data = ''; - ranking_data += '
'; + var ranking_data = ''; if (mkws_config.show_sort) { ranking_data += M('Sort by') + ' ' + mkwsHtmlSort() + ' '; } @@ -851,10 +882,10 @@ function team($, teamName) { node.submit(onFormSubmitEventHandler); node = findnode('.mkwsSort'); if (node.length) - node.change(onSelectDdChange); + node.change(onSortChange); node = findnode('.mkwsPerpage'); if (node.length) - node.change(onSelectDdChange); + node.change(onPerpageChange); // on first page, hide the termlist $(document).ready(function() { findnode(".mkwsTermlists").hide(); }); @@ -1048,21 +1079,13 @@ 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"); var details = template(data); return '
' + details + '
'; } + that.renderDetails = renderDetails; function loadTemplate(name) @@ -1088,6 +1111,7 @@ function team($, teamName) { return template; } + that.loadTemplate = loadTemplate; // The following PubSub code is modified from the jQuery manual: @@ -1499,7 +1523,7 @@ function team($, teamName) { // 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];
' + M('Target ID') + '' + M('Hits') + '