CGI-OptimalQuery
view release on metacpan or search on metacpan
lib/CGI/OptimalQuery/InteractiveFilter.pm view on Meta::CPAN
my $val = scalar $q->param('NEXT_EXPR');
my $findx = $q->param('FINDX');
$findx = 0 unless $findx > 0;
$findx++;
my $pn = 'F' . $findx . '_';
if( $val =~ /\(\)\Z/ ) { # ends with a ()
$q->param($pn.'FUNCT', $val);
} else {
$q->param($pn.'L_COLMN', $val);
$q->param($pn.'L_VALUE', '');
if ($o->typ4clm($val) eq 'char' ||
$o->typ4clm($val) eq 'clob') {
$q->param($pn.'CMPOP', 'contains');
} else {
$q->param($pn.'CMPOP', '=');
}
}
$q->param('FINDX', $findx);
$q->param('hideParen', ( $findx < 3 ) );
$q->param('NEXT_EXPR', '--- Choose Next Filter ---');
$$o{view} = 'html_filter_form';
}
# did user submit the filter?
elsif ($q->param('act') eq 'submit_filter') {
my $ftxt = $o->recreateFilterString();
$q->param('filter', $ftxt);
$$o{view} = 'html_parent_update';
if ($$o{error}) {
$$o{view} = 'html_filter_form';
}
}
# did user request to delete filter
elsif ($q->param('act') eq 'submit_del') {
delselForm( $q );
$$o{view} = 'html_filter_form';
}
return undef;
}
# ------------------------- cmp_val -------------------------
sub cmp_val ( $$$$ ) {
my( $q, $pnam, $vals, $lbls ) = @_;
my $isUserVal = ( $q->param($pnam.'COLMN') eq ''
|| $q->param($pnam.'ISVAL') );
return
$q->button( -name=>$pnam.'BTN',
-label=>$isUserVal?'value:':'column:',
-onClick=>"toggle_value('$pnam');",
-class=>'colvalbtn')
. $q->hidden( -name=>$pnam.'ISVAL', -default=>$isUserVal )
. $q->textfield( -name=>$pnam.'VALUE',
-class=> ( $isUserVal ? 'val' : 'hide' ) )
. $q->popup_menu( -name=>$pnam.'COLMN',
-values=> $vals, -labels=> $lbls,
-onChange=>"submit_act('refresh');",
-class=> $isUserVal ? 'hide' : 'col');
}
# ------------------------- recreateFilterString -------------------------
sub recreateFilterString {
my $o = shift;
my $q = $$o{q};
# pull out the fuctions arguments from the form
my %funct_args = ();
foreach my $fak ( $q->param() ){
my @ary = split 'ARG_', $fak;
$funct_args{$ary[0]}{$ary[1]} = $q->param($fak)
if defined $ary[1];
}
my $ftext = '';
my $ei = scalar $q->param('FINDX');
for( my $i = 1; $i <= $ei; $i++ ) {
my $p = 'F' . $i . '_';
my $parcnt = $q->param($p.'L_PAREN');
$ftext .= ($parcnt < 1 ? '' : '('x$parcnt . ' ' );
if( defined $q->param($p.'FUNCT')
&& $q->param($p.'FUNCT') ne '' ) {
# TODO: Grab the $p.'ARG_' and Dump it.
my $f = $q->param($p.'FUNCT');
$f =~ s/\(\)\Z//;
my $args = '';
while (my ($k,$v) = each %{ $funct_args{$p} }) {
$args .= ',' if $args;
$v = "'".$v."'" if $v =~ /\W/;
$args .= "$k,$v";
}
$ftext .= " $f($args) ";
} else {
if( $q->param($p.'L_ISVAL') ) {
$ftext .= '\'' . $q->param($p.'L_VALUE') . '\'';
} else {
$ftext .= '[' . $q->param($p.'L_COLMN') . ']';
# force operator to be "like/not like" if a numeric operator
if ($o->typ4clm(uc($q->param($p.'L_COLMN'))) eq 'clob' &&
$q->param($p.'CMPOP') !~ /\w/) {
if ($q->param($p.'CMPOP') =~ /\!/) {
$q->param($p.'CMPOP', "not like");
} else {
$q->param($p.'CMPOP', "like");
}
}
}
$ftext .= ' ' . $q->param($p.'CMPOP') . ' ';
if( $q->param($p.'R_ISVAL') ) {
lib/CGI/OptimalQuery/InteractiveFilter.pm view on Meta::CPAN
return true;
}
";
my $q = $o->{q};
# pull out the fuctions arguments from the form
my %funct_args = ();
foreach my $fak ( $q->param() ){
my @ary = split 'ARG_', $fak;
$funct_args{$ary[0]}{$ary[1]} = $q->param($fak)
if defined $ary[1];
}
my $html =
$q->start_html ( -title=>"Interactive Filter - $$o{schema}{title}",
-script=> $js,
-head=>
$$o{schema}{options}{'CGI::OptimalQuery::InteractiveFilter'}{css} ).
"<center>".
(($$o{error}) ? "<strong>".$q->escapeHTML($$o{error})."</strong>" : "").
$q->start_form( -action=> $$o{schema}{URI_standalone}, -name=>'filterForm',
-class=>'filterForm', -enctype=>'application/x-www-form-urlencoded');
if (ref($$o{schema}{state_params}) eq 'ARRAY') {
foreach my $p (@{ $$o{schema}{state_params} }) {
$html .= "<input type='hidden' name='$p' value='".$o->escape_html($q->param($p))."'>";
}
}
$html .=
$q->hidden ( -name=>'module', -value=>'InteractiveFilter',
-override=>1 )
. $q->hidden ( -name=>'act', -value=>'submit_filter',
-override=>1 )
. $q->hidden ( -name=>'hideParen', -value=>1 )
. $q->hidden ( -name=>'FINDX', -value=>'0') ;
$html .= "<TABLE COLUMNS=6>\n";
my $hideParen = $q->param('hideParen');
my $pnp; # parameter name prefix
my $thing_to_focus_on;
for( my $findx = 1; $findx <= $q->param('FINDX'); $findx++ ) {
$pnp = 'F' . $findx . '_';
$html .= '<TR><TD class="lp_col">'
. $q->button ( -name=>$pnp.'L_PARBTN', -label=>'(',
-onClick=>"toggle_paren('$pnp"."L_');",
-class=> $hideParen
? 'hide' : ( $q->param($pnp.'L_PAREN') > 0
? 'hide' : 'noparen' ) )
. $q->popup_menu
( -name=>$pnp.'L_PAREN', -values=>[0 .. 3], -default=>'0',
-labels=>{'0'=>'','1'=>'(','2'=>'((','3'=>'((('},
-onChange=>"update_paren_vis('$pnp"."L_');",
-class=>$q->param($pnp.'L_PAREN')<1 ?'hide':'paren' )
. '</TD>';
if( defined $q->param($pnp.'FUNCT') ) {
my $func_nam = $q->param($pnp.'FUNCT');
$func_nam =~ s/\(\)//;
# if a predefined named filter
if (ref($o->{schema}->{'named_filters'}{$func_nam}) eq 'ARRAY') {
$html .= '<TD class="f_col" colspan=3>'
. $q->popup_menu( -name=>$pnp.'FUNCT',
-values=> \ @functionLOV,
-labels=> \ %functionLBL,
-default=> $q->param($pnp.'FUNCT'),
-onChange=>"submit_act('refresh');" ) ;
$html .= '</TD>';
}
# if named filter has an html generator
elsif (exists $o->{schema}->{'named_filters'}{$func_nam}{html_generator}) {
$html .= '<TD class="f_col" colspan=3>'
. $q->popup_menu( -name=>$pnp.'FUNCT',
-values=> \ @functionLOV,
-labels=> \ %functionLBL,
-default=> $q->param($pnp.'FUNCT'),
-onChange=>"submit_act('refresh');" ) ;
$html .=
$o->{schema}->{'named_filters'}{$func_nam}{'html_generator'}->($q, $pnp.'ARG_');
$html .= '</TD>';
}
# else if named filter does not have a html_generator
else {
$html .= "<TD class='f_col' colspan=3><input type=hidden name='$pnp"."FUNCT' value='".$o->escape_html("$func_nam()")."' />";
my %args;
my $arg_prefix = quotemeta($pnp.'ARG_');
foreach my $param (grep { /^$arg_prefix/ } $q->param) {
my $k = $param; $k =~ s/$arg_prefix//;
my $v = $q->param($param);
$args{$k} = $v;
$html .= "<input type=hidden name='$param' value='".$o->escape_html($q->param($param))."' />";
}
my $rv = $o->{schema}->{'named_filters'}{$func_nam}{'sql_generator'}->(%args);
$html .= "<div class=RO_NAMED_FILTER>".$o->escape_html($$rv[2])."</div></TD>";
}
}
else {
$html .= '<TD class="l_col">'
. &cmp_val($q, $pnp.'L_', \ @columnLOV, \ %columnLBL)
. '</TD><TD class="c_col">'
. $q->popup_menu (
-name=>$pnp.'CMPOP', -values=> cmpopLOV(), -class=>'cmpop')
. '</TD><TD class="r_col">'
. &cmp_val($q, $pnp.'R_', \ @columnLOV, \ %columnLBL )
. '</TD>';
}
$html .= '<TD class="rp_col">'
. $q->popup_menu ( -name=>$pnp.'R_PAREN',
-values=>[0 .. 3], -default=>'0',
-labels=>
{'0'=>'', '1'=>')', '2'=>'))', '3'=>')))'},
-onChange=>"update_paren_vis('$pnp"."R_');",
-class=> ( $q->param($pnp.'R_PAREN')<1
? 'hide' : 'paren' ) )
. $q->button ( -name=>$pnp.'R_PARBTN', -label=>')',
-onClick=>"toggle_paren('$pnp"."R_');",
-class=> $hideParen
? 'hide'
: ( $q->param($pnp.'R_PAREN')>0
? 'hide' : 'noparen') )
. '</TD><TD class="d_col">'
. $q->checkbox ( -name=>$pnp.'DELME', -label=>'remove',
-value=>'1', -checked=>0, -override=>1,
-onClick=>'show_submit_del();',
-class=>'delbox' )
. "</TD></TR>\n<TR><TD colspan=5 align=center>"
. $q->popup_menu ( -name=>$pnp.'ANDOR', -values=> \ @andorLOV,
-class=>$findx == $q->param('FINDX')?'hide':'')
. "</TD></TR>\n" ;
}
$html .= '<TR><TD colspan=5><HR width="90%" /></TD><TD class="d_col">'
. $q->checkbox ( -name=>'CHECKALL', -label=>'ALL', -value=>'1',
-checked=>0, -override=>1,
-onClick=>'checkall_delme();',
-class=>'delbox' )
. '</TD></TR> <TR class="footer"><TD colspan=5></TD><TD class="d_col">'
. $q->button ( -name=>'SUBMIT_DEL', -label=>'REMOVE',
-onClick=>"submit_act('submit_del');",
-class=> 'hide' )
. '</TD></TR>'
if( $q->param('FINDX') > 0 ); # we printed something above here
my @sel_opts = ('-- add new filter element --', $q->optgroup ( -name=>'Column to compare:',
-values=> \ @columnLOV ,
-labels=> \ %columnLBL ) );
if (@functionLOV) {
push @sel_opts, $q->optgroup ( -name=>'Named Filters:',
-values=> \ @functionLOV ,
-labels=> \ %functionLBL );
}
$html .= "</TABLE>\n"
. '<DIV id="paren_warn" class="paren_match">( Parenthesis must be matching pairs )</DIV>'
. '<SPAN id="submit_add" class="submit_ok">'
. $q->popup_menu ( -name=>'NEXT_EXPR',
-default=>'--- Choose Next Filter ---',
-override=>1,
-values=>\@sel_opts,
-onChange=>"submit();" )
. '</SPAN><SPAN id="submit_text" class="submit_ok"> or '
. $q->submit( -name=>'SUBMIT', -class=>'submit_ok' )
. "</SPAN> "
. $q->end_form()
. "\n</center>
<script type='text/javascript'>
check_paren();
if (window.document.forms[0].elements['F".$q->param('FINDX')."_R_VALUE'])
window.document.forms[0].elements['F".$q->param('FINDX')."_R_VALUE'].focus();
</script><noscript>Javascript is required when viewing this page.</noscript>
".$q->end_html();
return $html;
}
1;
( run in 0.850 second using v1.01-cache-2.11-cpan-364913b4093 )