diff options
| author | Endi S. Dewata <edewata@redhat.com> | 2014-03-31 10:09:20 -0400 |
|---|---|---|
| committer | Endi S. Dewata <edewata@redhat.com> | 2014-04-08 16:06:15 -0400 |
| commit | 7cff6f3b53c9829a014d8eaa6de89f28394ebcf2 (patch) | |
| tree | 54b2fca353f2394edc95c85d7cbc732fafbc28d3 /base | |
| parent | aa48d5d8d503a894d3dae1d8e79d33242e65b150 (diff) | |
| download | pki-7cff6f3b53c9829a014d8eaa6de89f28394ebcf2.tar.gz pki-7cff6f3b53c9829a014d8eaa6de89f28394ebcf2.tar.xz pki-7cff6f3b53c9829a014d8eaa6de89f28394ebcf2.zip | |
Added add functionality for some TPS resources.
The add button in the list page for TPS profiles, connections, and
authenticators has been modified to show a blank form to add a new
entry. Once the entry is added, it will go back to the list page.
The DetailsPage has been renamed into EntryPage and modified to
support an add mode. In add mode the fields are editable. A new
AddEntryPage was added to change the behavior when closing the
page to return to the list page.
The Page container now has to be specified in the constructor. The
load() method is no longer taking any parameter. The open() has
been added to simplify loading page template and content.
The default length of the list page has been changed to 15
entries.
Fixed some bugs in ConnectionModel, AuthenticatorModel,
ConnectionDatabase, and in the HTML template.
Ticket #654
Diffstat (limited to 'base')
14 files changed, 232 insertions, 95 deletions
diff --git a/base/server/share/webapps/pki/js/pki-ui.js b/base/server/share/webapps/pki/js/pki-ui.js index dffa7d8e1..949096c96 100644 --- a/base/server/share/webapps/pki/js/pki-ui.js +++ b/base/server/share/webapps/pki/js/pki-ui.js @@ -131,7 +131,15 @@ var Page = Backbone.View.extend({ self.url = options.url; }, - load: function(container) { + open: function() { + var self = this; + // load template + self.$el.load(self.url, function(response, status, xhr) { + // load content + self.load(); + }); + }, + load: function() { } }); @@ -140,7 +148,6 @@ var Navigation = Backbone.View.extend({ var self = this; Navigation.__super__.initialize.call(self, options); - self.content = options.content; self.pages = options.pages; self.homePage = options.homePage; @@ -167,14 +174,14 @@ var Navigation = Backbone.View.extend({ }, load: function(name) { var self = this; + var page = self.pages[name]; if (!page) { alert("Invalid page: " + name); return; } - self.content.load(page.url, function(response, status, xhr) { - page.load(self.content); - }); + + page.open(); } }); @@ -408,7 +415,7 @@ var Table = Backbone.View.extend({ self.tableItem = options.tableItem || TableItem; // number of table rows - self.pageSize = options.pageSize || 5; + self.pageSize = options.pageSize || 15; // current page: 1, 2, 3, ... self.page = 1; @@ -818,12 +825,12 @@ var PropertiesTable = Table.extend({ } }); -var DetailsPage = Page.extend({ +var EntryPage = Page.extend({ initialize: function(options) { var self = this; - DetailsPage.__super__.initialize.call(self, options); + EntryPage.__super__.initialize.call(self, options); self.model = options.model; - self.mode = "view"; + self.mode = options.mode || "view"; }, load: function() { var self = this; @@ -880,8 +887,7 @@ var DetailsPage = Page.extend({ }); self.cancelButton.click(function(e) { - self.mode = "view"; - self.render(); + self.cancel(); e.preventDefault(); }); @@ -925,42 +931,72 @@ var DetailsPage = Page.extend({ render: function() { var self = this; + // in add mode, render blank form + if (self.mode == "add") { + self.attributes = {}; + self.propertiesTable.properties = []; + self.renderContent(); + return; + } + + // in view and edit modes, fetch entry then render the content self.model.fetch({ success: function(model, response, options) { - self.attributes = _.clone(self.model.attributes); self.propertiesTable.properties = self.attributes.properties; + self.renderContent(); + } + }); + }, + renderContent: function() { + var self = this; - self.$("span[name='id']").text(self.model.id); + if (self.mode == "add") { + // In add mode all fields are editable. + self.$(".pki-fields input").each(function(index) { + var input = $(this); + input.removeAttr("readonly"); + }); - var status = self.model.get("status"); - if (status == "Disabled") { - self.enableLink.show(); - self.disableLink.hide(); - } else if (status == "Enabled") { - self.enableLink.hide(); - self.disableLink.show(); - } + } else { + // In view and edit modes show entry ID in the title. + self.$("span[name='id']").text(self.attributes.id); - if (self.mode == "view") { - self.menu.show(); - self.buttons.hide(); - self.propertiesButtons.hide(); + // In view mode all fields are read-only. In edit mode + // currently all fields are read-only too, but it might + // need to be changed later to suppot editable fields. + self.$(".pki-fields input").each(function(index) { + var input = $(this); + input.attr("readonly", "readonly"); + }); + } - } else { - self.menu.hide(); - self.buttons.show(); - self.propertiesButtons.show(); - } + var status = self.attributes.status; + if (status == "Disabled") { + self.enableLink.show(); + self.disableLink.hide(); + } else if (status == "Enabled") { + self.enableLink.hide(); + self.disableLink.show(); + } - self.$(".pki-fields input").each(function(index) { - var input = $(this); - self.renderField(input); - }); + if (self.mode == "view") { + self.menu.show(); + self.buttons.hide(); + self.propertiesButtons.hide(); - self.propertiesTable.render(); - } + } else { + self.menu.hide(); + self.buttons.show(); + self.propertiesButtons.show(); + } + + self.$(".pki-fields input").each(function(index) { + var input = $(this); + self.renderField(input); }); + + self.propertiesTable.render(); }, renderField: function(input) { var self = this; @@ -969,6 +1005,15 @@ var DetailsPage = Page.extend({ if (!value) value = ""; input.val(value); }, + close: function() { + var self = this; + self.mode = "view"; + self.render(); + }, + cancel: function() { + var self = this; + self.close(); + }, save: function() { var self = this; @@ -985,25 +1030,38 @@ var DetailsPage = Page.extend({ attributes.properties = self.propertiesTable.properties; - // save changed attributes with PATCH - self.model.save(attributes, { - patch: true, - wait: true, - success: function(model, response, options) { - // redraw table after saving entries - self.mode = "view"; - self.render(); - }, - error: function(model, response, options) { - if (response.status == 200) { - // redraw table after saving entries - self.mode = "view"; - self.render(); - return; + if (self.mode == "add") { + // save new entry with POST + self.model.save(attributes, { + wait: true, + success: function(model, response, options) { + self.close(); + }, + error: function(model, response, options) { + if (response.status == 201) { + self.close(); + return; + } + alert("ERROR: " + response.responseText); } - alert("ERROR: " + response.responseText); - } - }); + }); + } else { + // save changed attributes with PATCH + self.model.save(attributes, { + patch: true, + wait: true, + success: function(model, response, options) { + self.close(); + }, + error: function(model, response, options) { + if (response.status == 200) { + self.close(); + return; + } + alert("ERROR: " + response.responseText); + } + }); + } }, saveField: function(input) { var self = this; @@ -1011,3 +1069,18 @@ var DetailsPage = Page.extend({ self.attributes[name] = input.val(); } }); + +var AddEntryPage = EntryPage.extend({ + initialize: function(options) { + var self = this; + options.mode = "add"; + AddEntryPage.__super__.initialize.call(self, options); + self.parentPage = options.parentPage; + }, + close: function() { + var self = this; + self.parentPage.$el.load(self.parentPage.url, function(response, status, xhr) { + self.parentPage.load(); + }); + } +});;
\ No newline at end of file diff --git a/base/tps-tomcat/shared/webapps/tps/js/activity.js b/base/tps-tomcat/shared/webapps/tps/js/activity.js index a2d451476..66e54b3ce 100644 --- a/base/tps-tomcat/shared/webapps/tps/js/activity.js +++ b/base/tps-tomcat/shared/webapps/tps/js/activity.js @@ -67,7 +67,9 @@ var ActivityCollection = Collection.extend({ }); var ActivityPage = Page.extend({ - load: function(container) { + load: function() { + var self = this; + var editDialog = new Dialog({ el: $("#activity-dialog"), title: "Edit Activity", @@ -80,6 +82,7 @@ var ActivityPage = Page.extend({ collection: new ActivityCollection(), editDialog: editDialog }); + table.render(); } }); diff --git a/base/tps-tomcat/shared/webapps/tps/js/authenticator.js b/base/tps-tomcat/shared/webapps/tps/js/authenticator.js index 9c632e160..64da4b938 100644 --- a/base/tps-tomcat/shared/webapps/tps/js/authenticator.js +++ b/base/tps-tomcat/shared/webapps/tps/js/authenticator.js @@ -31,7 +31,7 @@ var AuthenticatorModel = Model.extend({ }, createRequest: function(attributes) { return { - id: attributes.profileID, + id: attributes.authenticatorID, Status: attributes.status, Properties: { Property: attributes.properties @@ -86,29 +86,44 @@ var AuthenticatorsTable = Table.extend({ initialize: function(options) { var self = this; AuthenticatorsTable.__super__.initialize.call(self, options); - self.container = options.container; + self.parentPage = options.parentPage; }, open: function(item) { var self = this; - var page = new DetailsPage({ - el: self.container, + var page = new EntryPage({ + el: self.parentPage.$el, + url: "authenticator.html", model: item.model }); - self.container.load("authenticator.html", function(response, status, xhr) { - page.load(); + page.open(); + }, + add: function() { + var self = this; + + var page = new AddEntryPage({ + el: self.parentPage.$el, + url: "authenticator.html", + model: new AuthenticatorModel(), + mode: "add", + parentPage: self.parentPage }); + + page.open(); } }); var AuthenticatorsPage = Page.extend({ - load: function(container) { + load: function() { + var self = this; + var table = new AuthenticatorsTable({ el: $("table[name='authenticators']"), collection: new AuthenticatorCollection(), - container: container + parentPage: self }); + table.render(); } }); diff --git a/base/tps-tomcat/shared/webapps/tps/js/cert.js b/base/tps-tomcat/shared/webapps/tps/js/cert.js index 51fa8b8ac..e1f8d53df 100644 --- a/base/tps-tomcat/shared/webapps/tps/js/cert.js +++ b/base/tps-tomcat/shared/webapps/tps/js/cert.js @@ -73,7 +73,9 @@ var CertificateCollection = Collection.extend({ }); var CertificatePage = Page.extend({ - load: function(container) { + load: function() { + var self = this; + var editDialog = new Dialog({ el: $("#certificate-dialog"), title: "Edit Certificate", @@ -86,6 +88,7 @@ var CertificatePage = Page.extend({ collection: new CertificateCollection(), editDialog: editDialog }); + table.render(); } }); diff --git a/base/tps-tomcat/shared/webapps/tps/js/connection.js b/base/tps-tomcat/shared/webapps/tps/js/connection.js index 36b17bc27..83bd694a6 100644 --- a/base/tps-tomcat/shared/webapps/tps/js/connection.js +++ b/base/tps-tomcat/shared/webapps/tps/js/connection.js @@ -31,7 +31,7 @@ var ConnectionModel = Model.extend({ }, createRequest: function(attributes) { return { - id: attributes.profileID, + id: attributes.connectionID, Status: attributes.status, Properties: { Property: attributes.properties @@ -86,29 +86,44 @@ var ConnectionsTable = Table.extend({ initialize: function(options) { var self = this; ConnectionsTable.__super__.initialize.call(self, options); - self.container = options.container; + self.parentPage = options.parentPage; }, open: function(item) { var self = this; - var page = new DetailsPage({ - el: self.container, + var page = new EntryPage({ + el: self.parentPage.$el, + url: "connection.html", model: item.model }); - self.container.load("connection.html", function(response, status, xhr) { - page.load(); + page.open(); + }, + add: function() { + var self = this; + + var page = new AddEntryPage({ + el: self.parentPage.$el, + url: "connection.html", + model: new ConnectionModel(), + mode: "add", + parentPage: self.parentPage }); + + page.open(); } }); var ConnectionsPage = Page.extend({ - load: function(container) { + load: function() { + var self = this; + var table = new ConnectionsTable({ el: $("table[name='connections']"), collection: new ConnectionCollection(), - container: container + parentPage: self }); + table.render(); } }); diff --git a/base/tps-tomcat/shared/webapps/tps/js/group.js b/base/tps-tomcat/shared/webapps/tps/js/group.js index 101545454..95056860b 100644 --- a/base/tps-tomcat/shared/webapps/tps/js/group.js +++ b/base/tps-tomcat/shared/webapps/tps/js/group.js @@ -56,7 +56,9 @@ var GroupCollection = Collection.extend({ }); var GroupPage = Page.extend({ - load: function(container) { + load: function() { + var self = this; + var addDialog = new Dialog({ el: $("#group-dialog"), title: "Add Group", @@ -76,6 +78,7 @@ var GroupPage = Page.extend({ addDialog: addDialog, editDialog: editDialog }); + table.render(); } }); diff --git a/base/tps-tomcat/shared/webapps/tps/js/profile.js b/base/tps-tomcat/shared/webapps/tps/js/profile.js index caaa08ec6..719a71488 100644 --- a/base/tps-tomcat/shared/webapps/tps/js/profile.js +++ b/base/tps-tomcat/shared/webapps/tps/js/profile.js @@ -86,29 +86,44 @@ var ProfilesTable = Table.extend({ initialize: function(options) { var self = this; ProfilesTable.__super__.initialize.call(self, options); - self.container = options.container; + self.parentPage = options.parentPage; }, open: function(item) { var self = this; - var page = new DetailsPage({ - el: self.container, + var page = new EntryPage({ + el: self.parentPage.$el, + url: "profile.html", model: item.model }); - self.container.load("profile.html", function(response, status, xhr) { - page.load(); + page.open(); + }, + add: function() { + var self = this; + + var page = new AddEntryPage({ + el: self.parentPage.$el, + url: "profile.html", + model: new ProfileModel(), + mode: "add", + parentPage: self.parentPage }); + + page.open(); } }); var ProfilesPage = Page.extend({ - load: function(container) { + load: function() { + var self = this; + var table = new ProfilesTable({ el: $("table[name='profiles']"), collection: new ProfileCollection(), - container: container + parentPage: self }); + table.render(); } }); diff --git a/base/tps-tomcat/shared/webapps/tps/js/selftest.js b/base/tps-tomcat/shared/webapps/tps/js/selftest.js index 7ee988d63..39c0ceb37 100644 --- a/base/tps-tomcat/shared/webapps/tps/js/selftest.js +++ b/base/tps-tomcat/shared/webapps/tps/js/selftest.js @@ -61,7 +61,9 @@ var SelfTestCollection = Collection.extend({ }); var SelfTestPage = Page.extend({ - load: function(container) { + load: function() { + var self = this; + var editDialog = new Dialog({ el: $("#selftest-dialog"), title: "Edit Self Test", @@ -73,6 +75,7 @@ var SelfTestPage = Page.extend({ collection: new SelfTestCollection(), editDialog: editDialog }); + table.render(); } }); diff --git a/base/tps-tomcat/shared/webapps/tps/js/token.js b/base/tps-tomcat/shared/webapps/tps/js/token.js index 6f0750ee5..9da95e622 100644 --- a/base/tps-tomcat/shared/webapps/tps/js/token.js +++ b/base/tps-tomcat/shared/webapps/tps/js/token.js @@ -74,7 +74,9 @@ var TokenCollection = Collection.extend({ }); var TokenPage = Page.extend({ - load: function(container) { + load: function() { + var self = this; + var addDialog = new Dialog({ el: $("#token-dialog"), title: "Add Token", @@ -97,6 +99,7 @@ var TokenPage = Page.extend({ addDialog: addDialog, editDialog: editDialog }); + table.render(); } }); diff --git a/base/tps-tomcat/shared/webapps/tps/js/user.js b/base/tps-tomcat/shared/webapps/tps/js/user.js index 8e3a8fe54..6be78fbab 100644 --- a/base/tps-tomcat/shared/webapps/tps/js/user.js +++ b/base/tps-tomcat/shared/webapps/tps/js/user.js @@ -121,7 +121,9 @@ var UserDialog = Dialog.extend({ }); var UserPage = Page.extend({ - load: function(container) { + load: function() { + var self = this; + var addDialog = new UserDialog({ el: $("#user-dialog"), title: "Add User", @@ -142,6 +144,7 @@ var UserPage = Page.extend({ addDialog: addDialog, editDialog: editDialog }); + table.render(); } }); diff --git a/base/tps-tomcat/shared/webapps/tps/ui/connection.html b/base/tps-tomcat/shared/webapps/tps/ui/connection.html index 61cd4b9ed..055ef21a2 100644 --- a/base/tps-tomcat/shared/webapps/tps/ui/connection.html +++ b/base/tps-tomcat/shared/webapps/tps/ui/connection.html @@ -38,7 +38,7 @@ <div name="connection" class="pki-fields"> <fieldset> <label>Connection ID</label> - <input name="id" readonly="readonly"> + <input name="connectionID" readonly="readonly"> <br> <label>Status</label> <input name="status" readonly="readonly"> diff --git a/base/tps-tomcat/shared/webapps/tps/ui/index.html b/base/tps-tomcat/shared/webapps/tps/ui/index.html index 4f75c4da4..31f4ecacc 100644 --- a/base/tps-tomcat/shared/webapps/tps/ui/index.html +++ b/base/tps-tomcat/shared/webapps/tps/ui/index.html @@ -37,20 +37,20 @@ <script src="/tps/js/user.js"></script> <script> $(function() { + var content = $("#content"); var account = new Account(); new Navigation({ el: $("#navigation"), - content: $("#content"), pages: { - activities: new ActivityPage({ url: "activities.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" }), - profiles: new ProfilesPage({ url: "profiles.html" }), - selftests: new SelfTestPage({ url: "selftests.html" }), - tokens: new TokenPage({ url: "tokens.html" }), - users: new UserPage({ url: "users.html" }) + activities: new ActivityPage({ el: content, url: "activities.html" }), + authenticators: new AuthenticatorsPage({ el: content, url: "authenticators.html" }), + certs: new CertificatePage({ el: content, url: "certs.html" }), + connections: new ConnectionsPage({ el: content, url: "connections.html" }), + groups: new GroupPage({ el: content, url: "groups.html" }), + profiles: new ProfilesPage({ el: content, url: "profiles.html" }), + selftests: new SelfTestPage({ el: content, url: "selftests.html" }), + tokens: new TokenPage({ el: content, url: "tokens.html" }), + users: new UserPage({ el: content, url: "users.html" }) }, logout: function() { account.logout({ diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigDatabase.java index cded13af5..8cb874f3d 100644 --- a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigDatabase.java +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigDatabase.java @@ -156,6 +156,7 @@ public class ConfigDatabase extends Database<ConfigRecord> { String filter = createFilter(record, key); for (String name : properties.keySet()) { if (name.matches(filter)) continue; + CMS.debug("Property " + name + " doesn't match filter " + filter + "."); throw new BadRequestException("Invalid property: " + name); } } diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConnectionDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConnectionDatabase.java index 9755db85b..4e541ed87 100644 --- a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConnectionDatabase.java +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConnectionDatabase.java @@ -57,7 +57,7 @@ public class ConnectionDatabase extends CSCfgDatabase<ConnectionRecord> { Collection<ConnectionRecord> result = new ArrayList<ConnectionRecord>(); ConfigDatabase configDatabase = new ConfigDatabase(); - ConfigRecord configRecord = configDatabase.getRecord("Subsystem_Connections"); + ConfigRecord configRecord = configDatabase.getRecord(substoreName); for (String connectionID : configRecord.getKeys()) { if (filter != null && !connectionID.contains(filter)) continue; |
