Merge branch 'master' into 8-merge
Conflicts: docs/gotcha.txt lib/WebGUI.pm lib/WebGUI/Asset.pm lib/WebGUI/Asset/File/GalleryFile/Photo.pm lib/WebGUI/Asset/Post.pm lib/WebGUI/Asset/Story.pm lib/WebGUI/Asset/Template.pm lib/WebGUI/Asset/Wobject/Calendar.pm lib/WebGUI/Asset/Wobject/GalleryAlbum.pm lib/WebGUI/Asset/Wobject/Navigation.pm lib/WebGUI/AssetLineage.pm lib/WebGUI/AssetTrash.pm lib/WebGUI/Config.pm lib/WebGUI/Form/Template.pm lib/WebGUI/Group.pm lib/WebGUI/Inbox.pm lib/WebGUI/Workflow/Activity/DeleteExpiredSessions.pm lib/WebGUI/Workflow/Activity/TrashExpiredEvents.pm sbin/testEnvironment.pl t/AdSpace.t t/AdSpace/Ad.t t/Asset/Asset.t t/Asset/AssetExportHtml.t t/Asset/AssetLineage.t t/Asset/EMSSubmissionForm.t t/Asset/Event.t t/Asset/File/GalleryFile/Photo/00base.t t/Asset/File/GalleryFile/Photo/comment.t t/Asset/File/GalleryFile/Photo/download.t t/Asset/File/GalleryFile/Photo/edit.t t/Asset/File/GalleryFile/Photo/exif.t t/Asset/File/GalleryFile/Photo/makeResolutions.t t/Asset/File/GalleryFile/Photo/makeShortcut.t t/Asset/File/Image/setfile.t t/Asset/File/setfile.t t/Asset/Post.t t/Asset/Post/Thread/getAdjacentThread.t t/Asset/Sku.t t/Asset/Sku/ProductCollateral.t t/Asset/Story.t t/Asset/Template.t t/Asset/Template/HTMLTemplateExpr.t t/Asset/Wobject/Gallery/00base.t t/Asset/Wobject/GalleryAlbum/00base.t t/Asset/Wobject/GalleryAlbum/ajax.t t/Asset/Wobject/GalleryAlbum/delete.t t/Asset/Wobject/Matrix.t t/Asset/Wobject/StoryArchive.t t/Asset/Wobject/Survey/ExpressionEngine.t t/Asset/Wobject/Survey/Reports.t t/AssetAspect/RssFeed.t t/Auth/mech.t t/Config.t t/Group.t t/Help/isa.t t/International.t t/Mail/Send.t t/Operation/AdSpace.t t/Operation/Auth.t t/Pluggable.t t/Session.t t/Session/DateTime.t t/Session/ErrorHandler.t t/Session/Scratch.t t/Session/Stow.t t/Shop/Cart.t t/Shop/Pay.t t/Shop/PayDriver/ITransact.t t/Shop/PayDriver/PayPalStd.t t/Shop/Ship.t t/Shop/ShipDriver.t t/Shop/TaxDriver/EU.t t/Shop/TaxDriver/Generic.t t/Shop/Transaction.t t/Shop/Vendor.t t/VersionTag.t t/Workflow/Activity/ArchiveOldStories.t t/Workflow/Activity/ExpireIncompleteSurveyResponses.t t/lib/WebGUI/Test.pm
This commit is contained in:
commit
babfa74209
238 changed files with 4557 additions and 1287 deletions
|
|
@ -297,7 +297,7 @@ JS
|
|||
$output .= '<div class="crumbTrail">'.join(" > ", @crumb)."</div>\n<ul>";
|
||||
|
||||
my $useAssetUrls = $session->config->get("richEditorsUseAssetUrls");
|
||||
my $children = $base->getLineage(["children"]);
|
||||
my $children = $base->getLineageIterator(["children"]);
|
||||
while ( my $child = $children->() ) {
|
||||
next unless $child->canView;
|
||||
$output .= '<li>';
|
||||
|
|
|
|||
215
lib/WebGUI/Form/JsonTable.pm
Normal file
215
lib/WebGUI/Form/JsonTable.pm
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
package WebGUI::Form::JsonTable;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::International;
|
||||
use JSON;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::JsonTable
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a table to edit a JSON blob
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 fields
|
||||
|
||||
An array of hashrefs defining the fields in this JsonTable.
|
||||
|
||||
{
|
||||
type => "text", # One of "text", "select", or "readonly"
|
||||
name => "name", # The name of the field
|
||||
label => "Name", # an i18n label
|
||||
options => [ option => "label", ... ] # Options for select fields
|
||||
}
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $definition = shift || [];
|
||||
push @{$definition}, {
|
||||
fields => {
|
||||
defaultValue => [],
|
||||
},
|
||||
};
|
||||
return $class->SUPER::definition($session, $definition);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName ( session )
|
||||
|
||||
Returns the name of the form control.
|
||||
|
||||
=cut
|
||||
|
||||
sub getName {
|
||||
my ($class, $session) = @_;
|
||||
return WebGUI::International->new($session, "Form_JsonTable")->get("topicName");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getOriginalValue ( )
|
||||
|
||||
Get the original value, encoding to JSON if necessary
|
||||
|
||||
=cut
|
||||
|
||||
sub getOriginalValue {
|
||||
my ( $self ) = @_;
|
||||
my $value = $self->SUPER::getOriginalValue;
|
||||
if ( ref $value eq "ARRAY" ) {
|
||||
return JSON->new->encode( $value );
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValue ( value )
|
||||
|
||||
Get the value of the field. Substitute id fields with GUIDs.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValue {
|
||||
my ( $self, $value ) = @_;
|
||||
$value ||= $self->SUPER::getValue;
|
||||
|
||||
$self->session->log->info( "JsonTable Got $value from form" );
|
||||
$value = JSON->new->decode( $value );
|
||||
|
||||
for my $row ( @{$value} ) {
|
||||
for my $field ( @{$self->get('fields')} ) {
|
||||
if ( $field->{type} eq 'id' && $row->{ $field->{name} } eq "new" ) {
|
||||
$row->{ $field->{name} } = $self->session->id->generate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return JSON->new->encode( $value );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders an input tag of type text.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my ( $url, $style ) = $session->quick(qw( url style ));
|
||||
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->getOriginalValue)));
|
||||
my $output = '';
|
||||
|
||||
# Table headers
|
||||
$output .= '<table id="' . $self->get( 'id' ) . '"><thead><tr>';
|
||||
for my $field ( @{ $self->get('fields') } ) {
|
||||
$output .= '<th>' . $field->{label} . '</th>';
|
||||
}
|
||||
$output .= '<th> </th>'; # Extra column for buttons
|
||||
|
||||
# Buttons to add rows in the table footer
|
||||
my $cols = scalar @{ $self->get('fields') } + 1; # Extra column for buttons
|
||||
$output .= '</thead><tfoot><tr><td colspan="' . $cols . '">'
|
||||
. '<button id="' . $self->get('id') . '_add">' . "Add" . '</button>'
|
||||
. '</td></tr></tfoot>'
|
||||
;
|
||||
|
||||
# Build a hidden row to copy for new rows
|
||||
$output .= '<tbody><tr class="new_row" style="display: none">';
|
||||
for my $field ( @{ $self->get('fields') } ) {
|
||||
my $fieldName = join "_", $self->get('name'), $field->{name};
|
||||
# Drawing using raw HTML to sanitize field HTML and allow future merging with DataTable
|
||||
my $fieldHtml;
|
||||
|
||||
if ( $field->{type} eq "text" ) {
|
||||
$fieldHtml = '<input type="text" name="' . $fieldName . '" size="' . $field->{size} . '" />';
|
||||
}
|
||||
elsif ( $field->{type} eq "select" ) {
|
||||
$fieldHtml = '<select name="' . $fieldName . '" size="' . $field->{size} . '">';
|
||||
my $opts = @{$field->{options}} / 2; # options is arrayref of name => label
|
||||
for my $i ( 0 .. $opts-1 ) {
|
||||
my $optValue = $field->{options}[$i*2];
|
||||
my $optLabel = $field->{options}[$i*2+1];
|
||||
$fieldHtml .= '<option value="' . $optValue . '">' . $optLabel . '</option>';
|
||||
}
|
||||
$fieldHtml .= '</select>';
|
||||
}
|
||||
elsif ( $field->{type} eq "id" ) {
|
||||
$fieldHtml .= '<input type="hidden" class="jsontable_id" name="' . $fieldName . '" value="new" />';
|
||||
}
|
||||
else { # Readonly or unknown
|
||||
$fieldHtml = ' ';
|
||||
}
|
||||
|
||||
$output .= '<td>' . $fieldHtml . '</td>';
|
||||
}
|
||||
|
||||
$output .= '<td></td>' # Extra cell for buttons
|
||||
. '</tr></tbody></table>';
|
||||
|
||||
# Build the existing rows
|
||||
$output .= '<input type="hidden" name="' . $self->get('name') . '" value="' . $value . '" />';
|
||||
|
||||
# Existing rows are entirely built in javascript from the JSON in the hidden field
|
||||
$style->setScript(
|
||||
$url->extras('yui/build/yahoo-dom-event/yahoo-dom-event.js'),
|
||||
{ type => 'text/javascript' },
|
||||
);
|
||||
$style->setScript(
|
||||
$url->extras('yui/build/json/json-min.js'),
|
||||
{ type => 'text/javascript' },
|
||||
);
|
||||
$output .= sprintf '<script src="%s" type="text/javascript"></script>',
|
||||
$url->extras('yui-webgui/build/form/jsontable.js');
|
||||
$output .= '<script type="text/javascript">'
|
||||
. q{new WebGUI.Form.JsonTable("} . $self->get('name') . q{","} . $self->get( 'id' ) . q{", }
|
||||
. JSON->new->encode( $self->get('fields') ) . q{ );}
|
||||
. '</script>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
1;
|
||||
#vim:ft=perl
|
||||
|
|
@ -78,23 +78,23 @@ If true, this will limit the list of template to only include templates that are
|
|||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $definition = shift || [];
|
||||
my $i18n = WebGUI::International->new($session, 'Asset_Template');
|
||||
push(@{$definition}, {
|
||||
label=>{
|
||||
defaultValue=>$i18n->get("assetName")
|
||||
},
|
||||
name=>{
|
||||
defaultValue=>"templateId"
|
||||
},
|
||||
namespace=>{
|
||||
defaultValue=>undef
|
||||
},
|
||||
onlyCommitted=>{
|
||||
defaultValue=>''
|
||||
},
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $definition = shift || [];
|
||||
my $i18n = WebGUI::International->new($session, 'Asset_Template');
|
||||
push(@{$definition}, {
|
||||
label=>{
|
||||
defaultValue=>$i18n->get("assetName")
|
||||
},
|
||||
name=>{
|
||||
defaultValue=>"templateId"
|
||||
},
|
||||
namespace=>{
|
||||
defaultValue=>undef
|
||||
},
|
||||
onlyCommitted=>{
|
||||
defaultValue=>''
|
||||
},
|
||||
});
|
||||
return $class->SUPER::definition($session, $definition);
|
||||
}
|
||||
|
|
@ -138,16 +138,39 @@ sub isDynamicCompatible {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
=head2 getValueAsHtml ( )
|
||||
|
||||
Renders a template picker control.
|
||||
Returns the tempalte name of the selected template.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $onlyCommitted = $self->get('onlyCommitted') ? "assetData.status='approved'" : $self->get('onlyCommitted');
|
||||
my $templateList = WebGUI::Asset::Template->getList($self->session, $self->get("namespace"), $onlyCommitted);
|
||||
sub getValueAsHtml {
|
||||
my $self = shift;
|
||||
|
||||
$self->setOptions;
|
||||
|
||||
return $self->SUPER::getValueAsHtml;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 setOptions
|
||||
|
||||
Fills the options of the select list with the appropriate templates.
|
||||
|
||||
=cut
|
||||
|
||||
sub setOptions {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $userId = $session->user->userId;
|
||||
|
||||
my $onlyCommitted = $self->get( 'onlyCommitted' )
|
||||
? q{assetData.status='approved'}
|
||||
: $self->get( 'onlyCommitted' )
|
||||
;
|
||||
my $templateList = WebGUI::Asset::Template->getList( $session, $self->get( 'namespace' ), $onlyCommitted );
|
||||
|
||||
#Remove entries from template list that the user does not have permission to view.
|
||||
for my $assetId ( keys %{$templateList} ) {
|
||||
my $asset = WebGUI::Asset::Template->newById($self->session, $assetId);
|
||||
|
|
@ -155,8 +178,26 @@ sub toHtml {
|
|||
delete $templateList->{$assetId};
|
||||
}
|
||||
}
|
||||
$self->set("options", $templateList);
|
||||
return $self->SUPER::toHtml();
|
||||
|
||||
$self->set( 'options', $templateList );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a template picker control.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
|
||||
$self->setOptions;
|
||||
|
||||
return $self->SUPER::toHtml();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -36,6 +36,31 @@ The following methods are specifically available from this class. Check the supe
|
|||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName ( session )
|
||||
|
||||
Returns the human readable name of this control.
|
||||
|
||||
=cut
|
||||
|
||||
sub getName {
|
||||
my ($self, $session) = @_;
|
||||
return WebGUI::International->new($session, 'WebGUI')->get('user');
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isDynamicCompatible ( )
|
||||
|
||||
Since this Form field requires a thingId to work it is not dynamic compatible.
|
||||
|
||||
=cut
|
||||
|
||||
sub isDynamicCompatible {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_getThingFields ($session)
|
||||
|
|
|
|||
|
|
@ -58,6 +58,19 @@ Defaults to the setting textBoxSize or 30 if that's not set. Specifies how big o
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName ( session )
|
||||
|
||||
Returns the human readable name of this control.
|
||||
|
||||
=cut
|
||||
|
||||
sub getName {
|
||||
my ($self, $session) = @_;
|
||||
return WebGUI::International->new($session, 'Form_Username')->get('username');
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValue ( [ value ] )
|
||||
|
||||
Retrieves a value from a form GET or POST and returns it. If the value comes back as undef, this method will return the defaultValue instead. Strip newlines/carriage returns from the value.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue