# Copyright (c) 2008-2009 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: ListQueryForm.pm,v 2.6 2010/01/23 23:51:54 nagler Exp $ package Bivio::Biz::Model::ListQueryForm; use strict; use Bivio::Base 'Model.QuerySearchBaseForm'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.6 $ =~ /\d+/g); sub filter_keys { my($self) = @_; return [qr{^b_\w+$}]; } sub get_list_for_field { my($proto, $field) = @_; # defaults to List, subclasses can override this return $proto->get_instance( $proto->get_instance->get_field_type($field) ->simple_package_name . 'List'); } sub get_select_attrs { my($proto, $field) = @_; my($t) = $proto->get_instance->get_field_type($field); return { choices => $t, enum_sort => 'as_int', field => $field, } if $t->isa('Bivio::Type::Enum'); return { field => $field, choices => [sub { my($source, $proto, $field) = @_; return $source->req($proto->get_list_for_field($field) ->package_name); }, $proto, $field], list_display_field => $proto->get_list_for_field($field) ->get_info('order_by_names')->[0] || b_die($field, ': must have at least one order_by'), }; } sub internal_initialize { my($self) = @_; return $self->merge_initialize_info($self->SUPER::internal_initialize, { version => 1, visible => [ map({ my($n, $t, $overrides) = @$_; $t = Bivio::Type->get_instance($t); +{ name => $n, form_name => $n, type => $t, default_value => UNIVERSAL::isa($t, 'Bivio::Type::Enum') ? $t->get_default : undef, constraint => 'NONE', %{$overrides || {}}, }; } @{$self->internal_query_fields}), ], }); } 1;