');
acc.push('
' + data[i].name + ''
+ '
' + data[i].freq + '');
@@ -349,12 +416,24 @@ function domReady ()
// when search button pressed
function onFormSubmitEventHandler()
{
+ newSearch(document.mkwsSearchForm.mkwsQuery.value);
+ return false;
+}
+
+function newSearch(query, sort, targets)
+{
+ if (mkws_config.use_service_proxy && !mkws.authenticated) {
+ alert("searching before authentication");
+ return;
+ }
+
+ mkws.filters = []
+ redraw_navi();
resetPage();
loadSelect();
- triggerSearch();
+ triggerSearch(query, sort, targets);
mkws.switchView('records'); // In case it's configured to start off as hidden
submitted = true;
- return false;
}
function onSelectDdChange()
@@ -362,7 +441,7 @@ function onSelectDdChange()
if (!submitted) return false;
resetPage();
loadSelect();
- my_paz.show(0, recPerPage, curSort);
+ my_paz.show(0, recPerPage, mkws.sort);
return false;
}
@@ -372,16 +451,50 @@ function resetPage()
totalRec = 0;
}
-function triggerSearch ()
+function triggerSearch (query, sort, targets)
{
- my_paz.search(document.mkwsSearchForm.mkwsQuery.value, recPerPage, curSort, mkws.curFilter);
+ var pp2filter = "";
+ var pp2limit = "";
+
+ // Re-use previous query/sort if new ones are not specified
+ if (query) {
+ mkws.query = query;
+ }
+ if (sort) {
+ mkws.sort = sort;
+ }
+ if (targets) {
+ // ### should support multiple |-separated targets
+ mkws.filters.push({ id: targets, name: targets });
+ }
+
+ for (var i in mkws.filters) {
+ var filter = mkws.filters[i];
+ if (filter.id) {
+ if (pp2filter)
+ pp2filter += ",";
+ if (filter.id.match(/^[a-z:]+[=~]/)) {
+ debug("filter '" + filter.id + "' already begins with SETTING OP");
+ } else {
+ filter.id = 'pz:id=' + filter.id;
+ }
+ pp2filter += filter.id;
+ } else {
+ if (pp2limit)
+ pp2limit += ",";
+ pp2limit += filter.field + "=" + filter.value.replace(/[\\|,]/g, '\\$&');
+ }
+ }
+
+ debug("triggerSearch(" + mkws.query + "): filters = " + $.toJSON(mkws.filters) + ", pp2filter = " + pp2filter + ", pp2limit = " + pp2limit);
+ my_paz.search(mkws.query, recPerPage, mkws.sort, pp2filter, undefined, { limit: pp2limit });
}
function loadSelect ()
{
if (document.mkwsSelect) {
if (document.mkwsSelect.mkwsSort)
- curSort = document.mkwsSelect.mkwsSort.value;
+ mkws.sort = document.mkwsSelect.mkwsSort.value;
if (document.mkwsSelect.mkwsPerpage)
recPerPage = document.mkwsSelect.mkwsPerpage.value;
}
@@ -391,36 +504,99 @@ function loadSelect ()
mkws.limitQuery = function (field, value)
{
debug("limitQuery(field=" + field + ", value=" + value + ")");
- document.mkwsSearchForm.mkwsQuery.value += ' and ' + field + '="' + value + '"';
- onFormSubmitEventHandler();
+ mkws.filters.push({ field: field, value: value });
+ redraw_navi();
+ resetPage();
+ loadSelect();
+ triggerSearch();
+ return false;
}
// limit by target functions
mkws.limitTarget = function (id, name)
{
debug("limitTarget(id=" + id + ", name=" + name + ")");
- var navi = document.getElementById('mkwsNavi');
- navi.innerHTML =
- 'Source:
'
- + name + '';
- mkws.curFilter = 'pz:id=' + id;
+ mkws.filters.push({ id: id, name: name });
+ redraw_navi();
resetPage();
loadSelect();
triggerSearch();
return false;
}
-mkws.delimitTarget = function ()
+mkws.delimitQuery = function (field, value)
{
- var navi = document.getElementById('mkwsNavi');
- navi.innerHTML = '';
- mkws.curFilter = null;
+ debug("delimitQuery(field=" + field + ", value=" + value + ")");
+ var newFilters = [];
+ for (var i in mkws.filters) {
+ var filter = mkws.filters[i];
+ if (filter.field &&
+ field == filter.field &&
+ value == filter.value) {
+ debug("delimitTarget() removing filter " + $.toJSON(filter));
+ } else {
+ debug("delimitTarget() keeping filter " + $.toJSON(filter));
+ newFilters.push(filter);
+ }
+ }
+ mkws.filters = newFilters;
+
+ redraw_navi();
resetPage();
loadSelect();
triggerSearch();
return false;
}
+
+mkws.delimitTarget = function (id)
+{
+ debug("delimitTarget(id=" + id + ")");
+ var newFilters = [];
+ for (var i in mkws.filters) {
+ var filter = mkws.filters[i];
+ if (filter.id) {
+ debug("delimitTarget() removing filter " + $.toJSON(filter));
+ } else {
+ debug("delimitTarget() keeping filter " + $.toJSON(filter));
+ newFilters.push(filter);
+ }
+ }
+ mkws.filters = newFilters;
+
+ redraw_navi();
+ resetPage();
+ loadSelect();
+ triggerSearch();
+ return false;
+}
+
+
+function redraw_navi ()
+{
+ var navi = document.getElementById('mkwsNavi');
+ if (!navi) return;
+
+ var text = "";
+ for (var i in mkws.filters) {
+ if (text) {
+ text += " | ";
+ }
+ var filter = mkws.filters[i];
+ if (filter.id) {
+ text += 'Source:
' + filter.name + '';
+ } else {
+ text += filter.field + ':
' + filter.value + '';
+ }
+ }
+
+ navi.innerHTML = text;
+}
+
+
function drawPager (pagerDiv)
{
//client indexes pages from 1 but pz2 from 0
@@ -560,55 +736,106 @@ function replaceHtml(el, html) {
function renderDetails(data, marker)
{
- var details = '
';
- if (marker) details += ''+ marker + ' |
';
-
- 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 += 'No locations for record! |
';
- } else {
- details += renderField("Location" + (locations.length == 1 ? "" : "s"), locations);
+ if (mkws.templateRecord === undefined) {
+ loadTemplate("Record");
}
- details += '
';
- return details;
+ var template = mkws.templateRecord;
+ var details = template(data);
+ 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 = '
' + s + '';
-
- res += s
+function loadTemplate(name)
+{
+ var source = $("#mkwsTemplate" + name).html();
+ if (!source) {
+ source = defaultTemplate(name);
}
- if (data2 != undefined) {
- res = res + " (" + data2 + ")";
- }
+ var template = Handlebars.compile(source);
+ debug("compiled template '" + name + "'");
+ mkws['template' + name] = template;
+}
- if (data3 != undefined) {
- res = res + "
" + data3 + "";
+
+function defaultTemplate(name)
+{
+ if (name === 'Record') {
+ return '\
+
\
+ \
+ Title | \
+ \
+ {{md-title}}\
+ {{#if md-title-remainder}}\
+ ({{md-title-remainder}})\
+ {{/if}}\
+ {{#if md-title-responsibility}}\
+ {{md-title-responsibility}}\
+ {{/if}}\
+ | \
+
\
+ {{#if md-date}}\
+ \
+ Date | \
+ {{md-date}} | \
+
\
+ {{/if}}\
+ {{#if md-author}}\
+ \
+ Author | \
+ {{md-author}} | \
+
\
+ {{/if}}\
+ {{#if md-electronic-url}}\
+ \
+ URL | \
+ \
+ {{#each md-electronic-url}}\
+ {{this}} \
+ {{/each}}\
+ | \
+
\
+ {{/if}}\
+ {{#if-any location having="md-subject"}}\
+ \
+ Subject | \
+ \
+ {{#first location having="md-subject"}}\
+ {{#if md-subject}}\
+ {{md-subject}}\
+ {{/if}}\
+ {{/first}}\
+ | \
+
\
+ {{/if-any}}\
+ \
+ Locations | \
+ \
+ {{#commaList location}}\
+ {{attr "@name"}}{{/commaList}}\
+ | \
+
\
+
\
+';
+ } else if (name === "Summary") {
+ return '\
+
\
+ {{md-title}}\
+ \
+ {{#if md-title-remainder}}\
+
{{md-title-remainder}}\
+ {{/if}}\
+ {{#if md-title-responsibility}}\
+
{{md-title-responsibility}}\
+ {{/if}}\
+';
}
- return '
' + M(caption) + ' | ' + res + ' |
---|
';
+ var s = "There is no default '" + name +"' template!";
+ alert(s);
+ return s;
}
@@ -678,8 +905,9 @@ function mkws_html_all() {
mkws_html_switch();
if (mkws_config.use_service_proxy)
- mkws_service_proxy_auth(mkws_config.service_proxy_auth,
- mkws_config.service_proxy_auth_domain);
+ mkws_service_proxy_auth(mkws_config.service_proxy_auth,
+ mkws_config.service_proxy_auth_domain,
+ mkws_config.pazpar2_url);
if (mkws_config.responsive_design_width) {
// Responsive web design - change layout on the fly based on
@@ -702,6 +930,22 @@ function mkws_html_all() {
}
}
+
+function run_auto_searches() {
+ var node = $('#mkwsRecords');
+ if (node.attr('autosearch')) {
+ var query = node.attr('autosearch');
+ var sort = node.attr('sort');
+ var targets = node.attr('targets');
+ var s = "running auto search: '" + query + "'";
+ if (sort) s += " sorted by '" + sort + "'";
+ if (targets) s += " in targets '" + targets + "'";
+ debug(s);
+ newSearch(query, sort, targets);
+ }
+}
+
+
function mkws_set_lang() {
var lang = $.parseQuerystring().lang || mkws_config.lang;
if (!lang || !mkws.locale_lang[lang]) {
@@ -730,7 +974,7 @@ function mkws_html_switch() {
}
function mkws_html_sort() {
- debug("HTML sort");
+ debug("HTML sort, mkws.sort = '" + mkws.sort + "'");
var sort_html = '