X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=b1a04d713463aa8d77542b65c7f61b20c2994b73;hb=099876e5483d5fcc77aebc69e63b238e09889b1f;hp=fb54a8e3f577cea827b3b55ac05f633ff4c0609b;hpb=3d550d4fcd67dae13cb96f558a315ae06f8f4585;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index fb54a8e..b1a04d7 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -1,5 +1,5 @@ -/*! 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 */ @@ -67,7 +67,7 @@ Handlebars.registerHelper('commaList', function(items, options) { // Some functions are visible to be called from outside code, namely -// generated HTML: mkws.switchView(), showDetails(), limitTarget(), +// generated HTML: that.switchView(), showDetails(), limitTarget(), // limitQuery(), delimitTarget(), delimitQuery(), pagerPrev(), // pagerNext(), showPage(). Also mkws.M() is made available for the // Handlebars helper 'translate' @@ -86,6 +86,7 @@ var mkws = { "Authors": "Autoren", "Subjects": "Schlagwörter", "Sources": "Daten und Quellen", + "source": "datenquelle", "Termlists": "Termlisten", "Next": "Weiter", "Prev": "Zurück", @@ -99,8 +100,10 @@ var mkws = { "found": "gefunden", "Title": "Titel", "Author": "Autor", + "author": "autor", "Date": "Datum", "Subject": "Schlagwort", + "subject": "schlagwort", "Location": "Ort", "Records": "Datensätze", "Targets": "Datenbanken", @@ -112,6 +115,7 @@ var mkws = { "Authors": "Forfattere", "Subjects": "Emner", "Sources": "Kilder", + "source": "kilder", "Termlists": "Termlists", "Next": "Næste", "Prev": "Forrige", @@ -125,8 +129,10 @@ var mkws = { "found": "fandt", "Title": "Title", "Author": "Forfatter", + "author": "forfatter", "Date": "Dato", "Subject": "Emneord", + "subject": "emneord", "Location": "Lokation", "Records": "Poster", "Targets": "Baser", @@ -188,7 +194,7 @@ function team($, teamName) { } else if (mkws.debug_level >= 2) { console.log(timestamp + ">>> called from function " + arguments.callee.caller.name + ' <<<'); } - console.log(timestamp + string); + console.log(m_teamName + ": " + timestamp + string); } var debug = mkws.debug_function; // local alias debug("start running MKWS"); @@ -228,8 +234,8 @@ function team($, teamName) { "pazpar2path": mkws_config.pazpar2_url, "oninit": my_oninit, "onstat": my_onstat, - "onterm": my_onterm, - "termlist": "xtargets,subject,author", // ### should only request the ones we actually want + "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?) @@ -286,7 +292,7 @@ function team($, teamName) { { var template = loadTemplate("Summary"); hit._id = "mkwsRec_" + hit.recid; - hit._onclick = "mkws.showDetails(this.id, '" + m_teamName + "');return false;" + hit._onclick = "mkws.showDetails('" + m_teamName + "', this.id);return false;" return template(hit); } @@ -310,9 +316,9 @@ function team($, teamName) { var node = $(".mkwsTermlists.mkwsTeam_" + teamName); if (node.length == 0) return; - // no facets + // no facets: this should never happen if (!mkws_config.facets || mkws_config.facets.length == 0) { - debug("my_onterm called even though we have no facets: " + $.toJSON(data)); + alert("my_onterm called even though we have no facets: " + $.toJSON(data)); node.hide(); return; } @@ -325,11 +331,11 @@ function team($, teamName) { var facets = mkws_config.facets; for(var i = 0; i < facets.length; i++) { - if (facets[i] == "sources") { + if (facets[i] == "xtargets") { add_single_facet(acc, "Sources", data.xtargets, 16, null); - } else if (facets[i] == "subjects") { + } else if (facets[i] == "subject") { add_single_facet(acc, "Subjects", data.subject, 10, "subject"); - } else if (facets[i] == "authors") { + } else if (facets[i] == "author") { add_single_facet(acc, "Authors", data.author, 10, "author"); } else { alert("bad facet configuration: '" + facets[i] + "'"); @@ -341,7 +347,7 @@ function team($, teamName) { function add_single_facet(acc, caption, data, max, pzIndex) { - acc.push('
'); + acc.push('
'); acc.push('
' + M(caption) + '
'); for (var i = 0; i < data.length && i < max; i++) { acc.push('
'); @@ -350,9 +356,9 @@ function team($, teamName) { if (!pzIndex) { // Special case: target selection acc.push('target_id='+data[i].id+' '); - action = 'mkws.limitTarget(this.getAttribute(\'target_id\'),this.firstChild.nodeValue)'; + action = 'mkws.limitTarget(\'' + m_teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)'; } else { - action = 'mkws.limitQuery(\'' + pzIndex + '\', this.firstChild.nodeValue)'; + action = 'mkws.limitQuery(\'' + m_teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)'; } acc.push('onclick="' + action + ';return false;">' + data[i].name + '' + ' ' + data[i].freq + ''); @@ -410,7 +416,6 @@ function team($, teamName) { // wait until the DOM is ready function domReady () { - debug("starting domReady()"); $('.mkwsSearchForm.mkwsTeam_' + m_teamName).each(function (i, obj) { debug("adding search-forms for team '" + m_teamName + "'"); var node = this; @@ -420,13 +425,6 @@ function team($, teamName) { }); }); - debug("in domReady() 1"); - debug("document = '" + document + "'"); - debug("document.mkwsSearchForm = '" + document.mkwsSearchForm + "'"); - debug("document.mkwsSearchForm.mkwsQuery = '" + document.mkwsSearchForm.mkwsQuery + "'"); - debug("document.mkwsSearchForm.mkwsQuery.value = '" + document.mkwsSearchForm.mkwsQuery.value + "'"); - document.mkwsSearchForm.mkwsQuery.value = ''; - debug("in domReady() 2"); if (document.mkwsSelect) { debug("messing with mkwsSelect"); if (document.mkwsSelect.mkwsSort) @@ -434,7 +432,6 @@ function team($, teamName) { if (document.mkwsSelect.mkwsPerpage) document.mkwsSelect.mkwsPerpage.onchange = onSelectDdChange; } - debug("finished domReady()"); } @@ -460,7 +457,7 @@ function team($, teamName) { } m_filters = [] - redraw_navi(); // ### should use windowid + redraw_navi(); resetPage(); // ### the globals it resents should be indexed by windowid loadSelect(); // ### should use windowid triggerSearch(query, sort, targets, windowid); @@ -545,11 +542,11 @@ function team($, teamName) { } - // limit the query after clicking the facet - mkws.limitQuery = function (field, value) + // limit by target functions + that.limitTarget = function (id, name) { - debug("limitQuery(field=" + field + ", value=" + value + ")"); - m_filters.push({ field: field, value: value }); + debug("limitTarget(id=" + id + ", name=" + name + ")"); + m_filters.push({ id: id, name: name }); redraw_navi(); resetPage(); loadSelect(); @@ -558,11 +555,11 @@ function team($, teamName) { } - // limit by target functions - mkws.limitTarget = function (id, name) + // limit the query after clicking the facet + that.limitQuery = function (field, value) { - debug("limitTarget(id=" + id + ", name=" + name + ")"); - m_filters.push({ id: id, name: name }); + debug("limitQuery(field=" + field + ", value=" + value + ")"); + m_filters.push({ field: field, value: value }); redraw_navi(); resetPage(); loadSelect(); @@ -571,7 +568,7 @@ function team($, teamName) { } - mkws.delimitQuery = function (field, value) + that.delimitQuery = function (field, value) { debug("delimitQuery(field=" + field + ", value=" + value + ")"); var newFilters = []; @@ -580,9 +577,9 @@ function team($, teamName) { if (filter.field && field == filter.field && value == filter.value) { - debug("delimitTarget() removing filter " + $.toJSON(filter)); + debug("delimitQuery() removing filter " + $.toJSON(filter)); } else { - debug("delimitTarget() keeping filter " + $.toJSON(filter)); + debug("delimitQuery() keeping filter " + $.toJSON(filter)); newFilters.push(filter); } } @@ -596,7 +593,7 @@ function team($, teamName) { } - mkws.delimitTarget = function (id) + that.delimitTarget = function (id) { debug("delimitTarget(id=" + id + ")"); var newFilters = []; @@ -621,7 +618,7 @@ function team($, teamName) { function redraw_navi () { - var navi = document.getElementById('mkwsNavi'); + var navi = $('.mkwsNavi.mkwsTeam_' + m_teamName); if (!navi) return; var text = ""; @@ -631,16 +628,16 @@ function team($, teamName) { } var filter = m_filters[i]; if (filter.id) { - text += 'Source: ' + filter.name + ''; + text += M('source') + ': ' + filter.name + ''; } else { - text += filter.field + ': ' + filter.value + ''; } } - navi.innerHTML = text; + navi.html(text); } @@ -963,7 +960,7 @@ function team($, teamName) { debug("after domReady()"); // on first page, hide the termlist - $(document).ready(function() { $("#mkwsTermlists").hide(); }); + $(document).ready(function() { $(".mkwsTermlists.mkwsTeam_" + m_teamName).hide(); }); var motd = $(".mkwsMOTD.mkwsTeam_" + m_teamName); var container = $(".mkwsMOTDContainer.mkwsTeam_" + m_teamName); debug("for team '" + m_teamName + "', motd=" + motd + "(" + motd.length + "), container=" + container + "(" + container.length + ")"); @@ -1384,10 +1381,25 @@ function _mkws_jquery_plugin ($) { }; - mkws.showDetails = function (prefixRecId, tname) { + mkws.showDetails = function (tname, prefixRecId) { mkws.teams[tname].showDetails(prefixRecId); } + mkws.limitTarget = function (tname, id, name) { + mkws.teams[tname].limitTarget(id, name); + } + + mkws.limitQuery = function (tname, field, value) { + mkws.teams[tname].limitQuery(field, value); + } + + mkws.delimitTarget = function (tname, id) { + mkws.teams[tname].delimitTarget(id); + } + + mkws.delimitQuery = function (tname, field, value) { + mkws.teams[tname].delimitQuery(field, value); + } function default_mkws_config() { /* default mkws config */ @@ -1405,7 +1417,7 @@ function _mkws_jquery_plugin ($) { 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 */ + facets: ["xtargets", "subject", "author"], /* 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 */