X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=fe29a5eff399d0e1925208279e4c1a215f1b6968;hb=a69a66b88e3317022c375792df0b1c3689431496;hp=5c40cb3b74acbaa63339b1fd8a7482ab0ec8389b;hpb=27b7bc85372b54c732469f43950d3d6e15d13344;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 5c40cb3..fe29a5e 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -226,17 +226,7 @@ function team($, teamName) { debug("start running MKWS"); m_sort = mkws_config.sort_default; - debug("copied mkws_config.sort_default '" + mkws_config.sort_default + "' to m_sort"); - - if (!isNaN(parseInt(mkws_config.perpage_default))) { - m_perpage = parseInt(mkws_config.perpage_default); - } - - // protocol independent link for pazpar2: "//mkws/sp" -> "https://mkws/sp" - if (mkws_config.pazpar2_url.match(/^\/\//)) { - mkws_config.pazpar2_url = document.location.protocol + mkws_config.pazpar2_url; - debug("adjust protocol independent links: " + mkws_config.pazpar2_url); - } + m_perpage = mkws_config.perpage_default; debug("Create main pz2 object"); // create a parameters array and pass it to the pz2's constructor @@ -256,21 +246,6 @@ function team($, teamName) { }); - // Finds the node of the specified class within the current team - // Multiple OR-clauses separated by commas are handled - // More complex cases may not work - // - function findnode(selector, teamName) { - teamName = teamName || m_teamName; - - selector = selector.split(',').map(function(s) { - return s + '.mkwsTeam_' + teamName; - }).join(','); - - return $(selector); - } - - // // pz2.js event handlers: // @@ -283,10 +258,8 @@ function team($, teamName) { function onBytarget(data, teamName) { debug("target"); - var targetDiv = findnode('.mkwsBytarget'); - if (!targetDiv) { - return; - } + var node = findnode('.mkwsBytarget'); + if (node.length === 0) return; var table ='' + '' + @@ -305,17 +278,16 @@ function team($, teamName) { } table += '
' + M('Target ID') + '
'; - targetDiv.html(table); + node.html(table); } function onStat(data, teamName) { debug("stat"); - var stat = findnode('.mkwsStat'); - if (stat.length === 0) - return; + var node = findnode('.mkwsStat'); + if (node.length === 0) return; - stat.html('' + M('Status info') + '' + + node.html('' + M('Status info') + '' + ' -- ' + '' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '' + ' -- ' + @@ -400,15 +372,6 @@ function team($, teamName) { } - function renderSummary(hit) - { - var template = loadTemplate("Summary"); - hit._id = "mkwsRec_" + hit.recid; - hit._onclick = "mkws.showDetails('" + m_teamName + "', this.id);return false;" - return template(hit); - } - - function addSingleFacet(acc, caption, data, max, pzIndex) { acc.push('
'); acc.push('
' + M(caption) + '
'); @@ -790,120 +753,6 @@ function team($, teamName) { } - function renderDetails(data, marker) - { - var template = loadTemplate("Record"); - var details = template(data); - return '
' + details + '
'; - } - - - function loadTemplate(name) - { - var template = m_template[name]; - - if (template === undefined) { - // Fall back to generic template if there is no team-specific one - var node = findnode(".mkwsTemplate_" + name); - if (!node.length) { - node = findnode(".mkwsTemplate_" + name, "ALL"); - } - - var source = node.html(); - if (!source) { - source = defaultTemplate(name); - } - - template = Handlebars.compile(source); - debug("compiled template '" + name + "'"); - m_template[name] = template; - } - - return template; - } - - - function defaultTemplate(name) - { - if (name === 'Record') { - return '\ -\ - \ - \ - \ - \ - {{#if md-date}}\ - \ - \ - \ - \ - {{/if}}\ - {{#if md-author}}\ - \ - \ - \ - \ - {{/if}}\ - {{#if md-electronic-url}}\ - \ - \ - \ - \ - {{/if}}\ - {{#if-any location having="md-subject"}}\ - \ - \ - \ - \ - {{/if-any}}\ - \ - \ - \ - \ -
{{translate "Title"}}\ - {{md-title}}\ - {{#if md-title-remainder}}\ - ({{md-title-remainder}})\ - {{/if}}\ - {{#if md-title-responsibility}}\ - {{md-title-responsibility}}\ - {{/if}}\ -
{{translate "Date"}}{{md-date}}
{{translate "Author"}}{{md-author}}
{{translate "Links"}}\ - {{#each md-electronic-url}}\ - Link{{index1}}\ - {{/each}}\ -
{{translate "Subject"}}\ - {{#first location having="md-subject"}}\ - {{#if md-subject}}\ - {{#commaList md-subject}}\ - {{this}}{{/commaList}}\ - {{/if}}\ - {{/first}}\ -
{{translate "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}}\ -'; - } - - var s = "There is no default '" + name +"' template!"; - alert(s); - return s; - } - - /* * All the HTML stuff to render the search forms and * result pages. @@ -993,19 +842,6 @@ function team($, teamName) { } - // implement $.parseQuerystring() for parsing URL parameters - function parseQuerystring() { - var nvpair = {}; - var qs = window.location.search.replace('?', ''); - var pairs = qs.split('&'); - $.each(pairs, function(i, v){ - var pair = v.split('='); - nvpair[pair[0]] = pair[1]; - }); - return nvpair; - } - - function mkwsSetLang() { var lang = parseQuerystring().lang || mkws_config.lang; if (!lang || !mkws.locale_lang[lang]) { @@ -1157,6 +993,19 @@ function team($, teamName) { } + // implement $.parseQuerystring() for parsing URL parameters + function parseQuerystring() { + var nvpair = {}; + var qs = window.location.search.replace('?', ''); + var pairs = qs.split('&'); + $.each(pairs, function(i, v){ + var pair = v.split('='); + nvpair[pair[0]] = pair[1]; + }); + return nvpair; + } + + // This function is taken from a StackOverflow answer // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144 // ### should we unify this and parseQuerystring()? @@ -1180,6 +1029,144 @@ function team($, teamName) { mkws.M = M; // so the Handlebars helper can use it + // Finds the node of the specified class within the current team + // Multiple OR-clauses separated by commas are handled + // More complex cases may not work + // + function findnode(selector, teamName) { + teamName = teamName || m_teamName; + + selector = selector.split(',').map(function(s) { + return s + '.mkwsTeam_' + teamName; + }).join(','); + + return $(selector); + } + + + function renderSummary(hit) + { + var template = loadTemplate("Summary"); + hit._id = "mkwsRec_" + hit.recid; + hit._onclick = "mkws.showDetails('" + m_teamName + "', this.id);return false;" + return template(hit); + } + + + function renderDetails(data, marker) + { + var template = loadTemplate("Record"); + var details = template(data); + return '
' + details + '
'; + } + + + function loadTemplate(name) + { + var template = m_template[name]; + + if (template === undefined) { + // Fall back to generic template if there is no team-specific one + var node = findnode(".mkwsTemplate_" + name); + if (!node.length) { + node = findnode(".mkwsTemplate_" + name, "ALL"); + } + + var source = node.html(); + if (!source) { + source = defaultTemplate(name); + } + + template = Handlebars.compile(source); + debug("compiled template '" + name + "'"); + m_template[name] = template; + } + + return template; + } + + + function defaultTemplate(name) + { + if (name === 'Record') { + return '\ +\ + \ + \ + \ + \ + {{#if md-date}}\ + \ + \ + \ + \ + {{/if}}\ + {{#if md-author}}\ + \ + \ + \ + \ + {{/if}}\ + {{#if md-electronic-url}}\ + \ + \ + \ + \ + {{/if}}\ + {{#if-any location having="md-subject"}}\ + \ + \ + \ + \ + {{/if-any}}\ + \ + \ + \ + \ +
{{translate "Title"}}\ + {{md-title}}\ + {{#if md-title-remainder}}\ + ({{md-title-remainder}})\ + {{/if}}\ + {{#if md-title-responsibility}}\ + {{md-title-responsibility}}\ + {{/if}}\ +
{{translate "Date"}}{{md-date}}
{{translate "Author"}}{{md-author}}
{{translate "Links"}}\ + {{#each md-electronic-url}}\ + Link{{index1}}\ + {{/each}}\ +
{{translate "Subject"}}\ + {{#first location having="md-subject"}}\ + {{#if md-subject}}\ + {{#commaList md-subject}}\ + {{this}}{{/commaList}}\ + {{/if}}\ + {{/first}}\ +
{{translate "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}}\ +'; + } + + var s = "There is no default '" + name +"' template!"; + alert(s); + return s; + } + + // main (function() { try { @@ -1432,6 +1419,12 @@ function team($, teamName) { $(document).ready(function() { mkws.resizePage() }); } + // protocol independent link for pazpar2: "//mkws/sp" -> "https://mkws/sp" + if (mkws_config.pazpar2_url.match(/^\/\//)) { + mkws_config.pazpar2_url = document.location.protocol + mkws_config.pazpar2_url; + debug("adjust protocol independent links: " + mkws_config.pazpar2_url); + } + // Backwards compatibility: set new magic class names on any // elements that have the old magic IDs. var ids = [ "Switch", "Lang", "Search", "Pager", "Navi",