diff --git a/lib/WebGUI/Asset/Wobject/DataForm.pm b/lib/WebGUI/Asset/Wobject/DataForm.pm index ca5ddc971..c6461996c 100644 --- a/lib/WebGUI/Asset/Wobject/DataForm.pm +++ b/lib/WebGUI/Asset/Wobject/DataForm.pm @@ -123,6 +123,13 @@ sub _createTabInit { return $output; } +#------------------------------------------------------------------- + +sub defaultViewForm { + my $self = shift; + return ($self->get("defaultView") == 0); +} + #------------------------------------------------------------------- sub definition { my $class = shift; @@ -155,6 +162,10 @@ sub definition { defaultValue=>0, fieldType=>"yesNo" }, + defaultView=>{ + defaultValue=>0, + fieldType=>"integer" + } } }); return $class->SUPER::definition($definition); @@ -220,6 +231,13 @@ sub getEditForm { -label=>WebGUI::International::get(87,"Asset_DataForm"), -afterEdit=>'func=edit' ); + $tabform->getTab("display")->radioList( + -name=>"defaultView", + -options=>{ 0 => WebGUI::International::get('data form','Asset_DataForm'), + 1 => WebGUI::International::get('data list','Asset_DataForm'),}, + -label=>WebGUI::International::get('defaultView',"Asset_DataForm"), + -value=>$self->getValue("defaultView"), + ); $tabform->getTab("properties")->HTMLArea( -name=>"acknowledgement", -label=>WebGUI::International::get(16, "Asset_DataForm"), @@ -287,7 +305,7 @@ sub getIndexerParams { and asset.endDate > $now", fieldsToIndex => ['select distinct(value) from DataForm_entryData where assetId = \'$data{assetId}\''], contentType => 'assetDetail', - url => 'WebGUI::URL::append($data{url}, "func=view&entryId=list}")', + url => 'WebGUI::URL::append($data{url}, "func=viewList}")', headerShortcut => 'select title from asset where assetId = \'$data{assetId}\'', } }; @@ -299,8 +317,8 @@ sub getListTemplateVars { my $self = shift; my $var = shift; my @fieldLoop; - $var->{"back.url"} = $self->getUrl."&entryId=0"; - $var->{"back.label"} = WebGUI::International::get(18,"Asset_DataForm"); + $var->{"back.url"} = $self->getFormUrl; + $var->{"back.label"} = WebGUI::International::get('go to form',"Asset_DataForm"); #$var->{"entryId"} = $self->getId; #$var->{"delete.url"} = $self->getUrl."&func=deleteAllEntries"; #$var->{"delete.label"} = WebGUI::International::get(91,"Asset_DataForm"); @@ -318,7 +336,7 @@ sub getListTemplateVars { $a->finish; $var->{field_loop} = \@fieldLoop; my @recordLoop; - my $a = WebGUI::SQL->read("select ipAddress,username,userid,submissionDate,DataForm_entryId from DataForm_entry + $a = WebGUI::SQL->read("select ipAddress,username,userid,submissionDate,DataForm_entryId from DataForm_entry where assetId=".quote($self->getId)." order by submissionDate desc"); while (my $record = $a->hashRef) { my @dataLoop; @@ -353,13 +371,44 @@ sub getListTemplateVars { return $var; } +#------------------------------------------------------------------- + +sub getFormUrl { + my $self = shift; + my $params = shift; + my $url = $self->getUrl; + unless ($self->defaultViewForm) { + $url = WebGUI::URL::append($url, 'mode=form'); + } + if ($params) { + $url = WebGUI::URL::append($url, $params); + } + return $url; +} + +#------------------------------------------------------------------- + +sub getListUrl { + my $self = shift; + my $params = shift; + my $url = $self->getUrl; + if ($self->defaultViewForm) { + $url = WebGUI::URL::append($url, 'mode=list'); + } + if ($params) { + $url = WebGUI::URL::append($url, $params); + } + return $url; +} + #------------------------------------------------------------------- sub getRecordTemplateVars { my $self = shift; my $var = shift; $var->{error_loop} = [] unless (exists $var->{error_loop}); $var->{canEdit} = ($self->canEdit); - $var->{"entryList.url"} = $self->getUrl('func=view&entryId=list'); + #$var->{"entryList.url"} = $self->getUrl('func=view&entryId=list'); + $var->{"entryList.url"} = $self->getListUrl; $var->{"entryList.label"} = WebGUI::International::get(86,"Asset_DataForm"); $var->{"export.tab.url"} = $self->getUrl('func=exportTab'); $var->{"export.tab.label"} = WebGUI::International::get(84,"Asset_DataForm"); @@ -387,7 +436,7 @@ sub getRecordTemplateVars { $var->{userId} = $entry->{userId}; $var->{date} = WebGUI::DateTime::epochToHuman($entry->{submissionDate}); $var->{epoch} = $entry->{submissionDate}; - $var->{"edit.URL"} = $self->getUrl('func=view&entryId='.$var->{entryId}); + $var->{"edit.URL"} = $self->getFormUrl('entryId='.$var->{entryId}); $where .= " and b.DataForm_entryId=".quote($var->{entryId}); $join = "left join DataForm_entryData as b on a.DataForm_fieldId=b.DataForm_fieldId"; $select .= ", b.value"; @@ -609,13 +658,37 @@ sub view { my $self = shift; my $passedVars = shift; my $var; - $var->{entryId} = $session{form}{entryId} if ($self->canEdit); - if ($var->{entryId} eq "list" && $self->canEdit) { - return $self->processTemplate($self->getListTemplateVars,$self->get("listTemplateId")); - } - # add Tab StyleSheet and JavaScript + ##Priority encoding + if ( $session{form}{mode} eq "form") { + $self->viewForm($passedVars); + } + elsif ( $session{form}{mode} eq "list") { + $self->viewList; + } + elsif( $self->defaultViewForm ) { + $self->viewForm($passedVars); + } + else { + $self->viewList(); + } +} + +#------------------------------------------------------------------- + +sub viewList { + my $self = shift; + return $self->processTemplate($self->getListTemplateVars,$self->get("listTemplateId")); +} + +#------------------------------------------------------------------- + +sub viewForm { + my $self = shift; + my $passedVars = shift; WebGUI::Style::setLink($session{config}{extrasURL}.'/tabs/tabs.css', {"type"=>"text/css"}); WebGUI::Style::setScript($session{config}{extrasURL}.'/tabs/tabs.js', {"language"=>"JavaScript"}); + my $var; + $var->{entryId} = $session{form}{entryId} if ($self->canEdit); $var = $passedVars || $self->getRecordTemplateVars($var); return $self->processTemplate($var,$self->get("templateId")); } @@ -1017,7 +1090,7 @@ sub www_process { $self->www_view($var); } else { $self->sendEmail($var) if ($self->get("mailData") && !$updating); - return WebGUI::Style::process($self->processTemplate($var,$self->get("acknowlegementTemplateId")),$self->get("styleTemplateId")); + return WebGUI::Style::process($self->processTemplate($var,$self->get("acknowlegementTemplateId")),$self->get("styleTemplateId")) if $self->defaultViewForm; } } diff --git a/lib/WebGUI/i18n/English/Asset_DataForm.pm b/lib/WebGUI/i18n/English/Asset_DataForm.pm index 934ee1602..baf509ffb 100644 --- a/lib/WebGUI/i18n/English/Asset_DataForm.pm +++ b/lib/WebGUI/i18n/English/Asset_DataForm.pm @@ -17,21 +17,22 @@ our $I18N = { }, '71' => { - message => q|This wobject creates a simple multipurpose data-entry form. + message => q|This Asset creates a simple multipurpose data-entry and + display form. You -can add additional fields to the DataForm, create multiple tabs, or use the DataForm -as a web form to email gateway. +can add additional fields to the DataForm, create multiple tabs, use the DataForm +as a web form to email gateway, or easily create tables on your website with it.
Dataforms are Wobjects, so they inherit the properties of both Wobjects and Assets. They also have these unique properties:
^International("16","Asset_DataForm");
-This message will be displayed to the user after they submit their data..
+This message will be displayed to the user after they submit their data.
^International("74","Asset_DataForm"); If set to yes, some additional fields will be added to your form for dealing with email. These fields will then be used to email any data entered into the form to a person of your choice. By default the new fields are "Hidden" so that they can't be edited by the user.
-NOTE: The "To" field that is added as a result of setting this to yes can accept a standard email address, or a WebGUI username or a WebGUI group name. +NOTE: The "To" field that is added as a result of setting this to yes can accept a standard email address, or a WebGUI username or a WebGUI group name. To send an email to more than one address, separate them by commas.
^International("913","WebGUI");
@@ -49,6 +50,12 @@ Choose a template that will be used to display the acknowledgment.
^International("87","Asset_DataForm");
Choose a template that will be used to display the list of stored records in this Data Form.
+
+^International("defaultView","Asset_DataForm");
+Select the default view for the Data Form, either Form view (the default) or
+List view. When List view is selected, no acknowledgement will be displayed
+after data is entered in the form.
+
^International("744","Asset_DataForm");
After creating the Data Form, you may either begin to add fields to it
@@ -76,7 +83,7 @@ List all data that has been entered into the Data Form.
Export the data from the Data Form in tab deliniated format.
|,
- lastUpdated => 1112732067,
+ lastUpdated => 1113674254,
},
'editField-vertical-label' => {
@@ -124,6 +131,11 @@ Export the data from the Data Form in tab deliniated format.
lastUpdated => 1031514049
},
+ 'go to form' => {
+ message => q|Go to form|,
+ lastUpdated => 1113423537
+ },
+
'72' => {
message => q|
You may add as many additional fields to your Data Form as you like. @@ -790,6 +802,14 @@ A conditional indicating whether this field exists for the mail subsystem of the message => q|Default view|, lastUpdated => 1112929856, }, + 'data form' => { + message => q|Data Form|, + lastUpdated => 1113435285, + }, + 'data list' => { + message => q|Data List|, + lastUpdated => 1113435295, + }, };