From 8c420e5cde32faf589f9a834125110c56b912ce1 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Fri, 11 Apr 2014 13:24:33 -0400
Subject: [PATCH] Replaced user dialog with user page.

The dialog used to edit user attributes has been replaced with a
details page since it will be required for breadcrumbs. A new HTML
template has been added for this page.

The renderField() in EntryPage has been renamed to loadField() for
consistency with the Dialog clas.

Ticket #654
---
 base/server/share/webapps/pki/js/pki-ui.js       |  4 +-
 base/tps-tomcat/shared/webapps/tps/js/user.js    | 74 +++++++++++++++++-------
 base/tps-tomcat/shared/webapps/tps/ui/index.html |  2 +-
 base/tps-tomcat/shared/webapps/tps/ui/user.html  | 52 +++++++++++++++++
 base/tps-tomcat/shared/webapps/tps/ui/users.html | 29 ----------
 5 files changed, 108 insertions(+), 53 deletions(-)
 create mode 100644 base/tps-tomcat/shared/webapps/tps/ui/user.html

diff --git a/base/server/share/webapps/pki/js/pki-ui.js b/base/server/share/webapps/pki/js/pki-ui.js
index ce5d5ccffdf37e1b1265fe20ab40a03de05c056e..0800887cbc9faa16833a42d9425aa4c749812576 100644
--- a/base/server/share/webapps/pki/js/pki-ui.js
+++ b/base/server/share/webapps/pki/js/pki-ui.js
@@ -1024,10 +1024,10 @@ var EntryPage = Page.extend({
 
         self.$(".pki-fields input").each(function(index) {
             var input = $(this);
-            self.renderField(input);
+            self.loadField(input);
         });
     },
-    renderField: function(input) {
+    loadField: function(input) {
         var self = this;
         var name = input.attr("name");
         var value = self.entry[name];
diff --git a/base/tps-tomcat/shared/webapps/tps/js/user.js b/base/tps-tomcat/shared/webapps/tps/js/user.js
index cf78a4aed5fb9bf6c8bb9232a89ee8b557964c1e..310a49b711625d6adc00bfc0b719df92365362cd 100644
--- a/base/tps-tomcat/shared/webapps/tps/js/user.js
+++ b/base/tps-tomcat/shared/webapps/tps/js/user.js
@@ -86,13 +86,18 @@ var UserCollection = Collection.extend({
     }
 });
 
-var UserDialog = Dialog.extend({
+var UserPage = EntryPage.extend({
+    initialize: function(options) {
+        var self = this;
+        UserPage.__super__.initialize.call(self, options);
+        self.parentPage = options.parentPage;
+    },
     loadField: function(input) {
         var self = this;
 
         var name = input.attr("name");
         if (name != "tpsProfiles") {
-            UserDialog.__super__.loadField.call(self, input);
+            UserPage.__super__.loadField.call(self, input);
             return;
         }
 
@@ -107,7 +112,7 @@ var UserDialog = Dialog.extend({
 
         var name = input.attr("name");
         if (name != "tpsProfiles") {
-            UserDialog.__super__.saveField.call(self, input);
+            UserPage.__super__.saveField.call(self, input);
             return;
         }
 
@@ -117,32 +122,59 @@ var UserDialog = Dialog.extend({
             self.entry.attributes = attributes;
         }
         attributes.tpsProfiles = input.val();
+    },
+    close: function() {
+        var self = this;
+        if (self.parentPage) {
+            self.parentPage.open();
+        } else {
+            UserPage.__super__.close.call(self);
+        }
     }
 });
 
-var UserPage = Page.extend({
+var UsersTable = ModelTable.extend({
+    initialize: function(options) {
+        var self = this;
+        UsersTable.__super__.initialize.call(self, options);
+        self.parentPage = options.parentPage;
+    },
+    open: function(item, column) {
+        var self = this;
+
+        var page = new UserPage({
+            el: self.parentPage.$el,
+            url: "user.html",
+            model: self.collection.get(item.entry.id),
+            editable: ["fullName", "email", "tpsProfiles"]
+        });
+
+        page.open();
+    },
+    add: function() {
+        var self = this;
+
+        var page = new UserPage({
+            el: self.parentPage.$el,
+            url: "user.html",
+            model: new UserModel(),
+            mode: "add",
+            editable: ["userID", "fullName", "email", "tpsProfiles"],
+            parentPage: self.parentPage
+        });
+
+        page.open();
+    }
+});
+
+var UsersPage = Page.extend({
     load: function() {
         var self = this;
 
-        var addDialog = new UserDialog({
-            el: $("#user-dialog"),
-            title: "Add User",
-            readonly: ["type"],
-            actions: ["cancel", "add"]
-        });
-
-        var editDialog = new UserDialog({
-            el: $("#user-dialog"),
-            title: "Edit User",
-            readonly: ["userID", "type"],
-            actions: ["cancel", "save"]
-        });
-
-        var table = new ModelTable({
+        var table = new UsersTable({
             el: $("table[name='users']"),
             collection: new UserCollection(),
-            addDialog: addDialog,
-            editDialog: editDialog
+            parentPage: self
         });
 
         table.render();
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/index.html b/base/tps-tomcat/shared/webapps/tps/ui/index.html
index e8be636241b16afffc1c337d50c71e0ddecd0833..1d7a69b487e55d090e99d2f3b02c50412340b516 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/index.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/index.html
@@ -116,7 +116,7 @@ $(function() {
         url: "tokens.html"
     }));
 
-    navigation.page("users", new UserPage({
+    navigation.page("users", new UsersPage({
         el: content,
         url: "users.html"
     }));
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/user.html b/base/tps-tomcat/shared/webapps/tps/ui/user.html
new file mode 100644
index 0000000000000000000000000000000000000000..459f3ee367f2072bafea6bfe3c33d1371a7ca971
--- /dev/null
+++ b/base/tps-tomcat/shared/webapps/tps/ui/user.html
@@ -0,0 +1,52 @@
+<!-- --- 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 --- -->
+<div class="pki-header">
+
+<span class="pki-title">User <span name="id"></span></span>
+
+<span class="pki-actions">
+
+<span class="pki-menu" style="display: none;">
+<a name="edit" href="#">Edit</a><br>
+</span>
+
+<span class="pki-buttons" style="display: none;">
+<button name="cancel">Cancel</button>
+<button name="save" class="primary">Save</button>
+</span>
+
+</span>
+
+</div>
+
+<div name="user" class="pki-fields">
+<fieldset>
+    <label>User ID</label>
+    <input name="userID" readonly="readonly"><br>
+    <label>Full Name</label>
+    <input name="fullName" readonly="readonly"><br>
+    <label>Email</label>
+    <input name="email" readonly="readonly"><br>
+    <label>Type</label>
+    <input name="type" readonly="readonly"><br>
+    <label>State</label>
+    <input name="state" readonly="readonly"><br>
+    <label>TPS Profiles</label>
+    <input name="tpsProfiles" readonly="readonly"><br>
+</fieldset>
+</div>
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/users.html b/base/tps-tomcat/shared/webapps/tps/ui/users.html
index 847f0f8b2f1f5a08044fa640ee6daa272b1d820f..9c9450a70b0b7e2a9d33afa70da9865d7ce2c158 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/users.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/users.html
@@ -68,32 +68,3 @@
     </tr>
 </tfoot>
 </table>
-
-<div id="user-dialog" class="rcue-dialog-background">
-    <div class="rcue-dialog">
-        <header>
-            <h1>User</h1>
-            <a class="rcue-button-close" href="#"></a>
-        </header>
-        <fieldset>
-            <label>User ID</label>
-            <input name="userID" readonly="readonly"><br>
-            <label>Full Name</label>
-            <input name="fullName" readonly="readonly"><br>
-            <label>Email</label>
-            <input name="email" readonly="readonly"><br>
-            <label>Type</label>
-            <input name="type" readonly="readonly"><br>
-            <label>State</label>
-            <input name="state" readonly="readonly"><br>
-            <label>TPS Profiles</label>
-            <input name="tpsProfiles" readonly="readonly"><br>
-        </fieldset>
-        <footer>
-            <button name="add" class="primary">Add</button>
-            <button name="save" class="primary">Save</button>
-            <button name="remove" class="primary">Remove</button>
-            <button name="cancel">Cancel</button>
-        </footer>
-    </div>
-</div>
-- 
1.8.4.2

