var html = [];
for (var i = 0; i < data.hits.length; i++) {
var hit = data.hits[i];
- html.push('<div class="record" id="mkwsRecdiv_'+hit.recid+'" >'
- +'<a href="#" id="mkwsRec_'+hit.recid
- +'" onclick="mkws.showDetails(this.id);return false;"><b>'
- + hit["md-title"] +' </b></a>');
- if (hit["md-title-remainder"] !== undefined) {
- html.push('<span>' + hit["md-title-remainder"] + ' </span>');
- }
- if (hit["md-title-responsibility"] !== undefined) {
- html.push('<span><i>'+hit["md-title-responsibility"]+'</i></span>');
- }
- if (hit.recid == curDetRecId) {
+ html.push('<div class="record" id="mkwsRecdiv_' + hit.recid + '" >',
+ renderSummary(hit),
+ '</div>');
+ if (hit.recid == curDetRecId) {
html.push(renderDetails(curDetRecData));
- }
- html.push('</div>');
+ }
}
replaceHtml(results, html.join(''));
}
+
+function renderSummary(hit)
+{
+ if (mkws.templateSummary === undefined) {
+ loadTemplate("Summary");
+ }
+
+ hit._id = "mkwsRec_" + hit.recid;
+ hit._onclick = "mkws.showDetails(this.id);return false;"
+ return mkws.templateSummary(hit);
+}
+
+
function my_onstat(data) {
var stat = document.getElementById("mkwsStat");
if (stat == null)
// when search button pressed
function onFormSubmitEventHandler()
{
+ mkws.filters = []
+ redraw_navi();
resetPage();
loadSelect();
triggerSearch();
}
}
- debug("triggerSearch: filters = " + JSON.stringify(mkws.filters) + ", pp2filter = " + pp2filter + ", pp2limit = " + pp2limit);
+ debug("triggerSearch(" + document.mkwsSearchForm.mkwsQuery.value + "): filters = " + JSON.stringify(mkws.filters) + ", pp2filter = " + pp2filter + ", pp2limit = " + pp2limit);
my_paz.search(document.mkwsSearchForm.mkwsQuery.value, recPerPage, curSort, pp2filter, undefined, { limit: pp2limit });
}
function renderDetails(data, marker)
{
if (mkws.templateRecord === undefined) {
- maybeLoadTemplate("Record");
- }
-
- var details;
- if (mkws.templateRecord) {
- var template = mkws.templateRecord;
- details = template(data);
- } else {
- details = defaultRenderDetails(data, marker);
+ loadTemplate("Record");
}
+ var template = mkws.templateRecord;
+ var details = template(data);
return '<div class="details" id="mkwsDet_' + data.recid + '">' + details + '</div>';
}
-function maybeLoadTemplate(name)
+function loadTemplate(name)
{
var source = $("#mkwsTemplate" + name).html();
if (!source) {
- debug("no template '" + name + "': falling back to default behaviour");
- // Mark template as not provided
- mkws['template' + name] = 0;
- return;
+ source = defaultTemplate(name);
}
var template = Handlebars.compile(source);
}
-function defaultRenderDetails(data, marker)
+function defaultTemplate(name)
{
- var details = '<table>';
- if (marker) details += '<tr><td colspan="2">'+ marker + '</td></tr>';
-
- var locations = [];
- for (var i in data.location) {
- locations.push(data.location[i]['@name']);
- }
-
- details += renderField("Title", data["md-title"], data["md-title-remainder"], data["md-title-responsibility"]);
- details += renderField("Date", data["md-date"]);
- details += renderField("Author", data["md-author"]);
- details += renderField("URL", data["md-electronic-url"]);
- details += renderField("Subject", data["location"][0]["md-subject"]);
- if (locations.length == 0) {
- details += '<tr><td colspan="2">No locations for record!</td></tr>';
- } else {
- details += renderField("Location" + (locations.length == 1 ? "" : "s"), locations);
- }
- details += '</table>';
- return details;
-}
-
-
-function renderField(caption, data, data2, data3) {
- if (data === undefined) {
- return "";
- }
-
- var res = "";
- for (var i = 0; i < data.length; i++) {
- var s = data[i];
- if (i > 0)
- res += ", ";
-
- if (caption == "URL")
- s = '<a href="' + s + '" target="_blank">' + s + '</a>';
-
- res += s
- }
-
- if (data2 != undefined) {
- res = res + " (" + data2 + ")";
- }
-
- if (data3 != undefined) {
- res = res + " <i>" + data3 + "</i>";
+ if (name === 'Record') {
+ return '\
+ <table>\
+ <tr>\
+ <th>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>Date</th>\
+ <td>{{md-date}}</td>\
+ </tr>\
+ {{/if}}\
+ {{#if md-author}}\
+ <tr>\
+ <th>Author</th>\
+ <td>{{md-author}}</td>\
+ </tr>\
+ {{/if}}\
+ {{#if md-electronic-url}}\
+ <tr>\
+ <th>URL</th>\
+ <td>\
+ {{#each md-electronic-url}}\
+ <a href="{{this}}">{{this}}</a><br/>\
+ {{/each}}\
+ </td>\
+ </tr>\
+ {{/if}}\
+ {{#if-any location having="md-subject"}}\
+ <tr>\
+ <th>Subject</th>\
+ <td>\
+ {{#first location having="md-subject"}}\
+ {{#if md-subject}}\
+ {{md-subject}}\
+ {{/if}}\
+ {{/first}}\
+ </td>\
+ </tr>\
+ {{/if-any}}\
+ <tr>\
+ <th>Locations</th>\
+ <td>\
+ {{#commaList location}}\
+ {{attr "@name"}}{{/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}}\
+';
}
- return '<tr><th>' + M(caption) + '</th><td>' + res + '</td></tr>';
+ var s = "There is no default '" + name +"' template!";
+ alert(s);
+ return s;
}