Skip to content

Instantly share code, notes, and snippets.

@mrkurt
Created March 18, 2009 19:42
Show Gist options
  • Save mrkurt/81345 to your computer and use it in GitHub Desktop.
Save mrkurt/81345 to your computer and use it in GitHub Desktop.
#adds asset fields to appropriate forms
sub add_asset_fields{
my ($cb, $app, $param, $tmpl) = @_;
my $asset = $param->{asset};
#$asset->init_meta();
if($asset){
$tmpl->context->var('credit_url', $asset->credit_url);
$tmpl->context->var('credit_text', $asset->credit_text);
$tmpl->context->var('caption', $asset->caption);
}
#label (insert after)
# Get our marker
#MT->log(Dumper($param));;
my $label_field = $tmpl->getElementById('label');
$label_field = $tmpl->getElementById('file') unless $label_field;
my %fields = ('credit_url' => 'Credit Link', 'credit_text' => 'Credit', 'caption' => 'Caption');
while(my ($key, $value) = each(%fields)) {
# Create our element
my $setting = $tmpl->createElement('app:setting', {
id => $key, required => 0, label => $value, label_class => 'text-top'
});
my $innerHTML = '<div class="textarea-wrapper"><input type="text" name="'. $key . '" maxlength="250" class="full-width"
value="<mt:var name="' . $key . '" escape="html">" id="' . $key . '" /></div>';
$setting->innerHTML($innerHTML);
# Attach our element in the DOM before basename
$tmpl->insertAfter($setting, $label_field);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment