Abstract record-element ID generation to new recordElementId function
[mkws-moved-to-github.git] / tools / htdocs / mkws.js
index aced7e2..b4a52b2 100644 (file)
@@ -224,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;
@@ -349,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('<div class="record" id="mkwsRecdiv_' + team.name() + '_' + hit.recid + '" >',
-                         renderSummary(hit),
-                         '</div>');
+               var divId = team.recordElementId(hit.recid[0]);
+               html.push('<div class="record" id="' + 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.
@@ -399,32 +397,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;
-       }
+       });
     }
 }
 
@@ -547,12 +542,19 @@ function team($, teamName) {
        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 = document.getElementById(recordElementId(m_currentRecordData.recid[0]));
        var html = renderDetails(m_currentRecordData);
        $(recordDiv).append(html);
     }
 
 
+    // Used by promoteRecords() and onRecord()
+    function recordElementId(s) {
+       return 'mkwsRec_' + m_teamName + '_' + 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 ||