From e1163ff944f799a2d4652eed5dfad7431768a4e6 Mon Sep 17 00:00:00 2001 From: Yung Han Khoe Date: Fri, 28 Apr 2006 14:18:04 +0000 Subject: [PATCH] Added seperate form elements and loops to SQLForm search template. --- lib/WebGUI/Asset/Wobject/SQLForm.pm | 112 +++++++++++++++---- lib/WebGUI/Help/Asset_SQLForm.pm | 7 +- lib/WebGUI/i18n/English/Asset_SQLForm.pm | 130 +++++++++++++++++++++-- 3 files changed, 213 insertions(+), 36 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/SQLForm.pm b/lib/WebGUI/Asset/Wobject/SQLForm.pm index 828592bcf..7cc877b96 100644 --- a/lib/WebGUI/Asset/Wobject/SQLForm.pm +++ b/lib/WebGUI/Asset/Wobject/SQLForm.pm @@ -2362,14 +2362,18 @@ sub www_editRecord { -value => $formElement ); + my $fieldValue = $self->_getFieldValue($field, $properties, !$canEditRecord); + # Add element to the form loop push(@formLoop, { 'field.label' => $field->{displayName}, 'field.formElement' => $formElement, + 'field.value' => $fieldValue, }); $var->{'field.'.$field->{fieldName}.'.formElement'} = $formElement; $var->{'field.'.$field->{fieldName}.'.label'} = $field->{displayName}; + $var->{'field.'.$field->{fieldName}.'.value'} = $fieldValue; } if ($canEditRecord) { @@ -3268,6 +3272,36 @@ my @fields = $self->session->db->buildArray("select distinct fieldId from SQLFor $var->{'headerLoop'} = \@headerLoop; + $var->{searchFormHeader} = WebGUI::Form::formHeader($self->session, + {action => $self->getUrl}). + WebGUI::Form::hidden($self->session, {name=>'func', value=>'search'}). + WebGUI::Form::hidden($self->session, {name=>'searchType', value=>'or'}); + + $var->{'searchFormQuery.label'} = $i18n->get('s query'); + $var->{'searchFormQuery.form'} = WebGUI::Form::text($self->session,{ + name=>'searchQuery', + value=>$query + }); + $var->{'searchFormMode.label'} = $i18n->get('s mode'); + $var->{'searchFormMode.form'} = WebGUI::Form::radioList($self->session,{ + name=>'searchMode', + value=>$useRegex, + options=> {'normal' => 'Normal search', 'regexp' => 'Regex search'}, + }); + $var->{'searchFormSearchIn.label'} = $i18n->get('s search in fields'); + $var->{'searchFormSearchIn.form'} = WebGUI::Form::checkList($self->session,{ + name=>'searchIn', + value=>\@searchIn, + options=> \%searchableFields, + }); + $var->{'searchFormTrash.label'} = $i18n->get('s location'); + $var->{'searchFormTrash.form'} = WebGUI::Form::radioList($self->session,{ + name=>'searchInTrash', + value=>$searchInTrash, + options=> \%searchInTrashOptions, + }); + $var->{searchFormSubmit} = WebGUI::Form::submit($self->session,{value => $i18n->get('s search button')}); + $var->{searchFormFooter} = WebGUI::Form::formFooter($self->session); if (@searchIn && ($query || $searchInTrash)) { my $sql = $self->_constructSearchQuery(\@searchIn, \@showFields, \%fieldProperties, $query); @@ -3389,6 +3423,7 @@ Hashref containing the properties of the fields that are in the search. sub _constructSearchForm { my ($form, $js, %searchInTrashOptions, $i18n); my $self = shift; + my $var = shift; my $fieldList = shift; my $fieldProperties = shift; @@ -3400,35 +3435,45 @@ sub _constructSearchForm { 2 => $i18n->get('_csf normal and trash') ); - my $searchType = $self->session->form->process("searchType") || $self->session->scratch->get('SQLForm_'.$self->getId.'searchType') || 'or'; my $searchInTrash = $self->session->form->process("searchInTrash"); $searchInTrash = $self->session->scratch->get('SQLForm_'.$self->getId.'searchInTrash') unless (defined $self->session->form->process("searchInTrash")); $searchInTrash ||= '0'; - $form = WebGUI::Form::formHeader($self->session); - $form .= WebGUI::Form::hidden($self->session, {name => 'func', value => 'superSearch'}); - $form .= WebGUI::Form::hidden($self->session, {name => 'searchQueried', value => 1}); + $var->{searchFormHeader} = WebGUI::Form::formHeader($self->session ,{action => $self->getUrl}); + $var->{searchFormHeader} .= WebGUI::Form::hidden($self->session, {name => 'func', value => 'superSearch'}); + $var->{searchFormHeader} .= WebGUI::Form::hidden($self->session, {name => 'searchQueried', value => 1}); + + $form = $var->{searchFormHeader}; $form .= ''; $form .= ''; - $form .= ''; - $form .= ''; $self->session->scratch->set('SQLForm_'.$self->getId.'searchType', $searchType); $self->session->scratch->set('SQLForm_'.$self->getId.'searchInTrash', $searchInTrash); - + + my @field_loop; foreach (@$fieldList) { + my ($searchForm1, $searchForm2, $conditionalForm); if ($self->session->form->process("searchQueried")) { $self->session->scratch->delete('SQLForm_'.$self->getId.'---'.$_.'v1'); $self->session->scratch->delete('SQLForm_'.$self->getId.'---'.$_.'v2'); @@ -3457,7 +3502,7 @@ my $conditional = $self->session->form->process('_'.$_.'_conditional') || $self $form .= ''; $form .= ''; $form .= ''; + + push (@field_loop, { + 'field.'.$fieldProperties->{$_}->{fieldName}.'.id' => $_, + 'field.label' => $fieldProperties->{$_}->{displayName}, + 'field.conditionalForm' => $conditionalForm, + 'field.searchForm1' => $searchForm1, + 'field.searchForm2' => $searchForm2, + 'field.formValue1' => $formValue1, + 'field.formValue2' => $formValue2, + 'field.conditional' => $conditional, + }); + } - $form .= ''; - $form .= '
'.$i18n->get('s location').''.WebGUI::Form::radioList($self->session, { - name => "searchInTrash", - options => \%searchInTrashOptions, - value => $searchInTrash, + + $var->{'searchFormTrash.label'} = $i18n->get('s location'); + $var->{'searchFormTrash.form'} = WebGUI::Form::radioList($self->session, { + name => "searchInTrash", + options => \%searchInTrashOptions, + value => $searchInTrash, }); + + $form .= ''.$var->{'searchFormTrash.label'}.''.$var->{'searchFormTrash.form'}; $form .= '
'.$i18n->get('s search type').''.WebGUI::Form::radioList($self->session, { - name => "searchType", - options => {'or' => $i18n->get('or'), 'and' => $i18n->get('and')}, - value => $searchType, + $var->{'searchFormType.label'} = $i18n->get('s search type'); + $var->{'searchFormType.form'} = WebGUI::Form::radioList($self->session, { + name => "searchType", + options => {'or' => $i18n->get('or'), 'and' => $i18n->get('and')}, + value => $searchType, }); + + $form .= ''.$var->{'searchFormType.label'}.''.$var->{'searchFormType.form'}; $form .= '
'; if (exists $types->{$fieldProperties->{$_}->{type}}) { - $form .= WebGUI::Form::selectList($self->session, { + $conditionalForm = WebGUI::Form::selectList($self->session, { name => '_'.$_.'_conditional', value => [ $conditional || '' ], options => $types->{$fieldProperties->{$_}->{type}}, @@ -3467,6 +3512,7 @@ my $conditional = $self->session->form->process('_'.$_.'_conditional') || $self }); $js .= $typeFunctions->{$fieldProperties->{$_}->{type}}."('".$conditional."', '$_');"; } + $form .= $conditionalForm; $form .= ''; @@ -3479,7 +3525,8 @@ my $conditional = $self->session->form->process('_'.$_.'_conditional') || $self my $searchElement = $fieldProperties->{$_}->{searchElement}; $searchElement = 'text' if ($searchElement eq 'selectList'); my $cmd = "WebGUI::Form::$searchElement".'($self->session, $parameters)'; - $form .= eval($cmd); + $searchForm1 = eval($cmd); + $form .= $searchForm1; unless ($fieldProperties->{$_}->{type} eq 'text') { $searchElement = $fieldProperties->{$_}->{searchElement}; @@ -3494,19 +3541,38 @@ my $cmd = "WebGUI::Form::$searchElement".'($self->session, $parameters)'; } $cmd = "WebGUI::Form::$searchElement".'($self->session, $parameters)'; - $form .= eval($cmd); + $searchForm2 = eval($cmd); + $form .= $searchForm2; } $form .= '
'.WebGUI::Form::submit($self->session, {value => $i18n->get('s search button')}).'
'; - $form .= WebGUI::Form::formFooter($self->session); - $form .= ''; - $form .= ''; + $var->{'searchForm.field_loop'} = \@field_loop; - return $form; + $var->{searchFormSubmit} = WebGUI::Form::submit($self->session, {value => $i18n->get('s search button')}); + $var->{searchFormFooter} = WebGUI::Form::formFooter($self->session); + $var->{searchFormJavascript} = ''; + $var->{searchFormJavascript} .= ''; + + $form .= ''.$var->{searchFormSubmit}.''; + $form .= ''; + $form .= $var->{searchFormFooter}; + $form .= $var->{searchFormJavascript}; + + $var->{searchForm} = $form; } #------------------------------------------------------------------- @@ -3816,7 +3882,7 @@ my @showFields; # Construct search form - $var->{searchForm} = $self->_constructSearchForm(\@searchableFields, \%fieldProperties); + $self->_constructSearchForm($var, \@searchableFields, \%fieldProperties); # Build search query my $sql = $self->_constructSearchQuery(\@searchableFields, \@showFields, \%fieldProperties); diff --git a/lib/WebGUI/Help/Asset_SQLForm.pm b/lib/WebGUI/Help/Asset_SQLForm.pm index 80e425933..f96fd11e6 100644 --- a/lib/WebGUI/Help/Asset_SQLForm.pm +++ b/lib/WebGUI/Help/Asset_SQLForm.pm @@ -53,11 +53,12 @@ our $HELP = { namespace => 'Asset_SQLForm', }, - { - title => 'gef default view', + { + title => 'gef default view', description => 'gef default view description', namespace => 'Asset_SQLForm', - }, + }, + { title => 'gef submit group', diff --git a/lib/WebGUI/i18n/English/Asset_SQLForm.pm b/lib/WebGUI/i18n/English/Asset_SQLForm.pm index 43f9919da..6f57e21c7 100644 --- a/lib/WebGUI/i18n/English/Asset_SQLForm.pm +++ b/lib/WebGUI/i18n/English/Asset_SQLForm.pm @@ -1059,8 +1059,8 @@ seperate form header, footer or anything else.

