From 94bc17c477136306e721ae6192cf79f5429a034a Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Mon, 24 Mar 2014 13:39:35 -0400
Subject: [PATCH] Added details page for TPS authenticators.

A new page has been added to view TPS authenticator details. The
properties are displayed in a table which provides pagination and
search functionality. Currently the page is read-only. The edit
functionality will be added separately later.

Previously the AuthenticatorData had a problem with JSON mapping
because it incorrectly included a PropertyNames attribute. To fix the
problem the class has been modified to require explicit JAXB mapping by
setting the @XmlAccessorType to NONE.

Ticket #654
---
 .../tps/authenticator/AuthenticatorData.java       |  3 +
 .../shared/webapps/tps/js/authenticator.js         | 43 ++++++++++--
 .../shared/webapps/tps/ui/authenticator.html       | 77 ++++++++++++++++++++++
 base/tps-tomcat/shared/webapps/tps/ui/index.html   |  2 +-
 4 files changed, 120 insertions(+), 5 deletions(-)
 create mode 100644 base/tps-tomcat/shared/webapps/tps/ui/authenticator.html

diff --git a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorData.java b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorData.java
index 95fb5fefb67c70bf29dbd4b6d771e82facf6c11e..d55dde126a465d1b6452d40efb3a687d81832e8b 100644
--- a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorData.java
+++ b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorData.java
@@ -29,6 +29,8 @@ import java.util.Map;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
@@ -42,6 +44,7 @@ import org.jboss.resteasy.plugins.providers.atom.Link;
  * @author Endi S. Dewata
  */
 @XmlRootElement(name="Authenticator")
+@XmlAccessorType(XmlAccessType.NONE)
 public class AuthenticatorData {
 
     public static Marshaller marshaller;
diff --git a/base/tps-tomcat/shared/webapps/tps/js/authenticator.js b/base/tps-tomcat/shared/webapps/tps/js/authenticator.js
index 713b6ceeee3b81980d539f07cdc5d902b9e9957c..ec15dc93d6a70786a1fbb5279d2e838c61600ffd 100644
--- a/base/tps-tomcat/shared/webapps/tps/js/authenticator.js
+++ b/base/tps-tomcat/shared/webapps/tps/js/authenticator.js
@@ -24,7 +24,8 @@ var AuthenticatorModel = Model.extend({
     parseResponse: function(response) {
         return {
             id: response.id,
-            status: response.Status
+            status: response.Status,
+            properties: response.Properties.Property
         };
     },
     parseXML: function(data) {
@@ -124,7 +125,39 @@ var AuthenticatorDialog = Dialog.extend({
     }
 });
 
-var AuthenticatorPage = Page.extend({
+var AuthenticatorsTable = Table.extend({
+    initialize: function(options) {
+        var self = this;
+        AuthenticatorsTable.__super__.initialize.call(self, options);
+        self.url = options.url;
+        self.container = options.container;
+    },
+    open: function(item) {
+        var self = this;
+
+        // load entry properties
+        item.model.fetch({
+            success: function(model, response, options) {
+                self.container.load(self.url, function(response, status, xhr) {
+                    $("h1 span[name='id']", self.container).text(model.id);
+
+                    var fields = $("div[name='authenticator']", self.container);
+                    $("input[name='id']", fields).val(model.id);
+                    $("input[name='status']", fields).val(model.get("status"));
+
+                    var properties = new PropertiesTable({
+                        el: $("table[name='authenticator-properties']"),
+                        properties: model.get("properties"),
+                        pageSize: 10
+                    });
+                    properties.render();
+                });
+            }
+        });
+    }
+});
+
+var AuthenticatorsPage = Page.extend({
     load: function(container) {
         var editDialog = new AuthenticatorDialog({
             el: $("#authenticator-dialog"),
@@ -132,10 +165,12 @@ var AuthenticatorPage = Page.extend({
             readonly: ["id", "status"]
         });
 
-        var table = new Table({
+        var table = new AuthenticatorsTable({
+            url: "authenticator.html",
             el: $("table[name='authenticators']"),
             collection: new AuthenticatorCollection(),
-            editDialog: editDialog
+            editDialog: editDialog,
+            container: container
         });
         table.render();
     }
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/authenticator.html b/base/tps-tomcat/shared/webapps/tps/ui/authenticator.html
new file mode 100644
index 0000000000000000000000000000000000000000..034935cb7881df8e01549073b9728d14c3e9edf8
--- /dev/null
+++ b/base/tps-tomcat/shared/webapps/tps/ui/authenticator.html
@@ -0,0 +1,77 @@
+<!-- --- BEGIN COPYRIGHT BLOCK ---
+     This program is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published by
+     the Free Software Foundation; version 2 of the License.
+
+     This program is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+     GNU General Public License for more details.
+
+     You should have received a copy of the GNU General Public License along
+     with this program; if not, write to the Free Software Foundation, Inc.,
+     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+     Copyright (C) 2014 Red Hat, Inc.
+     All rights reserved.
+     --- END COPYRIGHT BLOCK --- -->
+<h1>Authenticator <span name="id"></span></h1>
+
+<div name="authenticator" class="pki-fields">
+<fieldset>
+    <label>Authenticator ID</label>
+    <input name="id" readonly>
+    <br>
+    <label>Status</label>
+    <input name="status" readonly>
+    <br>
+</fieldset>
+</div>
+
+<h2>Properties</h2>
+
+<table name="authenticator-properties">
+<thead>
+    <tr>
+         <th class="pki-table-actions" colspan="3">
+             <span name="search">
+                 <input name="search" type="text" placeholder="Search...">
+             </span>
+             <span name="actions">
+             </span>
+         </th>
+    </tr>
+    <tr>
+        <th class="pki-select-column"><input id="authenticator_selectall" type="checkbox"><label for="authenticator_selectall">&nbsp;</label></th>
+        <th class="pki-property-name-column">Name</th>
+        <th>Value</th>
+    </tr>
+</thead>
+<tbody>
+    <tr>
+        <td class="pki-select-column"><input id="authenticator_select" type="checkbox"><label for="authenticator_select">&nbsp;</label></td>
+        <td name="id" class="pki-property-name-column"><a href="authenticator.html">&nbsp;</a></td>
+        <td name="status">&nbsp;</td>
+    </tr>
+</tbody>
+<tfoot>
+    <tr>
+         <th class="pki-table-actions" colspan="3">
+             <span name="info">
+                 Total: <span name="totalEntries">0</span> entries
+             </span>
+             <span name="page-controls">
+                 <ul class="pagination">
+                     <li><a href="#" name="first"><span class="i fa fa-angle-double-left"></span></a></li>
+                     <li><a href="#" name="prev"><span class="i fa fa-angle-left"></span></a></li>
+                     <li><a href="#" name="next"><span class="i fa fa-angle-right"></span></a></li>
+                     <li><a href="#" name="last"><span class="i fa fa-angle-double-right"></span></a></li>
+                 </ul>
+             </span>
+             <span name="page-jump">
+                 Page <input name="page" type="text" value="1"> of <span name="totalPages">1</span>
+             </span>
+         </th>
+    </tr>
+</tfoot>
+</table>
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/index.html b/base/tps-tomcat/shared/webapps/tps/ui/index.html
index 85c4dcc11b38eb230dc07907f7ed512858cddd64..4f75c4da443b2814b98b90b6d386b53509393f10 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/index.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/index.html
@@ -43,7 +43,7 @@ $(function() {
         content: $("#content"),
         pages: {
             activities: new ActivityPage({ url: "activities.html" }),
-            authenticators: new AuthenticatorPage({ url: "authenticators.html" }),
+            authenticators: new AuthenticatorsPage({ url: "authenticators.html" }),
             certs: new CertificatePage({ url: "certs.html" }),
             connections: new ConnectionsPage({ url: "connections.html" }),
             groups: new GroupPage({ url: "groups.html" }),
-- 
1.8.4.2

