+ // 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 '<div class="details" id="mkwsDet_' + m_teamName + '_' + data.recid + '">' + details + '</div>';
+ }
+
+
+ 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 = mkws.defaultTemplate(name);
+ }
+
+ template = Handlebars.compile(source);
+ debug("compiled template '" + name + "'");
+ m_template[name] = template;
+ }
+
+ return template;
+ }
+
+
+ // 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
+ };
+ }
+ return queues[id];
+ }
+
+ that.queue = queue;
+
+