Added seperate form elements and loops to SQLForm search template.
This commit is contained in:
parent
dcf6d4f595
commit
e1163ff944
3 changed files with 213 additions and 36 deletions
|
|
@ -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 .= '<table>';
|
||||
$form .= '<tr valign="top">';
|
||||
$form .= '<td><b>'.$i18n->get('s location').'</b></td><td colspan="2">'.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 .= '<td><b>'.$var->{'searchFormTrash.label'}.'</b></td><td colspan="2">'.$var->{'searchFormTrash.form'};
|
||||
$form .= '</td></tr>';
|
||||
$form .= '<td><b>'.$i18n->get('s search type').'</b></td><td colspan="2">'.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 .= '<td><b>'.$var->{'searchFormType.label'}.'</b></td><td colspan="2">'.$var->{'searchFormType.form'};
|
||||
$form .= '</td></tr>';
|
||||
|
||||
$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 .= '<td>';
|
||||
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 .= '</td>';
|
||||
$form .= '<td>';
|
||||
|
||||
|
|
@ -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 .= '</td>';
|
||||
$form .= '</tr>';
|
||||
|
||||
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 .= '<td>'.WebGUI::Form::submit($self->session, {value => $i18n->get('s search button')}).'</td>';
|
||||
$form .= '</table>';
|
||||
$form .= WebGUI::Form::formFooter($self->session);
|
||||
$form .= '<script src="'.$self->session->config->get("extrasURL").'/wobject/SQLForm/SQLFormSearch.js" type="text/javascript"></script>';
|
||||
$form .= '<script type="text/javascript">'.$js.'</script>';
|
||||
$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} = '<script src="'.$self->session->config->get("extrasURL").'/wobject/SQLForm/SQLFormSearch.js" type="text/javascript"></script>';
|
||||
$var->{searchFormJavascript} .= '<script type="text/javascript">'.$js.'</script>';
|
||||
|
||||
$form .= '<td>'.$var->{searchFormSubmit}.'</td>';
|
||||
$form .= '</table>';
|
||||
$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);
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -1059,8 +1059,8 @@ seperate form header, footer or anything else.</p>
|
|||
|
||||
<p><b>formLoop</b><br />
|
||||
A loop containing each field. Using
|
||||
this loop will allow you to use a different layout that that of
|
||||
c<b>ompleteForm</b>. The <b>formLoop</b> loop provides the following
|
||||
this loop will allow you to use a different layout than that of
|
||||
<b>completeForm</b>. The <b>formLoop</b> loop provides the following
|
||||
variables:</p>
|
||||
|
||||
<blockquote>
|
||||
|
|
@ -1069,7 +1069,14 @@ The display name of the field.</p>
|
|||
|
||||
|
||||
<p> <b>field.formElement</b><br />
|
||||
The form Element for the field<br />
|
||||
In view mode this is the same as <b>field.value</b>.
|
||||
</p>
|
||||
|
||||
<p> <b>field.value</b><br />
|
||||
The value of the field</p>
|
||||
|
||||
|
||||
</blockquote>
|
||||
|
||||
<p>Finally there is the option of placing
|
||||
|
|
@ -1085,7 +1092,9 @@ variables:</p>
|
|||
<p><b>field.<fieldname>.formElement</b><br />
|
||||
Contains the form element of the field
|
||||
<fieldname>. You must substitute <fieldname> with the
|
||||
field name of the field you intend to place.</p>
|
||||
field name of the field you intend to place.<br />
|
||||
In view mode this is the same as <b>field<fieldname>.value</b>.
|
||||
</p>
|
||||
|
||||
|
||||
<p><b>field.<fieldname>.label</b><br />
|
||||
|
|
@ -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.</p>
|
||||
|
||||
<p><b>field.<fieldname>.value</b><br />
|
||||
Contains the value of the field
|
||||
<fieldname>. You must substitute <fieldname> with the
|
||||
field name of the field you intend to place.</p>
|
||||
|
||||
|
||||
<p><b>formHeader</b><br />
|
||||
The header of the the form. If you are
|
||||
The header of the form. If you are
|
||||
not using the <b>completeForm</b> You must include this variable
|
||||
before any other form variable. If you do use the <b>completeForm
|
||||
</b>variable, however, you must not use the <b>formHeader</b>
|
||||
|
|
@ -1103,9 +1117,9 @@ variable.</p>
|
|||
|
||||
|
||||
<p><b>formFooter</b><br />
|
||||
The footer of the the form. If you are
|
||||
The footer of the form. If you are
|
||||
not using the <b>completeForm</b> You must include this variable
|
||||
before any other form variable. If you do use the <b>completeForm</b>
|
||||
after every other form variable. If you do use the <b>completeForm</b>
|
||||
variable, however, you must not use the <b>formFooter</b> variable.</p>
|
||||
|
||||
<p>This template also provides some other
|
||||
|
|
@ -1142,7 +1156,7 @@ this record.</p>
|
|||
|
||||
<p><b>managementLinks</b><br />
|
||||
A string of links to all of the
|
||||
management fucntions.</p>|,
|
||||
management functions.</p>|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
|
|
@ -1157,7 +1171,8 @@ provides you with a way to customize the looks of the search
|
|||
functionality that the SQLForm offers.</p>
|
||||
|
||||
<p>There are two separate search methods, being normal and advanced search, but
|
||||
both use the same template.</p>
|
||||
both use the same template. In both cases a complete <b>searchForm</b> is available.
|
||||
The individual form Elements are also available, but note that different form Elements are used for normal and advanced search.</p>
|
||||
|
||||
<p>The following template variable are available to you:</p>
|
||||
|
||||
|
|
@ -1167,7 +1182,102 @@ In other words, this is false if every field is configured not to be displayed
|
|||
in the search results.</p>
|
||||
|
||||
<p><b>searchForm</b><br />
|
||||
Contains the form which allows users to search.</p>
|
||||
Contains the complete form which allows users to search.</p>
|
||||
|
||||
<p><b>searchFormHeader</b><br />
|
||||
The header of the form, available in normal and advanced search. If you are
|
||||
not using the complete <b>searchForm</b> You must include this variable
|
||||
before any other form variable. If you do use the complete <b>searchForm
|
||||
</b> variable, however, you must not use the <b>searchFormHeader</b>
|
||||
variable.</p>
|
||||
|
||||
<p><b>searchFormTrash.label</b><br />
|
||||
The label for the search in trash option. Available in normal and advanced search. Only use this if you are
|
||||
not using the complete <b>searchForm</b>.</p>
|
||||
<p><b>searchFormTrash.form</b><br />
|
||||
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 <b>searchForm</b>.</p>
|
||||
|
||||
<p><b>searchFormMode.label</b><br />
|
||||
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 <b>searchForm</b>.</p>
|
||||
<p><b>searchFormMode.form</b><br />
|
||||
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 <b>searchForm</b>.</p>
|
||||
|
||||
<p><b>searchFormQuery.label</b><br />
|
||||
The label for the search query. Available in normal search. Only use this if you are
|
||||
not using the complete <b>searchForm</b>.</p>
|
||||
<p><b>searchFormQuery.form</b><br />
|
||||
The form Element for the search query. Available in normal search. Only use this if you are
|
||||
not using the complete <b>searchForm</b>.</p>
|
||||
|
||||
<p><b>searchFormSearchIn.label</b><br />
|
||||
The label for the search in fields select list. Available in normal search. Only use this if you are
|
||||
not using the complete <b>searchForm</b>.</p>
|
||||
<p><b>searchFormSearchIn.form</b><br />
|
||||
The form Element for the search in fields select list. Available in normal search. Only use this if you are
|
||||
not using the complete <b>searchForm</b>.</p>
|
||||
|
||||
<p><b>searchFormType.label</b><br />
|
||||
The label for the search type option (or/and). Available in advanced search. Only use this if you are
|
||||
not using the complete <b>searchForm</b>.</p>
|
||||
<p><b>searchFormType.form</b><br />
|
||||
The form Element for the search type option (or/and). Available in advanced search. Only use this if you are
|
||||
not using the complete <b>searchForm</b>.</p>
|
||||
|
||||
<p><b>searchFormFooter</b><br />
|
||||
The footer of the form, available in normal and advanced search. If you are
|
||||
not using the complete <b>searchForm</b> You must use this variable
|
||||
after every other searchForm variable. If you do use the complete <b>searchForm</b>
|
||||
variable, however, you must not use the <b>searchFormFooter</b> variable.</p>
|
||||
|
||||
<p><b>searchFormSubmit</b><br />
|
||||
The submit button of the form, available in normal and advanced search. Only use this if you are
|
||||
not using the complete <b>searchForm</b>.</p>
|
||||
|
||||
<p><b>searchFormJavascript</b><br />
|
||||
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 <b>searchForm</b> you must include this variable
|
||||
for advanced search. If you do use the complete <b>searchForm</b>
|
||||
variable, however, you must not use the <b>searchFormJavascript</b> variable.</p>
|
||||
|
||||
<p><b>searchForm.field_loop</b><br />
|
||||
A loop containing each field, only available in advanced search.
|
||||
The <b>field_loop</b> provides the following
|
||||
variables:</p>
|
||||
|
||||
<blockquote>
|
||||
<p> <b>field.label</b><br />
|
||||
The display name of the field.</p>
|
||||
|
||||
<p> <b>field.conditionalForm</b><br />
|
||||
The form Element for the conditional for this field</p>
|
||||
|
||||
<p> <b>field.conditional</b><br />
|
||||
The value of the conditional form Element for this field</p>
|
||||
|
||||
<p> <b>field.searchForm1</b><br />
|
||||
The first search form Element for this field</p>
|
||||
|
||||
<p> <b>field.searchForm1</b><br />
|
||||
The second search form Element for this field</p>
|
||||
<p> <b>field.formValue1</b><br />
|
||||
The value of first search form Element for this field</p>
|
||||
|
||||
<p> <b>field.formValue2</b><br />
|
||||
The value of second search form Element for this field</p>
|
||||
|
||||
<p> <b>field.<fieldname>.id</b><br />
|
||||
Contains the id of the field
|
||||
<fieldname>. You must substitute <fieldname> with the
|
||||
field name of the field.<br />
|
||||
You can use this if you want to create a custom Advanced search form that completely overrides the default search form.
|
||||
</p>
|
||||
|
||||
</blockquote>
|
||||
|
||||
<p>The template provides variables for the search results that are the same for normal and advanced search.
|
||||
|
||||
<p><b>headerLoop</b><br />
|
||||
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.</p>
|
||||
|
||||
<p><b>searchResults.actionButtons</b><br />
|
||||
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.</p>
|
||||
|
||||
<p><b>searchResults.recordLoop</b><br />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue