fix template parser and attachments fields

This commit is contained in:
Doug Bell 2011-07-06 19:16:01 -05:00
parent cc26d97805
commit d15891dbb9
2 changed files with 33 additions and 44 deletions

View file

@ -58,7 +58,14 @@ property parser => (
fieldType => 'selectBox',
lazy => 1,
builder => '_default_parser',
lazy => 1,
options => sub {
my $self = shift;
my $session = $self->session;
tie my %parsers, 'Tie::IxHash';
for my $class ( @{$session->config->get('templateParsers')} ) {
$parsers{$class} = $self->getParser($session, $class)->getName();
}
},
);
sub _default_parser {
my $self = shift;
@ -107,7 +114,25 @@ property storageIdExample => (
property attachmentsJson => (
fieldType => 'JsonTable',
label => [ "attachments display label", "Asset_Template" ],
label => [ "attachment display label", "Asset_Template" ],
fields => [
{
type => "text",
name => "url",
label => [ 'attachment header url', 'Asset_Template' ],
size => '48',
},
{
type => "select",
name => "type",
label => ['attachment header type','Asset_Template'],
options => [
stylesheet => ['css label','Asset_Template'],
headScript => ['js head label','Asset_Template'],
bodyScript => ['js body label','Asset_Template'],
],
},
],
);
use WebGUI::International;
@ -417,47 +442,6 @@ override getEditForm => sub {
templatePreview.js
);
if($session->config->get("templateParsers")){
my @temparray = @{$session->config->get("templateParsers")};
tie my %parsers, 'Tie::IxHash';
while(my $a = shift @temparray){
$parsers{$a} = $self->getParser($session, $a)->getName();
}
my $value = [$self->parser];
$value = \[$session->config->get("defaultTemplateParser")] if(!$self->parser);
$tabform->getTab("properties")->addField( "SelectBox",
name=>"parser",
options=>\%parsers,
value=>$value,
label=>$i18n->get('parser'),
hoverHelp=>$i18n->get('parser description'),
);
}
$tabform->getTab('properties')->addField( "jsonTable",
name => 'attachmentsJson',
value => $self->get('attachmentsJson'),
label => $i18n->get("attachment display label"),
fields => [
{
type => "text",
name => "url",
label => $i18n->get('attachment header url'),
size => '48',
},
{
type => "select",
name => "type",
label => $i18n->get('attachment header type'),
options => [
stylesheet => $i18n->get('css label'),
headScript => $i18n->get('js head label'),
bodyScript => $i18n->get('js body label'),
],
},
],
);
$tabform->getTab('properties')->addField( image =>
name => 'storageIdExample',
value => $self->storageIdExample,

View file

@ -163,7 +163,8 @@ sub toHtml {
# Table headers
$output .= '<table id="' . $self->get( 'id' ) . '"><thead><tr>';
for my $field ( @{ $self->get('fields') } ) {
$output .= '<th>' . $field->{label} . '</th>';
my $label = ref $field->{label} eq 'ARRAY' ? $i18n->get(@{$field->{label}}) : $field->{label};
$output .= '<th>' . $label . '</th>';
}
$output .= '<th>&nbsp;</th>'; # Extra column for buttons
@ -190,6 +191,10 @@ sub toHtml {
for my $i ( 0 .. $opts-1 ) {
my $optValue = $field->{options}[$i*2];
my $optLabel = $field->{options}[$i*2+1];
# If the label is an arrayref, get the i18n value
if ( ref $optLabel eq 'ARRAY' ) {
$optLabel = $i18n->get(@{$optLabel});
}
$fieldHtml .= '<option value="' . $optValue . '">' . $optLabel . '</option>';
}
$fieldHtml .= '</select>';