X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=tools%2Fhtdocs%2Fmkws.js;h=3b907aa915d7df8c743cfca84188a5782f70fc53;hb=bb7fc481253131bd1513e01d9dead5a141652162;hp=00350a9fc6dfc61bc35c67cd7d401ec122a6a69c;hpb=2275826b255416ed4a7b70b98db1f568c0957322;p=mkws-moved-to-github.git
diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js
index 00350a9..3b907aa 100644
--- a/tools/htdocs/mkws.js
+++ b/tools/htdocs/mkws.js
@@ -1,4 +1,7 @@
-/*! MKWS, the MasterKey Widget Set. Copyright (C) 2013-2014, Index Data */
+/*! MKWS, the MasterKey Widget Set.
+ * Copyright (C) 2013-2014 Index Data
+ * See the file LICENSE for details
+ */
"use strict"; // HTML5: disable for debug_level >= 2
@@ -63,18 +66,11 @@ Handlebars.registerHelper('commaList', function(items, options) {
-// Some functions are visible to be called from outside code, namely
-// generated HTML: mkws.switchView(), showDetails(), limitTarget(),
-// limitQuery(), delimitTarget(), delimitQuery(), pagerPrev(),
-// pagerNext(), showPage(). Also mkws.M() is made available for the
-// Handlebars helper 'translate'
-
-
-// Set up global mkws object. Contains a hash of team objects,
-// indexed by windowid.
+// Set up global mkws object. Contains truly global state such as SP
+// authentication, and a hash of team objects, indexed by windowid.
+//
var mkws = {
authenticated: false,
- debug_function: undefined, // will be set during initialisation
debug_level: undefined, // will be initialised from mkws_config
paz: undefined, // will be set up during initialisation
teams: {},
@@ -83,6 +79,7 @@ var mkws = {
"Authors": "Autoren",
"Subjects": "Schlagwörter",
"Sources": "Daten und Quellen",
+ "source": "datenquelle",
"Termlists": "Termlisten",
"Next": "Weiter",
"Prev": "Zurück",
@@ -96,8 +93,10 @@ var mkws = {
"found": "gefunden",
"Title": "Titel",
"Author": "Autor",
+ "author": "autor",
"Date": "Datum",
"Subject": "Schlagwort",
+ "subject": "schlagwort",
"Location": "Ort",
"Records": "Datensätze",
"Targets": "Datenbanken",
@@ -109,6 +108,7 @@ var mkws = {
"Authors": "Forfattere",
"Subjects": "Emner",
"Sources": "Kilder",
+ "source": "kilder",
"Termlists": "Termlists",
"Next": "Næste",
"Prev": "Forrige",
@@ -122,8 +122,10 @@ var mkws = {
"found": "fandt",
"Title": "Title",
"Author": "Forfatter",
+ "author": "forfatter",
"Date": "Dato",
"Subject": "Emneord",
+ "subject": "emneord",
"Location": "Lokation",
"Records": "Poster",
"Targets": "Baser",
@@ -140,16 +142,23 @@ if (mkws_config == null || typeof mkws_config != 'object') {
}
-// wrapper for jQuery lib
+// Factory function for team objects. As much as possible, this uses
+// only member variables (prefixed "m_") and inner functions with
+// private scope. Some functions are visibl as member-functions to be
+// called from outside code -- specifically, from generated
+// HTML. These functions are that.switchView(), showDetails(),
+// limitTarget(), limitQuery(), delimitTarget(), delimitQuery(),
+// pagerPrev(), pagerNext(), showPage().
+//
function team($, teamName) {
var that = {};
var m_teamName = teamName;
var m_submitted = false;
var m_query; // initially undefined
- var m_sort = 'relevance';
+ var m_sort; // will be set below
+ var m_perpage; // will be set below
var m_filters = [];
var m_totalRec = 0;
- var m_recPerPage = 20;
var m_curPage = 1;
var m_curDetRecId = '';
var m_curDetRecData = null;
@@ -161,33 +170,14 @@ function team($, teamName) {
var m_paz; // will be initialised below
- // if (console && console.log) // disabled, will fail in IE8
- // console.log("run team(" + (teamName ? teamName : "") + ")");
-
-
- // Needs to be defined inside team() so it can see m_debug_time
- // ### member access won't work: there is only one instance of this function
- mkws.debug_function = function (string) {
- if (!mkws.debug_level)
- return;
-
- if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */
- return;
- }
-
+ var debug = function (s) {
var now = $.now();
var timestamp = ((now - m_debug_time.start)/1000).toFixed(3) + " (+" + ((now - m_debug_time.last)/1000).toFixed(3) + ") "
m_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);
+ mkws.debug(m_teamName + ": " + timestamp + s);
}
- var debug = mkws.debug_function; // local alias
+
debug("start running MKWS");
m_sort = mkws_config.sort_default;
@@ -225,15 +215,15 @@ function team($, teamName) {
"pazpar2path": mkws_config.pazpar2_url,
"oninit": my_oninit,
"onstat": my_onstat,
- "onterm": my_onterm,
- "termlist": "xtargets,subject,author",
+ "onterm": (mkws_config.facets.length ? my_onterm : undefined),
+ "termlist": mkws_config.facets.join(','),
"onbytarget": my_onbytarget,
"usesessions" : mkws_config.use_service_proxy ? false : true,
"showResponseType": '', // or "json" (for debugging?)
"onrecord": my_onrecord });
if (!isNaN(parseInt(mkws_config.perpage_default))) {
- m_recPerPage = parseInt(mkws_config.perpage_default);
+ m_perpage = parseInt(mkws_config.perpage_default);
}
@@ -241,24 +231,19 @@ function team($, teamName) {
// pz2.js event handlers:
//
function my_oninit(teamName) {
- debug("init for " + teamName);
+ debug("init");
m_paz.stat();
m_paz.bytarget();
}
function my_onshow(data, teamName) {
- debug("show for " + teamName);
+ debug("show");
m_totalRec = data.merged;
- // move it out
- var pager = document.getElementById("mkwsPager");
- if (pager) {
- pager.innerHTML = "";
- pager.innerHTML +='