Remove obsolete logging
[mkws-moved-to-github.git] / tools / htdocs / mkws.js
index 7436ae9..0e7902e 100644 (file)
@@ -65,13 +65,19 @@ Handlebars.registerHelper('commaList', function(items, options) {
 });
 
 
+Handlebars.registerHelper('index1', function(obj) {
+    return obj.data.index + 1;
+});
+
+
 
 // Set up global mkws object. Contains truly global state such as SP
 // authentication, and a hash of team objects, indexed by windowid.
 //
 var mkws = {
     authenticated: false,
-    debug_level: undefined, // will be initialised from mkws_config
+    debug_level: 1, // Will be overridden from mkws_config, but
+                   // initial value allows jQuery popup to use logging.
     paz: undefined, // will be set up during initialisation
     teams: {},
     locale_lang: {
@@ -348,7 +354,6 @@ function team($, teamName) {
 
 
     function target_filtered(id) {
-       debug("target_filtered(" + id + ")");
        for (var i = 0; i < m_filters.length; i++) {
            if (m_filters[i].id === id ||
                m_filters[i].id === 'pz:id=' + id) {
@@ -805,10 +810,10 @@ function team($, teamName) {
   {{/if}}\
   {{#if md-electronic-url}}\
   <tr>\
-    <th>{{translate "URL"}}</th>\
+    <th>{{translate "Links"}}</th>\
     <td>\
       {{#each md-electronic-url}}\
-       <a href="{{this}}">{{this}}</a><br/>\
+       <a href="{{this}}">Link{{index1}}</a>\
       {{/each}}\
     </td>\
   </tr>\
@@ -870,8 +875,8 @@ function team($, teamName) {
            mkws.handle_node_with_team(node, function(tname) {
                $(node).html('\
 <form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + tname + '" action="" >\
-  <input id="mkwsQuery" class="mkwsQuery mkwsTeam_' + tname + '" type="text" size="' + mkws_config.query_width + '" />\
-  <input id="mkwsButton" class="mkwsButton mkwsTeam_' + tname + '" type="submit" value="' + M('Search') + '" />\
+  <input class="mkwsQuery mkwsTeam_' + tname + '" type="text" size="' + mkws_config.query_width + '" />\
+  <input class="mkwsButton mkwsTeam_' + tname + '" type="submit" value="' + M('Search') + '" />\
 </form>');
            });
        });
@@ -891,13 +896,13 @@ function team($, teamName) {
 <table width="100%" border="0" cellpadding="6" cellspacing="0">\
   <tr>\
     <td class="mkwsTermlistContainer1 mkwsTeam_' + m_teamName + '" width="250" valign="top">\
-      <div id="mkwsTermlists" class="mkwsTermlists mkwsTeam_' + m_teamName + '"></div>\
+      <div class="mkwsTermlists mkwsTeam_' + m_teamName + '"></div>\
     </td>\
     <td class="mkwsMOTDContainer mkwsTeam_' + m_teamName + '" valign="top">\
-      <div id="mkwsRanking" class="mkwsRanking mkwsTeam_' + m_teamName + '"></div>\
-      <div id="mkwsPager" class="mkwsPager mkwsTeam_' + m_teamName + '"></div>\
-      <div id="mkwsNavi" class="mkwsNavi mkwsTeam_' + m_teamName + '"></div>\
-      <div id="mkwsRecords" class="mkwsRecords mkwsTeam_' + m_teamName + '"></div>\
+      <div class="mkwsRanking mkwsTeam_' + m_teamName + '"></div>\
+      <div class="mkwsPager mkwsTeam_' + m_teamName + '"></div>\
+      <div class="mkwsNavi mkwsTeam_' + m_teamName + '"></div>\
+      <div class="mkwsRecords mkwsTeam_' + m_teamName + '"></div>\
     </td>\
   </tr>\
   <tr>\
@@ -1310,6 +1315,24 @@ function team($, teamName) {
            // ### should check mkwsTermlist as well, for facet-only teams
            var node = $('.mkwsRecords.mkwsTeam_' + teamName);
            var query = node.attr('autosearch');
+
+           if (query.match(/^!param!/)) {
+               var param = query.replace(/^!param!/, '');
+               query = getParameterByName(param);
+               debug("obtained query '" + query + "' from param '" + param + "'");
+               if (!query) {
+                   alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter");
+               }
+           } else if (query.match(/^!path!/)) {
+               var index = query.replace(/^!path!/, '');
+               var path = window.location.pathname.split('/');
+               query = path[path.length - index];
+               debug("obtained query '" + query + "' from path-component '" + index + "'");
+               if (!query) {
+                   alert("This page has a MasterKey widget that needs a query specified by the path-component " + index);
+               }
+           }
+
            debug("teamName '" + teamName + "', node=" + node + ", class='" + node.className + "', query=" + query);
 
            if (query) {
@@ -1328,6 +1351,16 @@ function team($, teamName) {
     }
 
 
+    // This function is taken from a StackOverflow answer
+    // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144
+    function getParameterByName(name) {
+       name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
+       var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
+           results = regex.exec(location.search);
+       return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
+    }
+
+
     $(document).ready(function() {
        debug("on load ready");
        default_mkws_config();