Parent Directory
|
Revision Log
WeBWorK::HTML::ScrollingRecordList - HTML widget for a scrolling list of records. uses FormatRecords and SortRecords. see sample usage in Assigner.pm.
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: webwork-modperl/lib/WeBWorK/Utils/SortRecords.pm,v 1.1 2004/03/01 00:49:25 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 33 our @EXPORT = (); 34 our @EXPORT_OK = qw( 35 scrollingRecordList 36 ); 37 38 sub scrollingRecordList { 39 my ($options, @Records) = @_; 40 41 my %options = %$options; 42 43 croak "name not found in options" unless exists $options{name}; 44 croak "request not found in options" unless exists $options{request}; 45 my $name = $options{name}; 46 my $r = $options{request}; 47 48 my $default_sort = $options{default_sort} || ""; 49 my $default_format = $options{default_format} || ""; 50 warn "default_format=$default_format\n"; 51 52 my $size = $options{size}; 53 my $multiple = $options{multiple}; 54 55 my $sorts = []; 56 my $sort_labels = {}; 57 my $selected_sort = ""; 58 59 my $formats = []; 60 my $format_labels = {}; 61 my $selected_format = ""; 62 63 my @ids = (); 64 my %labels = (); 65 66 my @selected_records = $r->param("$name"); 67 68 if (@Records) { 69 my $class = ref $Records[0]; 70 71 ($sorts, $sort_labels) = getSortsForClass($class); 72 $selected_sort = $r->param("$name!sort") 73 || $default_sort 74 || (@$sorts ? $sorts->[0] : ""); 75 76 ($formats, $format_labels) = getFormatsForClass($class); 77 $selected_format = $r->param("$name!format") 78 || $default_format 79 || (@$formats ? $formats->[0] : ""); 80 warn "selected_format=$selected_format"; 81 82 @Records = sortRecords({preset=>$selected_sort}, @Records); 83 84 # generate IDs from keyfields 85 my @keyfields = $class->KEYFIELDS; 86 foreach my $Record (@Records) { 87 push @ids, join("!", map { $Record->$_ } @keyfields); 88 } 89 90 # generate labels hash 91 @labels{@ids} = @Records; 92 %labels = formatRecords({preset=>$selected_format}, %labels); 93 } 94 95 my %sort_popup_options = ( 96 -name => "$name!sort", 97 -values => $sorts, 98 -default => $selected_sort, 99 -labels => $sort_labels, 100 ); 101 102 my %format_popup_options = ( 103 -name => "$name!format", 104 -values => $formats, 105 -default => $selected_format, 106 -labels => $format_labels, 107 ); 108 109 my %list_options = ( 110 -name => "$name", 111 -values => \@ids, 112 -default => \@selected_records, 113 -labels => \%labels, 114 ); 115 $list_options{-size} = $size if $size; 116 $list_options{-multiple} = $multiple if $multiple; 117 118 return CGI::div({-class=>"ScrollingRecordList"}, 119 "Sort: ", CGI::popup_menu(%sort_popup_options), CGI::br(), 120 "Format: ", CGI::popup_menu(%format_popup_options), CGI::br(), 121 CGI::submit("$name!refresh", "Change Display Settings"), CGI::br(), 122 CGI::scrolling_list(%list_options) 123 ); 124 } 125 126 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |