/* --- 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, 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, 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 UserProfilesTableItem = TableItem.extend({ initialize: function(options) { var self = this; UserProfilesTableItem.__super__.initialize.call(self, options); }, renderColumn: function(td, templateTD) { var self = this; UserProfilesTableItem.__super__.renderColumn.call(self, td, templateTD); $("a", td).click(function(e) { e.preventDefault(); self.table.open(self); }); } }); var UserProfilesTable = Table.extend({ initialize: function(options) { var self = this; options.tableItem = UserProfilesTableItem; UserProfilesTable.__super__.initialize.call(self, options); }, sort: function() { var self = this; // sort profiles by id self.filteredEntries = _.sortBy(self.filteredEntries, function(entry) { return entry.id; }); }, add: function() { var self = this; profiles = new ProfileCollection(); profiles.fetch({ success: function(collection, response, options) { var dialog = self.addDialog; var select = dialog.$(".modal-body select").empty(); $('