Merge branch 'master' into templateallthemarkup
authorJason Skomorowski <jason@indexdata.com>
Mon, 22 Sep 2014 13:32:46 +0000 (09:32 -0400)
committerJason Skomorowski <jason@indexdata.com>
Mon, 22 Sep 2014 13:32:46 +0000 (09:32 -0400)
34 files changed:
.gitignore
README
examples/htdocs/jasmine-local-popup.html
examples/htdocs/jasmine-popup.html
examples/htdocs/mkws-widget-credo-bs.js [deleted file]
examples/htdocs/ref-bootstrap.html [deleted file]
examples/htdocs/topic-bootstrap.css [new file with mode: 0644]
examples/htdocs/topic-bootstrap.html [new file with mode: 0644]
examples/htdocs/two-teams.html
src/mkws-core.js
src/mkws-handlebars.js
src/mkws-team.js
src/mkws-widget-main.js
src/mkws-widget-main.templates/Done.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Image.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Lang.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Navi.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Pager.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Progress.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Ranking.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Record.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Records.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Results.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Search.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Stat.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Switch.handlebars [new file with mode: 0644]
src/mkws-widget-main.templates/Targets.handlebars [new file with mode: 0644]
src/mkws-widget-record.js
src/mkws-widget-reference.js
src/mkws-widget-reference.templates/Reference.handlebars [new file with mode: 0644]
src/mkws-widget-termlists.js
src/mkws-widget-termlists.templates/Facet.handlebars [new file with mode: 0644]
src/mkws-widget-termlists.templates/Termlists.handlebars [new file with mode: 0644]
tools/htdocs/Makefile

index b25c15b..b72f9be 100644 (file)
@@ -1 +1,2 @@
 *~
+*.swp
diff --git a/README b/README
index 5696cd1..7aacc48 100644 (file)
--- a/README
+++ b/README
@@ -30,6 +30,11 @@ or you can download the source from http://nodejs.org/download/ and build
 it yourself. Looks like you need node and npm, make install puts them
 into /usr/local/bin.
 
+To compile the default templates you'll need to install the stable version
+of Handlebars. Currently it's at 1.3.0 and available by npm:
+
+  npm install handlebars@1.3.0 -g
+
 For apache setup, see tools/apache2/README
 
 NEWS
index d5758b3..386e830 100644 (file)
@@ -10,7 +10,7 @@
     <script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
     <script type="text/javascript" src="tools/htdocs/pz2.js"></script>
     <script type="text/javascript" src="tools/htdocs/jquery.json-2.4.js"></script>
-    <script type="text/javascript" src="tools/htdocs/handlebars-v1.1.2.js"></script>
+    <script type="text/javascript" src="tools/htdocs/handlebars-v1.3.0.js"></script>
 
     <script type="text/javascript" src="src/mkws-handlebars.js"></script>
     <script type="text/javascript" src="src/mkws-core.js"></script>
@@ -24,6 +24,7 @@
     <script type="text/javascript" src="src/mkws-widget-categories.js"></script>
     <script type="text/javascript" src="src/mkws-widget-log.js"></script>
     <script type="text/javascript" src="src/mkws-widget-record.js"></script>
+    <script type="text/javascript" src="src/mkws-templates.js"></script>
     <script type="text/javascript" src="src/mkws-widget-reference.js"></script>
     <script type="text/javascript" src="src/mkws-widget-builder.js"></script>
 
index b2c7450..533dd4e 100644 (file)
@@ -10,7 +10,7 @@
     <script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
     <script type="text/javascript" src="tools/htdocs/pz2.js"></script>
     <script type="text/javascript" src="tools/htdocs/jquery.json-2.4.js"></script>
-    <script type="text/javascript" src="tools/htdocs/handlebars-v1.1.2.js"></script>
+    <script type="text/javascript" src="tools/htdocs/handlebars-v1.3.0.js"></script>
 
     <script type="text/javascript" src="src/mkws-handlebars.js"></script>
     <script type="text/javascript" src="src/mkws-core.js"></script>
@@ -18,6 +18,7 @@
     <script type="text/javascript" src="src/mkws-filter.js"></script>
     <script type="text/javascript" src="src/mkws-popup.js"></script>
     <script type="text/javascript" src="src/mkws-widget.js"></script>
+    <script type="text/javascript" src="src/mkws-templates.js"></script>
     <script type="text/javascript" src="src/mkws-widget-main.js"></script>
     <script type="text/javascript" src="src/mkws-widget-termlists.js"></script>
     <script type="text/javascript" src="src/mkws-widget-authname.js"></script>
