/*jsl:import ipa.js */ /* Authors: * Pavel Zuna * Adam Young * Endi S. 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, either version 3 of the License, or * (at your option) any later version. * * 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, see . */ /* IPA Object Details - populating definiton lists from entry data */ /* REQUIRES: ipa.js */ IPA.expanded_icon = 'expanded-icon'; IPA.collapsed_icon = 'collapsed-icon'; IPA.details_section = function(spec) { spec = spec || {}; var that = {}; that.name = spec.name || ''; that.label = spec.label || ''; that.entity = spec.entity; that.fields = $.ordered_map(); that.dirty = false; that.dirty_changed = IPA.observer(); that.get_field = function(name) { return that.fields.get(name); }; that.add_field = function(field) { field.entity = that.entity; that.fields.put(field.name, field); field.dirty_changed.attach(that.field_dirty_changed); return field; }; that.field = function(field) { that.add_field(field); return that; }; that.text = function(spec) { spec.entity = that.entity; var field = IPA.text_widget(spec); that.add_field(field); return that; }; that.multivalued_text = function(spec) { spec.entity = that.entity; var field = IPA.multivalued_text_widget(spec); that.add_field(field); return that; }; that.textarea = function(spec) { spec.entity = that.entity; var field = IPA.textarea_widget(spec); that.add_field(field); return that; }; that.radio = function(spec) { spec.entity = that.entity; var field = IPA.radio_widget(spec); that.add_field(field); return that; }; that.create = function(container) { that.container = container; var fields = that.fields.values; for (var i=0; i', { name: field.name, 'class': 'details-field' }).appendTo(container); field.create(field_container); } }; that.load = function(record) { that.record = record; var fields = that.fields.values; for (var j=0; j tag. * The attribute name is defined inside a
tag. The attribute * value is specified within a inside a
tag. If the * attribute has multiple values the will contain be * duplicated to display each value. * * Example: *
* *
First Name:
*
* * John Smith * *
* *
Telephone Number:
*
* *
111-1111
*
222-2222
*
*
* *
*/ IPA.details_list_section = function(spec) { spec = spec || {}; var that = IPA.details_section(spec); that.create = function(container) { that.container = container; // do not call section_create() here var dl = $('
', { 'id': that.name, 'class': 'entryattrs' }).appendTo(container); var fields = that.fields.values; for (var i=0; i', { html: label+':', title: label }).appendTo(dl); var dd = $('
').appendTo(dl); var field_container = $('
', { name: field.name, 'class': 'details-field' }).appendTo(dd); field.create(field_container); } }; that.list_section_create = that.create; return that; }; IPA.details_facet = function(spec) { spec = spec || {}; spec.name = spec.name || 'details'; var that = IPA.facet(spec); that.entity = spec.entity; that.pre_execute_hook = spec.pre_execute_hook; that.post_update_hook = spec.post_update_hook; that.label = spec.label || IPA.messages && IPA.messages.facets && IPA.messages.facets.details; that.facet_group = spec.facet_group || 'settings'; that.sections = $.ordered_map(); that.dirty = false; that.add_section = function(section) { section.entity = that.entity; that.sections.put(section.name, section); section.dirty_changed.attach(that.section_dirty_changed); return section; }; that.get_section = function(name) { return that.sections.get(name); }; that.create_section = function(spec) { spec.entity = that.entity; var section = IPA.details_section(spec); that.add_section(section); return section; }; /* the primary key used for show and update is built as an array. for most entities, this will be a single element long, but for some it requires the containing entities primary keys as well.*/ that.get_primary_key = function(from_url) { var pkey = that.entity.get_primary_key_prefix(); if (from_url) { pkey.push(that.pkey); } else { var pkey_name = that.entity.metadata.primary_key; if (!pkey_name){ return pkey; } var pkey_val = that.data[pkey_name]; if (pkey_val instanceof Array) { pkey.push(pkey_val[0]); } else { pkey.push(pkey_val); } } return pkey; }; that.create = function(container) { if (that.entity.facets.length == 1) { if (that.disable_breadcrumb === undefined) { that.disable_breadcrumb = true; } if (that.disable_facet_tabs === undefined) { that.disable_facet_tabs = true; } } that.facet_create(container); }; that.create_controls = function() { that.reset_button = IPA.action_button({ name: 'reset', label: IPA.messages.buttons.reset, icon: 'reset-icon', 'class': 'details-reset action-button-disabled', click: function() { if(!that.update_button.hasClass('action-button-disabled')) { that.reset(); } return false; } }).appendTo(that.controls); that.update_button = IPA.action_button({ name: 'update', label: IPA.messages.buttons.update, icon: 'update-icon', 'class': 'details-update action-button-disabled', click: function() { if(!that.update_button.hasClass('action-button-disabled')) { that.update(); } return false; } }).appendTo(that.controls); }; that.create_header = function(container) { that.facet_create_header(container); that.pkey = IPA.nav.get_state(that.entity.name+'-pkey'); that.create_controls(); that.expand_button = IPA.action_button({ name: 'expand_all', href: 'expand_all', label: IPA.messages.details.expand_all, 'class': 'right-aligned-facet-controls', style: 'display: none;', click: function() { that.expand_button.css('display', 'none'); that.collapse_button.css('display', 'inline'); var sections = that.sections.values; for (var i=0; i', { 'class': 'details-content' }).appendTo(container); var sections = that.sections.values; for (var i=0; i', { name: section.name, title: section.label }).appendTo(that.content); var icon = $('', { name: 'icon', 'class': 'icon section-expand '+IPA.expanded_icon }).appendTo(header); header.append(' '); header.append(section.label); var div = $('
', { name: section.name, 'class': 'details-section' }).appendTo(that.content); header.click(function(section, div) { return function() { var visible = div.is(":visible"); that.toggle(section, !visible); }; }(section, div)); section.create(div); if (i < sections.length-1) { that.content.append('
'); } } $('', { name: 'summary', 'class': 'details-summary' }).appendTo(container); }; that.show = function() { that.facet_show(); that.pkey = IPA.nav.get_state(that.entity.name+'-pkey'); that.header.set_pkey(that.pkey); }; that.toggle = function(section, visible) { var header = $('h2[name='+section.name+']', that.container); var icon = $('span[name=icon]', header); icon.toggleClass(IPA.expanded_icon, visible); icon.toggleClass(IPA.collapsed_icon, !visible); var div = section.container; if (visible != div.is(":visible")) { div.slideToggle('slow'); } }; that.needs_update = function() { var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); return pkey != that.pkey; }; that.section_dirty_changed = function(dirty) { if(dirty) { that.dirty = true; } else { that.dirty = that.is_dirty(); } that.enable_update(that.dirty); }; that.is_dirty = function() { var sections = that.sections.values; for (var i=0; i