X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;ds=inline;f=tools%2Fhtdocs%2Fmkws.js;h=78f1e46f5f468597c99a079bc7d4c1a666c4f308;hb=c81643e172cc00b4fb697a4c5209a62687e98cf0;hp=796fd2c2504c9a21ab0b0c448805d6b5a1a82279;hpb=a4549c27facf4260bf93d71ef26d7a755063d13b;p=mkws-moved-to-github.git
diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js
index 796fd2c..78f1e46 100644
--- a/tools/htdocs/mkws.js
+++ b/tools/htdocs/mkws.js
@@ -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 = {};
@@ -186,15 +163,19 @@ function widget($, team, type, node) {
} else if (type === 'Stat') {
promoteStat();
} else {
- // Unsupported widget type: call an extension?
+ // ### Handle other types here
}
- // ### More to do here, surely: e.g. wiring into the team
mkws.debug("made widget(team=" + team + ", 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() {
- mkws.queue("targets").subscribe(function(data) {
+ team.queue("targets").subscribe(function(data) {
if (node.length === 0) alert("huh?!");
var table ='
' +
@@ -221,7 +202,7 @@ function widget($, team, type, node) {
function promoteStat() {
- mkws.queue("stat").subscribe(function(data) {
+ team.queue("stat").subscribe(function(data) {
if (node.length === 0) alert("huh?!");
$(node).html('' + M('Status info') + '' +
@@ -231,9 +212,6 @@ function widget($, team, type, node) {
'' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '');
});
}
-
-
- return that;
}
@@ -248,6 +226,7 @@ function widget($, team, type, node) {
function team($, teamName) {
var that = {};
var m_teamName = teamName;
+ that.name = function() { return m_teamName; }
var m_submitted = false;
var m_query; // initially undefined
var m_sort; // will be set below
@@ -309,13 +288,13 @@ function team($, teamName) {
function onBytarget(data) {
debug("target");
- mkws.queue("targets").publish(data);
+ queue("targets").publish(data);
}
function onStat(data) {
debug("stat");
- mkws.queue("stat").publish(data);
+ queue("stat").publish(data);
}
@@ -390,9 +369,10 @@ function team($, teamName) {
var detRecordDiv = document.getElementById('mkwsDet_' + teamName + '_' + data.recid);
if (detRecordDiv) return;
m_curDetRecData = data;
+ // Can't use jQuery's $('#x') syntax to find this ID, because it contains spaces.
var recordDiv = document.getElementById('mkwsRecdiv_' + teamName + '_' + m_curDetRecData.recid);
var html = renderDetails(m_curDetRecData);
- recordDiv.innerHTML += html;
+ $(recordDiv).append(html);
}
@@ -1098,7 +1078,7 @@ function team($, teamName) {
var source = node.html();
if (!source) {
- source = defaultTemplate(name);
+ source = mkws.defaultTemplate(name);
}
template = Handlebars.compile(source);
@@ -1110,86 +1090,28 @@ function team($, teamName) {
}
- function defaultTemplate(name)
- {
- if (name === 'Record') {
- return '\
-\
- \
- {{translate "Title"}} | \
- \
- {{md-title}}\
- {{#if md-title-remainder}}\
- ({{md-title-remainder}})\
- {{/if}}\
- {{#if md-title-responsibility}}\
- {{md-title-responsibility}}\
- {{/if}}\
- | \
-
\
- {{#if md-date}}\
- \
- {{translate "Date"}} | \
- {{md-date}} | \
-
\
- {{/if}}\
- {{#if md-author}}\
- \
- {{translate "Author"}} | \
- {{md-author}} | \
-
\
- {{/if}}\
- {{#if md-electronic-url}}\
- \
- {{translate "Links"}} | \
- \
- {{#each md-electronic-url}}\
- Link{{index1}}\
- {{/each}}\
- | \
-
\
- {{/if}}\
- {{#if-any location having="md-subject"}}\
- \
- {{translate "Subject"}} | \
- \
- {{#first location having="md-subject"}}\
- {{#if md-subject}}\
- {{#commaList md-subject}}\
- {{this}}{{/commaList}}\
- {{/if}}\
- {{/first}}\
- | \
-
\
- {{/if-any}}\
- \
- {{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}}\
-';
+ // The following PubSub code is modified from the jQuery manual:
+ // https://api.jquery.com/jQuery.Callbacks/
+ //
+ // Use as:
+ // team.queue("eventName").subscribe(function(param1, param2 ...) { ... });
+ // team.queue("eventName").publish(arg1, arg2, ...);
+
+ var queues = {};
+ var queue = function(id) {
+ if (!queues[id]) {
+ var callbacks = $.Callbacks();
+ queues[id] = {
+ publish: callbacks.fire,
+ subscribe: callbacks.add,
+ unsubscribe: callbacks.remove
+ };
}
-
- var s = "There is no default '" + name +"' template!";
- alert(s);
- return s;
+ return queues[id];
}
+ that.queue = queue;
+
// main
(function() {
@@ -1325,6 +1247,87 @@ function team($, teamName) {
}
+ mkws.defaultTemplate = function(name)
+ {
+ if (name === 'Record') {
+ return '\
+\
+ \
+ {{translate "Title"}} | \
+ \
+ {{md-title}}\
+ {{#if md-title-remainder}}\
+ ({{md-title-remainder}})\
+ {{/if}}\
+ {{#if md-title-responsibility}}\
+ {{md-title-responsibility}}\
+ {{/if}}\
+ | \
+
\
+ {{#if md-date}}\
+ \
+ {{translate "Date"}} | \
+ {{md-date}} | \
+
\
+ {{/if}}\
+ {{#if md-author}}\
+ \
+ {{translate "Author"}} | \
+ {{md-author}} | \
+
\
+ {{/if}}\
+ {{#if md-electronic-url}}\
+ \
+ {{translate "Links"}} | \
+ \
+ {{#each md-electronic-url}}\
+ Link{{index1}}\
+ {{/each}}\
+ | \
+
\
+ {{/if}}\
+ {{#if-any location having="md-subject"}}\
+ \
+ {{translate "Subject"}} | \
+ \
+ {{#first location having="md-subject"}}\
+ {{#if md-subject}}\
+ {{#commaList md-subject}}\
+ {{this}}{{/commaList}}\
+ {{/if}}\
+ {{/first}}\
+ | \
+
\
+ {{/if-any}}\
+ \
+ {{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;
+ }
+
+
function defaultMkwsConfig() {
/* default mkws config */
var config_default = {