X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widgets.js;h=d5ec237905cde966bd3e5db7ca7d62e72882495b;hb=8d9cf5ca5921f2150742c41d1cbfbd4144ed4379;hp=2ec8fb54974cf0d97b6a7fdd2ea5d14d3082c0a8;hpb=1ed229b6def126d602b8c56e348e4f8d0832fdb0;p=mkws-moved-to-github.git diff --git a/src/mkws-widgets.js b/src/mkws-widgets.js index 2ec8fb5..d5ec237 100644 --- a/src/mkws-widgets.js +++ b/src/mkws-widgets.js @@ -83,6 +83,13 @@ widget.autosearch = function(widget) { if (!query) { alert("This page has a MasterKey widget that needs a query specified by the path-component " + index); } + } else if (query.match(/^!var!/)) { + var name = query.replace(/^!var!/, ''); + query = window[name]; // It's ridiculous that this works + widget.log("obtained query '" + query + "' from variable '" + name + "'"); + if (!query) { + alert("This page has a MasterKey widget that needs a query specified by the '" + name + "' variable"); + } } var sortOrder = widget.config.sort; @@ -118,6 +125,12 @@ mkws.registerWidgetType('Targets', function() { var that = this; var M = mkws.M; + $(this.node).html('\ +
\ +No information available yet.\ +
'); + $(this.node).css("display", "none"); + this.team.queue("targets").subscribe(function(data) { var table ='' + '' + @@ -237,6 +250,7 @@ mkws.registerWidgetType('Records', function() { var html = []; for (var i = 0; i < data.hits.length; i++) { var hit = data.hits[i]; + that.team.queue("record").publish(hit); var divId = team.recordElementId(hit.recid[0]); html.push('
', renderSummary(hit), '
'); // ### At some point, we may be able to move the @@ -267,28 +281,21 @@ mkws.registerWidgetType('Navi', function() { var M = mkws.M; this.team.queue("navi").subscribe(function() { - // This is very low-level poking around inside the filter structure - var filters = that.team.filters().list(); + var filters = that.team.filters(); var text = ""; - for (var i in filters) { - var filter = filters[i]; - if (filter.id) { - if (text) text += " | "; - text += M('source') + ': ' + filter.name + ''; - } - } + filters.visitTargets(function(id, name) { + if (text) text += " | "; + text += M('source') + ': ' + name + ''; + }); - for (var i in filters) { - var filter = filters[i]; - if (!filter.id) { - if (text) text += " | "; - text += M(filter.field) + ': ' + filter.value + ''; - } - } + filters.visitFields(function(field, value) { + if (text) text += " | "; + text += M(field) + ': ' + value + ''; + }); $(that.node).html(text); }); @@ -331,3 +338,196 @@ mkws.registerWidgetType('Done', function() { $(that.node).html("Search complete: found " + n + " records"); }); }); + + +mkws.registerWidgetType('Switch', function() { + var tname = this.team.name(); + $(this.node).html('\ +Records \ +| \ +Targets'); +}); + + +mkws.registerWidgetType('Search', function() { + var tname = this.team.name(); + var M = mkws.M; + + $(this.node).html('\ +\ + \ + \ +'); +}); + + +mkws.registerWidgetType('SearchForm', function() { + var team = this.team; + $(this.node).submit(function() { + var val = team.widget('Query').value(); + team.newSearch(val); + return false; + }); +}); + + +mkws.registerWidgetType('Results', function() { + var tname = this.team.name(); + + $(this.node).html('\ +
' + M('Target ID') + '
\ + \ + \ + \ + \ + \ + \ + \ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
'); +}); + + +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); + } +}); + +