Parent Directory
|
Revision Log
applied dpvc's filtering UI cleanup patch. closes bug #660.
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: webwork2/lib/WeBWorK/HTML/ScrollingRecordList.pm,v 1.5 2004/06/08 00:04:45 sh002i Exp $ 5 # 6 # This program is free software; you can redistribute it and/or modify it under 7 # the terms of either: (a) the GNU General Public License as published by the 8 # Free Software Foundation; either version 2, or (at your option) any later 9 # version, or (b) the "Artistic License" which comes with this package. 10 # 11 # This program is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the 14 # Artistic License for more details. 15 ################################################################################ 16 17 package WeBWorK::HTML::ScrollingRecordList; 18 use base qw(Exporter); 19 20 =head1 NAME 21 22 WeBWorK::HTML::ScrollingRecordList - HTML widget for a scrolling list of 23 records. 24 25 =cut 26 27 use strict; 28 use warnings; 29 use Carp; 30 use WeBWorK::Utils::FormatRecords qw/getFormatsForClass formatRecords/; 31 use WeBWorK::Utils::SortRecords qw/getSortsForClass sortRecords/; 32 use WeBWorK::Utils::FilterRecords qw/getFiltersForClass filterRecords/; 33 34 our @EXPORT = (); 35 our @EXPORT_OK = qw( 36 scrollingRecordList 37 ); 38 39 40 41 sub scrollingRecordList { 42 my ($options, @Records) = @_; 43 44 my %options = (default_filters=>[],default_sort=>"",default_format=>"",%$options); 45 # %options must contain: 46 # name - name of scrolling list -- use $r->param("$name") 47 # request - the WeBWorK::Request object for the current request 48 # may contain: 49 # default_sort - name of sort to use by default 50 # default_format - name of format to use by default 51 # default_filter - listref, names of filters to apply by default (unimpl.) 52 # allowed_filters - hashref, mapping field name to list of allowed values (unimpl.) 53 # size - number of rows shown in scrolling list 54 # multiple - are multiple selections allowed? 55 56 croak "name not found in options" unless exists $options{name}; 57 croak "request not found in options" unless exists $options{request}; 58 my $name = $options{name}; 59 my $r = $options{request}; 60 61 my $default_sort = $options{default_sort} || ""; 62 my $default_format = $options{default_format} || ""; 63 64 my @default_filters = @{$options{default_filters}} ; 65 66 my $size = $options{size}; 67 my $multiple = $options{multiple}; 68 69 my $sorts = []; 70 my $sort_labels = {}; 71 my $selected_sort = ""; 72 73 my $formats = []; 74 my $format_labels = {}; 75 my $selected_format = ""; 76 77 my $filters = []; 78 my $filter_labels = {}; 79 my @selected_filters= (); 80 81 my @ids = (); 82 my %labels = (); 83 84 my @selected_records = $r->param("$name"); 85 86 if (@Records) { 87 my $class = ref $Records[0]; 88 89 ($filters, $filter_labels) = getFiltersForClass(@Records); 90 if (defined $r->param("$name!filter")){ 91 @selected_filters = $r->param("$name!filter"); 92 @selected_filters = ("all") unless @selected_filters; 93 } 94 else { 95 @selected_filters = @default_filters; 96 } 97 98 ($sorts, $sort_labels) = getSortsForClass($class); 99 $selected_sort = $r->param("$name!sort") 100 || $default_sort 101 || (@$sorts ? $sorts->[0] : ""); 102 103 ($formats, $format_labels) = getFormatsForClass($class); 104 $selected_format = $r->param("$name!format") 105 || $default_format 106 || (@$formats ? $formats->[0] : ""); 107 108 @Records = filterRecords({filter=>\@selected_filters},@Records); 109 110 @Records = sortRecords({preset=>$selected_sort}, @Records); 111 112 # generate IDs from keyfields 113 my @keyfields = $class->KEYFIELDS; 114 foreach my $Record (@Records) { 115 push @ids, join("!", map { $Record->$_ } @keyfields); 116 } 117 118 # generate labels hash 119 @labels{@ids} = @Records; 120 %labels = formatRecords({preset=>$selected_format}, %labels); 121 } 122 123 my %sort_popup_options = ( 124 -name => "$name!sort", 125 -values => $sorts, 126 -default => $selected_sort, 127 -labels => $sort_labels, 128 ); 129 130 my %format_popup_options = ( 131 -name => "$name!format", 132 -values => $formats, 133 -default => $selected_format, 134 -labels => $format_labels, 135 ); 136 137 my %filter_options = ( 138 -name => "$name!filter", 139 -values => $filters, 140 -default => \@selected_filters, 141 -labels => $filter_labels, 142 -size => 5, 143 -multiple => 1, 144 ); 145 146 my %list_options = ( 147 -class=>"ScrollingRecordList", 148 -name => "$name", 149 -values => \@ids, 150 -default => \@selected_records, 151 -labels => \%labels, 152 ); 153 $list_options{-size} = $size if $size; 154 $list_options{-multiple} = $multiple if $multiple; 155 156 return CGI::div({-class=>"ScrollingRecordList"}, 157 CGI::table({-border=>0, -cellspacing=>0, -cellpadding=>0}, 158 CGI::Tr({valign=>"top"},[ 159 CGI::td({-align=>"right"},"Sort: "). 160 CGI::td(CGI::popup_menu(%sort_popup_options)), 161 162 CGI::td({-align=>"right"},"Format: "). 163 CGI::td(CGI::popup_menu(%format_popup_options)), 164 165 CGI::td({-align=>"right"},"Filter: "). 166 CGI::td(CGI::scrolling_list(%filter_options)), 167 ]), 168 ), 169 CGI::submit("$name!refresh", "Change Display Settings"), CGI::br(), 170 CGI::scrolling_list(%list_options), 171 ); 172 } 173 174 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |