X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=fc50e135bdd66c24ee01decd56097bfd335ec8b0;hb=9a5527fe29ae27c5e3e87bc9464b8c91c8225ead;hp=aced7e29eb57d0f588203f51045a14d17f7bdcbe;hpb=52099b8e0246b1a8977920a584710a7b6521513d;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index aced7e2..fc50e13 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -172,14 +172,18 @@ function widget($, team, type, node) { 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. @@ -224,7 +228,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; @@ -349,9 +352,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. @@ -365,8 +367,8 @@ function widget($, team, type, node) { 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); } }); @@ -399,32 +401,29 @@ function widget($, team, type, node) { function promoteSort() { - team.queue("navi").subscribe(function() {}) - $(node).change(onSortChange); - - function onSortChange() - { + // 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()) return false; - team.resetPage(); - team.reShow(); + if (team.submitted()) { + team.resetPage(); + team.reShow(); + } return false; - } + }); } function promotePerpage() { - team.queue("navi").subscribe(function() {}) - $(node).change(onPerpageChange); - - function onPerpageChange() - { + $(node).change(function() { team.set_perpage($(node).val()); - if (!team.submitted()) return false; - team.resetPage(); - team.reShow(); + if (team.submitted()) { + team.resetPage(); + team.reShow(); + } return false; - } + }); } } @@ -542,17 +541,32 @@ function team($, teamName) { 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 || @@ -776,13 +790,13 @@ function team($, teamName) { // 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); @@ -1056,7 +1070,7 @@ function team($, teamName) { { var template = loadTemplate("Record"); var details = template(data); - return '
' + details + '
'; + return '
' + details + '
'; } that.renderDetails = renderDetails;