reservations add/delete use ajax, no need to wait for the page to reload
[plewww.git] / plekit / table / table.js
index 8656af9..31ab09c 100644 (file)
@@ -1,4 +1,14 @@
-/* $Id$ */
+var debug=false;
+
+/* for debugging purposes */
+function plc_timestamp () {
+  var now = new Date();
+  return now.getMinutes() + ':' + now.getSeconds() + '.' + now.getMilliseconds() ; 
+}
+
+function plc_message (message) {
+  console.log ( plc_timestamp() + ' : ' + message);
+}
 
 /* when a table gets paginated, displays context info */
 function plekit_table_paginator (opts,table_id) {
@@ -67,7 +77,8 @@ function plekit_pagesize_reset(table_id, size_id, size) {
 function plekit_table_row_visible (row,visible) {
   var cn=row.className;
   /* clear */
-  cn=cn.replace(" invisibleRow","");
+  cn=cn.replace("invisibleRow","");
+  cn.strip();
   if (! visible) cn += " invisibleRow";
   row.className=cn;
 }
@@ -102,9 +113,21 @@ function plekit_tr_text (tr) {
   return text;
 }
 
+var plekit_table_filter_timeout = null;
 /* scan the table, and mark as visible 
    the rows that match (either AND or OR the patterns) */
-function plekit_table_filter (table_id,pattern_id,and_id) {
+function plekit_table_filter(table_id,pattern_id,and_id) {
+  clearTimeout(plekit_table_filter_timeout);
+  plekit_table_filter_timeout = setTimeout(function() {
+                                             plekit_lazy_table_filter(table_id,pattern_id,and_id)
+                                           },
+                                           200);
+}
+
+function plekit_lazy_table_filter (table_id,pattern_id,and_id) {
+
+  if (debug) plc_message ('entering plekit_lazy_table_filter');
+
   var table=$(table_id);
   var css='#'+table_id+'>tbody';
   var rows = $$(css)[0].rows;
@@ -139,14 +162,18 @@ function plekit_table_filter (table_id,pattern_id,and_id) {
     return;
   }
 
-  // re compile all patterns 
-  var pattern_texts = pattern_text.strip().split(" ");
+  if (debug) plc_message ('inside plekit_lazy_table_filter');
+
   var searches=new Array();
   var patterns=new Array();
-  for (var i=0; i < pattern_texts.length; i++) {
-    // ignore case
-    searches[i]=pattern_texts[i].toLowerCase();
-    patterns[i]=new RegExp(pattern_texts[i],"i");
+  if (pattern_text.length > 0) {
+      // re compile all patterns 
+      var pattern_texts = pattern_text.strip().split(" ");
+      for (var i=0; i < pattern_texts.length; i++) {
+          // ignore case
+          searches[i]=pattern_texts[i].toLowerCase();
+          patterns[i]=new RegExp(pattern_texts[i],"i");
+      }
   }
 
   // scan rows, elaborate 'visible'
@@ -193,6 +220,8 @@ function plekit_table_filter (table_id,pattern_id,and_id) {
   var end=(new Date).getTime();
   var match_ms=end-start;
 
+  if (debug) plc_message ('almost at end of plekit_lazy_table_filter');
+
   // optimize useless calls to init, by comparing # of matching entries
   var previous_matching=table['previous_matching'];
   if (matching_entries == previous_matching) {
@@ -204,7 +233,9 @@ function plekit_table_filter (table_id,pattern_id,and_id) {
   tablePaginater.init(table_id);
   var end2=(new Date).getTime();
   var paginate_ms=end2-end;
-  
+
+  if (debug) plc_message ('exiting plekit_lazy_table_filter with paginate_ms=' + paginate_ms);
+
 }
 
 function plekit_table_filter_reset (table_id, pattern_id,and_id) {