formLoop
A loop containing each field. Using -this loop will allow you to use a different layout that that of -completeForm. The formLoop loop provides the following +this loop will allow you to use a different layout than that of +completeForm. The formLoop loop provides the following variables:

@@ -1069,7 +1069,14 @@ The display name of the field.

field.formElement
+The form Element for the field
+In view mode this is the same as field.value. +

+ +

field.value
The value of the field

+ +

Finally there is the option of placing @@ -1085,7 +1092,9 @@ variables:

field.<fieldname>.formElement
Contains the form element of the field <fieldname>. You must substitute <fieldname> with the -field name of the field you intend to place.

+field name of the field you intend to place.
+In view mode this is the same as field<fieldname>.value. +

field.<fieldname>.label
@@ -1093,9 +1102,14 @@ Contains the display name of the field <fieldname>. You must substitute <fieldname> with the field name of the field you intend to place.

+

field.<fieldname>.value
+Contains the value of the field +<fieldname>. You must substitute <fieldname> with the +field name of the field you intend to place.

+

formHeader
-The header of the the form. If you are +The header of the form. If you are not using the completeForm You must include this variable before any other form variable. If you do use the completeForm variable, however, you must not use the formHeader @@ -1103,9 +1117,9 @@ variable.

formFooter
-The footer of the the form. If you are +The footer of the form. If you are not using the completeForm You must include this variable -before any other form variable. If you do use the completeForm +after every other form variable. If you do use the completeForm variable, however, you must not use the formFooter variable.

