From ed8a0dac5c926f8eef6aad9a674bb90e251c1024 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Tue, 15 Sep 2009 20:16:31 -0500 Subject: [PATCH] added direct value access in DataForm list view --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Wobject/DataForm.pm | 3 + lib/WebGUI/Help/Asset_DataForm.pm | 1 + lib/WebGUI/i18n/English/Asset_DataForm.pm | 6 + t/Asset/Wobject/DataForm/viewList.t | 190 ++++++++++++++++++++++ 5 files changed, 201 insertions(+) create mode 100644 t/Asset/Wobject/DataForm/viewList.t diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 1b658c4e3..ab3c819a3 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -39,6 +39,7 @@ - fixed #10913: User profiles: Impossible to delete field contents - fixed #10929: EMS Ticket Start Date Sort - fixed #10885: Code Editor breaks Javascript comments + - added direct value access in DataForm list view 7.7.19 - fixed #10838: Forwarded forum post email to new CS adds reply to original thread diff --git a/lib/WebGUI/Asset/Wobject/DataForm.pm b/lib/WebGUI/Asset/Wobject/DataForm.pm index 6fc73f631..d6d2f9fe9 100644 --- a/lib/WebGUI/Asset/Wobject/DataForm.pm +++ b/lib/WebGUI/Asset/Wobject/DataForm.pm @@ -713,9 +713,11 @@ sub getListTemplateVars { while ( my $entry = $entryIter->() ) { my $entryData = $entry->fields; my @dataLoop; + my %dataVars; for my $fieldName ( @{ $self->getFieldOrder } ) { my $field = $fieldConfig->{$fieldName}; my $form = $self->_createForm($field, $entryData->{$fieldName}); + $dataVars{ 'record.noloop.' . $fieldName } = $entryData->{$fieldName}; push @dataLoop, { "record.data.name" => $field->{name}, "record.data.label" => $field->{label}, @@ -725,6 +727,7 @@ sub getListTemplateVars { }; } push @recordLoop, { + %dataVars, "record.ipAddress" => $entry->ipAddress, "record.edit.url" => $self->getFormUrl("func=view;entryId=".$entry->getId), "record.edit.icon" => $self->session->icon->edit("func=view;entryId=".$entry->getId, $self->get('url')), diff --git a/lib/WebGUI/Help/Asset_DataForm.pm b/lib/WebGUI/Help/Asset_DataForm.pm index 36809b218..06e763014 100644 --- a/lib/WebGUI/Help/Asset_DataForm.pm +++ b/lib/WebGUI/Help/Asset_DataForm.pm @@ -179,6 +179,7 @@ our $HELP = { { 'name' => 'record.userId' }, { 'name' => 'record.submissionDate.epoch' }, { 'name' => 'record.submissionDate.human' }, + { 'name' => 'record.noloop.', description => 'help record.noloop', }, { 'name' => 'record.data_loop', 'variables' => [ { 'name' => 'record.data.name' }, diff --git a/lib/WebGUI/i18n/English/Asset_DataForm.pm b/lib/WebGUI/i18n/English/Asset_DataForm.pm index 0633925bc..6821246d0 100644 --- a/lib/WebGUI/i18n/English/Asset_DataForm.pm +++ b/lib/WebGUI/i18n/English/Asset_DataForm.pm @@ -1044,6 +1044,12 @@ be useful, others may not.|, context => q{The date that this entry was submitted to the site. i18n label for template}, }, + 'help record.noloop' => { + message => q{You can get any field's value in this record by name, ex: record.noloop.subject}, + lastUpdated => 0, + context => q{Help for template variable}, + }, + }; 1; diff --git a/t/Asset/Wobject/DataForm/viewList.t b/t/Asset/Wobject/DataForm/viewList.t new file mode 100644 index 000000000..d17bd163f --- /dev/null +++ b/t/Asset/Wobject/DataForm/viewList.t @@ -0,0 +1,190 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# 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 +#------------------------------------------------------------------ + +# Test the viewList and related methods of the DataForm +# +# + +use FindBin; +use strict; +use lib "$FindBin::Bin/../../../lib"; +use Test::More; +use Test::Deep; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + +my $df = WebGUI::Asset->getImportNode($session)->addChild( { + className => 'WebGUI::Asset::Wobject::DataForm', +} ); + +WebGUI::Test->tagsToRollback( WebGUI::VersionTag->getWorking( $session ) ); + +# Add fields to the dataform +$df->createField( "name", { type => "text", } ); +$df->createField( "message", { type => "text", } ); + +# Add entries to the dataform +my @entries = ( + $df->entryClass->newFromHash( + $df, { + name => "Andy", + subject => "Problem!", + message => "I need a Rita Heyworth", + } + ), + $df->entryClass->newFromHash( + $df, { + name => "Red", + subject => "Solution!", + message => "I need about tree fiddy", + } + ), +); +for my $entry (@entries) { + $entry->save; +} + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 2; # Increment this number for each test you create + +#---------------------------------------------------------------------------- +# Test getListTemplateVars + +my $tmplVar = $df->getListTemplateVars({}); + +# First our field definitions +my @fields = ( + { + name => "from", + type => "email", + isMailField => 1, + label => ignore(), + }, + { + name => "to", + type => "email", + isMailField => 1, + label => ignore(), + }, + { + name => "cc", + type => "email", + isMailField => 1, + label => ignore(), + }, + { + name => "bcc", + type => "email", + isMailField => 1, + label => ignore(), + }, + { + name => "subject", + type => "text", + isMailField => 1, + label => ignore(), + }, + { + name => "name", + type => "text", + isMailField => undef, + label => undef, + }, + { + name => "message", + type => "text", + isMailField => undef, + label => ignore(), + }, +); + +#------------------------------------- +# Test the field_loop +my $fieldVars = []; +for my $field ( @fields ) { + my $var = {}; + for my $key ( keys %$field ) { + $var->{ 'field.' . $key } = $field->{ $key }; + } + push @{$fieldVars}, $var; +} + +cmp_deeply( $tmplVar->{field_loop}, $fieldVars, 'field_loop is complete and correct' ); + +#------------------------------------- +# Test the record_loop +my $recordVars = []; +my $entryIdx = $#entries; # ordered by insert in reverse +while ( $entryIdx >= 0 ) { + my $var = { + 'record.noloop.bcc' => $entries[$entryIdx]->field('bcc'), + 'record.noloop.cc' => $entries[$entryIdx]->field('cc'), + 'record.noloop.from' => $entries[$entryIdx]->field('from'), + 'record.noloop.message' => $entries[$entryIdx]->field('message'), + 'record.noloop.name' => $entries[$entryIdx]->field('name'), + 'record.noloop.subject' => $entries[$entryIdx]->field('session'), + 'record.noloop.to' => $entries[$entryIdx]->field('to'), + + 'record.entryId' => $entries[$entryIdx]->getId, + 'record.userId' => $session->user->userId, + 'record.username' => $session->user->username, + 'record.ipAddress' => undef, + 'record.delete.icon' => ignore(), + 'record.delete.url' => ignore(), + 'record.edit.icon' => ignore(), + 'record.edit.url' => ignore(), + 'record.submissionDate.epoch' => ignore(), + 'record.submissionDate.human' => ignore(), + }; + + my $fieldVars = []; + for my $field ( @fields ) { + my $var = {}; + for my $key ( keys %$field ) { + $var->{ 'record.data.' . $key } = $field->{ $key }; + } + $var->{ record_data_type } = delete $var->{ 'record.data.type' }; + + + # Don't care about mail fields... + if ( $field->{isMailField} ) { + $var->{ 'record.data.value' } = ignore(); + } + else { + $var->{ 'record.data.value' } = $entries[$entryIdx]->field( $field->{name} ); + } + + push @{$fieldVars}, $var; + } + $var->{ 'record.data_loop' } = $fieldVars; + + push @{$recordVars}, $var; + + $entryIdx--; +} + +cmp_deeply( + $tmplVar->{record_loop}, + $recordVars, + 'getListTemplateVars is complete and correct', +); + + +#---------------------------------------------------------------------------- +# Cleanup + +#vim:ft=perl