Eliminate function onFormSubmitEventHandler, use closure instead.
[mkws-moved-to-github.git] / src / mkws-team.js
index 41c3c44..bbb59a9 100644 (file)
@@ -1,10 +1,12 @@
 // Factory function for team objects. As much as possible, this uses
 // only member variables (prefixed "m_") and inner functions with
-// private scope. Some functions are visibl as member-functions to be
-// called from outside code -- specifically, from generated
-// HTML. These functions are that.switchView(), showDetails(),
-// limitTarget(), limitQuery(), delimitTarget(), delimitQuery(),
-// pagerPrev(), pagerNext(), showPage().
+// private scope.
+//
+// Some functions are visible as member-functions to be called from
+// outside code -- specifically, from generated HTML. These functions
+// are that.switchView(), showDetails(), limitTarget(), limitQuery(),
+// delimitTarget(), delimitQuery(), showPage(), pagerPrev(),
+// pagerNext().
 //
 function team($, teamName) {
     var that = {};
@@ -26,6 +28,8 @@ function team($, teamName) {
     var m_paz; // will be initialised below
     var m_template = {};
 
+
+    // Accessor methods for individual widgets: readers
     that.name = function() { return m_teamName; }
     that.submitted = function() { return m_submitted; }
     that.perpage = function() { return m_perpage; }
@@ -35,11 +39,12 @@ function team($, teamName) {
     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 };
     that.set_perpage = function(val) { m_perpage = val };
 
 
-    var log = function (s) {
+    function log(s) {
        var now = $.now();
        var timestamp = ((now - m_logTime.start)/1000).toFixed(3) + " (+" + ((now - m_logTime.last)/1000).toFixed(3) + ") "
        m_logTime.last = now;
@@ -152,31 +157,6 @@ function team($, teamName) {
     ////////////////////////////////////////////////////////////////////////////////
 
 
-    // when search button pressed
-    function onFormSubmitEventHandler()
-    {
-       var val = findnode('.mkwsQuery').val();
-       newSearch(val);
-       return false;
-    }
-
-
-    function newSearch(query, sortOrder, targets)
-    {
-       log("newSearch: " + query);
-
-       if (mkws_config.use_service_proxy && !mkws.authenticated) {
-           alert("searching before authentication");
-           return;
-       }
-
-       m_filters = []
-       triggerSearch(query, sortOrder, targets);
-       switchView('records'); // In case it's configured to start off as hidden
-       m_submitted = true;
-    }
-
-
     // limit by target functions
     that.limitTarget  = function (id, name)
     {
@@ -239,6 +219,32 @@ function team($, teamName) {
     }
 
 
+    that.showPage = function (pageNum)
+    {
+       m_currentPage = pageNum;
+       m_paz.showPage(m_currentPage - 1);
+    }
+
+
+    that.pagerNext = function () {
+       if (m_totalRecordCount - m_perpage*m_currentPage > 0) {
+            m_paz.showNext();
+            m_currentPage++;
+       }
+    }
+
+
+    that.pagerPrev = function () {
+       if (m_paz.showPrev() != false)
+            m_currentPage--;
+    }
+
+
+    that.reShow = function() {
+       m_paz.show(0, m_perpage, m_sortOrder);
+    }
+
+
     function resetPage()
     {
        m_currentPage = 1;
@@ -247,6 +253,22 @@ function team($, teamName) {
     that.resetPage = resetPage;
 
 
+    function newSearch(query, sortOrder, targets)
+    {
+       log("newSearch: " + query);
+
+       if (mkws_config.use_service_proxy && !mkws.authenticated) {
+           alert("searching before authentication");
+           return;
+       }
+
+       m_filters = []
+       triggerSearch(query, sortOrder, targets);
+       switchView('records'); // In case it's configured to start off as hidden
+       m_submitted = true;
+    }
+
+
     function triggerSearch (query, sortOrder, targets)
     {
        resetPage();
@@ -297,34 +319,6 @@ function team($, teamName) {
     }
 
 
-    that.reShow = function() {
-       m_paz.show(0, m_perpage, m_sortOrder);
-    }
-
-
-
-    that.showPage = function (pageNum)
-    {
-       m_currentPage = pageNum;
-       m_paz.showPage(m_currentPage - 1);
-    }
-
-
-    // simple paging functions
-    that.pagerNext = function () {
-       if (m_totalRecordCount - m_perpage*m_currentPage > 0) {
-            m_paz.showNext();
-            m_currentPage++;
-       }
-    }
-
-
-    that.pagerPrev = function () {
-       if (m_paz.showPrev() != false)
-            m_currentPage--;
-    }
-
-
     // switching view between targets and records
     function switchView(view) {
        var targets = findnode('.mkwsTargets');
@@ -393,13 +387,11 @@ function team($, teamName) {
            mkwsHtmlLang();
 
        log("HTML search form");
-       mkws.handleNodeWithTeam(findnode('.mkwsSearch'), function(tname) {
-           this.html('\
-<form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + tname + '" action="" >\
-  <input class="mkwsQuery mkwsTeam_' + tname + '" type="text" size="' + mkws_config.query_width + '" />\
-  <input class="mkwsButton mkwsTeam_' + tname + '" type="submit" value="' + M('Search') + '" />\
+       findnode('.mkwsSearch').html('\
+<form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + m_teamName + '" action="" >\
+  <input class="mkwsQuery mkwsTeam_' + m_teamName + '" type="text" size="' + mkws_config.query_width + '" />\
+  <input class="mkwsButton mkwsTeam_' + m_teamName + '" type="submit" value="' + M('Search') + '" />\
 </form>');
-       });
 
        log("HTML records");
        // If the team has a .mkwsResults, populate it in the usual
@@ -443,7 +435,11 @@ function team($, teamName) {
 
        mkwsHtmlSwitch();
 
-       findnode('.mkwsSearchForm').submit(onFormSubmitEventHandler);
+       findnode('.mkwsSearchForm').submit(function() {
+           var val = findnode('.mkwsQuery').val();
+           newSearch(val);
+           return false;
+       });
 
        // on first page, hide the termlist
        $(document).ready(function() { findnode(".mkwsTermlists").hide(); });