# Copyright (c) 1999-2010 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: StandardSubmit.pm,v 2.4 2010/09/08 21:51:33 nagler Exp $ package Bivio::UI::HTML::Widget::StandardSubmit; use strict; use Bivio::Base 'HTMLWidget.Grid'; use Bivio::UI::ViewLanguageAUTOLOAD; # C Draws buttons associated with # the form. By default, the ok_button and cancel_button are rendered. Use # the buttons attribute to display an alternative. # # # # buttons : array_ref [] # # The buttons to render. If not specified, then ok_button and cancel_button # are rendered. # # form_model : array_ref (required, inherited, get_request) # # Which form are we dealing with. # # labels : hash_ref [] # # Mapping of button field names to labels. A button label defaults to its # field name. our($VERSION) = sprintf('%d.%02d', q$Revision: 2.4 $ =~ /\d+/g); my($_IDI) = __PACKAGE__->instance_data_index; my($_SEPARATION) = 10; sub initialize { # (self) : undef # Initialize grid. my($self) = @_; my($fields) = $self->[$_IDI]; return if $fields->{initialized}; $fields->{initialized} = 1; # load the grid with buttons my($values) = []; my($buttons) = $self->unsafe_get('buttons') || ['ok_button', 'cancel_button']; my($factory) = 'Bivio::UI::HTML::WidgetFactory'; Bivio::IO::ClassLoader->simple_require($factory); my($form) = Bivio::Biz::Model->get_instance( $self->ancestral_get('form_class')); my($labels) = $self->unsafe_get('labels') || {}; foreach my $button (reverse(@$buttons)) { unshift(@$values, $factory->create(ref($form).".$button", { attributes => $form->get_field_type($button)->isa( 'Bivio::Type::CancelButton') ? 'onclick="reset()"' : '', label => vs_text($form->simple_package_name, $labels->{$button} || $button), })); unshift(@$values, ClearDot()->as_html($_SEPARATION)) unless $button eq $buttons->[0]; } $self->put(values => [$values]); $self->SUPER::initialize; return; } sub internal_new_args { # (proto, any, ...) : any # Implements positional argument parsing for L. my(undef, $buttons, $attributes) = @_; return '"buttons" attribute must be defined' unless defined($buttons); return '"buttons" must be an array_ref' unless ref($buttons) eq 'ARRAY'; return { buttons => $buttons, ($attributes ? %$attributes : ()), }; } sub new { # (proto, array_ref, hash_ref) : Widget.StandardSubmit # (proto, hash_ref) : Widget.StandardSubmit # List of I can be supplied with options I. # # # Creates a new StandardSubmit widget from I. my($self) = shift->SUPER::new(@_); $self->[$_IDI] = {}; return $self; } 1;