afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
afuna ([personal profile] afuna) wrote in [site community profile] changelog2009-10-11 10:16 am

[dw-nonfree] Preview suggestions

[commit: http://hg.dwscoalition.org/dw-nonfree/rev/93544909339c]

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

Add preview and spellcheck to suggestions form.

Patch by [personal profile] yvi.

Files modified:
  • htdocs/site/suggest.bml
--------------------------------------------------------------------------------
diff -r 0f114ba0bf7d -r 93544909339c htdocs/site/suggest.bml
--- a/htdocs/site/suggest.bml	Sun Oct 11 09:20:20 2009 +0000
+++ b/htdocs/site/suggest.bml	Sun Oct 11 10:16:29 2009 +0000
@@ -45,7 +45,7 @@ body<=
 
     # handle the results of a POST request:
 
-    if ( LJ::did_post() ) {
+    if ( LJ::did_post() && $POST{post} ) {
 
         # verify that all fields are filled out:
         my @pieces = ( "title", "area", "summary", "description" );
@@ -154,6 +154,38 @@ body<=
             return "<h2>Success!</h2>\n<p>Your suggestion has been submitted to the moderation queue of $commname. Once approved, it will appear in the community for discussion and evaluation.";
         }
 
+    } elsif ( LJ::did_post() && $POST{preview} ) {
+        # make preview: first preview the title and text as it would show up in the entry later
+        # we don't need the poll in here, as the user can't influence it anyway
+        $ret .= "<p><h2>Preview:</h2></p>";
+
+        # generate entry text, escaping HTML, but with linebreaks
+        $suggestion .= "<p><em><strong>Title:</strong></em>\n";
+        $suggestion .= LJ::ehtml( $POST{title} ) . "</p>";
+        $suggestion .= "<p><em><strong>Area:</strong></em>\n";
+        $suggestion .= LJ::ehtml( $POST{area} ) . "</p>";
+        $suggestion .= "<p><em><strong>Summary:</strong></em>\n";
+        $suggestion .= LJ::ehtml( $POST{summary} ) . "</p>";
+        $suggestion .= "<p><em><strong>Description:</strong></em>\n";
+        $suggestion .= LJ::ehtml( $POST{description} ) . "</p>";
+
+        $ret .= LJ::html_newlines( $suggestion );
+
+        # then run a spellcheck and show that as a separate section
+        my $spellcheck_html;
+        if ( $LJ::SPELLER ) {
+            my $s = new LJ::SpellCheck { 'spellcommand' => $LJ::SPELLER,
+                                     'color' => '<?hotcolor?>', };
+            $spellcheck_html = $s->check_html(\$suggestion);
+            # unescape the <br />s for readability. All other HTML remains untouched.
+            $spellcheck_html =~ s/&lt;br \/&gt;/<br \/>/g;
+        }
+        if ( $spellcheck_html ) {
+            $ret .= "<hr><p><h2>Spellcheck:</h2></p>";
+            $ret .= $spellcheck_html . "<br />";
+        }
+
+        $ret .= "<hr>";
     }
 
 
@@ -172,7 +204,8 @@ body<=
     $ret .= LJ::html_text( { 
                             name => 'title',
                             size => 60,
-                            maxlength => 100
+                            maxlength => 100,
+                            value => $POST{title}
                           } );
 
     # Area (for tag cues)
@@ -180,7 +213,8 @@ body<=
     $ret .= LJ::html_text( { 
                             name => 'area',
                             size => 60,
-                            maxlength => 100
+                            maxlength => 100,
+                            value => $POST{area}
                           } );
 
 
@@ -190,7 +224,8 @@ body<=
                                 name => 'summary',
                                 rows => 3,
                                 cols => 60,
-                                wrap => 'soft'
+                                wrap => 'soft',
+                                value => $POST{summary}
                               } );
 
     # Full description:
@@ -199,12 +234,15 @@ body<=
                                 name => 'description',
                                 rows => 7,
                                 cols => 60,
-                                wrap => 'soft'
+                                wrap => 'soft',
+                                value => $POST{description}
                               } );
 
     # and, the submit button:
+    $ret .= "<p>" . LJ::html_submit( 'post', "Post Suggestion" ) . "</form>";
 
-    $ret .= "<p>" . LJ::html_submit( "Post Suggestion" ) . "</p></form>";
+    # preview and spellcheck button:
+    $ret .= "&nbsp" . LJ::html_submit( 'preview', "Preview & Spellcheck" ) . "</p></form>";
 
     return $ret;
 }
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org