diff --git a/examples/htdocs/mkws-widget-credo-bs.js b/examples/htdocs/mkws-widget-credo-bs.js
deleted file mode 100644 (file)
index 49651ea..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-// The Google Images database returns links like:
-//      http://images.google.com/url?q=http://eofdreams.com/fish.html&sa=U&ei=RAB-U9XNDo2Dqga1o4L4Bw&ved=0CC4Q9QEwAA&usg=AFQjCNFhRtn6GMevHbpITZ6kfx6rsHV2ow
-// This Handlebars helper avoids a pointless redirect by transforming
-// this to the URL of the underling page, in this case
-//      http://eofdreams.com/fish.html
-//
-Handlebars.registerHelper('mkws-googleurl', function(obj) {
-  if (!obj) {
-    return "obj undefined";
-  } else if (!obj[0]) {
-    return "obj[0] undefined, JSON=" + $.toJSON(obj);
-  } else {
-    return mkws.getParameterByName('q', obj[0]);
-  }
-});
-
-
-// ### This works inefficiently by having multiple teams all run the
-// same search against different sets of targets. A much better
-// approach would be run a single search, with all these panels
-// members of the same team, but picking out only the results relevant
-// to them. That will be more work.
-
-mkws.registerWidgetType('Credo', function() {
-  var that = this;
-
-  this.team.registerTemplate('CredoImage', '\
-      <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">\
-       <a href="{{mkws-googleurl md-electronic-url}}" target="_blank">\
-        {{#mkws-first md-thumburl}}\
-         <img src="{{this}}" alt="{{../md-title}}"/>\
-        {{/mkws-first}}\
-       <br/>\
-       </a>\
-       <p>{{{md-title}}}</p>\
-      </div>\
-');
-
-  var s = []
-  // Main panel: encylopaedia and images on the left, topics on the right
-  s.push('<div class="row">');
-
-  s.push('<div class="jumbotron panel col-md-8"><div class="panel-body">');
-  //s.push(section('encyclopaedia', 'Topic Page: <span class="x-mkws-title"/>',
-  s.push(this.subwidget('Reference', { _team: 'ref', paragraphs: 1 }));
-  // The Images widget needs to be in our team so we can set its template
-  s.push('</div></div>');
-
-  s.push('<div class="col-md-4">');
-  s.push(section('topics', 'Related Topics',
-                 this.subwidget('Facet', { _team: 'main', facet: 'subject' })));
-  s.push('</div>');
-
-  s.push('</div>');
-  
-  s.push('<div class="row">');
-  s.push(section('image col-md-12', 'Images', this.subwidget('GoogleImage', { maxrecs: 4, template: 'CredoImage', target: 'google_images_js' })));
-  s.push('</div>');
-  
-
-  s.push('<div class="row clearfix">');
-  s.push(section('entries clearfix col-md-4 col-sm-6', 'News',
-                 this.subwidget('Records', { _team: 'news', targetfilter: 'categories=news', perpage: 10 })));
-  s.push(section('articles clearfix col-md-4 col-sm-6', 'Articles',
-                    this.subwidget('Records', { _team: 'articles', targetfilter: 'categories=articles', perpage: 10 })));
-  s.push(section('books clearfix col-md-4 col-sm-6', 'Books',
-                    this.subwidget('Records', { _team: 'books', targetfilter: 'categories=books', perpage: 10 })));
-  s.push(section('news col-md-4 col-sm-6', 'Results from all targets',
-                    this.subwidget('Records', { _team: 'main' })));
-  s.push('</div>');
-  this.node.html(s.join(''));
-
-  // Fill in the titles from the query once widgets have all been prepared
-  var that = this;
-  this.team.queue("ready").subscribe(function() {
-    var query = toTitleCase(that.config.query);
-    that.log("got query '" + query + "' from team config");
-    mkws.$('.x-mkws-title').html(query);
-    mkws.$('title').html("MKWS: " + query);
-
-    mkws.$(".mkwsSummary img").addClass("media-object");
-    console.log(mkws.$("body").html());
-
-    // Derived from http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript
-    function toTitleCase(str) {
-      return str.replace(/\w\S*/g, function(txt) {
-        return txt.charAt(0).toUpperCase() + txt.substr(1);
-      });
-    }
-  });
-
-
-  function section(xclass, title, content) {
-    var s = [];
-    s.push('<div class="' + xclass + '"><div class="panel panel-default">');
-    s.push('<div class="panel-heading title"><h3 class="panel-title">' + title + '</h3></div>');
-    s.push('<div class="panel-body">' + content + '</div>');
-    s.push('</div></div>');
-    return s.join('');
-  }
-
-  function sectionRow(xclass, title, content) {
-    var s = [];
-    s.push('<div class="row">');
-    s.push(section(xclass, title, content));
-    s.push('</div>');
-    return s.join('');
-  }
-});
diff --git a/examples/htdocs/ref-bootstrap.html b/examples/htdocs/ref-bootstrap.html
deleted file mode 100644 (file)
index 503a8fe..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="utf-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <meta name="viewport" content="width=device-width, initial-scale=1">
-    <title>MKWS demo: Compound reference widget</title>
-    <!-- <link rel="stylesheet" type="text/css" href="mkws&#45;widget&#45;credo.css" /> -->
-    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
-    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
-    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
-    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
-    <script type="text/javascript">
-      var mkws_config = { service_proxy_auth: "//mkws.indexdata.com/service-proxy-credoauth" };
-    </script>
-    <script class="mkwsTemplate_FacetBootstrap" type="text/x-handlebars-template">
-      <h3>Results from Reference Universe</h3>
-      {{#each hits}}
-        <div class="refinement">
-          {{#mkws-first md-electronic-url}}
-          <a href="{{this}}">
-          {{/mkws-first}}
-            {{md-title}}
-          </a>
-        {{#if md-title-remainder}}
-          <span>{{md-title-remainder}}</span>
-        {{/if}}
-        {{#if md-title-responsibility}}
-          <span><i>{{md-title-responsibility}}</i></span>
-        {{/if}}
-        </div>
-      {{/each}}
-    </script>
-    <script type="text/javascript" src="//mkws.indexdata.com/mkws-complete.js"></script>
-    <script type="text/javascript" src="mkws-widget-credo-bs.js"></script>
-    <style>
-      .mkwsCredo {
-        max-width: 1440px;
-      }
-      .mkwsGoogleImage img {
-        max-width: 95%;
-      }
-    </style>
-  </head>
-  <body>
-    <div class='mkwsCredo page-header container-fluid' autosearch='!param!q'></div>
-  </body>
-</html>
diff --git a/examples/htdocs/topic-bootstrap.css b/examples/htdocs/topic-bootstrap.css
new file mode 100644 (file)
index 0000000..303942a
--- /dev/null
@@ -0,0 +1,102 @@
+body {
+  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 
+  background: radial-gradient(ellipse at center,  #ffffff 0%,#f8f8f8 100%);
+  font-weight: 300;
+}
+b, strong {
+  font-weight: 400; 
+}
+.panel {
+  border: none;
+  background: white;
+  padding: 1em .75em;
+  border-radius: 3px;
+  -moz-border-radius: 3px;
+  -webkit-border-radius: 3px;
+  color: #76868A;
+  box-shadow: 0 0 2px rgba(0, 0, 0, 0.09);
+  margin-bottom: 2em;
+}
+
+.panel-default > .panel-heading {
+  background-image: none; 
+  border: none;
+  background-color: white;
+}
+
+.panel-heading {
+  padding: 0.5em 15px 0;
+}
+
+.panel-title {
+  font-size: 130%;
+  color: #4A5456;
+}
+
+.panel-body {
+  padding: 10px 15px; 
+}
+
+.mkwsFacetTitle {
+  font-style: italic;
+  font-weight: 400;
+}
+  .mkwsTerm {
+    padding: .1em 0;
+  }
+  .mkwsTerm a {
+    padding-right: .5em; 
+    font-weight: 400;
+  }
+
+.mkwsSummary {
+  padding: .5em 0;
+  line-height: 1.35;
+}
+.mkwsSummary:last-child {
+  padding-bottom: 0;
+}
+  
+.container .jumbotron {
+  background: none;
+  padding: 0 2em 0 0;
+  box-shadow: none;
+  color: black;
+}  
+  .jumbotron .mkwsSummary {
+    line-height: 1.5;  
+  }
+  .jumbotron p{
+    font-size: 150%; 
+  }
+  .mkwsCredit {
+    font-size: 125% !important;
+    font-style: italic;
+  }
+  
+.mkwsGoogleImage .mkwsSummary {
+  padding: 0;
+  font-weight: 400;
+}
+  .mkwsGoogleImage img {
+    max-width: 100%;
+    max-height: 200px;
+    padding: 1em 0 .5em;
+  }
+.list-group-item {
+  padding: 10px 15px !important;
+}
+.list-group {
+  box-shadow: none;
+  -webkit-box-shadow: none;
+}
+@media screen and (min-width:700px) {
+  .multicol {
+    column-count: 2;
+    column-gap: 20px;
+    -moz-column-count: 2;
+    -moz-column-gap: 20px;
+    -webkit-column-count: 2;
+    -webkit-column-gap: 20px;
+  }
+}
diff --git a/examples/htdocs/topic-bootstrap.html b/examples/htdocs/topic-bootstrap.html
new file mode 100644 (file)
index 0000000..d72aa70
--- /dev/null
@@ -0,0 +1,127 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="utf-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1">
+  <title>MKWS demo: Compound reference widget, Bootstrap edition</title>
+  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
+  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
+  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
+  <!-- http://www.bootstrapcdn.com/#bootswatch_tab has some themes that look mediumly okay -->
+  <!-- <link href="//maxcdn.bootstrapcdn.com/bootswatch/3.1.1/cyborg/bootstrap.min.css" rel="stylesheet"> -->
+  <!-- <link href="//maxcdn.bootstrapcdn.com/bootswatch/3.1.1/amelia/bootstrap.min.css" rel="stylesheet"> -->
+  <!-- <link href="//maxcdn.bootstrapcdn.com/bootswatch/3.1.1/united/bootstrap.min.css" rel="stylesheet"> -->
+  <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
+  <script type="text/javascript">
+    var mkws_config = { service_proxy_auth: "//mkws.indexdata.com/service-proxy-credoauth" }
+  </script>
+  <script type="text/javascript" src="//mkws.indexdata.com/mkws-complete.js"></script>
+  <!-- <script type="text/javascript" src="//mkws.local/mkws&#45;complete.js"></script> -->
+  <link rel="stylesheet" type="text/css" href="topic-bootstrap.css">
+  <script>
+    // The Google Images database returns links like:
+    //      http://images.google.com/url?q=http://eofdreams.com/fish.html&sa=U&ei=RAB-U9XNDo2Dqga1o4L4Bw&ved=0CC4Q9QEwAA&usg=AFQjCNFhRtn6GMevHbpITZ6kfx6rsHV2ow
+    // This Handlebars helper avoids a pointless redirect by transforming
+    // this to the URL of the underling page, in this case
+    //      http://eofdreams.com/fish.html
+    Handlebars.registerHelper('mkws-googleurl', function(obj) {
+      if (!obj) {
+        return "obj undefined";
+      } else if (!obj[0]) {
+        return "obj[0] undefined, JSON=" + $.toJSON(obj);
+      } else {
+        return mkws.getParameterByName('q', obj[0]);
+      }
+    });
+  </script>
+  <script class="mkwsTemplate_TopicImage" type="text/x-handlebars-template">
+    {{#each hits}}
+      <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
+       <a href="{{mkws-googleurl md-electronic-url}}" target="_blank">
+        {{#mkws-first md-thumburl}}
+          <img src="{{this}}" alt="{{../md-title}}"/>
+        {{/mkws-first}}
+        <br/>
+       </a>
+       <p>{{{md-title}}}</p>
+      </div>
+    {{/each}}
+  </script>
+  <script class="mkwsTemplate_TopicFacet" type="text/x-handlebars-template">
+    {{#each terms}}
+      <li class="list-group-item mkwsTerm">
+        <span class="badge">{{count}}</span>
+        <a href="#" {{linkdata}}>{{term}}</a>
+      </li>
+    {{/each}}
+  </script>
+</head>
+<body>
+  <div class='page-header container' autosearch='!param!q'>
+    <div class="row">
+      <!-- reference entry -->
+      <div class="jumbotron panel col-md-8">
+        <div class="panel-body mkwsReference mkwsTeam_ref" autosearch="!param!q"
+             data-mkws-config='{"paragraphs":1}'></div>
+      </div>
+      <!-- related topics -->
+      <div class="col-md-offset-1 col-md-3"><div class="panel panel-default">
+        <div class="panel-heading title">
+          <h3 class="panel-title">Related Topics</h3>
+        </div>
+        <ul class="panel-body list-group mkwsFacet mkwsTeam_main"
+            autosearch="!param!q"
+            data-mkws-facet="subject"
+            data-mkws-config='{ "template": "TopicFacet" }'></ul>
+      </div></div>
+    </div>
+    <!-- images -->
+    <div class="row">
+      <div class="col-md-12"><div class="panel panel-default">
+        <div class="panel-heading title">
+          <h3 class="panel-title">Images</h3>
+        </div>
+        <div class="panel-body mkwsGoogleImage" autosearch="!param!q"
+             data-mkws-config='{ "maxrecs": 4, "template": "TopicImage", "target": "google_images_js" }'></div>
+      </div></div>
+    </div>
+
+    <!-- sources -->
+    <div class="row">
+        <div class="col-md-4 col-sm-6"><div class="panel panel-default">
+          <div class="panel-heading title">
+            <h3 class="panel-title">News</h3>
+          </div>
+          <div class="panel-body mkwsRecords mkwsTeam_news" autosearch="!param!q"
+               data-mkws-config='{"targetfilter":"categories=news",
+                                  "perpage":7}'></div>
+        </div></div>
+        <div class="col-md-4 col-sm-6"><div class="panel panel-default">
+          <div class="panel-heading title">
+            <h3 class="panel-title">Articles</h3>
+          </div>
+          <div class="panel-body mkwsRecords mkwsTeam_articles" autosearch="!param!q"
+               data-mkws-config='{"targetfilter":"categories=articles",
+                                  "perpage":7}'></div>
+        </div></div>
+        <div class="col-md-4 col-sm-6"><div class="panel panel-default">
+          <div class="panel-heading title">
+            <h3 class="panel-title">Books</h3>
+          </div>
+          <div class="panel-body mkwsRecords mkwsTeam_books" autosearch="!param!q"
+               data-mkws-config='{"targetfilter":"categories=books",
+                                  "perpage":7}'></div>
+        </div></div>
+    </div>
+    <div class="row">
+        <div class="col-md-12"><div class="panel panel-default">
+          <div class="panel-heading title">
+            <h3 class="panel-title">Results from all targets</h3>
+          </div>
+          <div class="panel-body multicol mkwsRecords mkwsTeam_main"></div>
+        </div></div>
+    </div>
+  </div>
+</body>
+</html>
index 006f11b..694522e 100644 (file)
@@ -9,7 +9,7 @@
     <script type="text/javascript" src="http://mkws.indexdata.com/jquery.json-2.4.js"></script>
     <script type="text/javascript" src="http://mkws.indexdata.com/handlebars-v1.1.2.js"></script>
     <script type="text/javascript" src="http://mkws.indexdata.com/pazpar2/js/pz2.js"></script>
-    <script type="text/javascript" src="http://mkws.indexdata.com/mkws.js"></script>
+    <script type="text/javascript" src="http://mkws.local/src/mkws.js"></script>
   </head>
   <body>
     <table width="100%" border="1">
index 6b3e00d..718c350 100644 (file)
@@ -20,6 +20,7 @@ window.mkws = {
                 // initial value allows jQuery popup to use logging.
   teams: {},
   widgetType2function: {},
+  defaultTemplates: {},
 
   locale_lang: {
     "de": {
@@ -188,6 +189,7 @@ mkws.setMkwsConfig = function(overrides) {
     facets: ["xtargets", "subject", "author"], /* display facets, in this order, [] for none */
     responsive_design_width: undefined, /* a page with less pixel width considered as narrow */
     log_level: 1,     /* log level for development: 0..2 */
+    template_vars: {}, /* values that may be exposed to templates */
 
     dummy: "dummy"
   };
@@ -211,110 +213,6 @@ mkws.objectInheritingFrom = function(o) {
 }
 
 
-mkws.defaultTemplate = function(name) {
-  if (name === 'Record') {
-    return '\
-<table>\
-  <tr>\
-    <th>{{mkws-translate "Title"}}</th>\
-    <td>\
-      {{md-title}}\
-      {{#if md-title-remainder}}\
-        ({{md-title-remainder}})\
-      {{/if}}\
-      {{#if md-title-responsibility}}\
-        <i>{{md-title-responsibility}}</i>\
-      {{/if}}\
-    </td>\
-  </tr>\
-  {{#if md-date}}\
-  <tr>\
-    <th>{{mkws-translate "Date"}}</th>\
-    <td>{{md-date}}</td>\
-  </tr>\
-  {{/if}}\
-  {{#if md-author}}\
-  <tr>\
-    <th>{{mkws-translate "Author"}}</th>\
-    <td>{{md-author}}</td>\
-  </tr>\
-  {{/if}}\
-  {{#if md-electronic-url}}\
-  <tr>\
-    <th>{{mkws-translate "Links"}}</th>\
-    <td>\
-      {{#each md-electronic-url}}\
-        <a href="{{this}}">Link{{mkws-index1}}</a>\
-      {{/each}}\
-    </td>\
-  </tr>\
-  {{/if}}\
-  {{#mkws-if-any location having="md-subject"}}\
-  <tr>\
-    <th>{{mkws-translate "Subject"}}</th>\
-    <td>\
-      {{#mkws-first location having="md-subject"}}\
-        {{#if md-subject}}\
-          {{#mkws-commaList md-subject}}\
-            {{this}}{{/mkws-commaList}}\
-        {{/if}}\
-      {{/mkws-first}}\
-    </td>\
-  </tr>\
-  {{/mkws-if-any}}\
-  <tr>\
-    <th>{{mkws-translate "Locations"}}</th>\
-    <td>\
-      {{#mkws-commaList location}}\
-        {{mkws-attr "@name"}}{{/mkws-commaList}}\
-    </td>\
-  </tr>\
-</table>\
-';
-  } else if (name === "Summary") {
-    return '\
-<a href="#" id="{{_id}}" onclick="{{_onclick}}">\
-  <b>{{md-title}}</b>\
-</a>\
-{{#if md-title-remainder}}\
-  <span>{{md-title-remainder}}</span>\
-{{/if}}\
-{{#if md-title-responsibility}}\
-  <span><i>{{md-title-responsibility}}</i></span>\
-{{/if}}\
-{{#if md-date}}, {{md-date}}\
-{{#if location}}\
-, {{#mkws-first location}}{{mkws-attr "@name"}}{{/mkws-first}}\
-{{/if}}\
-{{#if md-medium}}\
-<span>, {{md-medium}}</span>\
-{{/if}}\
-{{/if}}\
-';
-  } else if (name === "Image") {
-    return '\
-      <a href="#" id="{{_id}}" onclick="{{_onclick}}">\
-        {{#mkws-first md-thumburl}}\
-          <img src="{{this}}" alt="{{../md-title}}"/>\
-        {{/mkws-first}}\
-        <br/>\
-      </a>\
-';
-  } else if (name === 'Facet') {
-    return '\
-<a href="#"\
-{{#if fn}}\
-onclick="mkws.{{fn}}(\'{{team}}\', \'{{field}}\', \'{{term}}\');return false;"\
-{{/if}}\
->{{term}}</a>\
-<span>{{count}}</span>\
-';
-  }
-
-  return null;
-};
-
-
 // The following functions are dispatchers for team methods that
 // are called from the UI using a team-name rather than implicit
 // context.
index 866dc8a..bd9af8d 100644 (file)
@@ -96,3 +96,11 @@ Handlebars.registerHelper('mkws-commaList', function(items, options) {
 Handlebars.registerHelper('mkws-index1', function(obj) {
   return obj.data.index + 1;
 });
+
+Handlebars.registerHelper('mkws-repeat', function(count, options) {
+  var out = "";
+  for (var i = 0; i < count; i++) {
+    out += options.fn(this);
+  }
+  return out;
+});
index 011d643..92536f1 100644 (file)
@@ -41,11 +41,13 @@ function team($, teamName) {
   that.submitted = function() { return m_submitted; };
   that.sortOrder = function() { return m_sortOrder; };
   that.perpage = function() { return m_perpage; };
+  that.query = function() { return m_query; };
   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_filterSet; };
+  that.gotRecords = function() { return m_gotRecords; };
 
   // Accessor methods for individual widgets: writers
   that.set_sortOrder = function(val) { m_sortOrder = val };
@@ -149,6 +151,7 @@ function team($, teamName) {
     log("record");
     // FIXME: record is async!!
     clearTimeout(m_paz.recordTimer);
+    queue("record").publish(data);
     var detRecordDiv = findnode(recordDetailsId(data.recid[0]));
     if (detRecordDiv.length) {
       // in case on_show was faster to redraw element
@@ -303,6 +306,12 @@ function team($, teamName) {
     m_paz.search(m_query, m_perpage, m_sortOrder, pp2filter, undefined, params);
   }
 
+  // fetch record details to be retrieved from the record queue
+  that.fetchDetails = function(recId) {
+    log("fetchDetails() requesting record '" + recId + "'");
+    m_paz.record(recId);
+  };
+
 
   // switching view between targets and records
   function switchView(view) {
@@ -389,38 +398,34 @@ function team($, teamName) {
 
   function loadTemplate(name, fallbackString) {
     var template = m_template[name];
-
-    if (template === undefined) {
-      // Fall back to generic template if there is no team-specific one
+    if (template === undefined && Handlebars.compile) {
       var source;
       var node = $(".mkwsTemplate_" + name + " .mkwsTeam_" + that.name());
       if (node && node.length < 1) {
         node = $(".mkwsTemplate_" + name);
       }
-      if (node) {
-        source = node.html();
-      }
-
-      // If the template is not defined in HTML, check the following
-      // in order: template registered in the team by a widget;
-      // fallback string provided on this invocation; global default.
-      if (!source) {
-        source = m_templateText[name];
-      }
-      if (!source) {
-        source = fallbackString;
+      if (node) source = node.html();
+      if (!source) source = m_templateText[name];
+      if (source) {
+        template = Handlebars.compile(source);
+        log("compiled template '" + name + "'");
       }
-      if (!source) {
-        source = mkws.defaultTemplate(name);
-      }
-
-      if (!source) return null;
-      template = Handlebars.compile(source);
-      log("compiled template '" + name + "'");
+    }
+    //if (template === undefined) template = mkws_templatesbyteam[m_teamName][name];
+    if (template === undefined && Handlebars.templates) {
+      template = Handlebars.templates[name];
+    }
+    if (template === undefined && mkws.defaultTemplates) {
+      template = mkws.defaultTemplates[name];
+    }
+    if (template) {
       m_template[name] = template;
+      return template;
     }
-
-    return template;
+    else {
+      mkws.log("No MKWS template for " + name);
+      return null;
+    }  
   }
   that.loadTemplate = loadTemplate;
 
index fcffe5b..fce4779 100644 (file)
@@ -6,43 +6,36 @@
 mkws.registerWidgetType('Targets', function() {
   if (!this.config.show_switch) return;
   var that = this;
-  var M = mkws.M;
 
   this.node.html('No information available yet.');
   this.node.css("display", "none");
 
   this.team.queue("targets").subscribe(function(data) {
-    var table ='<table><thead><tr>' +
-      '<td>' + M('Target ID') + '</td>' +
-      '<td>' + M('Hits') + '</td>' +
-      '<td>' + M('Diags') + '</td>' +
-      '<td>' + M('Records') + '</td>' +
-      '<td>' + M('State') + '</td>' +
-      '</tr></thead><tbody>';
-
+    // There is a bug in pz2.js wherein it makes each data object an array but
+    // simply assigns properties to it.
+    // TODO: remove this when PAZ-946 is addressed.
+    var cleandata = [];
     for (var i = 0; i < data.length; i++) {
-      table += "<tr><td>" + data[i].id +
-        "</td><td>" + data[i].hits +
-        "</td><td>" + data[i].diagnostic +
-        "</td><td>" + data[i].records +
-        "</td><td>" + data[i].state + "</td></tr>";
+      var cur = {};
+      cur.id = data[i].id;
+      cur.hits = data[i].hits;
+      cur.diagnostic = data[i].diagnostic;
+      cur.records = data[i].records;
+      cur.state = data[i].state;
+      cleandata.push(cur);
     }
 
-    table += '</tbody></table>';
-    that.node.html(table);
+    var template = that.team.loadTemplate(that.config.template || "Targets");
+    that.node.html(template({data: cleandata}));
   });
 });
 
 
 mkws.registerWidgetType('Stat', function() {
   var that = this;
-  var M = mkws.M;
-
   this.team.queue("stat").subscribe(function(data) {
-    that.node.html(' -- ' +
-                      '<span class="mkwsClientCount">' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '</span>' +
-                      ' -- ' +
-                      M('Retrieved records') + ': ' + data.records + '/' + data.hits);
+    var template = that.team.loadTemplate(that.config.template || "Stat");
+    that.node.html(template(data));
   });
 });
 
@@ -52,92 +45,92 @@ mkws.registerWidgetType('Pager', function() {
   var M = mkws.M;
 
   this.team.queue("pager").subscribe(function(data) {
-    that.node.html(drawPager(data))
-
-    function drawPager(data) {
-      var teamName = that.team.name();
-      var s = '<div style="float: right">' + M('Displaying') + ': '
-        + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) +
-        ' ' + M('of') + ' ' + data.merged + ' (' + M('found') + ': '
-        + data.total + ')</div>';
-
-      //client indexes pages from 1 but pz2 from 0
-      var onsides = 6;
-      var pages = Math.ceil(that.team.totalRecordCount() / that.team.perpage());
-      var currentPage = that.team.currentPage();
-
-      var firstClkbl = (currentPage - onsides > 0)
-        ? currentPage - onsides
-        : 1;
-
-      var lastClkbl = firstClkbl + 2*onsides < pages
-        ? firstClkbl + 2*onsides
-        : pages;
-
-      var prev = '<span class="mkwsPrev">&#60;&#60; ' + M('Prev') + '</span> | ';
-      if (currentPage > 1)
-        prev = '<a href="#" class="mkwsPrev" onclick="mkws.pagerPrev(\'' + teamName + '\');">'
-        +'&#60;&#60; ' + M('Prev') + '</a> | ';
-
-      var middle = '';
-      for(var i = firstClkbl; i <= lastClkbl; i++) {
-        var numLabel = i;
-        if(i == currentPage)
-          numLabel = '<span class="mkwsCurrentPage">' + i + '</span>';
-
-        middle += '<a href="#" onclick="mkws.showPage(\'' + teamName + '\', ' + i + ')"> '
-          + numLabel + ' </a>';
+    var teamName = that.team.name();
+    var output = {};
+    output.first = data.start + 1;
+    output.last = data.start + data.num;
+    output.count = data.merged;
+    output.found = data.total;
+
+    //client indexes pages from 1 but pz2 from 0
+    var onsides = 6;
+    var pages = Math.ceil(that.team.totalRecordCount() / that.team.perpage());
+    var currentPage = that.team.currentPage();
+
+    var firstClkbl = (currentPage - onsides > 0)
+      ? currentPage - onsides
+      : 1;
+    var lastClkbl = firstClkbl + 2*onsides < pages
+      ? firstClkbl + 2*onsides
+      : pages;
+
+    if (firstClkbl > 1) output.morePrev = true;
+    if (lastClkbl < pages) output.moreNext = true;
+
+    if (currentPage > 1) output.prevClick = "mkws.pagerPrev(\'" + teamName + "\');";
+
+    output.pages = [];
+    for(var i = firstClkbl; i <= lastClkbl; i++) {
+      var o = {};
+      o.number = i;
+      if (i !== currentPage) {
+        o.click = "mkws.showPage(\'" + teamName + "\', " + i + ");";
       }
+      output.pages.push(o);
+    }
 
-      var next = ' | <span class="mkwsNext">' + M('Next') + ' &#62;&#62;</span>';
-      if (pages - currentPage > 0)
-        next = ' | <a href="#" class="mkwsNext" onclick="mkws.pagerNext(\'' + teamName + '\')">'
-        + M('Next') + ' &#62;&#62;</a>';
-
-      var predots = '';
-      if (firstClkbl > 1)
-        predots = '...';
-
-      var postdots = '';
-      if (lastClkbl < pages)
-        postdots = '...';
+    if (pages - currentPage > 0) output.nextClick = "mkws.pagerNext(\'" + teamName + "\')";
 
-      s += '<div style="float: clear">'
-        + prev + predots + middle + postdots + next + '</div>';
+    var template = that.team.loadTemplate(that.config.template || "Pager");
+    that.node.html(template(output));
+  });
+});
 
-      return s;
+mkws.registerWidgetType('Details', function() {
+  var that = this;
+  var recid = that.node.attr("data-mkws-recid");
+  if (this.team.gotRecords()) { 
+    that.team.fetchDetails(recid);
+  } else {
+    this.team.queue("firstrecords").subscribe(function() {
+      that.team.fetchDetails(recid);
+    });
+  }
+  this.team.queue("record").subscribe(function(data) {
+    console.log(data);
+    if ($.inArray(recid, data.recid) > -1) {
+      var template = that.team.loadTemplate(that.config.template || "Record");
+      that.node.html(template(data));
     }
   });
+  that.autosearch();
 });
 
-
 mkws.registerWidgetType('Records', function() {
   var that = this;
   var team = this.team;
 
   this.team.queue("records").subscribe(function(data) {
-    var html = [];
     for (var i = 0; i < data.hits.length; i++) {
       var hit = data.hits[i];
       that.team.queue("record").publish(hit);
-      var divId = team.recordElementId(hit.recid[0]);
-      html.push('<div class="mkwsSummary mkwsTeam_' + team.name() + ' ' + divId + '">', renderSummary(hit), '</div>');
+      hit.detailLinkId = team.recordElementId(hit.recid[0]);
+      hit.detailClick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;";
+      hit.containerClass = "mkwsSummary mkwsTeam_" + team.name();
+      hit.containerClass += " " + hit.detailLinkId;
       // ### 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()));
+        if (team.currentRecordData()) {
+          hit.renderedDetails = team.renderDetails(team.currentRecordData());
+          console.log(hit.renderedDetails); 
+        } 
       }
     }
-    that.node.html(html.join(''));
-
-    function renderSummary(hit) {
-      var template = team.loadTemplate(that.config.template || "Summary");
-      hit._id = team.recordElementId(hit.recid[0]);
-      hit._onclick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"
-      return template(hit);
-    }
+    var template = team.loadTemplate(that.config.template || "Records");
+    var targs = $.extend({}, {"hits": data.hits}, that.config.template_vars);
+    that.node.html(template(targs));
   });
 
   that.autosearch();
@@ -147,26 +140,29 @@ mkws.registerWidgetType('Records', function() {
 mkws.registerWidgetType('Navi', function() {
   var that = this;
   var teamName = this.team.name();
-  var M = mkws.M;
 
   this.team.queue("navi").subscribe(function() {
     var filters = that.team.filters();
-    var text = "";
+    var output = {filters:[]};
 
     filters.visitTargets(function(id, name) {
-      if (text) text += " | ";
-      text += M('source') + ': <a class="mkwsRemovable" href="#" onclick="mkws.delimitTarget(\'' + teamName +
-        "', '" + id + "'" + ');return false;">' + name + '</a>';
+      var cur = {};
+      cur.facet = 'source';
+      cur.value = name;
+      cur.click = "mkws.delimitTarget('" + teamName + "', '" + id + "'); return false;";
+      output.filters.push(cur);
     });
 
     filters.visitFields(function(field, value) {
-      if (text) text += " | ";
-      text += M(field) + ': <a class="mkwsRemovable" href="#" onclick="mkws.delimitQuery(\'' + teamName +
-        "', '" + field + "', '" + value + "'" +
-        ');return false;">' + value + '</a>';
+      var cur = {};
+      cur.facet = field;
+      cur.value = value;
+      cur.click = "mkws.delimitQuery('" + teamName + "', '" + field + "', '" + value + "'" + ");return false;";
+      output.filters.push(cur);
     });
 
-    that.node.html(text);
+    var template = that.team.loadTemplate(that.config.template || "Navi");
+    that.node.html(template(output));
   });
 });
 
@@ -202,9 +198,9 @@ mkws.registerWidgetType('Perpage', function() {
 
 mkws.registerWidgetType('Done', function() {
   var that = this;
-
   this.team.queue("complete").subscribe(function(n) {
-    that.node.html("Search complete: found " + n + " records");
+    var template = that.team.loadTemplate(that.config.template || "Done");
+    that.node.html(template({count: n}));
   });
 });
 
@@ -212,23 +208,21 @@ mkws.registerWidgetType('Done', function() {
 mkws.registerWidgetType('Switch', function() {
   if (!this.config.show_switch) return;
   var tname = this.team.name();
-  this.node.html('\
-<a href="#" onclick="mkws.switchView(\'' + tname + '\', \'records\')">Records</a><span> \
-| \
-</span><a href="#" onclick="mkws.switchView(\'' + tname + '\', \'targets\')">Targets</a>');
+  var output = {};
+  output.recordClick = "mkws.switchView(\'" + tname + "\', \'records\')";
+  output.targetClick = "mkws.switchView(\'" + tname + "\', \'targets\')";
+  var template = this.team.loadTemplate(this.config.template || "Switch");
+  this.node.html(template(output));
   this.hideWhenNarrow();
 });
 
 
 mkws.registerWidgetType('Search', function() {
-  var tname = this.team.name();
-  var M = mkws.M;
-
-  this.node.html('\
-<form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + tname + '" action="" >\
-  <input class="mkwsQuery mkwsTeam_' + tname + '" type="text" size="' + this.config.query_width + '" />\
-  <input class="mkwsButton mkwsTeam_' + tname + '" type="submit" value="' + M('Search') + '" />\
-</form>');
+  var output = {};
+  output.team = this.team.name();
+  output.queryWidth = this.config.query_width;
+  var template = this.team.loadTemplate(this.config.template || "Search");
+  this.node.html(template(output));
 });
 
 
@@ -243,90 +237,42 @@ mkws.registerWidgetType('SearchForm', function() {
 
 
 mkws.registerWidgetType('Results', function() {
-  var tname = this.team.name();
-
-  this.node.html('\
-<table width="100%" border="0" cellpadding="6" cellspacing="0">\
-  <tr>\
-    <td class="mkwsTermlists-Container-wide mkwsTeam_' + tname + '" width="250" valign="top">\
-      <div class="mkwsTermlists mkwsTeam_' + tname + '"></div>\
-    </td>\
-    <td class="mkwsMOTDContainer mkwsTeam_' + tname + '" valign="top">\
-      <div class="mkwsRanking mkwsTeam_' + tname + '"></div>\
-      <div class="mkwsPager mkwsTeam_' + tname + '"></div>\
-      <div class="mkwsNavi mkwsTeam_' + tname + '"></div>\
-      <div class="mkwsRecords mkwsTeam_' + tname + '"></div>\
-    </td>\
-  </tr>\
-  <tr>\
-    <td colspan="2">\
-      <div class="mkwsTermlists-Container-narrow mkwsTeam_' + tname + '"></div>\
-    </td>\
-  </tr>\
-</table>');
-
+  var template = this.team.loadTemplate(this.config.template || "Results");
+  this.node.html(template({team: this.team.name()}));
   this.autosearch();
 });
 
 
 mkws.registerWidgetType('Ranking', function() {
-  var tname = this.team.name();
-  var that = this;
-  var M = mkws.M;
-
-  var s = '<form>';
-  if (this.config.show_sort) {
-    s +=  M('Sort by') + ' ' + mkwsHtmlSort() + ' ';
-  }
-  if (this.config.show_perpage) {
-    s += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.';
+  var output = {};
+  output.perPage = [];
+  output.sort = [];
+  output.team = this.team.name();
+  output.showSort = this.config.show_sort;
+  output.showPerPage = this.config.show_perpage;
+
+  var order = this.team.sortOrder();
+  this.log("making sort, sortOrder = '" + order + "'");
+  for (var i = 0; i < this.config.sort_options.length; i++) {
+    var cur = {};
+    var opt = this.config.sort_options[i];
+    cur.key = opt[0];
+    cur.label = opt.length == 1 ? opt[0] : opt[1];
+    if (order == cur.key || order == cur.label) cur.selected = true;
+    output.sort.push(cur);
   }
-  s += '</form>';
-
-  this.node.html(s);
-
-
-  function mkwsHtmlSort() {
-    var order = that.team.sortOrder();
-
-    that.log("making sort HTML, sortOrder = '" + order + "'");
-    var sort_html = '<select class="mkwsSort mkwsTeam_' + tname + '">';
-
-    for(var i = 0; i < that.config.sort_options.length; i++) {
-      var opt = that.config.sort_options[i];
-      var key = opt[0];
-      var val = opt.length == 1 ? opt[0] : opt[1];
 
-      sort_html += '<option value="' + key + '"';
-      if (order == key || order == val) {
-        sort_html += ' selected="selected"';
-      }
-      sort_html += '>' + M(val) + '</option>';
-    }
-    sort_html += '</select>';
-
-    return sort_html;
+  var perpage = this.team.perpage();
+  this.log("making perpage, perpage = " + perpage);
+  for(var i = 0; i < this.config.perpage_options.length; i++) {
+    var cur = {};
+    cur.perPage = this.config.perpage_options[i];
+    if (cur.perPage == perpage) cur.selected = true;
+    output.perPage.push(cur);
   }
 
-  function mkwsHtmlPerpage() {
-    var perpage = that.team.perpage();
-
-    that.log("making perpage HTML, perpage = " + perpage);
-    var perpage_html = '<select class="mkwsPerpage mkwsTeam_' + tname + '">';
-
-    for(var i = 0; i < that.config.perpage_options.length; i++) {
-      var key = that.config.perpage_options[i];
-
-      perpage_html += '<option value="' + key + '"';
-      if (key == perpage) {
-        perpage_html += ' selected="selected"';
-      }
-      perpage_html += '>' + key + '</option>';
-    }
-    perpage_html += '</select>';
-
-    return perpage_html;
-  }
+  var template = this.team.loadTemplate(this.config.template || "Ranking");
+  this.node.html(template(output));
 });
 
 
@@ -347,34 +293,30 @@ mkws.registerWidgetType('Lang', function() {
   }
 
   for (var k in mkws.locale_lang) {
-    if (toBeIncluded[k] || lang_options.length == 0)
-      list.push(k);
+    if (toBeIncluded[k] || lang_options.length == 0) {
+      cur = {};
+      if (lang === k) cur.selected = true;
+      cur.code = k;
+      cur.url = lang_url(k);
+      list.push(cur);
+    }
   }
 
   // add english link
-  if (lang_options.length == 0 || toBeIncluded[lang_default])
-    list.push(lang_default);
+  if (lang_options.length == 0 || toBeIncluded[lang_default]) {
+      cur = {};
+      if (lang === lang_default) cur.selected = true;
+      cur.code = lang_default;
+      cur.url = lang_url(lang_default);
+      list.push(cur);
+  }
 
   this.log("language menu: " + list.join(", "));
 
-  /* the HTML part */
-  var data = "";
-  for (var i = 0; i < list.length; i++) {
-    var l = list[i];
-    if (data)
-      data += ' | ';
-
-    if (lang == l) {
-      data += ' <span>' + l + '</span> ';
-    } else {
-      data += ' <a href="' + lang_url(l) + '">' + l + '</a> '
-    }
-  }
-
-  this.node.html(data);
+  var template = this.team.loadTemplate(this.config.template || "Lang");
+  this.node.html(template({languages: list}));
   this.hideWhenNarrow();
 
-
   // set or re-set "lang" URL parameter
   function lang_url(lang) {
     var query = location.search;
@@ -422,19 +364,13 @@ mkws.registerWidgetType('Config', function() {
 
 mkws.registerWidgetType('Progress', function() {
   var that = this;
-
   this.node.hide();
   this.team.queue("stat").subscribe(function(data) {
-    var s = '<span class="mkwsDone">';
-    for (var i = 0; i < data.clients; i++) {
-      if (i == data.clients - data.activeclients) {
-        s += '</span>';
-        s += '<span class="mkwsWaiting">';
-      }
-      s += '&#x2588;';
-    }
-    s += '</span>';
-    that.node.html(s);
+    var template = that.team.loadTemplate(that.config.template || "Progress");
+    that.node.html(template({
+      done: data.clients - data.activeclients,
+      waiting: data.activeclients
+    }));
     that.node.show();
   });
 });
diff --git a/src/mkws-widget-main.templates/Done.handlebars b/src/mkws-widget-main.templates/Done.handlebars
new file mode 100644 (file)
index 0000000..59a0b4f
--- /dev/null
@@ -0,0 +1,7 @@
+{{!
+Displayed on search completion
+
+count - number of results found
+}}
+{{{mkws-translate "Search complete: found"}}} {{count}} {{{mkws-translate "records"}}}
+
diff --git a/src/mkws-widget-main.templates/Image.handlebars b/src/mkws-widget-main.templates/Image.handlebars
new file mode 100644 (file)
index 0000000..abee587
--- /dev/null
@@ -0,0 +1,18 @@
+{{!
+Records presented as images.
+
+hits:
+  containerClass - class  attribute for same
+  detailLinkId - id for the element triggering detail display
+  detailClick - a click event handler for details
+  renderedDetails - active record details rendered from the Record template
+  md-* - metadata fields passed through from backend
+}}
+{{#each hits}}
+  <a href="#" id="{{detailLinkId}}" onclick="{{detailClick}}">
+    {{#mkws-first md-thumburl}}
+      <img src="{{this}}" alt="{{../md-title}}"/>
+    {{/mkws-first}}
+    <br/>
+  </a>
+{{/each}}
diff --git a/src/mkws-widget-main.templates/Lang.handlebars b/src/mkws-widget-main.templates/Lang.handlebars
new file mode 100644 (file)
index 0000000..26ee6da
--- /dev/null
@@ -0,0 +1,19 @@
+{{!
+Language selection widget
+
+languages
+  code - two character language identifier
+  selected - exists for the current language
+  url - url to switch to this language
+}}
+{{#each languages}}
+  {{~#if selected~}}
+    <span>{{code}}</span>
+  {{~else~}}
+    <a href="{{{url}}}">{{code}}</a>
+  {{~/if~}}
+  {{#unless last}}
+    |
+  {{/unless}}
+{{/each}}
+
diff --git a/src/mkws-widget-main.templates/Navi.handlebars b/src/mkws-widget-main.templates/Navi.handlebars
new file mode 100644 (file)
index 0000000..7f3c554
--- /dev/null
@@ -0,0 +1,13 @@
+{{!
+Facet breadcrumbs -- filters on the current search
+
+filters
+  facet - name of facet being limited
+  value - limit to this value
+  click - handler script to remove limit
+}}
+{{#each filters}}
+  {{{mkws-translate facet}}}: <a class="mkwsRemovable" href="#" onclick="{{{click}}}">{{value}}</a>
+  {{#unless @last}}|{{/unless}}
+{{/each}}
+
diff --git a/src/mkws-widget-main.templates/Pager.handlebars b/src/mkws-widget-main.templates/Pager.handlebars
new file mode 100644 (file)
index 0000000..3f098e6
--- /dev/null
@@ -0,0 +1,46 @@
+{{!
+Pager
+
+nextClick - handler script for "next" button, only available if there is a next page
+prevClick - handler script for "previous" button if there is a previous page
+moreNext - indicates there are more pages following those displayed
+morePrev - indicates there are more pages preceding
+first - first record displayed
+last - last record displayed
+count - number of records available
+found - number of records found
+pages:
+  number - page number
+  click - script to go to this page unless it is the current one
+}}
+<div style="float: right">
+  {{mkws-translate "Displaying"}}:
+  {{first}} {{mkws-translate "to"}} {{last}}
+  {{mkws-translate "of"}} {{count}} ({{{mkws-translate "found"}}}: {{found}})
+</div>
+
+<div style="float: clear">
+  {{#if prevClick}}
+    <a href="#" class="mkwsPrev" onclick="{{prevClick}}">&#60;&#60; {{{mkws-translate "Prev"}}}</a> |
+  {{else}}
+    <span class="mkwsPrev">&#60;&#60; {{{mkws-translate "Prev"}}}</span> |
+  {{/if}}
+
+  {{#if morePrev}}...{{/if}}
+
+  {{#each pages}}
+    {{#if click}}
+      <a href="#" onclick="{{click}}">{{number}}</a>
+    {{else}}
+      <span class="mkwsCurrentPage">{{number}}</span>
+    {{/if}}
+  {{/each}}
+
+  {{#if moreNext}}...{{/if}}
+
+  {{#if nextClick}}
+    | <a href="#" class="mkwsNext" onclick="{{nextClick}}">{{{mkws-translate "Next"}}} &#62;&#62;</a>
+  {{else}}
+    | <span class="mkwsNext">{{{mkws-translate "Next"}}} &#62;&#62;</span>
+  {{/if}}
+</div>
diff --git a/src/mkws-widget-main.templates/Progress.handlebars b/src/mkws-widget-main.templates/Progress.handlebars
new file mode 100644 (file)
index 0000000..1b08a2c
--- /dev/null
@@ -0,0 +1,11 @@
+{{!
+Progress
+
+done - number of targets complete
+waiting - number of targets waiting
+}}
+<span class="mkwsDone">{{#mkws-repeat done}}&#x2588;{{/mkws-repeat}}</span>
+{{~#if waiting~}}
+<span class="mkwsWaiting">{{#mkws-repeat waiting}}&#x2588;{{/mkws-repeat}}</span>
+{{~/if~}}
+
diff --git a/src/mkws-widget-main.templates/Ranking.handlebars b/src/mkws-widget-main.templates/Ranking.handlebars
new file mode 100644 (file)
index 0000000..0f2bc17
--- /dev/null
@@ -0,0 +1,42 @@
+{{!
+Ranking -- widget to select sort ordering and number of records to display
+
+team - team for this widget
+showSort
+showPerPage
+sort
+  key - machine readable value for this sort option
+  label - text to display for this sort option
+  selected - exists if this sort is selected
+perPage
+  perPage - a number of records per page that can be selected
+  selected - exists if this number is the current selection
+}}
+<form>
+  {{~#if showSort~}}
+    {{{mkws-translate "Sort by"}}}
+    <select class="mkwsSort mkwsTeam_{{team}}">
+      {{#each sort}}
+        {{#if selected}}
+          <option value="{{{key}}}" selected="selected">{{{mkws-translate label}}}</option>
+        {{else}}
+          <option value="{{key}}">{{{mkws-translate label}}}</option>
+        {{/if}}
+      {{/each}}  
+    </select>
+  {{~/if~}}
+  {{~#if showPerPage~}}
+    {{{mkws-translate "and show"}}}
+    <select class="mkwsPerpage mkwsTeam_{{team}}">
+      {{#each perPage}}
+        {{#if selected}}
+          <option value="{{perPage}}" selected="selected">{{perPage}}</option>
+        {{else}}
+          <option value="{{perPage}}">{{perPage}}</option>
+        {{/if}}
+      {{/each}}  
+    </select>
+    {{{mkws-translate "per page."}}}
+  {{~/if~}}
+</form>
+
diff --git a/src/mkws-widget-main.templates/Record.handlebars b/src/mkws-widget-main.templates/Record.handlebars
new file mode 100644 (file)
index 0000000..f8bf951
--- /dev/null
@@ -0,0 +1,59 @@
+{{!
+Full record display.
+}}
+<table>
+  <tr>
+    <th>{{mkws-translate "Title"}}</th>
+    <td>
+      {{md-title}}
+      {{#if md-title-remainder}}
+        ({{md-title-remainder}})
+      {{/if}}
+      {{#if md-title-responsibility}}
+        <i>{{md-title-responsibility}}</i>
+      {{/if}}
+    </td>
+  </tr>
+  {{#if md-date}}
+  <tr>
+    <th>{{mkws-translate "Date"}}</th>
+    <td>{{md-date}}</td>
+  </tr>
+  {{/if}}
+  {{#if md-author}}
+  <tr>
+    <th>{{mkws-translate "Author"}}</th>
+    <td>{{md-author}}</td>
+  </tr>
+  {{/if}}
+  {{#if md-electronic-url}}
+  <tr>
+    <th>{{mkws-translate "Links"}}</th>
+    <td>
+      {{#each md-electronic-url}}
+        <a href="{{this}}">Link{{mkws-index1}}</a>
+      {{/each}}
+    </td>
+  </tr>
+  {{/if}}
+  {{#mkws-if-any location having="md-subject"}}
+  <tr>
+    <th>{{mkws-translate "Subject"}}</th>
+    <td>
+      {{#mkws-first location having="md-subject"}}
+        {{#if md-subject}}
+          {{#mkws-commaList md-subject}}
+            {{this}}{{/mkws-commaList}}
+        {{/if}}
+      {{/mkws-first}}
+    </td>
+  </tr>
+  {{/mkws-if-any}}
+  <tr>
+    <th>{{mkws-translate "Locations"}}</th>
+    <td>
+      {{#mkws-commaList location}}
+        {{mkws-attr "@name"}}{{/mkws-commaList}}
+    </td>
+  </tr>
+</table>
diff --git a/src/mkws-widget-main.templates/Records.handlebars b/src/mkws-widget-main.templates/Records.handlebars
new file mode 100644 (file)
index 0000000..03ba9a2
--- /dev/null
@@ -0,0 +1,26 @@
+{{!
+Records from a search.
+
+hits:
+  containerClass - class  attribute for same
+  detailLinkId - id for the element triggering detail display
+  detailClick - a click event handler for details
+  renderedDetails - active record details rendered from the Record template
+  md-* - metadata fields passed through from backend
+}}
+{{#each hits}}
+  <div class="{{containerClass}}">
+    <a href="#" id="{{detailLinkId}}" onclick="{{detailClick}}">
+      <b>{{md-title}}</b>
+    </a>
+    {{#if md-title-remainder}}
+      <span>{{md-title-remainder}}</span>
+    {{/if}}
+    {{#if md-title-responsibility}}
+      <span><i>{{md-title-responsibility}}</i></span>
+    {{/if}}
+    {{#if renderedDetails}}
+      {{{renderedDetails}}}
+    {{/if}}
+  </div>
+{{/each}}
diff --git a/src/mkws-widget-main.templates/Results.handlebars b/src/mkws-widget-main.templates/Results.handlebars
new file mode 100644 (file)
index 0000000..f0d405c
--- /dev/null
@@ -0,0 +1,24 @@
+{{!
+Results -- compound widget to display search results
+
+team - team for this widget
+}}
+<table width="100%" border="0" cellpadding="6" cellspacing="0">
+  <tr>
+    <td class="mkwsTermlists-Container-wide mkwsTeam_{{team}}" width="250" valign="top">
+      <div class="mkwsTermlists mkwsTeam_{{team}}"></div>
+    </td>
+    <td class="mkwsMOTDContainer mkwsTeam_{{team}}" valign="top">
+      <div class="mkwsRanking mkwsTeam_{{team}}"></div>
+      <div class="mkwsPager mkwsTeam_{{team}}"></div>
+      <div class="mkwsNavi mkwsTeam_{{team}}"></div>
+      <div class="mkwsRecords mkwsTeam_{{team}}"></div>
+    </td>
+  </tr>
+  <tr>
+    <td colspan="2">
+      <div class="mkwsTermlists-Container-narrow mkwsTeam_{{team}}"></div>
+    </td>
+  </tr>
+</table>
+
diff --git a/src/mkws-widget-main.templates/Search.handlebars b/src/mkws-widget-main.templates/Search.handlebars
new file mode 100644 (file)
index 0000000..5530013
--- /dev/null
@@ -0,0 +1,11 @@
+{{!
+Search form
+
+team - MKWS team
+queryWidth - configured width for search box
+}}
+<form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_{{team}}" action="">
+  <input class="mkwsQuery mkwsTeam_{{team}}" type="text" size="{{queryWidth}}">
+  <input class="mkwsButton mkwsTeam_{{team}}" type="submit" value="{{{mkws-translate "Search"}}}">
+</form>
+
diff --git a/src/mkws-widget-main.templates/Stat.handlebars b/src/mkws-widget-main.templates/Stat.handlebars
new file mode 100644 (file)
index 0000000..d8ae997
--- /dev/null
@@ -0,0 +1,9 @@
+{{!
+Search statistics
+
+activeclients - number of targets currently searching
+clients - total targets for this search
+records - number of records returned and available
+hits - number of hits across all targets
+}}
+ -- <span class="mkwsClientCount">{{{mkws-translate "Active clients"}}} : {{activeclients}}/{{clients}}</span> -- {{{mkws-translate "Retrieved records"}}} : {{records}}/{{hits}}
diff --git a/src/mkws-widget-main.templates/Switch.handlebars b/src/mkws-widget-main.templates/Switch.handlebars
new file mode 100644 (file)
index 0000000..2b8e29c
--- /dev/null
@@ -0,0 +1,9 @@
+{{!
+Switch between record and target view
+
+recordClick - handler to switch to record view
+targetClick - handler to switch to target view
+}}
+<a href="#" onclick="{{{recordClick}}}">{{{mkws-translate "Records"}}}</a>
+<span>|</span>
+<a href="#" onclick="{{{targetClick}}}">{{{mkws-translate "Targets"}}}</a>
diff --git a/src/mkws-widget-main.templates/Targets.handlebars b/src/mkws-widget-main.templates/Targets.handlebars
new file mode 100644 (file)
index 0000000..99ed801
--- /dev/null
@@ -0,0 +1,33 @@
+{{!
+Target detail
+
+data:
+  id - target id
+  hits - number of hits for this target
+  diagnostic - 
+  records - 
+  state - target state
+}}
+<table>
+  <thead>
+    <tr>
+      <td>{{{mkws-translate "Target ID"}}}</td>
+      <td>{{{mkws-translate "Hits"}}}</td>
+      <td>{{{mkws-translate "Diags"}}}</td>
+      <td>{{{mkws-translate "Records"}}}</td>
+      <td>{{{mkws-translate "State"}}}</td>
+      </td>
+    </tr>
+  </thead>
+  <tbody>
+  {{#each data}}
+    <tr>
+      <td>{{{id}}}</td>
+      <td>{{hits}}</td>
+      <td>{{diagnostic}}</td>
+      <td>{{records}}</td>
+      <td>{{hits}}</td>
+    </tr>
+  {{/each}}
+  </tbody>
+</table>
index 106c8a3..13d67c3 100644 (file)
@@ -1,10 +1,18 @@
+// A widget for one record
 mkws.registerWidgetType('Record', function() {
-  mkws.promotionFunction('Records').call(this);
   if (!this.config.maxrecs) this.config.maxrecs = 1;
+  var that = this;
+  var team = this.team;
+  team.queue("records").subscribe(function(data) {
+    var template = team.loadTemplate(that.config.template || "Record");
+    var targs = $.extend({}, data.hits[0], that.config.template_vars);
+    that.node.html(template(targs));
+  });
+  that.autosearch();
 });
 
 mkws.registerWidgetType('Image', function() {
-  mkws.promotionFunction('Record').call(this);
+  mkws.promotionFunction('Records').call(this);
   if (!this.config.template) this.config.template = 'Image';
 });
 
index b1044d2..c8d41be 100644 (file)
@@ -2,19 +2,6 @@ mkws.registerWidgetType('Reference', function() {
   mkws.promotionFunction('Record').call(this);
   if (!this.config.target) this.config.target = 'wikimedia_wikipedia_single_result';
   if (!this.config.template) this.config.template = 'Reference';
-  var nPara = this.config.paragraphs || 0;
-  var nSent = this.config.sentences || 0;
-
-  this.team.registerTemplate('Reference', '\
-  <img src="{{md-thumburl}}" alt="{{md-title}}">\
-  <h1><a href="{{md-electronic-url}}">{{md-title}}</a></h1>\
-{{#if md-title-remainder}}\
-  <b>{{md-title-remainder}}</b>\
-{{/if}}\
-{{#if md-title-responsibility}}\
-  <i>{{md-title-responsibility}}</i>\
-{{/if}}\
-  {{{mkws-paragraphs md-description ' + nPara + ' ' + nSent + '}}}\
-  <p class="mkwsCredit">Wikipedia</p>\
-');
+  this.config.template_vars.paragraphs = this.config.paragraphs || 0;
+  this.config.template_vars.sentences = this.config.sentences || 0;
 });
diff --git a/src/mkws-widget-reference.templates/Reference.handlebars b/src/mkws-widget-reference.templates/Reference.handlebars
new file mode 100644 (file)
index 0000000..62a9d2a
--- /dev/null
@@ -0,0 +1,17 @@
+{{!
+Paragraphs and images from a reference source.
+
+sentences - number of sentences to include
+paragraphs - number of paragraphs to include
+md-* - metadata fields passed through from backend
+}}
+<img src="{{md-thumburl}}" alt="{{md-title}}">
+<h1><a href="{{md-electronic-url}}">{{md-title}}</a></h1>
+{{#if md-title-remainder}}
+<b>{{md-title-remainder}}</b>
+{{/if}}
+{{#if md-title-responsibility}}
+<i>{{md-title-responsibility}}</i>
+{{/if}}
+{{{mkws-paragraphs md-description paragraphs sentences}}}
+<p class="mkwsCredit">Wikipedia</p>
index fef616f..8f6e467 100644 (file)
@@ -1,22 +1,19 @@
 mkws.registerWidgetType('Termlists', function() {
-  var that = this;
-
   // Initially hide the termlists; display when we get results
+  var that = this;
+  var team = this.team;
   mkws.$(document).ready(function() {
     that.node.hide();
   });
-  this.team.queue("termlists").subscribe(function(data) {
+  team.queue("termlists").subscribe(function(data) {
     that.node.show();
   });
 
-  var acc = [];
-  var facets = this.config.facets;
-  acc.push('<div class="mkwsTermlistsTitle">' + mkws.M('Termlists') + '</div>');
-  for (var i = 0; i < facets.length; i++) {
-    acc.push('<div class="mkwsFacet mkwsTeam_', this.team.name(), '" data-mkws-facet="', facets[i], '">', '</div>');
-  }
-  this.node.html(acc.join(''));
-
+  var template = team.loadTemplate(this.config.template || "Termlists");
+  this.node.html(template({
+    team: team.name(),
+    facets: this.config.facets
+  }));
   this.autosearch();
 });
 
@@ -27,8 +24,8 @@ mkws.registerWidgetType('Facet', function() {
     subject:  [ "Subjects", 10, true ],
     author:   [ "Authors",  10, true ]
   }
-
   var that = this;
+  var team = this.team;
   var name = that.config.facet;
   var ref = facetConfig[name] || [ "Unknown", 10, true ];
   var caption = this.config['facet_caption_' + name] || ref[0];
@@ -36,47 +33,50 @@ mkws.registerWidgetType('Facet', function() {
   var pzIndex = ref[2] ? name : null;
 
   that.toString = function() {
-    return '[Widget ' + that.team.name() + ':' + that.type + '(' + name + ')]';
+    return '[Widget ' + team.name() + ':' + that.type + '(' + name + ')]';
   };
 
-  var t2 = that.team.loadTemplate('Facet-' + caption);
-  that.log("template for Facet-" + caption + " is " + !!t2);
-  if (!t2) {
-    that.log("no " + caption + "-specific template, falling back");
-    t2 = that.team.loadTemplate('Facet');
-  }
-  that.log("template for Facet is " + !!t2);
-
-  that.team.queue("termlists").subscribe(function(data) {
+  team.queue("termlists").subscribe(function(data) {
     data = data[name];
-    var t1 = that.team.loadTemplate('facetTitle-' + caption, mkws.M(caption))
-    var title = t1({ query: that.config.query });
-    var acc = [];
-    acc.push('<div class="mkwsFacetTitle">', title, '</div>');
-
-    var teamName = that.team.name();
+    var terms = [];
+    var teamName = team.name();
     for (var i = 0; i < data.length && i < max; i++) {
-      var fn, field;
-      // General case modifies the query; special case selects a target
-      if (pzIndex) {
-        fn = 'limitQuery'; field = pzIndex;
-      } else if (!that.team.targetFiltered(data[i].id)) {
-        fn = 'limitTarget'; field = data[i].id;
+      var linkdata = "";
+      var action = "";
+      if (!pzIndex) {
+        // Special case: target selection
+        linkdata += ('target_id='+data[i].id+' ');
+        if (!team.targetFiltered(data[i].id)) {
+          action = 'mkws.limitTarget(\'' + teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
+        }
+      } else {
+        action = 'mkws.limitQuery(\'' + teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)';
       }
-
-      var s = t2({ 
-        team: teamName,
-        fn: fn,
-        field: field,
+      linkdata += 'onclick="' + action + ';return false;"';
+      terms.push({
         term: data[i].name,
         count: data[i].freq,
-        query: that.config.query
-      });
-      acc.push('<div class="mkwsTerm">', s, '</div>');
+        linkdata: linkdata
+      }); 
     }
-
-    that.node.html(acc.join(''));
+    // configured template > facet specific template > default facet template
+    var template;
+    if (that.config.template) {
+      template = team.loadTemplate(that.config.template);
+    } else {
+      template = team.loadTemplate("Facet-" + caption);
+      if (template) {
+        that.log("Using Facet-" + caption + " template.")
+      } else {
+        that.log("No " + caption + " specific template, using default.")
+        template = team.loadTemplate("Facet");
+      }
+    }
+    that.node.html(template({
+      name: name,
+      caption: caption,
+      terms: terms
+    }));
   });
-
   this.autosearch();
 });
diff --git a/src/mkws-widget-termlists.templates/Facet.handlebars b/src/mkws-widget-termlists.templates/Facet.handlebars
new file mode 100644 (file)
index 0000000..621c9c1
--- /dev/null
@@ -0,0 +1,17 @@
+{{!
+A facet in the search.
+
+name - facet identifier, typically English and lowercase
+caption - caption for this facet
+terms:
+  term - term name
+  count - count of items matching in the current search for this team
+  linkdata - attributes to add to the term element including an onclick handler
+}}
+
+<div class="mkwsFacetTitle">{{caption}}</div>
+{{#each terms}}
+  <div class="mkwsTerm">
+    <a href="#" {{{linkdata}}}>{{term}}</a> <span>{{count}}</span>
+  </div>
+{{/each}}
diff --git a/src/mkws-widget-termlists.templates/Termlists.handlebars b/src/mkws-widget-termlists.templates/Termlists.handlebars
new file mode 100644 (file)
index 0000000..7c6f3b8
--- /dev/null
@@ -0,0 +1,11 @@
+{{!
+Termlists, a container of all configured facets.
+
+team - the current team
+facets - array of facet names
+}}
+
+<div class="mkwsTermlistsTitle">Termlists</div>
+{{#each facets}}
+  <div class="mkwsFacet mkwsTeam_{{../team}}" data-mkws-facet="{{this}}"></div>
+{{/each}}
index 420bb49..1f78719 100644 (file)
@@ -2,7 +2,7 @@
 
 SRC=   ../../src
 
-HANDLEBARS_FILE = handlebars-v1.1.2.js
+HANDLEBARS_FILE = handlebars-v1.3.0.js
 JQUERY_FILE = jquery-1.10.0.min.js
 JQUERY_JSON_FILE = jquery.json-2.4.js
 PP2_FILE = pz2.js
@@ -19,6 +19,7 @@ COMPONENTS = ${SRC}/mkws-handlebars.js \
        ${SRC}/mkws-core.js \
        ${SRC}/mkws-team.js \
        ${SRC}/mkws-filter.js \
+       ${SRC}/mkws-templates.js \
        ${SRC}/mkws-popup.js \
        ${SRC}/mkws-widget.js \
        ${SRC}/mkws-widget-main.js \
@@ -31,7 +32,7 @@ COMPONENTS = ${SRC}/mkws-handlebars.js \
        ${SRC}/mkws-widget-builder.js
 
 GENERATED = ${HANDLEBARS_FILE} ${JQUERY_FILE} ${JQUERY_JSON_FILE} ${PP2_FILE} \
-       mkws.js mkws.min.js mkws-complete.js mkws-complete.min.js
+       mkws.js mkws.min.js mkws-complete.js mkws-complete.min.js mkws-templates.js
 
 **make-default**: all
 
@@ -89,12 +90,15 @@ release: mkws.js mkws-complete.js mkws.min.js mkws-complete.min.js
                echo "Made release $(VERSION)"; \
        fi
 
-mkws.js: $(COMPONENTS) Makefile
+mkws.js: mkws-templates.js $(COMPONENTS) Makefile
        rm -f $@
        cat ${COMPONENTS} > $@.tmp
        mv -f $@.tmp $@
        chmod 444 $@
 
+mkws-templates.js:
+       handlebars -n mkws.defaultTemplates ${SRC}/*.templates/*.handlebars -f ${SRC}/mkws-templates.js
+
 mkws-html-includes: 
        echo $(COMPONENTS) | perl -npe "s,${SRC},,g; s/\s+/\0/g" | \
          perl -n0e 'chomp(); print qq{    <script type="text/javascript" src="src$$_"></script>\n}'