From d99ebc0f3798c84e612c79c43eb85c31b20ab1ce Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Tue, 2 Nov 2010 20:16:55 -0500 Subject: HBAC Details Page The UI framework has been extended to include a collection of widgets: - ipa_widget: base class - ipa_text_widget: text field - ipa_radio_widget: radio button - ipa_textarea_widget: textarea - ipa_button_widget: button - ipa_column_widget: column for table - ipa_table_widget: table These widgets can be used to create input controls. They can also be extended to create custom controls. The framework has also been enhanced to support custom layouts. This can be used to change the look of the application without changing the code. Initially this is only available in details section. Layout consists of a collection of HTML templates. Each template is a complete and valid HTML file representing a portion of a page. The template will be loaded and initialized by the code, then filled with the data from the server. The layouts are located in install/static/layouts/ folder. By default, if no templates are used, the fields in the details page are rendered vertically using dd/dt/dd tags. For pages that require different layout, a custom UI needs to be developed. There are two ways to do that: - write a custom widget to generate the UI dynamically - create an HTML template and write the initialization code For components that are quite complex or used frequently, it's might be better to use the first method. For simple pages that are used only in one location or need to support customization, the second method might be preferable. Other benefits of templates: - cleaner code and UI separation - more flexibility in customization - new pages can be developed quickly and require less coding - multiple templates can be used with the same initialization code - easier to maintain The HBAC details page has been implemented using both methods. By default it will use custom widgets to generate the page. To use a custom layout, add the following parameter to the URL, then reload the page: &layout= Currently the only available layout is 'default' which produces the same look as the custom widgets. The HBAC details page is usable, but it still needs additional work. The access time is not working yet. There is no undo button, hint, or validation yet. The table in the association facet has also been changed to use ipa_association_widget which is derived from ipa_table_widget. The Makefile has been updated to include the layouts. The unit tests have been updated as well. --- install/static/widget.js | 473 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 473 insertions(+) create mode 100755 install/static/widget.js (limited to 'install/static/widget.js') diff --git a/install/static/widget.js b/install/static/widget.js new file mode 100755 index 00000000..bf893e04 --- /dev/null +++ b/install/static/widget.js @@ -0,0 +1,473 @@ +/* Authors: + * Endi Sukma Dewata + * + * Copyright (C) 2010 Red Hat + * see file 'COPYING' for use and warranty information + * + * 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 only + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* REQUIRES: ipa.js */ + +function ipa_widget(spec) { + + spec = spec || {}; + + var that = {}; + + that.id = spec.id; + that.name = spec.name; + that.label = spec.label; + that.read_only = spec.read_only; + that._entity_name = spec.entity_name; + + that.create = spec.create || create; + that.setup = spec.setup || setup; + that.load = spec.load || load; + that.save = spec.save || save; + + that.super = function(name) { + var method = that[name]; + return function () { + return method.apply(that, arguments); + }; + }; + + that.__defineGetter__("entity_name", function(){ + return that._entity_name; + }); + + that.__defineSetter__("entity_name", function(entity_name){ + that._entity_name = entity_name; + }); + + function create(container) { + } + + function setup(container) { + } + + function load(container, result) { + } + + function save(container) { + return []; + } + + return that; +} + +function ipa_text_widget(spec) { + + spec = spec || {}; + + spec.setup = spec.setup || setup; + spec.load = spec.load || load; + spec.save = spec.save || save; + + var that = ipa_widget(spec); + + function setup(container) { + } + + function load(container, result) { + that.value = result[that.name] || ''; + var input = $('input[name="'+that.name+'"]', container); + + var param_info = ipa_get_param_info(that.entity_name, that.name); + if (param_info.primary_key) { + input.replaceWith($('