Termlists widget creates the individual Facet widgets therein.
[mkws-moved-to-github.git] / src / mkws-team.js
index b02b441..8f4235e 100644 (file)
@@ -26,7 +26,8 @@ function team($, teamName) {
        "last": $.now()
     };
     var m_paz; // will be initialised below
-    var m_template = {};
+    var m_tempateText = {}; // widgets can register tempates to be compiled
+    var m_template = {}; // compiled templates, from any source
     var m_config = mkws.objectInheritingFrom(mkws.config);
     var m_widgets = {}; // Maps widget-type to object
 
@@ -186,7 +187,7 @@ function team($, teamName) {
     that.limitCategory = function(id) {
        log("limitCategory(id=" + id + ")");
         // Only one category filter at a time
-       m_filterSet.removeMatching(function(f) { return f.type === 'category' });        
+       m_filterSet.removeMatching(function(f) { return f.type === 'category' });
         if (id !== '') m_filterSet.add(categoryFilter(id));
         if (m_query) triggerSearch();
        return false;
@@ -267,15 +268,17 @@ function team($, teamName) {
        if (query) m_query = query;
        if (sortOrder) m_sortOrder = sortOrder;
        if (perpage) m_perpage = perpage;
-       if (targets) m_filterSet.add(targetFilter(id, id));
+       if (targets) m_filterSet.add(targetFilter(targets, targets));
 
        var pp2filter = m_filterSet.pp2filter();
        var pp2limit = m_filterSet.pp2limit(limit);
         var pp2catLimit = m_filterSet.pp2catLimit();
+       if (pp2catLimit) {
+            pp2filter = pp2filter ? pp2filter + "," + pp2catLimit : pp2catLimit;
+        }
 
        var params = {};
        if (pp2limit) params.limit = pp2limit;
-       if (pp2catLimit) params.categoryfilter = pp2catLimit;
        if (maxrecs) params.maxrecs = maxrecs;
        if (torusquery) {
            if (!mkws.config.use_service_proxy)
@@ -353,13 +356,6 @@ function team($, teamName) {
        if (m_config.show_lang)
            mkwsHtmlLang();
 
-       log("HTML search form");
-       findnode('.mkwsSearch').html('\
-<form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + m_teamName + '" action="" >\
-  <input class="mkwsQuery mkwsTeam_' + m_teamName + '" type="text" size="' + m_config.query_width + '" />\
-  <input class="mkwsButton mkwsTeam_' + m_teamName + '" type="submit" value="' + M('Search') + '" />\
-</form>');
-
        log("HTML records");
        // If the team has a .mkwsResults, populate it in the usual
        // way. If not, assume that it's a smarter application that
@@ -409,16 +405,11 @@ function team($, teamName) {
         ranking_data += '</form>';
        findnode(".mkwsRanking").html(ranking_data);
 
-       mkwsHtmlSwitch();
-
-       findnode('.mkwsSearchForm').submit(function() {
-           var val = widgetNode('Query').val();
-           newSearch(val);
-           return false;
-       });
-
        // on first page, hide the termlist
-       $(document).ready(function() { widgetNode("Termlists").hide(); });
+       $(document).ready(function() {
+            var t = widgetNode("Termlists");
+            if (t) t.hide();
+        });
         var container = findnode(".mkwsMOTDContainer");
        if (container.length) {
            // Move the MOTD from the provided element down into the container
@@ -439,7 +430,27 @@ function team($, teamName) {
        return m_config.lang;
     }
 
+    // set or re-set "lang" URL parameter
+    function lang_url(lang) {
+       var query = location.search;
+       // no query parameters? done
+       if (!query) {
+           return "?lang=" + lang;
+       }
+
+       // parameter does not exists
+       if (!query.match(/[\?&]lang=/)) {
+            return query + "&lang=" + lang;
+        }
+
+       // replace existing parameter
+       query = query.replace(/\?lang=([^&#;]*)/, "?lang=" + lang);
+       query = query.replace(/\&lang=([^&#;]*)/, "&lang=" + lang);
 
+       return query;
+    }
+   
+       // dynamic URL or static page? /path/foo?query=test
     /* create locale language menu */
     function mkwsHtmlLang() {
        var lang_default = "en";
@@ -475,7 +486,7 @@ function team($, teamName) {
            if (lang == l) {
                data += ' <span>' + l + '</span> ';
            } else {
-               data += ' <a href="?lang=' + l + '">' + l + '</a> '
+               data += ' <a href="' + lang_url(l) + '">' + l + '</a> '
            }
        }
 
@@ -523,24 +534,6 @@ function team($, teamName) {
     }
 
 
-    function mkwsHtmlSwitch() {
-       log("HTML switch for team " + m_teamName);
-
-       var node = findnode(".mkwsSwitch");
-       node.append($('<a href="#" onclick="mkws.switchView(\'' + m_teamName + '\', \'records\')">' + M('Records') + '</a>'));
-       node.append($("<span/>", { text: " | " }));
-       node.append($('<a href="#" onclick="mkws.switchView(\'' + m_teamName + '\', \'targets\')">' + M('Targets') + '</a>'));
-
-       log("HTML targets");
-       var node = findnode(".mkwsTargets");
-       node.html('\
-<div class="mkwsBytarget mkwsTeam_' + m_teamName + '">\
-  No information available yet.\
-</div>');
-       node.css("display", "none");
-    }
-
-
     // Translation function. At present, this is properly a
     // global-level function (hence the assignment to mkws.M) but we
     // want to make it per-team so different teams can operate in
@@ -591,6 +584,11 @@ function team($, teamName) {
     that.renderDetails = renderDetails;
 
 
+    that.registerTemplate = function(name, text) {
+        m_tempateText[name] = text;
+    };
+
+
     function loadTemplate(name) {
        var template = m_template[name];
 
@@ -606,6 +604,9 @@ function team($, teamName) {
             }
 
            if (!source) {
+                source = m_tempateText[name];
+            }
+           if (!source) {
                source = defaultTemplate(name);
            }