fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-02-28 01:30 pm

[dw-free] More scale options allowed in polls

[commit: http://hg.dwscoalition.org/dw-free/rev/f199a27c29c2]

http://bugs.dwscoalition.org/show_bug.cgi?id=3475

Make error message for having too large a scale much much clearer, so it's
obvious how to fix it.

Patch by [personal profile] yvi.

Files modified:
  • bin/upgrading/en.dat
  • cgi-bin/LJ/Poll.pm
  • htdocs/poll/create.bml
  • htdocs/poll/create.bml.text
--------------------------------------------------------------------------------
diff -r f89a10575f39 -r f199a27c29c2 bin/upgrading/en.dat
--- a/bin/upgrading/en.dat	Mon Feb 28 21:18:32 2011 +0800
+++ b/bin/upgrading/en.dat	Mon Feb 28 21:29:57 2011 +0800
@@ -2442,7 +2442,7 @@ poll.error.scalefromlessto=Scale 'from' 
 
 poll.error.scaleincrement=Scale increment must be at least 1.
 
-poll.error.scaletoobig=Your scale exceeds the limit of 20 selections (to-from)/by > 20.
+poll.error.scaletoobig1=Your scale exceeds the limit of [[maxselections]] selections by [[selections]].
 
 poll.error.tagnotopen=You cannot close an [[tag]] tag that's not open.
 
diff -r f89a10575f39 -r f199a27c29c2 cgi-bin/LJ/Poll.pm
--- a/cgi-bin/LJ/Poll.pm	Mon Feb 28 21:18:32 2011 +0800
+++ b/cgi-bin/LJ/Poll.pm	Mon Feb 28 21:29:57 2011 +0800
@@ -343,8 +343,9 @@ sub new_from_html {
                     if ($from >= $to) {
                         return $err->('poll.error.scalelessto');
                     }
-                    if ((($to-$from)/$by) > 20) {
-                        return $err->('poll.error.scaletoobig');
+                    my $scaleoptions = ( ( $to - $from ) / $by ) + 1;
+                    if ( $scaleoptions > 21 ) {
+                        return $err->( 'poll.error.scaletoobig1', { 'maxselections' => 21, 'selections' => $scaleoptions - 21 } );
                     }
                     $qopts{'opts'} = "$from/$to/$by";
                 }
diff -r f89a10575f39 -r f199a27c29c2 htdocs/poll/create.bml
--- a/htdocs/poll/create.bml	Mon Feb 28 21:18:32 2011 +0800
+++ b/htdocs/poll/create.bml	Mon Feb 28 21:29:57 2011 +0800
@@ -55,7 +55,7 @@ _c?>
                   "from" => 1,             # default from value for a scale
                   "to" => 10,             # default to value for a scale
                   "by" => 1,             # default by value for a scale
-                  "maxitems" => 20,         # maximum number of items allowed in a scale
+                  "maxitems" => 21,         # maximum number of items allowed in a scale
               },
               "checkbox" => {
                   "checkmin" => 0,      # number of checkboxes a user must tick in that question (default 0: no limit)  
@@ -247,8 +247,10 @@ _c?>
                         $err->{$q}->{'from'} = $ML{'.error.scalemaxlessmin'};
                     }
 
-                    if ((($qrec->{'to'}-$qrec->{'from'})/$qrec->{'by'}) > $RULES{'scale'}->{'maxitems'}) {
-                        $err->{$q}->{'to'} = BML::ml('.error.scaletoobig', { 'max' => $RULES{'scale'}->{'maxitems'} });
+                    my $scaleoptions = ( ( $qrec->{to} - $qrec->{from} ) / $qrec->{by} ) + 1;
+                    if ( $scaleoptions > $RULES{scale}->{maxitems} ) {
+                        $err->{$q}->{to} = BML::ml( '.error.scaletoobig1', { 'maxselections' => $RULES{scale}->{maxitems},
+                            'selections' => $scaleoptions - $RULES{scale}->{maxitems} } );
                     }
 
                     next;
diff -r f89a10575f39 -r f199a27c29c2 htdocs/poll/create.bml.text
--- a/htdocs/poll/create.bml.text	Mon Feb 28 21:18:32 2011 +0800
+++ b/htdocs/poll/create.bml.text	Mon Feb 28 21:29:57 2011 +0800
@@ -39,7 +39,7 @@
 
 .error.scalemininvalid=Scale increment must be at least [[min]].
 
-.error.scaletoobig=Limit of [[max]] selections (to-from)/by > 20
+.error.scaletoobig1=Your scale exceeds the limit of [[maxselections]] selections by [[selections]].
 
 .error.texttoolong=The text of your option is too long and has been truncated.
 
--------------------------------------------------------------------------------