X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=53d07fed9c708b99e1a7c837aae6c73368dd4dd8;hb=eef5cd690b9dcb379c4dad874ddff8afea6ac67c;hp=aeb0d129f8dca8717da6753b54f8a7b4896c45a4;hpb=3ef390ce1f70178ffc78957ccb74216ce169fd59;p=mkws-moved-to-github.git
diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js
index aeb0d12..53d07fe 100644
--- a/tools/htdocs/mkws.js
+++ b/tools/htdocs/mkws.js
@@ -72,7 +72,7 @@ Handlebars.registerHelper('index1', function(obj) {
// Set up global mkws object. Contains truly global state such as SP
-// authentication, and a hash of team objects, indexed by windowid.
+// authentication, and a hash of team objects, indexed by team-name.
//
var mkws = {
authenticated: false,
@@ -142,29 +142,6 @@ var mkws = {
};
-// The following PubSub code is modified from the jQuery manual:
-// https://api.jquery.com/jQuery.Callbacks/
-//
-// Use as:
-// mkws.queue("eventName").subscribe(function(param1, param2 ...) { ... });
-// mkws.queue("eventName").publish(arg1, arg2, ...);
-
-(function() {
- var queues = {};
- mkws.queue = function(id) {
- if (!queues[id]) {
- var callbacks = $.Callbacks();
- queues[id] = {
- publish: callbacks.fire,
- subscribe: callbacks.add,
- unsubscribe: callbacks.remove
- };
- }
- return queues[id];
- }
-}());
-
-
// Define empty mkws_config for simple applications that don't define it.
if (mkws_config == null || typeof mkws_config != 'object') {
var mkws_config = {};
@@ -179,10 +156,244 @@ function widget($, team, type, node) {
node: node
};
- // ### More to do here, surely: e.g. wiring into the team
- mkws.debug("made widget(team=" + team + ", type=" + type + ", node=" + node);
+ var M = mkws.M;
+
+ var type2fn = {
+ Targets: promoteTargets,
+ Stat: promoteStat,
+ Termlists: promoteTermlists,
+ Pager: promotePager,
+ Records: promoteRecords,
+ Navi: promoteNavi
+ };
+
+ var promote = type2fn[type];
+ if (promote) {
+ promote();
+ team.debug("made " + type + " widget(node=" + node + ")");
+ } else {
+ team.debug("made UNENCAPSULATED widget(type=" + type + ", node=" + node + ")");
+ }
return that;
+
+
+ // Functions follow for promoting the regular widget object into
+ // widgets of specific types. These could be moved outside of the
+ // widget object, or even into their own source files.
+
+ function promoteTargets() {
+ team.queue("targets").subscribe(function(data) {
+ var table ='
' +
+ '
' + M('Target ID') + '
' +
+ '
' + M('Hits') + '
' +
+ '
' + M('Diags') + '
' +
+ '
' + M('Records') + '
' +
+ '
' + M('State') + '
' +
+ '
';
+
+ for (var i = 0; i < data.length; i++) {
+ table += "
" + data[i].id +
+ "
" + data[i].hits +
+ "
" + data[i].diagnostic +
+ "
" + data[i].records +
+ "
" + data[i].state + "
";
+ }
+
+ table += '
';
+ var subnode = $(node).children('.mkwsBytarget');
+ subnode.html(table);
+ });
+ }
+
+
+ function promoteStat() {
+ team.queue("stat").subscribe(function(data) {
+ if (node.length === 0) alert("huh?!");
+
+ $(node).html('' + M('Status info') + '' +
+ ' -- ' +
+ '' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '' +
+ ' -- ' +
+ '' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '');
+ });
+ }
+
+
+ function promoteTermlists() {
+ team.queue("termlists").subscribe(function(data) {
+ mkws.debug("in termlist consumer");
+ if (!node) {
+ alert("termlists event when there are no termlists");
+ return;
+ }
+
+ // no facets: this should never happen
+ if (!mkws_config.facets || mkws_config.facets.length == 0) {
+ alert("onTerm called even though we have no facets: " + $.toJSON(data));
+ $(node).hide();
+ return;
+ }
+
+ // display if we first got results
+ $(node).show();
+
+ var acc = [];
+ acc.push('
\
-';
- } 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.
*/
- // ### This and other multi-word identifiers should be camelCase
- function mkws_html_all() {
- mkws_set_lang();
+ function mkwsHtmlAll() {
+ mkwsSetLang();
if (mkws_config.show_lang)
- mkws_html_lang();
+ mkwsHtmlLang();
debug("HTML search form");
- mkws.handle_node_with_team(findnode('.mkwsSearch'), function(tname) {
+ mkws.handleNodeWithTeam(findnode('.mkwsSearch'), function(tname) {
this.html('\