From 7c2e92adaca004c0c0226298f66150ad77eb2b56 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Mon, 17 Mar 2014 11:43:19 -0400
Subject: [PATCH] Added search filter for TPS UI.

The tables in TPS UI has been modified to handle search filters. When
the user presses enter in the search field, the UI will perform a search
operation using the filter specified in the field. The table will be
updated with the new results. If the filter is empty it will show all
entries.

Ticket #847
---
 base/server/share/webapps/pki/js/pki-ui.js         | 39 +++++++++++++++++-----
 .../shared/webapps/tps/ui/activities.html          |  2 +-
 .../shared/webapps/tps/ui/authenticators.html      |  2 +-
 base/tps-tomcat/shared/webapps/tps/ui/certs.html   |  2 +-
 .../shared/webapps/tps/ui/connections.html         |  2 +-
 base/tps-tomcat/shared/webapps/tps/ui/groups.html  |  2 +-
 .../tps-tomcat/shared/webapps/tps/ui/profiles.html |  2 +-
 .../shared/webapps/tps/ui/selftests.html           |  2 +-
 base/tps-tomcat/shared/webapps/tps/ui/tokens.html  |  2 +-
 base/tps-tomcat/shared/webapps/tps/ui/users.html   |  2 +-
 10 files changed, 39 insertions(+), 18 deletions(-)

