# Copyright (c) 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: FormModeBaseForm.pm,v 2.1 2010/12/25 22:38:15 nagler Exp $ package Bivio::Biz::Model::FormModeBaseForm; use strict; use Bivio::Base 'Biz.FormModel'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.1 $ =~ /\d+/g); my($_FM) = b_use('Type.FormMode'); sub execute_empty { return _dispatch(@_); } sub execute_ok { return _dispatch(@_); } sub internal_initialize { my($self) = @_; return $self->merge_initialize_info($self->SUPER::internal_initialize, { version => 1, other => [ $self->field_decl([ [qw(form_mode FormMode)], ['list_model', 'Model.' . $self->LIST_MODEL], ]), ], }); } sub internal_pre_execute { my($self) = @_; my(@res) = shift->SUPER::internal_pre_execute(@_); my($lm) = $self->new_other($self->LIST_MODEL); my($fm) = $_FM->setup_by_list_this($lm, $self->PROPERTY_MODEL); $self->internal_put_field( map( ($_ => $lm->get($_)), @{$lm->get_info('primary_key_names')}, ), ) if $fm->eq_edit; $self->internal_put_field( form_mode => $fm, list_model => $lm, ); return @res; } sub is_create { return shift->get('form_mode')->eq_create; } sub is_edit { return shift->get('form_mode')->eq_edit; } sub _dispatch { my($self) = shift; my($method) = $self->my_caller . ($self->get('form_mode')->eq_edit ? '_edit' : '_create'); return $self->$method(@_); } 1;