diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2011-11-22 17:33:09 +0100 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2011-12-05 16:00:50 +0000 |
commit | e0215421208d853e853f9c7b66add1e145982fbc (patch) | |
tree | f2d9d495dbe4f839f5b65a3348c0e11f8ac25d9a /install/ui/widget.js | |
parent | 6cdf09812dd13531acb29f1413de87ce7cd5218f (diff) | |
download | freeipa.git-e0215421208d853e853f9c7b66add1e145982fbc.tar.gz freeipa.git-e0215421208d853e853f9c7b66add1e145982fbc.tar.xz freeipa.git-e0215421208d853e853f9c7b66add1e145982fbc.zip |
Removing sections as special type of object
Sections are changed into pure widget objects. Introduced IPA.composite_widget, basic widget for widget nesting (it's using IPA.widget_container). It's base class for section widgets.
TODO: change old custom sections into custom fields and widgets.
Note: usage of section in HBAC and SUDO is kept - whole logic will be removed in #1515 patch.
https://fedorahosted.org/freeipa/ticket/2040
Diffstat (limited to 'install/ui/widget.js')
-rw-r--r-- | install/ui/widget.js | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/install/ui/widget.js b/install/ui/widget.js index 1a5696b9..e6213951 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -1786,6 +1786,171 @@ IPA.button = function(spec) { return button; }; +IPA.composite_widget = function(spec) { + + spec = spec || {}; + + var that = IPA.widget(spec); + + that.widgets = IPA.widget_container(); + + that.create = function(container) { + + that.widget_create(container); + that.widgets.create(container); + }; + + that.clear = function() { + + var widgets = that.widgets.get_widgets(); + + for (var i=0; i< widgets.length; i++) { + widgets[i].clear(); + } + }; + + that.composite_widget_create = that.create; + that.composite_widget_clear = that.clear; + + return that; +}; + +IPA.collapsible_section = function(spec) { + + spec = spec || {}; + + var that = IPA.composite_widget(spec); + + that.create = function(container) { + + that.header = $('<h2/>', { + name: that.name, + title: that.label + }).appendTo(container); + + that.icon = $('<span/>', { + name: 'icon', + 'class': 'icon section-expand '+IPA.expanded_icon + }).appendTo(that.header); + + that.header.append(' '); + + that.header.append(that.label); + + that.content_container = $('<div/>', { + name: that.name, + 'class': 'details-section' + }).appendTo(container); + + that.header.click(function() { + var visible = that.content_container.is(":visible"); + that.toggle(!visible); + }); + + that.composite_widget_create(that.content_container); + }; + + that.toggle = function(visible) { + + that.icon.toggleClass(IPA.expanded_icon, visible); + that.icon.toggleClass(IPA.collapsed_icon, !visible); + + if (visible != that.content_container.is(":visible")) { + that.content_container.slideToggle('slow'); + } + }; + + return that; +}; + +IPA.details_section = IPA.collapsible_section; + +IPA.details_table_section = function(spec) { + + spec = spec || {}; + + var that = IPA.details_section(spec); + + that.rows = $.ordered_map(); + + that.composite_widget_create = function(container) { + + var table = $('<table/>', { + 'class': 'section-table' + }).appendTo(container); + + var widgets = that.widgets.get_widgets(); + for (var i=0; i<widgets.length; i++) { + var widget = widgets[i]; + var tr = $('<tr/>'); + that.add_row(widget.name, tr); + + if (widget.hidden) { + tr.css('display', 'none'); + } + + tr.appendTo(table); + + var td = $('<td/>', { + 'class': 'section-cell-label', + title: widget.label + }).appendTo(tr); + + $('<label/>', { + name: widget.name, + 'class': 'field-label', + text: widget.label+':' + }).appendTo(td); + + if(widget.create_required) { + widget.create_required(td); + } + + td = $('<td/>', { + 'class': 'section-cell-field', + title: widget.label + }).appendTo(tr); + + var widget_container = $('<div/>', { + name: widget.name, + 'class': 'field' + }).appendTo(td); + + widget.create(widget_container); + } + }; + + + that.add_row = function(name, row) { + that.rows.put(name, row); + }; + + that.get_row = function(name) { + return that.rows.get(name); + }; + + that.set_row_visible = function(name, visible) { + var row = that.get_row(name); + row.css('display', visible ? '' : 'none'); + }; + + that.table_section_create = that.composite_widget_create; + + return that; +}; + +//non-collabsible section +IPA.details_table_section_nc = function(spec) { + + spec = spec || {}; + + var that = IPA.details_table_section(spec); + + that.create = that.table_section_create; + + return that; +}; + IPA.observer = function(spec) { var that = {}; |