diff --git a/base/server/share/webapps/pki/js/pki-ui.js b/base/server/share/webapps/pki/js/pki-ui.js
index 44e0444dad1550c27f8b249098bb1eb907e5b0aa..00c9f05c7da1453862210786233698d08cb8e484 100644
--- a/base/server/share/webapps/pki/js/pki-ui.js
+++ b/base/server/share/webapps/pki/js/pki-ui.js
@@ -46,16 +46,9 @@ var Collection = Backbone.Collection.extend({
     initialize: function(options) {
         var self = this;
 
-        // convert options into URL query
-        var query = "";
-        _(options).each(function(value, name) {
-            query = query == "" ? "?" : query + "&";
-            query = query + name + "=" + encodeURIComponent(value);
-        });
-
         self.options = options;
-        self.currentURL = self.urlRoot + query;
         self.links = {};
+        self.filter(null);
     },
     url: function() {
         return this.currentURL;
@@ -104,6 +97,22 @@ var Collection = Backbone.Collection.extend({
     go: function(name) {
         if (this.links[name] == undefined) return;
         this.currentURL = this.links[name];
+    },
+    filter: function(filter) {
+        var self = this;
+
+        var query = "";
+        _(self.options).each(function(value, name) {
+            query = query == "" ? "?" : query + "&";
+            query = query + name + "=" + encodeURIComponent(value);
+        });
+
+        if (filter) {
+            query = query == "" ? "?" : query + "&";
+            query = query + "filter=" + encodeURIComponent(filter);
+        }
+
+        self.currentURL = self.urlRoot + query;
     }
 });
 
@@ -443,6 +452,15 @@ var Table = Backbone.View.extend({
 
         self.thead = $("thead", self.$el);
 
+        // setup search field handler
+        $("input[name='search']", self.thead).keypress(function(e) {
+            if (e.which == 13) {
+                var input = $(e.target);
+                self.collection.filter(input.val());
+                self.render();
+            }
+        });
+
         // setup add button handler
         $("button[name='add']", self.thead).click(function(e) {
             var dialog = self.addDialog;
@@ -508,7 +526,7 @@ var Table = Backbone.View.extend({
         var self = this;
         self.collection.fetch({
             reset: true,
-            success: function() {
+            success: function(collection, response, options) {
                 self.tbody.empty();
 
                 // display result page
@@ -533,6 +551,9 @@ var Table = Backbone.View.extend({
                         self.tbody.append(item.$el);
                     }
                 }
+            },
+            error: function(collection, response, options) {
+                alert(response.statusText);
             }
         });
     }
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/activities.html b/base/tps-tomcat/shared/webapps/tps/ui/activities.html
index c5d363e3e1bf8fcd7bf7c6086601d09fd0721f2c..04995e5726677e0a13f935b80c8097302aae0099 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/activities.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/activities.html
@@ -21,7 +21,7 @@
 <thead>
     <tr>
          <th class="rcue-table-actions" colspan="8">
-             <span><input type="text" placeholder="Search..."></span>
+             <span><input name="search" type="text" placeholder="Search..."></span>
              <span></span>
          </th>
     </tr>
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/authenticators.html b/base/tps-tomcat/shared/webapps/tps/ui/authenticators.html
index 021b948893762c5471df8f0972fd4a5be1ff9d61..c7e0e3e967ac446a2551d349b4821d4783bac477 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/authenticators.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/authenticators.html
@@ -21,7 +21,7 @@
 <thead>
     <tr>
          <th class="rcue-table-actions" colspan="3">
-             <span><input type="text" placeholder="Search..."></span>
+             <span><input name="search" type="text" placeholder="Search..."></span>
              <span>
                  <button name="add">Add</button>
                  <button name="remove">Remove</button>
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/certs.html b/base/tps-tomcat/shared/webapps/tps/ui/certs.html
index d09af2530b35c8892a78a5e2ddeb6f5df4e2f4a5..c454170d1c20df03816620667dd3fff5af8dc14f 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/certs.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/certs.html
@@ -21,7 +21,7 @@
 <thead>
     <tr>
          <th class="rcue-table-actions" colspan="10">
-             <span><input type="text" placeholder="Search..."></span>
+             <span><input name="search" type="text" placeholder="Search..."></span>
              <span></span>
          </th>
     </tr>
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/connections.html b/base/tps-tomcat/shared/webapps/tps/ui/connections.html
index d3df0a16fe6bb6f7cb17253e5ce37cbbed485baf..0d438470323dbd70e24d2b6cb791ffdc80738be7 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/connections.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/connections.html
@@ -21,7 +21,7 @@
 <thead>
     <tr>
          <th class="rcue-table-actions" colspan="3">
-             <span><input type="text" placeholder="Search..."></span>
+             <span><input name="search" type="text" placeholder="Search..."></span>
              <span>
                  <button name="add">Add</button>
                  <button name="remove">Remove</button>
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/groups.html b/base/tps-tomcat/shared/webapps/tps/ui/groups.html
index 2bd9b5ba83e5a8dc3897b954fa51ad8bf3f60901..a835180b7f507ce1322faca4cc94ec3fe966be2f 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/groups.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/groups.html
@@ -21,7 +21,7 @@
 <thead>
     <tr>
          <th class="rcue-table-actions" colspan="3">
-             <span><input type="text" placeholder="Search..."></span>
+             <span><input name="search" type="text" placeholder="Search..."></span>
              <span>
                  <button name="add">Add</button>
                  <button name="remove">Remove</button>
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/profiles.html b/base/tps-tomcat/shared/webapps/tps/ui/profiles.html
index faf528bab3c754803bd9957ad2f8639a7480fc5b..57c86df10fed5e53f7574a36ae561c12980c9847 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/profiles.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/profiles.html
@@ -21,7 +21,7 @@
 <thead>
     <tr>
          <th class="rcue-table-actions" colspan="3">
-             <span><input type="text" placeholder="Search..."></span>
+             <span><input name="search" type="text" placeholder="Search..."></span>
              <span>
                  <button name="add">Add</button>
                  <button name="remove">Remove</button>
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/selftests.html b/base/tps-tomcat/shared/webapps/tps/ui/selftests.html
index fac64d205d63109be47b645f06c908522d6a795c..d184703c818b3dcf585a6c03f9360e26c2b7dcf6 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/selftests.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/selftests.html
@@ -21,7 +21,7 @@
 <thead>
     <tr>
          <th class="rcue-table-actions" colspan="6">
-             <span><input type="text" placeholder="Search..."></span>
+             <span><input name="search" type="text" placeholder="Search..."></span>
              <span></span>
          </th>
     </tr>
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/tokens.html b/base/tps-tomcat/shared/webapps/tps/ui/tokens.html
index 1575b046c67631ec68ee2f341513d99652177a3c..3edcd2cd4248841ec5ae193b33e901928787c952 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/tokens.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/tokens.html
@@ -21,7 +21,7 @@
 <thead>
     <tr>
          <th class="rcue-table-actions" colspan="9">
-             <span><input type="text" placeholder="Search..."></span>
+             <span><input name="search" type="text" placeholder="Search..."></span>
              <span>
                  <button name="add">Add</button>
                  <button name="remove">Remove</button>
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/users.html b/base/tps-tomcat/shared/webapps/tps/ui/users.html
index 20e622cbc6209f4e64085b4474fd4e321314701e..4757ff5d9214e7593d2da1988fc53609c47248a3 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/users.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/users.html
@@ -21,7 +21,7 @@
 <thead>
     <tr>
          <th class="rcue-table-actions" colspan="3">
-             <span><input type="text" placeholder="Search..."></span>
+             <span><input name="search" type="text" placeholder="Search..."></span>
              <span>
                  <button name="add">Add</button>
                  <button name="remove">Remove</button>
-- 
1.8.4.2