This template also provides some other @@ -1142,7 +1156,7 @@ this record.

managementLinks
A string of links to all of the -management fucntions.

|, +management functions.

|, lastUpdated => 0, }, @@ -1157,7 +1171,8 @@ provides you with a way to customize the looks of the search functionality that the SQLForm offers.

There are two separate search methods, being normal and advanced search, but -both use the same template.

+both use the same template. In both cases a complete searchForm is available. +The individual form Elements are also available, but note that different form Elements are used for normal and advanced search.

The following template variable are available to you:

@@ -1167,7 +1182,102 @@ In other words, this is false if every field is configured not to be displayed in the search results.

searchForm
-Contains the form which allows users to search.

+Contains the complete form which allows users to search.

+ +

searchFormHeader
+The header of the form, available in normal and advanced search. If you are +not using the complete searchForm You must include this variable +before any other form variable. If you do use the complete searchForm + variable, however, you must not use the searchFormHeader +variable.

+ +

searchFormTrash.label
+The label for the search in trash option. Available in normal and advanced search. Only use this if you are +not using the complete searchForm.

+

searchFormTrash.form
+The form Element for the search in trash option. Available in normal and advanced search. Only use this if you are +not using the complete searchForm.

+ +

searchFormMode.label
+The label for the search mode option (with regex or not). Available in normal search. Only use this if you are +not using the complete searchForm.

