From: Wolfram Schneider Date: Tue, 29 Apr 2014 13:26:25 +0000 (+0000) Subject: Merge remote branch 'origin/master' into wosch X-Git-Tag: 1.0.0~621^2~15 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=8d9cf5ca5921f2150742c41d1cbfbd4144ed4379;hp=879ac5e92cfb287ff4e0126ed1e9b5abaf0ff077;p=mkws-moved-to-github.git Merge remote branch 'origin/master' into wosch --- diff --git a/examples/htdocs/mike.html b/examples/htdocs/mike.html index b887ecf..5b1fd4a 100644 --- a/examples/htdocs/mike.html +++ b/examples/htdocs/mike.html @@ -33,5 +33,6 @@
+
Hello, world!
diff --git a/src/mkws-core.js b/src/mkws-core.js index 0bfc174..e0811ff 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -88,7 +88,8 @@ mkws.log = function(string) { // you need to disable use strict at the top of the file!!! if (mkws.log_level >= 3) { - console.log(arguments.callee.caller); + // Works in Chrome; not sure about elsewhere + console.trace(); } else if (mkws.log_level >= 2) { console.log(">>> called from function " + arguments.callee.caller.name + ' <<<'); } @@ -163,6 +164,95 @@ mkws.objectInheritingFrom = function(o) { } +mkws.defaultTemplate = function(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}}\ +'; + } else if (name === "Image") { + return '\ + \ + {{#first md-thumburl}}\ + {{../md-title}}\ + {{/first}}\ +
\ +
\ +'; + } + + var s = "There is no default '" + name +"' template!"; + alert(s); + return s; +}; + + // The following functions are dispatchers for team methods that // are called from the UI using a team-name rather than implicit // context. diff --git a/src/mkws-team.js b/src/mkws-team.js index 8f4235e..2bac42e 100644 --- a/src/mkws-team.js +++ b/src/mkws-team.js @@ -36,6 +36,7 @@ function team($, teamName) { // Accessor methods for individual widgets: readers that.name = function() { return m_teamName; }; that.submitted = function() { return m_submitted; }; + that.sortOrder = function() { return m_sortOrder; }; that.perpage = function() { return m_perpage; }; that.totalRecordCount = function() { return m_totalRecordCount; }; that.currentPage = function() { return m_currentPage; }; @@ -313,13 +314,6 @@ function team($, teamName) { if (blanket) blanket.css('display', 'block'); if (motd) motd.css('display', 'none'); break; - case 'none': - alert("mkws.switchView(" + m_teamName + ", 'none') shouldn't happen"); - if (targets) targets.css('display', 'none'); - if (results) results.css('display', 'none'); - if (blanket) blanket.css('display', 'none'); - if (motd) motd.css('display', 'none'); - break; default: alert("Unknown view '" + view + "'"); } @@ -347,193 +341,6 @@ function team($, teamName) { }; - /* - * All the HTML stuff to render the search forms and - * result pages. - */ - function mkwsHtmlAll() { - mkwsSetLang(); - if (m_config.show_lang) - mkwsHtmlLang(); - - log("HTML records"); - // If the team has a .mkwsResults, populate it in the usual - // way. If not, assume that it's a smarter application that - // defines its own subcomponents, some or all of the - // following: - // .mkwsTermlists - // .mkwsRanking - // .mkwsPager - // .mkwsNavi - // .mkwsRecords - findnode(".mkwsResults").html('\ -\ - \ - \ - \ - \ - \ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
'); - - var acc = []; - var facets = m_config.facets; - acc.push('
' + M('Termlists') + '
'); - for (var i = 0; i < facets.length; i++) { - acc.push('
'); - acc.push('
'); - } - findnode(".mkwsTermlists").html(acc.join('')); - - var ranking_data = '
'; - if (m_config.show_sort) { - ranking_data += M('Sort by') + ' ' + mkwsHtmlSort() + ' '; - } - if (m_config.show_perpage) { - ranking_data += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.'; - } - ranking_data += '
'; - findnode(".mkwsRanking").html(ranking_data); - - // on first page, hide the termlist - $(document).ready(function() { - var t = widgetNode("Termlists"); - if (t) t.hide(); - }); - var container = findnode(".mkwsMOTDContainer"); - if (container.length) { - // Move the MOTD from the provided element down into the container - findnode(".mkwsMOTD").appendTo(container); - } - } - - - function mkwsSetLang() { - var lang = mkws.getParameterByName("lang") || m_config.lang; - if (!lang || !mkws.locale_lang[lang]) { - m_config.lang = "" - } else { - m_config.lang = lang; - } - - log("Locale language: " + (m_config.lang ? m_config.lang : "none")); - return m_config.lang; - } - - // set or re-set "lang" URL parameter - function lang_url(lang) { - var query = location.search; - // no query parameters? done - if (!query) { - return "?lang=" + lang; - } - - // parameter does not exists - if (!query.match(/[\?&]lang=/)) { - return query + "&lang=" + lang; - } - - // replace existing parameter - query = query.replace(/\?lang=([^&#;]*)/, "?lang=" + lang); - query = query.replace(/\&lang=([^&#;]*)/, "&lang=" + lang); - - return query; - } - - // dynamic URL or static page? /path/foo?query=test - /* create locale language menu */ - function mkwsHtmlLang() { - var lang_default = "en"; - var lang = m_config.lang || lang_default; - var list = []; - - /* display a list of configured languages, or all */ - var lang_options = m_config.lang_options || []; - var toBeIncluded = {}; - for (var i = 0; i < lang_options.length; i++) { - toBeIncluded[lang_options[i]] = true; - } - - for (var k in mkws.locale_lang) { - if (toBeIncluded[k] || lang_options.length == 0) - list.push(k); - } - - // add english link - if (lang_options.length == 0 || toBeIncluded[lang_default]) - list.push(lang_default); - - log("Language menu for: " + list.join(", ")); - - /* the HTML part */ - var data = ""; - for(var i = 0; i < list.length; i++) { - var l = list[i]; - - if (data) - data += ' | '; - - if (lang == l) { - data += ' ' + l + ' '; - } else { - data += ' ' + l + ' ' - } - } - - findnode(".mkwsLang").html(data); - } - - - function mkwsHtmlSort() { - log("HTML sort, m_sortOrder = '" + m_sortOrder + "'"); - var sort_html = ''; - - return sort_html; - } - - - function mkwsHtmlPerpage() { - log("HTML perpage, m_perpage = " + m_perpage); - var perpage_html = ''; - - return perpage_html; - } - - // Translation function. At present, this is properly a // global-level function (hence the assignment to mkws.M) but we // want to make it per-team so different teams can operate in @@ -607,7 +414,7 @@ function team($, teamName) { source = m_tempateText[name]; } if (!source) { - source = defaultTemplate(name); + source = mkws.defaultTemplate(name); } template = Handlebars.compile(source); @@ -620,94 +427,6 @@ function team($, teamName) { that.loadTemplate = loadTemplate; - 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}}\ -'; - } else if (name === "Image") { - return '\ - \ - {{#first md-thumburl}}\ - {{../md-title}}\ - {{/first}}\ -
\ -
\ -'; - } - - var s = "There is no default '" + name +"' template!"; - alert(s); - return s; - } - that.addWidget = function(w) { if (!m_widgets[w.type]) { m_widgets[w.type] = w; @@ -731,7 +450,15 @@ function team($, teamName) { return m_widgets[type]; } - mkwsHtmlAll() + + var lang = mkws.getParameterByName("lang") || m_config.lang; + if (!lang || !mkws.locale_lang[lang]) { + m_config.lang = "" + } else { + m_config.lang = lang; + } + + log("Locale language: " + (m_config.lang ? m_config.lang : "none")); return that; }; diff --git a/src/mkws-widget-termlists.js b/src/mkws-widget-termlists.js index e29ede0..33d12b9 100644 --- a/src/mkws-widget-termlists.js +++ b/src/mkws-widget-termlists.js @@ -1,13 +1,23 @@ mkws.registerWidgetType('Termlists', function() { var that = this; - var facets = that.config.facets; + // Initially hide the termlists; display when we get results + $(document).ready(function() { + $(that.node).hide(); + }); this.team.queue("termlists").subscribe(function(data) { - // display if we first got results $(that.node).show(); }); - widget.autosearch(that); + var acc = []; + var facets = this.config.facets; + acc.push('
' + mkws.M('Termlists') + '
'); + for (var i = 0; i < facets.length; i++) { + acc.push('
', '
'); + } + $(this.node).html(acc.join('')); + + widget.autosearch(this); }); diff --git a/src/mkws-widgets.js b/src/mkws-widgets.js index 90f1794..d5ec237 100644 --- a/src/mkws-widgets.js +++ b/src/mkws-widgets.js @@ -371,3 +371,163 @@ mkws.registerWidgetType('SearchForm', function() { }); +mkws.registerWidgetType('Results', function() { + var tname = this.team.name(); + + $(this.node).html('\ +\ + \ + \ + \ + \ + \ + \ + \ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
'); +}); + + +mkws.registerWidgetType('Ranking', function() { + var tname = this.team.name(); + var that = this; + var M = mkws.M; + + var s = '
'; + if (this.config.show_sort) { + s += M('Sort by') + ' ' + mkwsHtmlSort() + ' '; + } + if (this.config.show_perpage) { + s += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.'; + } + s += '
'; + + $(this.node).html(s); + + + function mkwsHtmlSort() { + var order = that.team.sortOrder(); + + that.log("HTML sort, sortOrder = '" + order + "'"); + var sort_html = ''; + + return sort_html; + } + + function mkwsHtmlPerpage() { + var perpage = that.team.perpage(); + + that.log("HTML perpage, perpage = " + perpage); + var perpage_html = ''; + + return perpage_html; + } +}); + + +mkws.registerWidgetType('Lang', function() { + // dynamic URL or static page? /path/foo?query=test + /* create locale language menu */ + if (!this.config.show_lang) return; + + var lang_default = "en"; + var lang = this.config.lang || lang_default; + var list = []; + + /* display a list of configured languages, or all */ + var lang_options = this.config.lang_options || []; + var toBeIncluded = {}; + for (var i = 0; i < lang_options.length; i++) { + toBeIncluded[lang_options[i]] = true; + } + + for (var k in mkws.locale_lang) { + if (toBeIncluded[k] || lang_options.length == 0) + list.push(k); + } + + // add english link + if (lang_options.length == 0 || toBeIncluded[lang_default]) + list.push(lang_default); + + this.log("Language menu for: " + list.join(", ")); + + /* the HTML part */ + var data = ""; + for (var i = 0; i < list.length; i++) { + var l = list[i]; + if (data) + data += ' | '; + + if (lang == l) { + data += ' ' + l + ' '; + } else { + data += ' ' + l + ' ' + } + } + + $(this.node).html(data); + + + // set or re-set "lang" URL parameter + function lang_url(lang) { + var query = location.search; + // no query parameters? done + if (!query) { + return "?lang=" + lang; + } + + // parameter does not exist + if (!query.match(/[\?&]lang=/)) { + return query + "&lang=" + lang; + } + + // replace existing parameter + query = query.replace(/\?lang=([^&#;]*)/, "?lang=" + lang); + query = query.replace(/\&lang=([^&#;]*)/, "&lang=" + lang); + return query; + } +}); + + +mkws.registerWidgetType('MOTD', function() { + var container = this.team.widget('MOTDContainer'); + if (container) { + // Move the MOTD from the provided element down into the container + $(this.node).appendTo(container.node); + } +}); + +