diff options
Diffstat (limited to 'base/tps/shared/webapps/tps/js')
-rw-r--r-- | base/tps/shared/webapps/tps/js/account.js | 37 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/activity.js | 97 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/audit.js | 232 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/authenticator.js | 109 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/cert.js | 100 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/config.js | 51 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/connector.js | 109 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/group.js | 232 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/profile-mapping.js | 109 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/profile.js | 109 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/selftest.js | 88 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/token.js | 258 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/tps.js | 231 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/user.js | 150 |
14 files changed, 1912 insertions, 0 deletions
diff --git a/base/tps/shared/webapps/tps/js/account.js b/base/tps/shared/webapps/tps/js/account.js new file mode 100644 index 000000000..97b222aaa --- /dev/null +++ b/base/tps/shared/webapps/tps/js/account.js @@ -0,0 +1,37 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +function Account() { + + this.url = "/tps/rest/account"; + + this.login = function(options) { + var jqxhr = $.get(this.url + "/login", null, null, "json"); + jqxhr.done(options.success); + jqxhr.fail(options.error); + }; + + this.logout = function(options) { + var jqxhr = $.get(this.url + "/logout"); + jqxhr.done(options.success); + jqxhr.fail(options.error); + }; +};
\ No newline at end of file diff --git a/base/tps/shared/webapps/tps/js/activity.js b/base/tps/shared/webapps/tps/js/activity.js new file mode 100644 index 000000000..cbc724e23 --- /dev/null +++ b/base/tps/shared/webapps/tps/js/activity.js @@ -0,0 +1,97 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +var ActivityModel = Model.extend({ + urlRoot: "/tps/rest/activities", + parseResponse: function(response) { + return { + id: response.id, + tokenID: response.TokenID, + userID: response.UserID, + ip: response.IP, + operation: response.Operation, + result: response.Result, + message: response.Message, + date: new Date(response.Date) + }; + }, + createRequest: function(attributes) { + return { + id: attributes.id, + TokenID: attributes.tokenID, + UserID: attributes.userID, + IP: attributes.ip, + Operation: attributes.operation, + Result: attributes.result, + Message: attributes.message, + Date: attributes.date.getTime()/1000 + 'Z' + }; + } +}); + +var ActivityCollection = Collection.extend({ + urlRoot: "/tps/rest/activities", + getEntries: function(response) { + return response.entries; + }, + getLinks: function(response) { + return response.Link; + }, + parseEntry: function(entry) { + return new ActivityModel({ + id: entry.id, + tokenID: entry.TokenID, + userID: entry.UserID, + ip: entry.IP, + operation: entry.Operation, + result: entry.Result, + message: entry.Message, + date: new Date(entry.Date) + }); + } +}); + +var ActivityPage = EntryPage.extend({ + initialize: function(options) { + var self = this; + ActivityPage.__super__.initialize.call(self, options); + } +}); + +var ActivitiesTable = ModelTable.extend({ + initialize: function(options) { + var self = this; + ActivitiesTable.__super__.initialize.call(self, options); + } +}); + +var ActivitiesPage = Page.extend({ + load: function() { + var self = this; + + var table = new ActivitiesTable({ + el: $("table[name='activities']"), + collection: new ActivityCollection() + }); + + table.render(); + } +}); diff --git a/base/tps/shared/webapps/tps/js/audit.js b/base/tps/shared/webapps/tps/js/audit.js new file mode 100644 index 000000000..986596e1d --- /dev/null +++ b/base/tps/shared/webapps/tps/js/audit.js @@ -0,0 +1,232 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +var AuditModel = Model.extend({ + url: function() { + return "/tps/rest/audit"; + }, + parseResponse: function(response) { + return { + id: "audit", + status: response.Status, + signed: response.Signed, + interval: response.Interval, + bufferSize: response.BufferSize, + events: response.Events.Event + }; + }, + createRequest: function(entry) { + return { + Status: entry.status, + Signed: entry.signed, + Interval: entry.interval, + BufferSize: entry.bufferSize, + Events: { + Event: entry.events + } + }; + }, + enable: function(options) { + var self = this; + $.ajax({ + type: "POST", + url: self.url() + "?action=enable", + dataType: "json" + }).done(function(data, textStatus, jqXHR) { + self.set(self.parseResponse(data)); + if (options.success) options.success.call(self, data, textStatus, jqXHR); + }).fail(function(jqXHR, textStatus, errorThrown) { + if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown); + }); + }, + disable: function(options) { + var self = this; + $.ajax({ + type: "POST", + url: self.url() + "?action=disable", + dataType: "json" + }).done(function(data, textStatus, jqXHR) { + self.set(self.parseResponse(data)); + if (options.success) options.success.call(self, data, textStatus, jqXHR); + }).fail(function(jqXHR, textStatus, errorThrown) { + if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown); + }); + } +}); + +var AuditTableItem = TableItem.extend({ + initialize: function(options) { + var self = this; + AuditTableItem.__super__.initialize.call(self, options); + }, + renderColumn: function(td, templateTD) { + var self = this; + + AuditTableItem.__super__.renderColumn.call(self, td, templateTD); + + $("a", td).click(function(e) { + e.preventDefault(); + self.open(); + }); + }, + open: function() { + var self = this; + + var value = self.get("value"); + var dialog; + + if (self.table.mode == "view" || value == "mandatory") { + // In view mode all events are read-only. + // Mandatory events are always read-only. + dialog = new Dialog({ + el: self.table.parent.$("#event-dialog"), + title: "Event", + readonly: ["name", "value"], + actions: ["close"] + }); + + } else if (self.table.mode == "edit" && value != "mandatory") { + // Optional events are editable in edit mode. + dialog = new Dialog({ + el: self.table.parent.$("#event-dialog"), + title: "Edit Event", + readonly: ["name"], + actions: ["cancel", "save"] + }); + + dialog.handler("save", function() { + + // save changes + dialog.save(); + _.extend(self.entry, dialog.entry); + + // redraw table + self.table.render(); + dialog.close(); + }); + } + + dialog.entry = _.clone(self.entry); + + dialog.open(); + } +}); + +var AuditPage = EntryPage.extend({ + initialize: function(options) { + var self = this; + options.model = new AuditModel(); + options.editable = ["signed", "interval", "bufferSize"]; + AuditPage.__super__.initialize.call(self, options); + }, + setup: function() { + var self = this; + + AuditPage.__super__.setup.call(self); + + self.enableLink = $("a[name='enable']", self.menu); + self.disableLink = $("a[name='disable']", self.menu); + + self.enableLink.click(function(e) { + + e.preventDefault(); + + var message = "Are you sure you want to enable this entry?"; + if (!confirm(message)) return; + self.model.enable({ + success: function(data, textStatus, jqXHR) { + self.entry = _.clone(self.model.attributes); + self.render(); + }, + error: function(jqXHR, textStatus, errorThrown) { + new ErrorDialog({ + el: $("#error-dialog"), + title: "HTTP Error " + jqXHR.responseJSON.Code, + content: jqXHR.responseJSON.Message + }).open(); + } + }); + }); + + self.disableLink.click(function(e) { + + e.preventDefault(); + + var message = "Are you sure you want to disable this entry?"; + if (!confirm(message)) return; + self.model.disable({ + success: function(data, textStatus, jqXHR) { + self.entry = _.clone(self.model.attributes); + self.render(); + }, + error: function(jqXHR, textStatus, errorThrown) { + new ErrorDialog({ + el: $("#error-dialog"), + title: "HTTP Error " + jqXHR.responseJSON.Code, + content: jqXHR.responseJSON.Message + }).open(); + } + }); + }); + + self.eventsTable = new Table({ + el: self.$("table[name='events']"), + columnMappings: { + id: "name" + }, + pageSize: 10, + tableItem: AuditTableItem, + parent: self + }); + }, + renderContent: function() { + var self = this; + + AuditPage.__super__.renderContent.call(self); + + var status = self.entry.status; + if (status == "Disabled") { + self.enableLink.show(); + self.disableLink.hide(); + + } else if (status == "Enabled") { + self.enableLink.hide(); + self.disableLink.show(); + } + + if (self.mode == "edit") { + self.eventsTable.mode = "edit"; + + } else { // self.mode == "view" + self.eventsTable.mode = "view"; + } + + self.eventsTable.entries = self.entry.events; + self.eventsTable.render(); + }, + saveFields: function() { + var self = this; + + AuditPage.__super__.saveFields.call(self); + + self.entry.events = self.eventsTable.entries; + } +}); diff --git a/base/tps/shared/webapps/tps/js/authenticator.js b/base/tps/shared/webapps/tps/js/authenticator.js new file mode 100644 index 000000000..f91cf6bfe --- /dev/null +++ b/base/tps/shared/webapps/tps/js/authenticator.js @@ -0,0 +1,109 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +var AuthenticatorModel = Model.extend({ + urlRoot: "/tps/rest/authenticators", + parseResponse: function(response) { + return { + id: response.id, + authenticatorID: response.id, + status: response.Status, + properties: response.Properties.Property + }; + }, + createRequest: function(attributes) { + return { + id: attributes.authenticatorID, + Status: attributes.status, + Properties: { + Property: attributes.properties + } + }; + }, + enable: function(options) { + var self = this; + $.ajax({ + type: "POST", + url: self.url() + "?action=enable", + dataType: "json" + }).done(function(data, textStatus, jqXHR) { + self.set(self.parseResponse(data)); + if (options.success) options.success.call(self, data, textStatus, jqXHR); + }).fail(function(jqXHR, textStatus, errorThrown) { + if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown); + }); + }, + disable: function(options) { + var self = this; + $.ajax({ + type: "POST", + url: self.url() + "?action=disable", + dataType: "json" + }).done(function(data, textStatus, jqXHR) { + self.set(self.parseResponse(data)); + if (options.success) options.success.call(self, data, textStatus, jqXHR); + }).fail(function(jqXHR, textStatus, errorThrown) { + if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown); + }); + } +}); + +var AuthenticatorCollection = Collection.extend({ + urlRoot: "/tps/rest/authenticators", + getEntries: function(response) { + return response.entries; + }, + getLinks: function(response) { + return response.Link; + }, + parseEntry: function(entry) { + return new AuthenticatorModel({ + id: entry.id, + status: entry.Status + }); + } +}); + +var AuthenticatorsTable = ModelTable.extend({ + initialize: function(options) { + var self = this; + AuthenticatorsTable.__super__.initialize.call(self, options); + }, + add: function() { + var self = this; + + window.location.hash = "#new-authenticator"; + } +}); + +var AuthenticatorsPage = Page.extend({ + load: function() { + var self = this; + + var table = new AuthenticatorsTable({ + el: $("table[name='authenticators']"), + collection: new AuthenticatorCollection(), + parent: self + }); + + table.render(); + } +}); diff --git a/base/tps/shared/webapps/tps/js/cert.js b/base/tps/shared/webapps/tps/js/cert.js new file mode 100644 index 000000000..016b56ee0 --- /dev/null +++ b/base/tps/shared/webapps/tps/js/cert.js @@ -0,0 +1,100 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +var CertificateModel = Model.extend({ + urlRoot: "/tps/rest/certs", + parseResponse: function(response) { + return { + id: response.id, + serialNumber: response.SerialNumber, + subject: response.Subject, + tokenID: response.TokenID, + userID: response.UserID, + keyType: response.KeyType, + status: response.Status, + createTime: response.CreateTime, + modifyTime: response.ModifyTime + }; + }, + createRequest: function(attributes) { + return { + id: attributes.id, + SerialNumber: attributes.serialNumber, + Subject: attributes.subject, + TokenID: attributes.tokenID, + UserID: attributes.userID, + KeyType: attributes.keyType, + Status: attributes.status, + CreateTime: attributes.createTime, + ModifyTime: attributes.modifyTime + }; + } +}); + +var CertificateCollection = Collection.extend({ + urlRoot: "/tps/rest/certs", + getEntries: function(response) { + return response.entries; + }, + getLinks: function(response) { + return response.Link; + }, + parseEntry: function(entry) { + return new CertificateModel({ + id: entry.id, + serialNumber: entry.SerialNumber, + subject: entry.Subject, + tokenID: entry.TokenID, + userID: entry.UserID, + keyType: entry.KeyType, + status: entry.Status, + createTime: entry.CreateTime, + modifyTime: entry.ModifyTime + }); + } +}); + +var CertificatePage = EntryPage.extend({ + initialize: function(options) { + var self = this; + CertificatePage.__super__.initialize.call(self, options); + } +}); + +var CertificatesTable = ModelTable.extend({ + initialize: function(options) { + var self = this; + CertificatesTable.__super__.initialize.call(self, options); + } +}); + +var CertificatesPage = Page.extend({ + load: function() { + var self = this; + + var table = new CertificatesTable({ + el: $("table[name='certificates']"), + collection: new CertificateCollection() + }); + + table.render(); + } +}); diff --git a/base/tps/shared/webapps/tps/js/config.js b/base/tps/shared/webapps/tps/js/config.js new file mode 100644 index 000000000..5b651a09d --- /dev/null +++ b/base/tps/shared/webapps/tps/js/config.js @@ -0,0 +1,51 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +var ConfigModel = Model.extend({ + url: function() { + return "/tps/rest/config"; + }, + parseResponse: function(response) { + return { + id: "config", + status: response.Status, + properties: response.Properties.Property + }; + }, + createRequest: function(entry) { + return { + Status: entry.status, + Properties: { + Property: entry.properties + } + }; + } +}); + +var ConfigPage = ConfigEntryPage.extend({ + initialize: function(options) { + var self = this; + options.model = new ConfigModel(); + options.tableItem = PropertiesTableItem; + options.tableSize = 15; + ConfigPage.__super__.initialize.call(self, options); + } +}); diff --git a/base/tps/shared/webapps/tps/js/connector.js b/base/tps/shared/webapps/tps/js/connector.js new file mode 100644 index 000000000..bc7e4c2bd --- /dev/null +++ b/base/tps/shared/webapps/tps/js/connector.js @@ -0,0 +1,109 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +var ConnectorModel = Model.extend({ + urlRoot: "/tps/rest/connectors", + parseResponse: function(response) { + return { + id: response.id, + connectorID: response.id, + status: response.Status, + properties: response.Properties.Property + }; + }, + createRequest: function(attributes) { + return { + id: attributes.connectorID, + Status: attributes.status, + Properties: { + Property: attributes.properties + } + }; + }, + enable: function(options) { + var self = this; + $.ajax({ + type: "POST", + url: self.url() + "?action=enable", + dataType: "json" + }).done(function(data, textStatus, jqXHR) { + self.set(self.parseResponse(data)); + if (options.success) options.success.call(self, data, textStatus, jqXHR); + }).fail(function(jqXHR, textStatus, errorThrown) { + if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown); + }); + }, + disable: function(options) { + var self = this; + $.ajax({ + type: "POST", + url: self.url() + "?action=disable", + dataType: "json" + }).done(function(data, textStatus, jqXHR) { + self.set(self.parseResponse(data)); + if (options.success) options.success.call(self, data, textStatus, jqXHR); + }).fail(function(jqXHR, textStatus, errorThrown) { + if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown); + }); + } +}); + +var ConnectorCollection = Collection.extend({ + urlRoot: "/tps/rest/connectors", + getEntries: function(response) { + return response.entries; + }, + getLinks: function(response) { + return response.Link; + }, + parseEntry: function(entry) { + return new ConnectorModel({ + id: entry.id, + status: entry.Status + }); + } +}); + +var ConnectorsTable = ModelTable.extend({ + initialize: function(options) { + var self = this; + ConnectorsTable.__super__.initialize.call(self, options); + }, + add: function() { + var self = this; + + window.location.hash = "#new-connector"; + } +}); + +var ConnectorsPage = Page.extend({ + load: function() { + var self = this; + + var table = new ConnectorsTable({ + el: $("table[name='connectors']"), + collection: new ConnectorCollection(), + parent: self + }); + + table.render(); + } +}); diff --git a/base/tps/shared/webapps/tps/js/group.js b/base/tps/shared/webapps/tps/js/group.js new file mode 100644 index 000000000..50d7d6c67 --- /dev/null +++ b/base/tps/shared/webapps/tps/js/group.js @@ -0,0 +1,232 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +var GroupModel = Model.extend({ + urlRoot: "/tps/rest/admin/groups", + parseResponse: function(response) { + return { + id: response.id, + groupID: response.GroupID, + description: response.Description + }; + }, + createRequest: function(attributes) { + return { + id: this.id, + GroupID: attributes.groupID, + Description: attributes.description + }; + } +}); + +var GroupCollection = Collection.extend({ + model: GroupModel, + urlRoot: "/tps/rest/admin/groups", + getEntries: function(response) { + return response.entries; + }, + getLinks: function(response) { + return response.Link; + }, + parseEntry: function(entry) { + return new GroupModel({ + id: entry.id, + groupID: entry.GroupID, + description: entry.Description + }); + } +}); + +var GroupMemberModel = Model.extend({ + url: function() { + var self = this; + + // There's an attribute name mismatch for group ID: the + // server uses GroupID and the client uses groupID. In other + // models the mismatch can be translated just fine, but in + // this model it becomes a problem because the model needs + // to construct the URL using the attribute. + // + // During read operation it needs to use the attribute that's + // already translated for client (i.e. groupID), but during + // add it needs to use the attribute meant for server (i.e. + // GroupID). So the workaround is to read whichever available. + var groupID = self.get("groupID"); // for read + groupID = groupID || self.get("GroupID"); // for add + + var url = "/tps/rest/admin/groups/" + groupID + "/members"; + + // append member ID for read + if (self.id) url = url + "/" + self.id; + + return url; + }, + parseResponse: function(response) { + return { + id: response.id, + memberID: response.id, + groupID: response.GroupID + }; + }, + createRequest: function(entry) { + return { + id: entry.memberID, + GroupID: entry.groupID + }; + } +}); + +var GroupMemberCollection = Collection.extend({ + initialize: function(models, options) { + var self = this; + GroupMemberCollection.__super__.initialize.call(self, models, options); + options = options || {}; + self.groupID = options.groupID; + self.urlRoot = "/tps/rest/admin/groups/" + self.groupID + "/members"; + }, + getEntries: function(response) { + return response.Member; + }, + getLinks: function(response) { + return response.Link; + }, + model: function(attrs, options) { + return new GroupMemberModel({ + groupID: this.groupID + }); + }, + parseEntry: function(entry) { + return new GroupMemberModel({ + id: entry.id, + memberID: entry.id, + groupID: entry.GroupID + }); + } +}); + +var GroupMembersTableItem = TableItem.extend({ + initialize: function(options) { + var self = this; + GroupMembersTableItem.__super__.initialize.call(self, options); + }, + renderColumn: function(td, templateTD) { + var self = this; + + GroupMembersTableItem.__super__.renderColumn.call(self, td, templateTD); + + $("a", td).click(function(e) { + e.preventDefault(); + self.table.open(self); + }); + } +}); + +var GroupPage = EntryPage.extend({ + initialize: function(options) { + var self = this; + GroupPage.__super__.initialize.call(self, options); + }, + setup: function() { + var self = this; + + GroupPage.__super__.setup.call(self); + + var dialog = self.$("#member-dialog"); + + var addDialog = new Dialog({ + el: dialog, + title: "Add Member", + readonly: ["groupID"], + actions: ["cancel", "add"] + }); + + var editDialog = new Dialog({ + el: dialog, + title: "Member", + readonly: ["groupID", "memberID"], + actions: ["close"] + }); + + self.membersTable = new ModelTable({ + el: self.$("table[name='members']"), + pageSize: 10, + addDialog: addDialog, + editDialog: editDialog, + tableItem: GroupMembersTableItem, + parent: self + }); + }, + renderContent: function() { + var self = this; + + GroupPage.__super__.renderContent.call(self); + + // Since the members table is backed by a REST resource any + // changes will be executed immediately even if the page is + // in view mode. To avoid confusion, the members table will + // be disabled in page edit mode. + if (self.mode == "edit") { + // In page edit mode, the members tables is read-only. + self.membersTable.mode = "view"; + + self.membersTable.collection = new GroupMemberCollection(null, { groupID: self.entry.id }); + + } else if (self.mode == "add") { + // In page add mode, the members table is read-only. + self.membersTable.mode = "view"; + + // self.membersTable.collection is undefined for new group + + } else { // self.mode == "view" + // In page view mode, the members table is editable. + self.membersTable.mode = "edit"; + + self.membersTable.collection = new GroupMemberCollection(null, { groupID: self.entry.id }); + } + + self.membersTable.render(); + } +}); + +var GroupsTable = ModelTable.extend({ + initialize: function(options) { + var self = this; + GroupsTable.__super__.initialize.call(self, options); + }, + add: function() { + var self = this; + + window.location.hash = "#new-group"; + } +}); + +var GroupsPage = Page.extend({ + load: function() { + var self = this; + + var table = new GroupsTable({ + el: $("table[name='groups']"), + collection: new GroupCollection() + }); + + table.render(); + } +}); diff --git a/base/tps/shared/webapps/tps/js/profile-mapping.js b/base/tps/shared/webapps/tps/js/profile-mapping.js new file mode 100644 index 000000000..54c042562 --- /dev/null +++ b/base/tps/shared/webapps/tps/js/profile-mapping.js @@ -0,0 +1,109 @@ +/* --- 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 --- + * + * @author Endi S. Dewata + */ + +var ProfileMappingModel = Model.extend({ + urlRoot: "/tps/rest/profile-mappings", + parseResponse: function(response) { + return { + id: response.id, + profileMappingID: response.id, + status: response.Status, + properties: response.Properties.Property + }; + }, + createRequest: function(attributes) { + return { + id: attributes.profileMappingID, + Status: attributes.status, + Properties: { + Property: attributes.properties + } + }; + }, + enable: function(options) { + var self = this; + $.ajax({ + type: "POST", + url: self.url() + "?action=enable", + dataType: "json" + }).done(function(data, textStatus, jqXHR) { + self.set(self.parseResponse(data)); + if (options.success) options.success.call(self, data, textStatus, jqXHR); + }).fail(function(jqXHR, textStatus, errorThrown) { + if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown); + }); + }, + disable: function(options) { + var self = this; + $.ajax({ + type: "POST", + url: self.url() + "?action=disable", + dataType: "json" + }).done(function(data, textStatus, jqXHR) { + self.set(self.parseResponse(data)); + if (options.success) options.success.call(self, data, textStatus, jqXHR); + }).fail(function(jqXHR, textStatus, errorThrown) { + if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown); + }); + } +}); + +var ProfileMappingCollection = Collection.extend({ + urlRoot: "/tps/rest/profile-mappings", + getEntries: function(response) { + return response.entries; + }, + getLinks: function(response) { + return response.Link; + }, + parseEntry: function(entry) { + return new ProfileMappingModel({ + id: entry.id, + status: entry.Status + }); + } +}); + +var ProfileMappingsTable = ModelTable.extend({ + initialize: function(options) { + var self = this; + ProfileMappingsTable.__super__.initialize.call(self, options); + }, + add: function() { + var self = this; + + window.location.hash = "#new-profile-mapping"; + } +}); + +var ProfileMappingsPage = Page.extend({ + load: function() { + var self = this; + + var table = new ProfileMappingsTable({ + el: $("table[name='profile-mappings']"), + collection: new ProfileMappingCollection(), + parent: self + }); + + table.render(); + } +}); diff --git a/base/tps/shared/webapps/tps/js/profile.js b/base/tps/shared/webapps/tps/js/profile.js new file mode 100644 index 000000000..0454686a9 --- /dev/null +++ b/base/tps/shared/webapps/tps/js/profile.js @@ -0,0 +1,109 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +var ProfileModel = Model.extend({ + urlRoot: "/tps/rest/profiles", + parseResponse: function(response) { + return { + id: response.id, + profileID: response.id, + status: response.Status, + properties: response.Properties.Property + }; + }, + createRequest: function(attributes) { + return { + id: attributes.profileID, + Status: attributes.status, + Properties: { + Property: attributes.properties + } + }; + }, + enable: function(options) { + var self = this; + $.ajax({ + type: "POST", + url: self.url() + "?action=enable", + dataType: "json" + }).done(function(data, textStatus, jqXHR) { + self.set(self.parseResponse(data)); + if (options.success) options.success.call(self, data, textStatus, jqXHR); + }).fail(function(jqXHR, textStatus, errorThrown) { + if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown); + }); + }, + disable: function(options) { + var self = this; + $.ajax({ + type: "POST", + url: self.url() + "?action=disable", + dataType: "json" + }).done(function(data, textStatus, jqXHR) { + self.set(self.parseResponse(data)); + if (options.success) options.success.call(self, data, textStatus, jqXHR); + }).fail(function(jqXHR, textStatus, errorThrown) { + if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown); + }); + } +}); + +var ProfileCollection = Collection.extend({ + urlRoot: "/tps/rest/profiles", + getEntries: function(response) { + return response.entries; + }, + getLinks: function(response) { + return response.Link; + }, + parseEntry: function(entry) { + return new ProfileModel({ + id: entry.id, + status: entry.Status + }); + } +}); + +var ProfilesTable = ModelTable.extend({ + initialize: function(options) { + var self = this; + ProfilesTable.__super__.initialize.call(self, options); + }, + add: function() { + var self = this; + + window.location.hash = "#new-profile"; + } +}); + +var ProfilesPage = Page.extend({ + load: function() { + var self = this; + + var table = new ProfilesTable({ + el: $("table[name='profiles']"), + collection: new ProfileCollection(), + parent: self + }); + + table.render(); + } +}); diff --git a/base/tps/shared/webapps/tps/js/selftest.js b/base/tps/shared/webapps/tps/js/selftest.js new file mode 100644 index 000000000..d28907817 --- /dev/null +++ b/base/tps/shared/webapps/tps/js/selftest.js @@ -0,0 +1,88 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +var SelfTestModel = Model.extend({ + urlRoot: "/tps/rest/selftests", + parseResponse: function(response) { + return { + id: response.id, + enabledAtStartup: response.EnabledAtStartup, + criticalAtStartup: response.CriticalAtStartup, + enabledOnDemand: response.EnabledOnDemand, + criticalOnDemand: response.CriticalOnDemand, + }; + }, + createRequest: function(attributes) { + return { + id: attributes.id, + EnabledAtStartup: attributes.enabledAtStartup, + CriticalAtStartup: attributes.criticalAtStartup, + EnabledOnDemand: attributes.enabledOnDemand, + CriticalOnDemand: attributes.criticalOnDemand + }; + } +}); + +var SelfTestCollection = Collection.extend({ + urlRoot: "/tps/rest/selftests", + getEntries: function(response) { + return response.entries; + }, + getLinks: function(response) { + return response.Link; + }, + parseEntry: function(entry) { + return new SelfTestModel({ + id: entry.id, + enabledAtStartup: entry.EnabledAtStartup, + criticalAtStartup: entry.CriticalAtStartup, + enabledOnDemand: entry.EnabledOnDemand, + criticalOnDemand: entry.CriticalOnDemand, + }); + } +}); + +var SelfTestPage = EntryPage.extend({ + initialize: function(options) { + var self = this; + SelfTestPage.__super__.initialize.call(self, options); + } +}); + +var SelfTestsTable = ModelTable.extend({ + initialize: function(options) { + var self = this; + SelfTestsTable.__super__.initialize.call(self, options); + } +}); + +var SelfTestsPage = Page.extend({ + load: function() { + var self = this; + + var table = new SelfTestsTable({ + el: $("table[name='selftests']"), + collection: new SelfTestCollection() + }); + + table.render(); + } +}); diff --git a/base/tps/shared/webapps/tps/js/token.js b/base/tps/shared/webapps/tps/js/token.js new file mode 100644 index 000000000..2ea17714e --- /dev/null +++ b/base/tps/shared/webapps/tps/js/token.js @@ -0,0 +1,258 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +var TokenStatus = { + UNINITIALIZED: "Uninitialized", + ACTIVE: "Active", + TEMP_LOST: "Temporarily lost", + PERM_LOST: "Permanently lost", + DAMAGED: "Physically damaged", + TERMINATED: "Terminated" +}; + +var TokenModel = Model.extend({ + urlRoot: "/tps/rest/tokens", + parseResponse: function(response) { + return { + id: response.id, + tokenID: response.TokenID, + userID: response.UserID, + type: response.Type, + status: response.Status, + statusLabel: TokenStatus[response.Status], + appletID: response.AppletID, + keyInfo: response.KeyInfo, + policy: response.Policy, + createTimestamp: response.CreateTimestamp, + modifyTimestamp: response.ModifyTimestamp + }; + }, + createRequest: function(attributes) { + return { + id: this.id, + TokenID: attributes.tokenID, + UserID: attributes.userID, + Type: attributes.type, + Status: attributes.status, + AppletID: attributes.appletID, + KeyInfo: attributes.keyInfo, + Policy: attributes.policy, + CreateTimestamp: attributes.createTimestamp, + ModifyTimestamp: attributes.modifyTimestamp + }; + }, + changeStatus: function(options) { + var self = this; + $.ajax({ + type: "POST", + url: self.url() + "?status=" + options.status, + dataType: "json" + }).done(function(data, textStatus, jqXHR) { + self.set(self.parseResponse(data)); + if (options.success) options.success.call(self, data, textStatus, jqXHR); + }).fail(function(jqXHR, textStatus, errorThrown) { + if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown); + }); + } +}); + +var TokenCollection = Collection.extend({ + model: TokenModel, + urlRoot: "/tps/rest/tokens", + getEntries: function(response) { + return response.entries; + }, + getLinks: function(response) { + return response.Link; + }, + parseEntry: function(entry) { + return new TokenModel({ + id: entry.id, + tokenID: entry.TokenID, + userID: entry.UserID, + type: entry.Type, + status: entry.Status, + statusLabel: TokenStatus[entry.Status], + appletID: entry.AppletID, + keyInfo: entry.KeyInfo, + policy: entry.Policy, + createTimestamp: entry.CreateTimestamp, + modifyTimestamp: entry.ModifyTimestamp + }); + } +}); + +var TokenPage = EntryPage.extend({ + initialize: function(options) { + var self = this; + TokenPage.__super__.initialize.call(self, options); + }, + setup: function() { + var self = this; + + TokenPage.__super__.setup.call(self); + + self.changeStatusLink = $("a[name='changeStatus']", self.menu); + + self.changeStatusLink.click(function(e) { + + e.preventDefault(); + + var dialog = new Dialog({ + el: $("#token-status-dialog"), + title: "Change Token Status", + readonly: ["tokenID"], + actions: ["cancel", "save"] + }); + + dialog.entry = _.clone(self.model.attributes); + + dialog.handler("save", function() { + + // save changes + dialog.save(); + + // check if the status was changed + if (dialog.entry.status != self.model.attributes.status) { + + self.model.changeStatus({ + status: dialog.entry.status, + success: function(data, textStatus, jqXHR) { + self.render(); + }, + error: function(jqXHR, textStatus, errorThrow) { + new ErrorDialog({ + el: $("#error-dialog"), + title: "HTTP Error " + jqXHR.responseJSON.Code, + content: jqXHR.responseJSON.Message + }).open(); + } + }); + } + + dialog.close(); + }); + + dialog.open(); + }); + }, + renderContent: function() { + var self = this; + + TokenPage.__super__.renderContent.call(self); + + if (self.mode == "add") { + self.changeStatusLink.hide(); + } else { + self.changeStatusLink.show(); + } + } +}); + +var TokenTableItem = TableItem.extend({ + initialize: function(options) { + var self = this; + TokenTableItem.__super__.initialize.call(self, options); + }, + renderColumn: function(td, templateTD) { + var self = this; + + TokenTableItem.__super__.renderColumn.call(self, td, templateTD); + + var name = td.attr("name"); + if (name == "status") { + $("a", td).click(function(e) { + e.preventDefault(); + self.editStatus(); + }); + } + }, + editStatus: function() { + var self = this; + + var model = self.table.collection.get(self.entry.id); + + var dialog = new Dialog({ + el: $("#token-status-dialog"), + title: "Change Token Status", + readonly: ["tokenID", "userID", "type", + "appletID", "keyInfo", "policy", + "createTimestamp", "modifyTimestamp"], + actions: ["cancel", "save"] + }); + + dialog.entry = _.clone(model.attributes); + + dialog.handler("save", function() { + + // save changes + dialog.save(); + + // check if the status was changed + if (dialog.entry.status != model.attributes.status) { + + model.changeStatus({ + status: dialog.entry.status, + success: function(data, textStatus, jqXHR) { + self.table.render(); + }, + error: function(jqXHR, textStatus, errorThrow) { + new ErrorDialog({ + el: $("#error-dialog"), + title: "HTTP Error " + jqXHR.responseJSON.Code, + content: jqXHR.responseJSON.Message + }).open(); + } + }); + } + + dialog.close(); + }); + + dialog.open(); + } +}); + +var TokensTable = ModelTable.extend({ + initialize: function(options) { + var self = this; + options.tableItem = TokenTableItem; + TokensTable.__super__.initialize.call(self, options); + }, + add: function() { + var self = this; + + window.location.hash = "#new-token"; + } +}); + +var TokensPage = Page.extend({ + load: function() { + var self = this; + + var table = new TokensTable({ + el: $("table[name='tokens']"), + collection: new TokenCollection() + }); + + table.render(); + } +}); diff --git a/base/tps/shared/webapps/tps/js/tps.js b/base/tps/shared/webapps/tps/js/tps.js new file mode 100644 index 000000000..476533759 --- /dev/null +++ b/base/tps/shared/webapps/tps/js/tps.js @@ -0,0 +1,231 @@ +/* --- 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 --- + * + * @author Endi S. Dewata + */ + +var PropertiesTableItem = TableItem.extend({ + initialize: function(options) { + var self = this; + PropertiesTableItem.__super__.initialize.call(self, options); + }, + get: function(name) { + var self = this; + + if (name.substring(0, 7) == "parent.") { + name = name.substring(7); + return self.table.parent.entry[name]; + } + + return PropertiesTableItem.__super__.get.call(self, name); + }, + renderColumn: function(td, templateTD) { + var self = this; + + PropertiesTableItem.__super__.renderColumn.call(self, td, templateTD); + + $("a", td).click(function(e) { + e.preventDefault(); + self.open(); + }); + }, + open: function() { + var self = this; + + var dialog; + + if (self.table.mode == "view") { + // In view mode all properties are read-only. + dialog = new Dialog({ + el: self.table.parent.$("#property-dialog"), + title: "Property", + readonly: ["name", "value"], + actions: ["close"] + }); + + } else { + // In edit mode all properties are editable. + dialog = new Dialog({ + el: self.table.parent.$("#property-dialog"), + title: "Edit Property", + readonly: ["name"], + actions: ["cancel", "save"] + }); + + dialog.handler("save", function() { + + // save changes + dialog.save(); + _.extend(self.entry, dialog.entry); + + // redraw table + self.table.render(); + dialog.close(); + }); + } + + dialog.entry = _.clone(self.entry); + + dialog.open(); + } +}); + +var PropertiesTable = Table.extend({ + initialize: function(options) { + var self = this; + options.columnMappings = { + id: "name" + }; + PropertiesTable.__super__.initialize.call(self, options); + }, + sort: function() { + var self = this; + + // sort properties by name + self.filteredEntries = _.sortBy(self.filteredEntries, function(entry) { + return entry.name; + }); + }, + remove: function(items) { + var self = this; + + // remove selected entries + self.entries = _.reject(self.entries, function(entry) { + return _.contains(items, entry.name); + }); + + // redraw table + self.render(); + } +}); + +var ConfigEntryPage = EntryPage.extend({ + initialize: function(options) { + var self = this; + ConfigEntryPage.__super__.initialize.call(self, options); + self.tableItem = options.tableItem || PropertiesTableItem; + self.tableSize = options.tableSize || 10; + }, + setup: function() { + var self = this; + + ConfigEntryPage.__super__.setup.call(self); + + self.enableLink = $("a[name='enable']", self.menu); + self.disableLink = $("a[name='disable']", self.menu); + + self.enableLink.click(function(e) { + + e.preventDefault(); + + var message = "Are you sure you want to enable this entry?"; + if (!confirm(message)) return; + self.model.enable({ + success: function(data, textStatus, jqXHR) { + self.entry = _.clone(self.model.attributes); + self.render(); + }, + error: function(jqXHR, textStatus, errorThrown) { + new ErrorDialog({ + el: $("#error-dialog"), + title: "HTTP Error " + jqXHR.responseJSON.Code, + content: jqXHR.responseJSON.Message + }).open(); + } + }); + }); + + self.disableLink.click(function(e) { + + e.preventDefault(); + + var message = "Are you sure you want to disable this entry?"; + if (!confirm(message)) return; + self.model.disable({ + success: function(data, textStatus, jqXHR) { + self.entry = _.clone(self.model.attributes); + self.render(); + }, + error: function(jqXHR, textStatus, errorThrown) { + new ErrorDialog({ + el: $("#error-dialog"), + title: "HTTP Error " + jqXHR.responseJSON.Code, + content: jqXHR.responseJSON.Message + }).open(); + } + }); + }); + + var dialog = self.$("#property-dialog"); + + var addDialog = new Dialog({ + el: dialog, + title: "Add Property", + actions: ["cancel", "add"] + }); + + var table = self.$("table[name='properties']"); + self.addButton = $("button[name='add']", table); + self.removeButton = $("button[name='remove']", table); + + self.propertiesTable = new PropertiesTable({ + el: table, + addDialog: addDialog, + tableItem: self.tableItem, + pageSize: self.tableSize, + parent: self + }); + }, + renderContent: function() { + var self = this; + + ConfigEntryPage.__super__.renderContent.call(self); + + var status = self.entry.status; + if (status == "Disabled") { + self.enableLink.show(); + self.disableLink.hide(); + + } else if (status == "Enabled") { + self.enableLink.hide(); + self.disableLink.show(); + } + + if (self.mode == "add") { + self.propertiesTable.mode = "edit"; + self.propertiesTable.entries = []; + + } else if (self.mode == "edit") { + self.propertiesTable.mode = "edit"; + self.propertiesTable.entries = self.entry.properties; + + } else { // self.mode == "view" + self.propertiesTable.mode = "view"; + self.propertiesTable.entries = self.entry.properties; + } + + self.propertiesTable.render(); + }, + saveFields: function() { + var self = this; + + ConfigEntryPage.__super__.saveFields.call(self); + + self.entry.properties = self.propertiesTable.entries; + } +}); diff --git a/base/tps/shared/webapps/tps/js/user.js b/base/tps/shared/webapps/tps/js/user.js new file mode 100644 index 000000000..3a29f1dd1 --- /dev/null +++ b/base/tps/shared/webapps/tps/js/user.js @@ -0,0 +1,150 @@ +/* --- 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) 2013 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + * + * @author Endi S. Dewata + */ + +var UserModel = Model.extend({ + urlRoot: "/tps/rest/admin/users", + parseResponse: function(response) { + + var attrs = {}; + if (response.Attributes) { + var attributes = response.Attributes.Attribute; + attributes = attributes == undefined ? [] : [].concat(attributes); + + _(attributes).each(function(attribute) { + var name = attribute.name; + var value = attribute.value; + attrs[name] = value; + }); + } + + return { + id: response.id, + userID: response.UserID, + fullName: response.FullName, + email: response.Email, + state: response.State, + type: response.Type, + attributes: attrs + }; + }, + createRequest: function(attributes) { + var attrs = []; + _(attributes.attributes).each(function(value, name) { + attrs.push({ + name: name, + value: value + }); + }); + + return { + id: this.id, + UserID: attributes.userID, + FullName: attributes.fullName, + Email: attributes.email, + State: attributes.state, + Type: attributes.type, + Attributes: { + Attribute: attrs + } + }; + } +}); + +var UserCollection = Collection.extend({ + model: UserModel, + urlRoot: "/tps/rest/admin/users", + getEntries: function(response) { + return response.entries; + }, + getLinks: function(response) { + return response.Link; + }, + parseEntry: function(entry) { + return new UserModel({ + id: entry.id, + userID: entry.UserID, + fullName: entry.FullName + }); + } +}); + +var UserPage = EntryPage.extend({ + initialize: function(options) { + var self = this; + UserPage.__super__.initialize.call(self, options); + }, + loadField: function(input) { + var self = this; + + var name = input.attr("name"); + if (name != "tpsProfiles") { + UserPage.__super__.loadField.call(self, input); + return; + } + + var attributes = self.entry.attributes; + if (attributes) { + var value = attributes.tpsProfiles; + input.val(value); + } + }, + saveField: function(input) { + var self = this; + + var name = input.attr("name"); + if (name != "tpsProfiles") { + UserPage.__super__.saveField.call(self, input); + return; + } + + var attributes = self.entry.attributes; + if (attributes == undefined) { + attributes = {}; + self.entry.attributes = attributes; + } + attributes.tpsProfiles = input.val(); + } +}); + +var UsersTable = ModelTable.extend({ + initialize: function(options) { + var self = this; + UsersTable.__super__.initialize.call(self, options); + }, + add: function() { + var self = this; + + window.location.hash = "#new-user"; + } +}); + +var UsersPage = Page.extend({ + load: function() { + var self = this; + + var table = new UsersTable({ + el: $("table[name='users']"), + collection: new UserCollection() + }); + + table.render(); + } +}); |