+

searchFormMode.form
+The form Element for the search mode option (with regex or not). Available in normal search. Only use this if you are +not using the complete searchForm.

+ +

searchFormQuery.label
+The label for the search query. Available in normal search. Only use this if you are +not using the complete searchForm.

+

searchFormQuery.form
+The form Element for the search query. Available in normal search. Only use this if you are +not using the complete searchForm.

+ +

searchFormSearchIn.label
+The label for the search in fields select list. Available in normal search. Only use this if you are +not using the complete searchForm.

+

searchFormSearchIn.form
+The form Element for the search in fields select list. Available in normal search. Only use this if you are +not using the complete searchForm.

+ +

searchFormType.label
+The label for the search type option (or/and). Available in advanced search. Only use this if you are +not using the complete searchForm.

+

searchFormType.form
+The form Element for the search type option (or/and). Available in advanced search. Only use this if you are +not using the complete searchForm.

+ +

searchFormFooter
+The footer of the form, available in normal and advanced search. If you are +not using the complete searchForm You must use this variable +after every other searchForm variable. If you do use the complete searchForm +variable, however, you must not use the searchFormFooter variable.

+ +

searchFormSubmit
+The submit button of the form, available in normal and advanced search. Only use this if you are +not using the complete searchForm.

+ +

searchFormJavascript
+Only used for advanced search. This links the SQLFormSearch.js file and contains some inline javascript that is used by advanced search. If you are +not using the complete searchForm you must include this variable +for advanced search. If you do use the complete searchForm +variable, however, you must not use the searchFormJavascript variable.

+ +

searchForm.field_loop
+A loop containing each field, only available in advanced search. +The field_loop provides the following +variables:

+ +
+

field.label
+The display name of the field.

+ +

field.conditionalForm
+The form Element for the conditional for this field

+ +

field.conditional
+The value of the conditional form Element for this field

+ +

field.searchForm1
+The first search form Element for this field

+ +

field.searchForm1
+The second search form Element for this field

+

field.formValue1
+The value of first search form Element for this field

+ +

field.formValue2
+The value of second search form Element for this field

+ +

field.<fieldname>.id
+Contains the id of the field +<fieldname>. You must substitute <fieldname> with the +field name of the field.
+You can use this if you want to create a custom Advanced search form that completely overrides the default search form. +

+ +
+ +

The template provides variables for the search results that are the same for normal and advanced search.

headerLoop
A loop containing the display names of each field, inclding sort controls. The @@ -1198,7 +1308,7 @@ Contains the form footer for the search results batch functions. Put this template variable somewhere after the searchResults loop.

searchResults.actionButtons
-Contains the the restore and purge buttons for the batch operations. Put this +Contains the restore and purge buttons for the batch operations. Put this variable between searchResults.header and searchResults.footer.

searchResults.recordLoop