X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=985707236f707d7db52dfbc5011302cfa68cbcdf;hb=38bd281971a9caf99c2aa7bee851619b626e5501;hp=3676a51329cbc5bfc0503e75cc295835787665ca;hpb=d6ff4d136832a719d8e9357369f457e1ece9cf7c;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 3676a51..9857072 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -4,7 +4,9 @@ "use strict"; // HTML5: disable for debug_level >= 2 // Set up namespace and some state. -var mkws = {}; +var mkws = { + filters: [], +}; /* * global config object: mkws_config @@ -98,6 +100,60 @@ mkws.debug_function = function (string) { } var debug = mkws.debug_function; // local alias + +Handlebars.registerHelper('json', function(obj) { + return JSON.stringify(obj); +}); + + +// We need {{attr '@name'}} because Handlebars can't parse {{@name}} +Handlebars.registerHelper('attr', function(attrName) { + return this[attrName]; +}); + + +/* + * Use as follows: {{#if-any NAME1 having="NAME2"}} + * Applicable when NAME1 is the name of an array + * The guarded code runs only if at least one element of the NAME1 + * array has a subelement called NAME2. + */ +Handlebars.registerHelper('if-any', function(items, options) { + var having = options.hash.having; + for (var i in items) { + var item = items[i] + if (!having || item[having]) { + return options.fn(this); + } + } + return ""; +}); + + +Handlebars.registerHelper('first', function(items, options) { + var having = options.hash.having; + for (var i in items) { + var item = items[i] + if (!having || item[having]) { + return options.fn(item); + } + } + return ""; +}); + + +Handlebars.registerHelper('commaList', function(items, options) { + var out = ""; + + for (var i in items) { + if (i > 0) out += ", "; + out += options.fn(items[i]) + } + + return out; +}); + + { /* default mkws config */ var config_default = { @@ -176,7 +232,6 @@ var totalRec = 0; var curDetRecId = ''; var curDetRecData = null; var curSort = 'relevance'; -var curFilter = null; var submitted = false; var SourceMax = 16; var SubjectMax = 10; @@ -257,9 +312,9 @@ function my_onterm(data) { if (facets[i] == "sources") { add_single_facet(acc, "Sources", data.xtargets, SourceMax, null); } else if (facets[i] == "subjects") { - add_single_facet(acc, "Subjects", data.subject, SubjectMax, "su"); + add_single_facet(acc, "Subjects", data.subject, SubjectMax, "subject"); } else if (facets[i] == "authors") { - add_single_facet(acc, "Authors", data.author, AuthorMax, "au"); + add_single_facet(acc, "Authors", data.author, AuthorMax, "author"); } else { alert("bad facet configuration: '" + facets[i] + "'"); } @@ -269,19 +324,19 @@ function my_onterm(data) { replaceHtml(termlist, acc.join('')); } -function add_single_facet(acc, caption, data, max, cclIndex) { +function add_single_facet(acc, caption, data, max, pzIndex) { acc.push('
'+ marker + ' | |
No locations for record! |
Title | \ +\ + {{md-title}}\ + {{#if md-title-remainder}}\ + ({{md-title-remainder}})\ + {{/if}}\ + {{#if md-title-responsibility}}\ + {{md-title-responsibility}}\ + {{/if}}\ + | \ +
---|---|
Date | \ +{{md-date}} | \ +
Author | \ +{{md-author}} | \ +
URL | \ +\
+ {{#each md-electronic-url}}\
+ {{this}} \ + {{/each}}\ + | \
+
Subject | \ +\ + {{#first location having="md-subject"}}\ + {{#if md-subject}}\ + {{md-subject}}\ + {{/if}}\ + {{/first}}\ + | \ +
Locations | \ +\ + {{#commaList location}}\ + {{attr "@name"}}{{/commaList}}\ + | \ +