[dw-free] Have the ability to add labels to the low and high end of scale questions
[commit: http://hg.dwscoalition.org/dw-free/rev/fce23e6b8dfe]
http://bugs.dwscoalition.org/show_bug.cgi?id=1584
Labels for scale questions, to reduce confusion.
Patch by
yvi.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=1584
Labels for scale questions, to reduce confusion.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/upgrading/update-db-general.pl
- cgi-bin/LJ/Poll.pm
- cgi-bin/LJ/Poll/Question.pm
- htdocs/poll/create.bml
- htdocs/poll/create.bml.text
-------------------------------------------------------------------------------- diff -r 69d517428701 -r fce23e6b8dfe bin/upgrading/update-db-general.pl --- a/bin/upgrading/update-db-general.pl Wed Dec 07 21:53:03 2011 +0800 +++ b/bin/upgrading/update-db-general.pl Wed Dec 07 22:41:45 2011 +0800 @@ -2441,7 +2441,7 @@ pollqid TINYINT UNSIGNED NOT NULL, sortorder TINYINT UNSIGNED NOT NULL DEFAULT '0', type ENUM('check','radio','drop','text','scale') NOT NULL, - opts VARCHAR(20) DEFAULT NULL, + opts VARCHAR(255) DEFAULT NULL, qtext TEXT, PRIMARY KEY (journalid,pollid,pollqid) @@ -4026,6 +4026,12 @@ "MODIFY COLUMN value VARCHAR(1024) DEFAULT NULL"); } + # changes opts size of pollquestion2 to 255 in order to accommodate labels + if ( column_type( 'pollquestion2', 'opts' ) eq "varchar(20)" ) { + do_alter( 'pollquestion2', + "ALTER TABLE pollquestion2 MODIFY COLUMN opts VARCHAR(255) DEFAULT NULL"); + } + }); diff -r 69d517428701 -r fce23e6b8dfe cgi-bin/LJ/Poll.pm --- a/cgi-bin/LJ/Poll.pm Wed Dec 07 21:53:03 2011 +0800 +++ b/cgi-bin/LJ/Poll.pm Wed Dec 07 22:41:45 2011 +0800 @@ -327,6 +327,8 @@ my $from = 1; my $to = 10; my $by = 1; + my $lowlabel = ""; + my $highlabel = ""; if (defined $opts->{'from'}) { $from = int($opts->{'from'}); @@ -337,6 +339,12 @@ if (defined $opts->{'by'}) { $by = int($opts->{'by'}); } + if ( defined $opts->{'lowlabel'} ) { + $lowlabel = LJ::strip_html( $opts->{'lowlabel'} ); + } + if ( defined $opts->{'highlabel'} ) { + $highlabel = LJ::strip_html( $opts->{'highlabel'} ); + } if ($by < 1) { return $err->('poll.error.scaleincrement'); } @@ -347,7 +355,7 @@ if ( $scaleoptions > 21 ) { return $err->( 'poll.error.scaletoobig1', { 'maxselections' => 21, 'selections' => $scaleoptions - 21 } ); } - $qopts{'opts'} = "$from/$to/$by"; + $qopts{'opts'} = "$from/$to/$by/$lowlabel/$highlabel"; } $qopts{'type'} = lc($opts->{'type'}) || "text"; @@ -1107,7 +1115,7 @@ 'selected' => $prevanswer }, @optlist); } elsif ($q->type eq "scale" && $do_form) { #### scales (from 1-10) questions - my ($from, $to, $by) = split(m!/!, $q->opts); + my ( $from, $to, $by, $lowlabel, $highlabel ) = split( m!/!, $q->opts ); $by ||= 1; my $count = int(($to-$from)/$by) + 1; my $do_radios = ($count <= 11); @@ -1117,6 +1125,9 @@ $results_table .= "<table summary=''><tr valign='top' align='center'>"; + # appends the lower end + $results_table .= "<td style='padding-right: 5px;'><b>$lowlabel</b></td>" if defined $lowlabel; + for (my $at=$from; $at<=$to; $at+=$by) { my $selectedanswer = !$clearanswers && ( defined $preval{$qid} && $at == $preval{$qid}); @@ -1127,6 +1138,9 @@ $results_table .= "<br /><label for='pollq-$pollid-$qid-$at'>$at</label></td>"; } + # appends the higher end + $results_table .= "<td style='padding-left: 5px;'><b>$highlabel</b></td>" if defined $highlabel; + $results_table .= "</tr></table>\n"; # many opts, display select @@ -1135,9 +1149,15 @@ $prevanswer = $clearanswers ? "" : $preval{$qid}; my @optlist = ('', ''); - for (my $at=$from; $at<=$to; $at+=$by) { + push @optlist, ( $from, $from . " " . $lowlabel ); + + my $at = 0; + for ( $at=$from+$by; $at<=$to-$by; $at+=$by ) { push @optlist, ($at, $at); } + + push @optlist, ( $at, $at . " " . $highlabel ); + $results_table .= LJ::html_select({ 'name' => "pollq-$qid", 'class'=>"poll-$pollid", 'selected' => $prevanswer }, @optlist); } @@ -1159,11 +1179,14 @@ # generate poll items dynamically if this is a scale if ($q->type eq 'scale') { - my ($from, $to, $by) = split(m!/!, $q->opts); + my ( $from, $to, $by, $lowlabel, $highlabel ) = split( m!/!, $q->opts ); $by = 1 unless ($by > 0 and int($by) == $by); - for (my $at=$from; $at<=$to; $at+=$by) { - push @items, [$at, $at]; # note: fake itemid, doesn't matter, but needed to be uniqeu + + push @items, [ $from, "$lowlabel $from" ]; + for (my $at=$from+$by; $at<=$to-$by; $at+=$by) { + push @items, [$at, $at]; # note: fake itemid, doesn't matter, but needed to be unique } + push @items, [ $to, "$highlabel $to" ]; } foreach my $item (@items) { @@ -1548,7 +1571,7 @@ } } if ($q->type eq "scale") { - my ($from, $to, $by) = split(m!/!, $q->opts); + my ( $from, $to, $by, $lowlabel, $highlabel ) = split( m!/!, $q->opts ); if ($val < $from || $val > $to) { # bogus! cheating? $val = ""; diff -r 69d517428701 -r fce23e6b8dfe cgi-bin/LJ/Poll/Question.pm --- a/cgi-bin/LJ/Poll/Question.pm Wed Dec 07 21:53:03 2011 +0800 +++ b/cgi-bin/LJ/Poll/Question.pm Wed Dec 07 22:41:45 2011 +0800 @@ -105,7 +105,7 @@ # scale questions } elsif ($type eq 'scale') { - my ($from, $to, $by) = split(m!/!, $opts); + my ( $from, $to, $by, $lowlabel, $highlabel ) = split( m!/!, $opts ); $by ||= 1; my $count = int(($to-$from)/$by) + 1; my $do_radios = ($count <= 11); @@ -113,17 +113,25 @@ # few opts, display radios if ($do_radios) { $ret .= "<table summary=''><tr valign='top' align='center'>\n"; + $ret .= "<td style='padding-right: 5px;'><b>$lowlabel</b></td>"; for (my $at = $from; $at <= $to; $at += $by) { $ret .= "<td>" . LJ::html_check({ 'type' => 'radio' }) . "<br />$at</td>\n"; } + $ret .= "<td style='padding-left: 5px;'><b>$highlabel</b></td>"; $ret .= "</tr></table>\n"; # many opts, display select } else { - my @optlist = (); - for (my $at = $from; $at <= $to; $at += $by) { + my @optlist = ( '', ' ' ); + push @optlist, ( $from, $from . " " . $lowlabel ); + + my $at = 0; + for ( $at=$from+$by; $at<=$to-$by; $at+=$by ) { push @optlist, ('', $at); } + + push @optlist, ( $at, $at . " " . $highlabel ); + $ret .= LJ::html_select({}, @optlist); } diff -r 69d517428701 -r fce23e6b8dfe htdocs/poll/create.bml --- a/htdocs/poll/create.bml Wed Dec 07 21:53:03 2011 +0800 +++ b/htdocs/poll/create.bml Wed Dec 07 22:41:45 2011 +0800 @@ -184,7 +184,7 @@ my $qrec = {}; # validate question attributes - foreach my $atr (qw(type question opts size maxlength from to by checkmin checkmax)) { + foreach my $atr (qw(type question opts size maxlength from to by checkmin checkmax lowlabel highlabel)) { my $val = $POST{"pq_${q}_$atr"}; next unless defined $val; @@ -603,12 +603,21 @@ # scale type } elsif ($elem->{'type'} eq 'scale') { + $ret .= "<br/>\n"; foreach my $atr ( qw(from to by) ) { $ret .= ' ' . ucfirst($atr) . ": "; $ret .= LJ::html_text({ 'name' => "pq_${q}_$atr", 'value' => defined $elem->{$atr} ? $elem->{$atr} : $RULES{'scale'}->{$atr}, 'size' => '3', 'maxlength' => '9' }) . "\n"; } + $ret .= "<br />"; + foreach my $atr ( qw(lowlabel highlabel) ) { + $ret .= $ML{'.scale.' . $atr}; + $ret .= LJ::html_text({ 'name' => "pq_${q}_$atr", + 'value' => defined $elem->{$atr} ? $elem->{$atr} : "", + 'size' => '20', 'maxlength' => '50' }) . " \n"; + } + foreach my $atr ( qw(from to by items) ) { $ret .= "<br /><font size='1'><b>[$err->{$q}->{$atr}]</b></font>\n" if $err->{$q}->{$atr}; @@ -662,7 +671,7 @@ $ret .= " $el='" . LJ::ehtml($elem->{$el}) . "'"; } } elsif ($elem->{'type'} eq 'scale') { - foreach my $el ( qw(from to by) ) { + foreach my $el ( qw(from to by lowlabel highlabel) ) { $ret .= " $el='" . LJ::ehtml($elem->{$el}) . "'"; } } elsif ($elem->{'type'} eq 'check') { diff -r 69d517428701 -r fce23e6b8dfe htdocs/poll/create.bml.text --- a/htdocs/poll/create.bml.text Wed Dec 07 21:53:03 2011 +0800 +++ b/htdocs/poll/create.bml.text Wed Dec 07 22:41:45 2011 +0800 @@ -63,6 +63,10 @@ .questions=Poll Questions +.scale.lowlabel=Low label: + +.scale.highlabel=High label: + .seecode.desc=This is the code for your poll. Use the buttons below to go back and make changes, or to post it to your journal. .title=Poll Creator --------------------------------------------------------------------------------