From 4bcd1e397682cf2e85a0dc93c42c1835506c190c Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Fri, 22 Apr 2011 17:02:06 -0500 Subject: [PATCH] fix Map/MapPoint editing --- lib/WebGUI/Asset/MapPoint.pm | 15 ++- lib/WebGUI/Asset/Wobject/Map.pm | 7 +- lib/WebGUI/Command/test_content.pm | 159 +++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 12 deletions(-) diff --git a/lib/WebGUI/Asset/MapPoint.pm b/lib/WebGUI/Asset/MapPoint.pm index bd5a19d8a..752b7ae65 100644 --- a/lib/WebGUI/Asset/MapPoint.pm +++ b/lib/WebGUI/Asset/MapPoint.pm @@ -273,15 +273,13 @@ sub getTemplateVarsEditForm { } ); # Stuff from this class's definition - my $definition = __PACKAGE__->definition($session)->[0]->{properties}; - for my $key ( keys %{$definition} ) { - next if $definition->{$key}->{noFormPost}; + foreach my $key ( $self->getProperties ) { + my $fieldHash = $self->getFieldData( $key ); + next if $fieldHash->{noFormPost}; next if $key eq 'latitude' || $key eq 'longitude'; - $definition->{$key}->{name} = $key; - $definition->{$key}->{value} = $self->$key; $var->{ "form_$key" } - = WebGUI::Form::dynamicField( $session, %{$definition->{$key}} ); + = WebGUI::Form::dynamicField( $session, $fieldHash ); } # Stuff from Asset @@ -325,9 +323,8 @@ sub processAjaxEditForm { my $prop = {}; # Stuff from this class's definition - my $definition = __PACKAGE__->definition($session)->[0]->{properties}; - for my $key ( keys %{$definition} ) { - my $field = $definition->{$key}; + for my $key ( $self->getProperties ) { + my $field = $self->getFieldData( $key ); next if $field->{noFormPost}; $prop->{$key} = $form->get($key,$field->{fieldType},$field->{defaultValue},$field); diff --git a/lib/WebGUI/Asset/Wobject/Map.pm b/lib/WebGUI/Asset/Wobject/Map.pm index 30ed3d4db..7528965bd 100644 --- a/lib/WebGUI/Asset/Wobject/Map.pm +++ b/lib/WebGUI/Asset/Wobject/Map.pm @@ -549,9 +549,10 @@ sub www_ajaxEditPointSave { } ); } else { - $asset = WebGUI::Asset->newById( $session, $assetId ); - return JSON->new->encode({message => $i18n->get("error edit unauthorized")}) - unless $asset && $asset->canEdit; + eval { $asset = WebGUI::Asset->newById( $session, $assetId ) }; + if ( $@ || !$asset || !$asset->canEdit ) { + return JSON->new->encode({message => $i18n->get("error edit unauthorized")}); + } $asset = $asset->addRevision; } diff --git a/lib/WebGUI/Command/test_content.pm b/lib/WebGUI/Command/test_content.pm index 9b949d098..edbc87b1e 100644 --- a/lib/WebGUI/Command/test_content.pm +++ b/lib/WebGUI/Command/test_content.pm @@ -5,6 +5,7 @@ use strict; use warnings; use Try::Tiny; use File::Spec::Functions qw(catfile); +use JSON; use WebGUI::Paths; use WebGUI::Session; @@ -249,6 +250,164 @@ my $DT_NOW = DateTime->now; ], }, ], + 'WebGUI::Asset::Wobject::DataForm' => [ + { + title => 'Data Form', + isHidden => 1, + defaultView => 0, + useCaptcha => 1, + templateId => 'PBtmpl0000000000000141', # Default dataform + fieldConfiguration => JSON->new->encode( [ + { + name => "from", + label => 'From', + status => "required", + type => "email", + }, + { + name => 'subject', + label => 'Subject', + status => 'required', + type => 'text', + }, + { + name => 'date', + label => 'Date', + status => 'editable', + type => 'date', + }, + { + name => 'body', + label => 'Body', + status => 'editable', + type => 'textarea', + }, + ] ), + }, + { + title => 'Data Form (list)', + defaultView => 1, + }, + { + title => 'Data Form (tabbed)', + defaultView => 0, + templateId => 'PBtmpl0000000000000116', # Tab form + fieldConfiguration => JSON->new->encode( [ + { + name => "from", + label => 'From', + status => "required", + type => "email", + tabId => 0, + }, + { + name => 'subject', + label => 'Subject', + status => 'required', + type => 'text', + tabId => 'one', + }, + { + name => 'date', + label => 'Date', + status => 'editable', + type => 'date', + tabId => 'one', + }, + { + name => 'body', + label => 'Body', + status => 'editable', + type => 'textarea', + tabId => 'two', + }, + ] ), + tabConfiguration => JSON->new->encode( [ + { + tabId => 'one', + label => "One", + subtext => "The oneth page", + }, + { + tabId => 'two', + label => 'Two', + subtext => 'The twoth page', + }, + ] ), + }, + ], + 'WebGUI::Asset::Wobject::DataTable' => [ + { + title => 'DataTable (YUI)', + isHidden => 1, + templateId => '3rjnBVJRO6ZSkxlFkYh_ug', + data => JSON->new->encode( { + columns => [ + { + key => 'ID', + formatter => 'text', + }, + { + key => 'Name', + formatter => 'text', + }, + { + key => 'URL', + formatter => 'link', + }, + ], + rows => [ + { + ID => '1', + Name => 'WebGUI', + URL => 'http://webgui.org', + }, + { + ID => '2', + Name => 'Plain Black Corp.', + URL => 'http://plainblack.com', + }, + ], + } ), + }, + { + title => 'DataTable (HTML)', + templateId => 'TuYPpHx7TUyk08639Pc8Bg', + }, + ], + 'WebGUI::Asset::Wobject::Map' => [ + { + title => 'Map', + mapApiKey => 'ABQIAAAAxadBCYjK6rRsw7rJkBgiEBT7g5bZECU_gqoByQmzcFSTeCxKshSKEU-GQYssxXNgQ1qkA3XtjOGYog', + # Key only works for "localhost:5000" + startLatitude => '43.068888', + startLongitude => '-89.384251', + startZoom => '6', + _children => [ + { + className => 'WebGUI::Asset::MapPoint', + title => 'Lake Poygan', + latitude => '44.166445', + longitude => '-88.791504', + description => 'I have never heard of this place before', + }, + { + className => 'WebGUI::Asset::MapPoint', + title => 'Chicago', + latitude => '41.885921', + longitude => '-87.670898', + description => 'Best pizza in the world', + }, + { + className => 'WebGUI::Asset::MapPoint', + title => 'Dubuque', + latitude => '42.569264', + longitude => '-90.725098', + description => 'At the corner of three states', + }, + ], + }, + ], ); sub getPropertySets {