/* A very simple client that shows a basic usage of the pz2.js
*/
-"use strict"; // HTML5: disable for debug >= 2
+"use strict"; // HTML5: disable for debug_level >= 2
+
+// Set up namespace and some state.
+var mkws = {
+ filters: [],
+};
/*
* global config object: mkws_config
*
- * needs to be defined in the HTML header before
- * including this JS file
+ * Needs to be defined in the HTML header before including this JS file.
+ * Define empty mkws_config for simple applications that don't define it.
*/
-
if (!mkws_config)
- var mkws_config = {}; // for the guys who forgot to define mkws_config...
-
-if (typeof mkws_config.use_service_proxy === 'undefined')
- mkws_config.use_service_proxy = true;
-
-// global debug flag
-var mkws_debug;
-
-var pazpar2_url = mkws_config.pazpar2_url ? mkws_config.pazpar2_url : "/pazpar2/search.pz2";
-var service_proxy_url = mkws_config.service_proxy_url ? mkws_config.service_proxy_url : "http://mkws.indexdata.com/service-proxy/";
+ var mkws_config = {};
-var pazpar2path = mkws_config.use_service_proxy ? service_proxy_url : pazpar2_url;
-var usesessions = mkws_config.use_service_proxy ? false : true;
+// Wrapper for jQuery
+(function ($) {
-
-var mkws_locale_lang = {
+mkws.locale_lang = {
"de": {
"Authors": "Autoren",
"Subjects": "Schlagwörter",
"Date": "Datum",
"Subject": "Schlagwort",
"Location": "Ort",
+ // ### to add: Records, Targets
"dummy": "dummy"
},
"Date": "Dato",
"Subject": "Emneord",
"Location": "Lokation",
+ // ### to add: Records, Targets
"dummy": "dummy"
}
};
+// keep time state for debugging
+mkws.debug_time = {
+ "start": $.now(),
+ "last": $.now()
+};
+
+mkws.debug_function = function (string) {
+ if (!mkws.debug_level)
+ return;
+
+ if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */
+ return;
+ }
+
+ var now = $.now();
+ var timestamp = (now - mkws.debug_time.start)/1000 + " (+" + (now - mkws.debug_time.last)/1000 + ") "
+ mkws.debug_time.last = now;
+
+ // you need to disable use strict at the top of the file!!!
+ if (mkws.debug_level >= 3) {
+ console.log(timestamp + arguments.callee.caller);
+ } else if (mkws.debug_level >= 2) {
+ console.log(timestamp + ">>> called from function " + arguments.callee.caller.name + ' <<<');
+ }
+ console.log(timestamp + string);
+}
+var debug = mkws.debug_function; // local alias
+
+
+Handlebars.registerHelper('link', function(a) {
+ var result = "";
+ for (var i in a) {
+ if (i > 0) result += "<br/>";
+ var text = Handlebars.Utils.escapeExpression(a[i]);
+ result += '<a href="' + text + '">' + text + '</a>';
+ }
+
+ return new Handlebars.SafeString(result);
+});
+
+
+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 "";
+});
+
+
+{
+ /* default mkws config */
+ var config_default = {
+ use_service_proxy: true,
+ service_proxy_auth: "http://mkws.indexdata.com/service-proxy-auth",
+ lang: "",
+ sort_options: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]],
+ perpage_options: [10, 20, 30, 50],
+ sort_default: "relevance",
+ perpage_default: 20,
+ query_width: 50,
+ show_lang: true, /* show/hide language menu */
+ show_sort: true, /* show/hide sort menu */
+ show_perpage: true, /* show/hide perpage menu */
+ lang_options: [], /* display languages links for given languages, [] for all */
+ facets: ["sources", "subjects", "authors"], /* display facets, in this order, [] for none */
+ responsive_design_width: undefined, /* a page with less pixel width considered as narrow */
+ debug_level: 1, /* debug level for development: 0..2 */
+
+ dummy: "dummy"
+ };
+
+ /* set global debug_level flag early */
+ if (typeof mkws_config.debug_level !== 'undefined') {
+ mkws.debug_level = mkws_config.debug_level;
+ } else if (typeof config_default.debug_level !== 'undefined') {
+ mkws.debug_level = config_default.debug_level;
+ }
+
+ /* override standard config values by function parameters */
+ for (var k in config_default) {
+ if (typeof mkws_config[k] === 'undefined')
+ mkws_config[k] = config_default[k];
+ debug("Set config: " + k + ' => ' + mkws_config[k]);
+ }
+}
+
+if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
+ debug("Reset query width: " + mkws_config.query_width);
+ mkws_config.query_width = 50;
+}
for (var key in mkws_config) {
if (mkws_config.hasOwnProperty(key)) {
if (key.match(/^language_/)) {
var lang = key.replace(/^language_/, "");
// Copy custom languages into list
- mkws_locale_lang[lang] = mkws_config[key];
+ mkws.locale_lang[lang] = mkws_config[key];
+ debug("Added locally configured language '" + lang + "'");
}
}
}
// autoInit is set to true on default
var my_paz = new pz2( { "onshow": my_onshow,
"showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way
- "pazpar2path": pazpar2path,
+ "pazpar2path": mkws_config.pazpar2_url || "http://mkws.indexdata.com/service-proxy/",
"oninit": my_oninit,
"onstat": my_onstat,
"onterm": my_onterm,
"termlist": "xtargets,subject,author",
"onbytarget": my_onbytarget,
- "usesessions" : usesessions,
+ "usesessions" : mkws_config.use_service_proxy ? false : true,
"showResponseType": '', // or "json" (for debugging?)
"onrecord": my_onrecord } );
+
+mkws.my_paz = my_paz; // export
+
// some state vars
var curPage = 1;
var recPerPage = 20;
var curDetRecId = '';
var curDetRecData = null;
var curSort = 'relevance';
-var curFilter = null;
var submitted = false;
var SourceMax = 16;
var SubjectMax = 10;
totalRec = data.merged;
// move it out
var pager = document.getElementById("mkwsPager");
- pager.innerHTML = "";
- pager.innerHTML +='<div style="float: right">' + M('Displaying') + ': '
- + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) +
- ' ' + M('of') + ' ' + data.merged + ' (' + M('found') + ': '
- + data.total + ')</div>';
- drawPager(pager);
+ if (pager) {
+ pager.innerHTML = "";
+ pager.innerHTML +='<div style="float: right">' + M('Displaying') + ': '
+ + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) +
+ ' ' + M('of') + ' ' + data.merged + ' (' + M('found') + ': '
+ + data.total + ')</div>';
+ drawPager(pager);
+ }
+
// navi
var results = document.getElementById("mkwsRecords");
for (var i = 0; i < data.hits.length; i++) {
var hit = data.hits[i];
html.push('<div class="record" id="mkwsRecdiv_'+hit.recid+'" >'
- +'<span>'+ (i + 1 + recPerPage * (curPage - 1)) +'. </span>'
+'<a href="#" id="mkwsRec_'+hit.recid
- +'" onclick="showDetails(this.id);return false;"><b>'
+ +'" 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 (stat == null)
return;
- stat.innerHTML = '<span class="head">Status info</span>' +
+ stat.innerHTML = '<span class="head">' + M('Status info') + '</span>' +
' -- ' +
- '<span class="clients">' + data.activeclients + '/' + data.clients + '</span>' +
+ '<span class="clients">' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '</span>' +
' -- ' +
- '<span class="records">' + data.records + '/' + data.hits + '</span>';
+ '<span class="records">' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '</span>';
}
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] + "'");
}
replaceHtml(termlist, acc.join(''));
}
-function add_single_facet(acc, caption, data, max, cclIndex) {
+function add_single_facet(acc, caption, data, max, pzIndex) {
acc.push('<div class="facet" id="mkwsFacet' + caption + '">');
acc.push('<div class="termtitle">' + M(caption) + '</div>');
for (var i = 0; i < data.length && i < max; i++ ) {
acc.push('<div class="term">');
acc.push('<a href="#" ');
var action;
- if (!cclIndex) {
+ if (!pzIndex) {
// Special case: target selection
acc.push('target_id='+data[i].id+' ');
- action = 'limitTarget(this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
+ action = 'mkws.limitTarget(this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
} else {
- action = 'limitQuery(\'' + cclIndex + '\', this.firstChild.nodeValue)';
+ action = 'mkws.limitQuery(\'' + pzIndex + '\', this.firstChild.nodeValue)';
}
acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
+ ' <span>' + data[i].freq + '</span>');
function my_onbytarget(data) {
var targetDiv = document.getElementById("mkwsBytarget");
- var table ='<table><thead><tr><td>Target ID</td><td>Hits</td><td>Diags</td>'
- +'<td>Records</td><td>State</td></tr></thead><tbody>';
+ if (!targetDiv) {
+ // No mkwsTargets div.
+ return;
+ }
+
+ 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>';
for (var i = 0; i < data.length; i++ ) {
table += "<tr><td>" + data[i].id +
resetPage();
loadSelect();
triggerSearch();
- switchView('records'); // In case it's configured to start off as hidden
+ mkws.switchView('records'); // In case it's configured to start off as hidden
submitted = true;
return false;
}
function triggerSearch ()
{
- my_paz.search(document.mkwsSearchForm.mkwsQuery.value, recPerPage, curSort, curFilter);
+ var pp2filter = "";
+ var pp2limit = "";
+
+ 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: filters = " + JSON.stringify(mkws.filters) + ", pp2filter = " + pp2filter + ", pp2limit = " + pp2limit);
+ my_paz.search(document.mkwsSearchForm.mkwsQuery.value, recPerPage, curSort, pp2filter, undefined, { limit: pp2limit });
}
function loadSelect ()
}
// limit the query after clicking the facet
-function limitQuery (field, value)
+mkws.limitQuery = function (field, value)
{
- document.mkwsSearchForm.mkwsQuery.value += ' and ' + field + '="' + value + '"';
- onFormSubmitEventHandler();
+ debug("limitQuery(field=" + field + ", value=" + value + ")");
+ mkws.filters.push({ field: field, value: value });
+ redraw_navi();
+ resetPage();
+ loadSelect();
+ triggerSearch();
+ return false;
}
// limit by target functions
-function limitTarget (id, name)
+mkws.limitTarget = function (id, name)
{
- var navi = document.getElementById('mkwsNavi');
- navi.innerHTML =
- 'Source: <a class="crossout" href="#" onclick="delimitTarget();return false;">'
- + name + '</a>';
- curFilter = 'pz:id=' + id;
+ debug("limitTarget(id=" + id + ", name=" + name + ")");
+ mkws.filters.push({ id: id, name: name });
+ redraw_navi();
resetPage();
loadSelect();
triggerSearch();
return false;
}
-function delimitTarget ()
+mkws.delimitQuery = function (field, value)
{
- var navi = document.getElementById('mkwsNavi');
- navi.innerHTML = '';
- 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 " + JSON.stringify(filter));
+ } else {
+ debug("delimitTarget() keeping filter " + JSON.stringify(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 " + JSON.stringify(filter));
+ } else {
+ debug("delimitTarget() keeping filter " + JSON.stringify(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: <a class="crossout" href="#" onclick="mkws.delimitTarget(' +
+ "'" + filter.id + "'" + ');return false;">' + filter.name + '</a>';
+ } else {
+ text += filter.field + ': <a class="crossout" href="#" onclick="mkws.delimitQuery(' +
+ "'" + filter.field + "', '" + filter.value + "'" +
+ ');return false;">' + filter.value + '</a>';
+ }
+ }
+
+ navi.innerHTML = text;
+}
+
+
function drawPager (pagerDiv)
{
//client indexes pages from 1 but pz2 from 0
var prev = '<span id="mkwsPrev"><< ' + M('Prev') + '</span><b> | </b>';
if (curPage > 1)
- prev = '<a href="#" id="mkwsPrev" onclick="pagerPrev();">'
+ prev = '<a href="#" id="mkwsPrev" onclick="mkws.pagerPrev();">'
+'<< ' + M('Prev') + '</a><b> | </b>';
var middle = '';
if(i == curPage)
numLabel = '<b>' + i + '</b>';
- middle += '<a href="#" onclick="showPage(' + i + ')"> '
+ middle += '<a href="#" onclick="mkws.showPage(' + i + ')"> '
+ numLabel + ' </a>';
}
var next = '<b> | </b><span id="mkwsNext">' + M('Next') + ' >></span>';
if (pages - curPage > 0)
- next = '<b> | </b><a href="#" id="mkwsNext" onclick="pagerNext()">'
+ next = '<b> | </b><a href="#" id="mkwsNext" onclick="mkws.pagerNext()">'
+ M('Next') + ' >></a>';
var predots = '';
+ prev + predots + middle + postdots + next + '</div>';
}
-function showPage (pageNum)
+mkws.showPage = function (pageNum)
{
curPage = pageNum;
my_paz.showPage( curPage - 1 );
// simple paging functions
-function pagerNext() {
+mkws.pagerNext = function () {
if ( totalRec - recPerPage*curPage > 0) {
my_paz.showNext();
curPage++;
}
}
-function pagerPrev() {
+mkws.pagerPrev = function () {
if ( my_paz.showPrev() != false )
curPage--;
}
// switching view between targets and records
-function switchView(view) {
+mkws.switchView = function(view) {
+ debug("switchView: " + view);
+
var targets = document.getElementById('mkwsTargets');
var results = document.getElementById('mkwsResults') ||
document.getElementById('mkwsRecords');
}
// detailed record drawing
-function showDetails (prefixRecId) {
+mkws.showDetails = function (prefixRecId) {
var recId = prefixRecId.replace('mkwsRec_', '');
var oldRecId = curDetRecId;
curDetRecId = recId;
function renderDetails(data, marker)
{
- var details = '<div class="details" id="mkwsDet_'+data.recid+'"><table>';
- if (marker) details += '<tr><td>'+ marker + '</td></tr>';
+ if (mkws.templateRecord === undefined) {
+ maybeLoadTemplate("Record");
+ }
+
+ var details;
+ if (mkws.templateRecord) {
+ var template = mkws.templateRecord;
+ details = template(data);
+ } else {
+ details = defaultRenderDetails(data, marker);
+ }
+
+ return '<div class="details" id="mkwsDet_' + data.recid + '">' + details + '</div>';
+}
+
+
+function maybeLoadTemplate(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;
+ }
+
+ var template = Handlebars.compile(source);
+ debug("compiled template '" + name + "'");
+ mkws['template' + name] = template;
+}
+
+
+function defaultRenderDetails(data, marker)
+{
+ 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"]);
- details += renderField("Location", data["location"][0]["@name"], data["location"][0]["@id"]);
- details += '</table></div>';
-
+ 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 "";
}
- if (caption == "URL") {
- data = '<a href="' + data + '" target="_blank">' + data + '</a>';
+ 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) {
- data = data + " (" + data2 + ")";
+ res = res + " (" + data2 + ")";
}
if (data3 != undefined) {
- data = data + " <i>" + data3 + "</i>";
+ res = res + " <i>" + data3 + "</i>";
}
- return '<tr><th>' + M(caption) + '</th><td>' + data + '</td></tr>';
+ return '<tr><th>' + M(caption) + '</th><td>' + res + '</td></tr>';
}
* All the HTML stuff to render the search forms and
* result pages.
*/
-function mkws_html_all(config) {
-
- /* default mkws config */
- var mkws_config_default = {
- sort: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]],
- perpage: [10, 20, 30, 50],
- sort_default: "relevance",
- perpage_default: 20,
- query_width: 50,
- switch_menu: false, /* show/hide Records|Targets menu */
- lang_menu: true, /* show/hide language menu */
- sort_menu: true, /* show/hide sort menu */
- perpage_menu: true, /* show/hide perpage menu */
- lang_display: [], /* display languages links for given languages, [] for all */
- facets: ["sources", "subjects", "authors"], /* display facets, in this order, [] for none */
- responsive_design_width: 980, /* a page with less pixel width considered as narrow */
- debug: 1, /* debug level for development: 0..2 */
-
- dummy: "dummy"
- };
-
- /* set global debug flag early */
- if (typeof config.debug !== 'undefined') {
- mkws_debug = config.debug;
- } else if (typeof mkws_config_default.debug !== 'undefined') {
- mkws_debug = mkws_config_default.debug;
- }
-
- /* override standard config values by function parameters */
- for (var k in mkws_config_default) {
- if (typeof config[k] === 'undefined')
- mkws_config[k] = mkws_config_default[k];
- debug("Set config: " + k + ' => ' + mkws_config[k]);
- }
-
- if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
- debug("Reset query width: " + mkws_config.query_width);
- mkws_config.query_width = 50;
- }
-
- mkws_set_lang(mkws_config);
- if (mkws_config.lang_menu)
- mkws_html_lang(mkws_config);
+function mkws_html_all() {
+ mkws_set_lang();
+ if (mkws_config.show_lang)
+ mkws_html_lang();
// For some reason, doing this programmatically results in
// document.mkwsSearchForm.mkwsQuery being undefined, hence the raw HTML.
if ($("#mkwsRanking").length) {
var ranking_data = '';
ranking_data += '<form name="mkwsSelect" id="mkwsSelect" action="" >';
- if (config.sort_menu) {
- ranking_data += M('Sort by') + ' ' + mkws_html_sort(config) + ' ';
+ if (mkws_config.show_sort) {
+ ranking_data += M('Sort by') + ' ' + mkws_html_sort() + ' ';
}
- if (config.perpage_menu) {
- ranking_data += M('and show') + ' ' + mkws_html_perpage(config) + ' ' + M('per page') + '.';
+ if (mkws_config.show_perpage) {
+ ranking_data += M('and show') + ' ' + mkws_html_perpage() + ' ' + M('per page') + '.';
}
ranking_data += '</form>';
$("#mkwsRanking").html(ranking_data);
}
- mkws_html_switch(config);
+ mkws_html_switch();
if (mkws_config.use_service_proxy)
- mkws_service_proxy_auth(config.service_proxy_auth);
+ mkws_service_proxy_auth(mkws_config.service_proxy_auth,
+ mkws_config.service_proxy_auth_domain);
- if (mkws_config.responsive_design) {
+ if (mkws_config.responsive_design_width) {
// Responsive web design - change layout on the fly based on
// current screen width. Required for mobile devices.
$(window).resize( function(e) { mkws_resize_page() });
}
}
-function mkws_set_lang(mkws_config) {
- var lang = $.parseQuerystring().lang || mkws_config.lang || "";
- if (!lang || !mkws_locale_lang[lang]) {
+function mkws_set_lang() {
+ var lang = $.parseQuerystring().lang || mkws_config.lang;
+ if (!lang || !mkws.locale_lang[lang]) {
mkws_config.lang = ""
} else {
mkws_config.lang = lang;
return mkws_config.lang;
}
-function mkws_html_switch(config) {
+function mkws_html_switch() {
debug("HTML switch");
- $("#mkwsSwitch").html($("<a/>", {
- href: '#',
- onclick: "switchView(\'records\')",
- text: M("Records")
- }));
+ $("#mkwsSwitch").append($('<a href="#" id="mkwsSwitch_records" onclick="mkws.switchView(\'records\')">' + M('Records') + '</a>'));
$("#mkwsSwitch").append($("<span/>", { text: " | " }));
- $("#mkwsSwitch").append($("<a/>", {
- href: '#',
- onclick: "switchView(\'targets\')",
- text: M("Targets")
- }));
+ $("#mkwsSwitch").append($('<a href="#" id="mkwsSwitch_targets" onclick="mkws.switchView(\'targets\')">' + M('Targets') + '</a>'));
debug("HTML targets");
$("#mkwsTargets").html('\
No information available yet.\
</div>');
$("#mkwsTargets").css("display", "none");
-
- if (!config.switch_menu) {
- debug("disable switch menu");
- $("#mkwsSwitch").css("display", "none");
- }
}
-function mkws_html_sort(config) {
+function mkws_html_sort() {
debug("HTML sort");
var sort_html = '<select name="mkwsSort" id="mkwsSort">';
- for(var i = 0; i < config.sort.length; i++) {
- var key = config.sort[i][0];
- var val = config.sort[i].length == 1 ? config.sort[i][0] : config.sort[i][1];
+ for(var i = 0; i < mkws_config.sort_options.length; i++) {
+ var opt = mkws_config.sort_options[i];
+ var key = opt[0];
+ var val = opt.length == 1 ? opt[0] : opt[1];
sort_html += '<option value="' + key + '"';
- if (key == config.sort_default) {
+ if (key == mkws_config.sort_default) {
sort_html += ' selected="selected"';
}
- sort_html += '>' + val + '</option>';
+ sort_html += '>' + M(val) + '</option>';
}
sort_html += '</select>';
return sort_html;
}
-function mkws_html_perpage(config) {
+function mkws_html_perpage() {
debug("HTML perpage");
var perpage_html = '<select name="mkwsPerpage" id="mkwsPerpage">';
- for(var i = 0; i < config.perpage.length; i++) {
- var key = config.perpage[i];
+ for(var i = 0; i < mkws_config.perpage_options.length; i++) {
+ var key = mkws_config.perpage_options[i];
perpage_html += '<option value="' + key + '"';
- if (key == config.perpage_default) {
+ if (key == mkws_config.perpage_default) {
perpage_html += ' selected="selected"';
}
perpage_html += '>' + key + '</option>';
* The username/password is configured in the apache config file
* for the site.
*/
-function mkws_service_proxy_auth(auth_url) {
- if (!auth_url)
- auth_url = "http://mkws.indexdata.com/service-proxy-auth";
-
+function mkws_service_proxy_auth(auth_url, auth_domain) {
debug("Run service proxy auth URL: " + auth_url);
var request = new pzHttpRequest(auth_url, function(err) {
- alert("HTTP call for authentication failed: " + err)
- return;
- });
+ alert("HTTP call for authentication failed: " + err)
+ return;
+ }, auth_domain);
+
request.get(null, function(data) {
if (!$.isXMLDoc(data)) {
alert("service proxy auth response document is not valid XML document, give up!");
alert("service proxy auth repsonse status: " + status.text() + ", give up!");
return;
}
+
+ debug("Service proxy auth successfully done");
+ mkws.service_proxy_auth = true;
});
}
/* create locale language menu */
-function mkws_html_lang(mkws_config) {
+function mkws_html_lang() {
var lang_default = "en";
var lang = mkws_config.lang || lang_default;
var list = [];
/* display a list of configured languages, or all */
- var lang_display = mkws_config.lang_display || [];
+ var lang_options = mkws_config.lang_options || [];
var hash = {};
- for (var i = 0; i < lang_display.length; i++) {
- hash[lang_display[i]] = 1;
+ for (var i = 0; i < lang_options.length; i++) {
+ hash[lang_options[i]] = 1;
}
- for (var k in mkws_locale_lang) {
- if (hash[k] == 1 || lang_display.length == 0)
+ for (var k in mkws.locale_lang) {
+ if (hash[k] == 1 || lang_options.length == 0)
list.push(k);
}
// add english link
- if (lang_display.length == 0 || hash[lang_default] == 1)
+ if (lang_options.length == 0 || hash[lang_default] == 1)
list.push(lang_default);
debug("Language menu for: " + list.join(", "));
function mkws_resize_page () {
var list = ["mkwsSwitch"];
- var width = mkws_config.responsive_design_width || 980;
+ var width = mkws_config.responsive_design_width;
var parentId = $("#mkwsTermlists").parent().attr('id');
if ($(window).width() <= width &&
function M(word) {
var lang = mkws_config.lang;
- if (!lang || !mkws_locale_lang[lang])
+ if (!lang || !mkws.locale_lang[lang])
return word;
- return mkws_locale_lang[lang][word] ? mkws_locale_lang[lang][word] : word;
+ return mkws.locale_lang[lang][word] || word;
}
/*
});
};
-function debug(string) {
- if (!mkws_debug)
- return;
- if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */
- return;
- }
- // you need to disable use strict at the top of the file!!!
- if (mkws_debug >= 3) {
- console.log(arguments.callee.caller);
- } else if (mkws_debug >= 2) {
- console.log(">>> called from function " + arguments.callee.caller.name + ' <<<');
+
+/* magic */
+$(document).ready(function() {
+ try {
+ mkws_html_all()
}
- console.log(string);
-}
+ catch (e) {
+ mkws_config.error = e.message;
+ // alert(e.message);
+ }
+});
-/* magic */
-$(document).ready(function() { mkws_html_all(mkws_config) });
+})(jQuery);