Add team.widgetTypes function, returns sorted list of contained types.
[mkws-moved-to-github.git] / src / mkws-team.js
index a5a2d03..8872eb3 100644 (file)
@@ -27,7 +27,8 @@ function team($, teamName) {
     };
     var m_paz; // will be initialised below
     var m_template = {};
-    var m_config = Object.create(mkws.config);
+    var m_config = mkws.objectInheritingFrom(mkws.config);
+    var m_widgets = {}; // Maps widget-type to object
 
     that.toString = function() { return '[Team ' + teamName + ']'; };
 
@@ -48,12 +49,12 @@ function team($, teamName) {
 
 
     // The following PubSub code is modified from the jQuery manual:
-    // https://api.jquery.com/jQuery.Callbacks/
+    // http://api.jquery.com/jQuery.Callbacks/
     //
     // Use as:
     // team.queue("eventName").subscribe(function(param1, param2 ...) { ... });
     // team.queue("eventName").publish(arg1, arg2, ...);
-
+    //
     var queues = {};
     function queue(id) {
        if (!queues[id]) {
@@ -115,8 +116,9 @@ function team($, teamName) {
     }
 
     function onStat(data) {
-       log("stat");
        queue("stat").publish(data);
+       if (parseInt(data.activeclients[0], 10) === 0)
+           queue("complete").publish(parseInt(data.hits[0], 10));
     }
 
     function onTerm(data) {
@@ -239,6 +241,7 @@ function team($, teamName) {
 
 
     that.reShow = function() {
+       resetPage();
        m_paz.show(0, m_perpage, m_sortOrder);
     };
 
@@ -602,7 +605,12 @@ function team($, teamName) {
        teamName = teamName || m_teamName;
 
        selector = $.map(selector.split(','), function(s, i) {
-           return s + '.mkwsTeam_' + teamName;
+           if (teamName === 'AUTO') {
+               return (s + '.mkwsTeam_' + teamName + ',' +
+                       s + ':not([class^="mkwsTeam"],[class*=" mkwsTeam"])');
+           } else {
+               return s + '.mkwsTeam_' + teamName;
+           }
        }).join(',');
 
        var node = $(selector);
@@ -734,6 +742,28 @@ function team($, teamName) {
        return s;
     }
 
+    that.addWidget = function(w) {
+        if (!m_widgets[w.type]) {
+            m_widgets[w.type] = widget;
+            log("Registered '" + w.type + "' widget in team '" + m_teamName + "'");
+        } else if (typeof(m_widgets[w.type]) !== 'number') {
+            m_widgets[w.type] = 2;
+            log("Registered duplicate '" + w.type + "' widget in team '" + m_teamName + "'");
+        } else {
+            m_widgets[w.type] += 1;
+            log("Registered '" + w.type + "' widget #" + m_widgets[w.type] + "' in team '" + m_teamName + "'");
+        }
+    }
+
+    that.widgetTypes = function() {
+        var keys = [];
+        for (var k in m_widgets) keys.push(k);
+        return keys.sort();
+    }
+
+    that.widget = function(type) {
+        return m_widgets[type];
+    }
 
     mkwsHtmlAll()