');
acc.push('
' + data[i].name + ''
+ '
' + data[i].freq + '');
@@ -350,12 +410,24 @@ function domReady ()
// when search button pressed
function onFormSubmitEventHandler()
{
+ newSearch(document.mkwsSearchForm.mkwsQuery.value);
+ return false;
+}
+
+function newSearch(query)
+{
+ if (!mkws.authenticated) {
+ alert("searching before authentication");
+ return;
+ }
+
+ mkws.filters = []
+ redraw_navi();
resetPage();
loadSelect();
- triggerSearch();
+ triggerSearch(query);
mkws.switchView('records'); // In case it's configured to start off as hidden
submitted = true;
- return false;
}
function onSelectDdChange()
@@ -373,10 +445,31 @@ function resetPage()
totalRec = 0;
}
-function triggerSearch ()
+function triggerSearch (query)
{
- debug("triggerSearch: filters = " + JSON.stringify(mkws.filters));
- my_paz.search(document.mkwsSearchForm.mkwsQuery.value, recPerPage, curSort, mkws.pp2filter);
+ var pp2filter = "";
+ var pp2limit = "";
+
+ // Re-use previous query if a new one is not specified
+ if (query) {
+ mkws.query = query;
+ }
+
+ for (var i in mkws.filters) {
+ var filter = mkws.filters[i];
+ if (filter.id) {
+ if (pp2filter)
+ pp2filter += ",";
+ pp2filter += 'pz:id=' + filter.id;
+ } else {
+ if (pp2limit)
+ pp2limit += ",";
+ pp2limit += filter.field + "=" + filter.value.replace(/[\\|,]/g, '\\$&');
+ }
+ }
+
+ debug("triggerSearch(" + mkws.query + "): filters = " + JSON.stringify(mkws.filters) + ", pp2filter = " + pp2filter + ", pp2limit = " + pp2limit);
+ my_paz.search(mkws.query, recPerPage, curSort, pp2filter, undefined, { limit: pp2limit });
}
function loadSelect ()
@@ -395,8 +488,10 @@ mkws.limitQuery = function (field, value)
debug("limitQuery(field=" + field + ", value=" + value + ")");
mkws.filters.push({ field: field, value: value });
redraw_navi();
- document.mkwsSearchForm.mkwsQuery.value += ' and ' + field + '="' + value + '"';
- onFormSubmitEventHandler();
+ resetPage();
+ loadSelect();
+ triggerSearch();
+ return false;
}
// limit by target functions
@@ -405,7 +500,6 @@ mkws.limitTarget = function (id, name)
debug("limitTarget(id=" + id + ", name=" + name + ")");
mkws.filters.push({ id: id, name: name });
redraw_navi();
- mkws.pp2filter = 'pz:id=' + id;
resetPage();
loadSelect();
triggerSearch();
@@ -430,7 +524,6 @@ mkws.delimitQuery = function (field, value)
mkws.filters = newFilters;
redraw_navi();
- mkws.pp2filter = null;
resetPage();
loadSelect();
triggerSearch();
@@ -454,7 +547,6 @@ mkws.delimitTarget = function (id)
mkws.filters = newFilters;
redraw_navi();
- mkws.pp2filter = null;
resetPage();
loadSelect();
triggerSearch();
@@ -626,55 +718,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;
}
@@ -768,6 +911,19 @@ 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');
+ debug("running auto search: '" + query + "' sorted by '" + sort + "'");
+ // ### currently ignoring sort
+ newSearch(query);
+ }
+}
+
+
function mkws_set_lang() {
var lang = $.parseQuerystring().lang || mkws_config.lang;
if (!lang || !mkws.locale_lang[lang]) {
@@ -858,7 +1014,8 @@ function mkws_service_proxy_auth(auth_url, auth_domain) {
}
debug("Service proxy auth successfully done");
- mkws.service_proxy_auth = true;
+ mkws.authenticated = true;
+ run_auto_searches();
});
}