/*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.expand_icon = 'ui-icon-minus'; IPA.collapse_icon = 'ui-icon-plus'; IPA.details_section = function(spec) { spec = spec || {}; var that = {}; that.name = spec.name || ''; that.label = spec.label || ''; that.template = spec.template; that._entity_name = spec.entity_name; that.fields = []; that.fields_by_name = {}; that.__defineGetter__('entity_name', function() { return that._entity_name; }); that.__defineSetter__('entity_name', function(entity_name) { that._entity_name = entity_name; for (var i=0; i', { 'name': field.name }).appendTo(container); field.create(span); } }; that.setup = function(container) { that.container = container; if (that.template) return; var fields = that.fields; for (var i = 0; i < fields.length; ++i) { var field = fields[i]; var span = $('span[name='+field.name+']', this.container).first(); field.setup(span); } }; that.load = function(record) { that.record = record; var fields = that.fields; if (that.template) { var template = IPA.get_template(that.template); this.container.load( template, function(data, text_status, xhr) { for (var i = 0; i < fields.length; ++i) { var field = fields[i]; var span = $('span[name='+field.name+']', this.container).first(); field.setup(span); field.load(record); } } ); return; } 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) { // do not call section_create() here if (that.template) return; var dl = $('
', { 'id': that.name, 'class': 'entryattrs' }).appendTo(container); var fields = that.fields; for (var i = 0; i < fields.length; ++i) { var field = fields[i]; var label = field.label || ''; $('
', { html: label+':', title: label }).appendTo(dl); var dd = $('
', { 'class': 'first' }).appendTo(dl); var span = $('', { 'name': field.name }).appendTo(dd); field.create(span); } }; return that; }; /* shorthand notation used for declarative definitions of details pages */ IPA.stanza = function(spec) { spec = spec || {}; var that = IPA.details_list_section(spec); // This is to allow declarative style programming for details that.input = function(spec) { that.text(spec); return that; }; that.custom_input = function(input) { that.add_field(input); return that; }; return that; }; IPA.details_facet = function(spec) { spec = spec || {}; spec.name = spec.name || 'details'; var that = IPA.facet(spec); that.label = ( IPA.messages && IPA.messages.facets && IPA.messages.facets.details) || spec.label; that.is_dirty = spec.is_dirty || is_dirty; that.create = spec.create || create; that.setup = spec.setup || setup; that.load = spec.load || load; that.update = spec.update || IPA.details_update; that.reset = spec.reset || reset; that.refresh = spec.refresh || IPA.details_refresh; that.sections = []; that.__defineGetter__("entity_name", function(){ return that._entity_name; }); that.__defineSetter__("entity_name", function(entity_name){ that._entity_name = entity_name; for (var i=0; i',{ html: ""+title }).append(IPA.create_network_spinner()). appendTo(container); var details = $('
', { 'class': 'content' }).appendTo(container); $('', { name: 'expand_all', href: 'expand_all', text: 'Expand All', 'class': 'expand-collapse-all', style: 'display: none;' }).appendTo(details); $('', { name: 'collapse_all', href: 'collapse_all', text: 'Collapse All', 'class': 'expand-collapse-all' }).appendTo(details); details.append('
'); var action_panel = that.get_action_panel(); var ul = $('ul', action_panel); var buttons = $('.action-controls',action_panel); $('', { 'type': 'text', 'name': 'reset' }).appendTo(buttons); $('', { 'type': 'text', 'name': 'update' }).appendTo(buttons); for (var i = 0; i < that.sections.length; ++i) { var section = that.sections[i]; var header = $('

', { name: section.name, title: section.label }).appendTo(details); var icon = $('', { name: 'icon', 'class': 'ui-icon section-expand '+IPA.expand_icon }).appendTo(header); header.append(' '); header.append(section.label); var div = $('
', { name: section.name, 'class': 'details-section' }).appendTo(details); section.create(div); details.append('
'); } } function setup(container) { that.facet_setup(container); var button = $('input[name=reset]', that.container); that.reset_button = IPA.action_button({ 'label': 'Reset', 'icon': 'ui-icon-refresh', 'class': 'details-reset', 'click': function() { that.reset(); return false; } }); button.replaceWith(that.reset_button); button = $('input[name=update]', that.container); that.update_button = IPA.action_button({ 'label': 'Update', 'icon': 'ui-icon-check', 'class': 'details-update', 'click': function() { that.update(); return false; } }); button.replaceWith(that.update_button); var details = $('div.content', that.container); var expand_all = $('a[name=expand_all]', details); expand_all.click(function() { expand_all.css('display', 'none'); collapse_all.css('display', 'inline'); for (var i=0; i', { id: spec.id, html: spec.label, title: spec.title || spec.label, 'class': 'ui-state-default ui-corner-all' }); if (spec.click) { button.click(spec.click); } if (spec['class']) button.addClass(spec['class']); if (spec.icon) { button.addClass('input_link'); button.append(' '); } else { button.addClass('button-without-icon'); } return button; }; IPA.details_refresh = function() { var that = this; that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) ; var command = IPA.command({ method: that.entity_name+'_show', args: [], options: { 'all': true, 'rights': true } }); if (that.pkey){ command.args = [that.pkey]; } command.on_success = function(data, text_status, xhr) { that.load(data.result.result); }; command.on_error = function(xhr, text_status, error_thrown) { var details = $('.details', that.container).empty(); details.append('

Error: '+error_thrown.name+'

'); details.append('

'+error_thrown.title+'

'); details.append('

'+error_thrown.message+'

'); }; command.execute(); }; IPA.details_update = function(on_win, on_fail) { var that = this; var entity_name = that.entity_name; function on_success(data, text_status, xhr) { if (on_win) on_win(data, text_status, xhr); if (data.error) return; var result = data.result.result; that.load(result); } function on_error(xhr, text_status, error_thrown) { if (on_fail) on_fail(xhr, text_status, error_thrown); } var values; var modlist = {'all': true, 'setattr': [], 'addattr': [], 'rights': true}; var attrs_wo_option = {}; for (var i=0; i 1){ if (field.join) { modlist[field.name] = values.join(','); } else { modlist[field.name] = values; } } else if (param_info['multivalue']){ modlist[field.name] = []; } } else { if (values.length) attrs_wo_option[field.name] = values; } } } for (var attr in attrs_wo_option) { values = attrs_wo_option[attr]; modlist['setattr'].push(attr + '=' + values[0]); for (var k = 1; k < values.length; ++k){ modlist['addattr'].push(attr + '=' + values[k]); } } var pkey = that.get_primary_key(); var args = pkey ? [pkey] : []; var command = IPA.command({ method: entity_name+'_mod', args: args, options: modlist, on_success: on_success, on_error: on_error }); //alert(JSON.stringify(command.to_json())); command.execute(); };