Move defaultMkwsConfig out of auto-executer.
[mkws-moved-to-github.git] / src / mkws-team.js
index 61f677d..100ce3e 100644 (file)
@@ -28,16 +28,17 @@ function team($, teamName) {
     var m_paz; // will be initialised below
     var m_template = {};
 
+    that.toString = function() { return '[Team ' + teamName + ']'; };
 
     // Accessor methods for individual widgets: readers
-    that.name = function() { return m_teamName; }
-    that.submitted = function() { return m_submitted; }
-    that.perpage = function() { return m_perpage; }
-    that.totalRecordCount = function() { return m_totalRecordCount; }
-    that.currentPage = function() { return m_currentPage; }
-    that.currentRecordId = function() { return m_currentRecordId; }
-    that.currentRecordData = function() { return m_currentRecordData; }
-    that.filters = function() { return m_filters; }
+    that.name = function() { return m_teamName; };
+    that.submitted = function() { return m_submitted; };
+    that.perpage = function() { return m_perpage; };
+    that.totalRecordCount = function() { return m_totalRecordCount; };
+    that.currentPage = function() { return m_currentPage; };
+    that.currentRecordId = function() { return m_currentRecordId; };
+    that.currentRecordData = function() { return m_currentRecordData; };
+    that.filters = function() { return m_filters; };
 
     // Accessor methods for individual widgets: writers
     that.set_sortOrder = function(val) { m_sortOrder = val };
@@ -76,34 +77,28 @@ function team($, teamName) {
                    });
 
 
-    //
     // pz2.js event handlers:
-    //
     function onInit() {
        log("init");
        m_paz.stat();
        m_paz.bytarget();
     }
 
-
     function onBytarget(data) {
        log("target");
        queue("targets").publish(data);
     }
 
-
     function onStat(data) {
        log("stat");
        queue("stat").publish(data);
     }
 
-
     function onTerm(data) {
        log("term");
        queue("termlists").publish(data);
     }
 
-
     function onShow(data, teamName) {
        log("show");
        m_totalRecordCount = data.merged;
@@ -111,14 +106,12 @@ function team($, teamName) {
        queue("records").publish(data);
     }
 
-
     function onRecord(data, args, teamName) {
        log("record");
        // FIXME: record is async!!
        clearTimeout(m_paz.recordTimer);
-       // ##### restrict to current team
-       var detRecordDiv = document.getElementById(recordDetailsId(data.recid[0]));
-       if (detRecordDiv) {
+       var detRecordDiv = findnode(recordDetailsId(data.recid[0]));
+       if (detRecordDiv.length) {
            // in case on_show was faster to redraw element
            return;
        }
@@ -129,7 +122,7 @@ function team($, teamName) {
     }
 
 
-    // Used by promoteRecords() and onRecord()
+    // Used by the Records widget and onRecord()
     function recordElementId(s) {
        return 'mkwsRec_' + s.replace(/[^a-z0-9]/ig, '_');
     }
@@ -139,7 +132,6 @@ function team($, teamName) {
     function recordDetailsId(s) {
        return 'mkwsDet_' + s.replace(/[^a-z0-9]/ig, '_');
     }
-    that.recordElementId = recordElementId;
 
 
     that.targetFiltered = function(id) {
@@ -150,28 +142,28 @@ function team($, teamName) {
            }
        }
        return false;
-    }
+    };
 
 
-    that.limitTarget  = function (id, name)
+    that.limitTarget = function(id, name)
     {
        log("limitTarget(id=" + id + ", name=" + name + ")");
        m_filters.push({ id: id, name: name });
        triggerSearch();
        return false;
-    }
+    };
 
 
-    that.limitQuery = function (field, value)
+    that.limitQuery = function(field, value)
     {
        log("limitQuery(field=" + field + ", value=" + value + ")");
        m_filters.push({ field: field, value: value });
        triggerSearch();
        return false;
-    }
+    };
 
 
-    that.delimitTarget = function (id)
+    that.delimitTarget = function(id)
     {
        log("delimitTarget(id=" + id + ")");
        var newFilters = [];
@@ -188,10 +180,10 @@ function team($, teamName) {
 
        triggerSearch();
        return false;
-    }
+    };
 
 
-    that.delimitQuery = function (field, value)
+    that.delimitQuery = function(field, value)
     {
        log("delimitQuery(field=" + field + ", value=" + value + ")");
        var newFilters = [];
@@ -210,33 +202,33 @@ function team($, teamName) {
 
        triggerSearch();
        return false;
-    }
+    };
 
 
-    that.showPage = function (pageNum)
+    that.showPage = function(pageNum)
     {
        m_currentPage = pageNum;
        m_paz.showPage(m_currentPage - 1);
-    }
+    };
 
 
-    that.pagerNext = function () {
+    that.pagerNext = function() {
        if (m_totalRecordCount - m_perpage*m_currentPage > 0) {
             m_paz.showNext();
             m_currentPage++;
        }
-    }
+    };
 
 
-    that.pagerPrev = function () {
+    that.pagerPrev = function() {
        if (m_paz.showPrev() != false)
             m_currentPage--;
-    }
+    };
 
 
     that.reShow = function() {
        m_paz.show(0, m_perpage, m_sortOrder);
-    }
+    };
 
 
     function resetPage()
@@ -263,7 +255,7 @@ function team($, teamName) {
     }
 
 
-    function triggerSearch (query, sortOrder, targets)
+    function triggerSearch(query, sortOrder, targets)
     {
        resetPage();
        queue("navi").publish();
@@ -348,7 +340,7 @@ function team($, teamName) {
 
 
     // detailed record drawing
-    that.showDetails = function (recId) {
+    that.showDetails = function(recId) {
        var oldRecordId = m_currentRecordId;
        m_currentRecordId = recId;
 
@@ -368,7 +360,7 @@ function team($, teamName) {
        // request the record
        log("showDetails() requesting record '" + recId + "'");
        m_paz.record(recId);
-    }
+    };
 
 
     /*
@@ -592,7 +584,7 @@ function team($, teamName) {
        log(s);
 
        newSearch(query, sortOrder, targets);
-    }
+    };
 
 
     // This function is taken from a StackOverflow answer
@@ -632,7 +624,9 @@ function team($, teamName) {
            return s + '.mkwsTeam_' + teamName;
        }).join(',');
 
-       return $(selector);
+       var node = $(selector);
+       //log('findnode(' + selector + ') found ' + node.length + ' nodes');
+       return node;
     }
 
 
@@ -770,21 +764,10 @@ function team($, teamName) {
            };
        }
        return queues[id];
-    }
+    };
     that.queue = queue;
 
-
-    // main
-    (function() {
-       try {
-           mkwsHtmlAll()
-       }
-
-       catch (e) {
-           mkws_config.error = e.message;
-           // alert(e.message);
-       }
-    })();
+    mkwsHtmlAll()
 
     return that;
 };