fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-10-13 05:27 am

[dw-free] Can't create new entry after previewing it.

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

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

Replace the entry links with a message, to make it clear that we are in a
preview.

Patch by [personal profile] tyggerdev.

Files modified:
  • bin/upgrading/s2layers/core2.s2
  • htdocs/preview/entry.bml
  • htdocs/preview/entry.bml.text
--------------------------------------------------------------------------------
diff -r 7b31b791448e -r 891879298ff0 bin/upgrading/s2layers/core2.s2
--- a/bin/upgrading/s2layers/core2.s2	Wed Oct 13 12:37:28 2010 +0800
+++ b/bin/upgrading/s2layers/core2.s2	Wed Oct 13 13:27:24 2010 +0800
@@ -572,6 +572,7 @@ class Page
     function print_wrapper_start() "Start the body wrapper for this page; includes default classes";
     function print_wrapper_start(string{} opts) "Start the body wrapper for this page; includes default classes and takes a hash using the key 'class'";
     function print_wrapper_end() "End the body wrapper for this entry or comment.";
+    function print_entry_footer(Entry e) "Close up the entry";
 
     function print_time
     "Print the time when the page was created.";
@@ -837,6 +838,13 @@ class EntryPage extends Page
     function builtin print_multiform_start "Prints start of form tag and hidden elements to do a multi-comment action (multiple delete, screen, unscreen, etc...)";
     function builtin print_multiform_end "Prints end of form tag to do a multi-comment action.";
     function builtin print_multiform_actionline "Prints the line of the multiform giving instructions, options, and the submit button, using the text of the different \$*text_multiform_ properties.";
+}
+
+class EntryPreviewPage extends EntryPage
+"We disable funtionality for previews, and print messages about that"
+{
+    var string preview_warn_text "Text to display instead of management controls for previews";
+    function print_standout_box(string message) "Prints a standout box containing a message";
 }
 
 class ReplyForm
@@ -3175,6 +3183,11 @@ function Page::print_stylesheets()
         println """</style>""";
     }
 }
+function EntryPreviewPage::print_standout_box(string message)
+"Prints a standout box for warnings, etc "
+{
+    println "<div class='standout'><div class='standout-inner'><p> $message </p></div></div>";
+}
 
 function FriendsPage::print_stylesheets() {
 #This creates entry-specific CSS to allow custom colors on reading page. Rather than override this, layouts should change custom_foreground_element, custom_background_element (and custom_colors_template for advanced options) instead
@@ -4315,24 +4328,35 @@ function Page::print_entry(Entry e)
     """</div>\n""";
     """</div>\n""";
     """</div>\n""";
+
     """<div class="footer">\n""";
     """<div class="inner">\n""";
     $e->print_tags();
+    $this->print_entry_footer($e);
+    "</div>\n</div>\n";
+
+    $e->print_wrapper_end();
+
+}
+function EntryPreviewPage::print_entry_footer(Entry e)
+"Disable links to avoid people trying to edit from a preview"
+{
+    $this->print_standout_box($this.preview_warn_text);
+}
+
+function EntryPage::print_entry_footer(Entry e) {
     $e->print_management_links();
-    if ($this isa EntryPage) {
-        """<hr class="above-entry-interaction-links" />""";
-        $e->print_interaction_links("topcomment");
-        $this->print_reply_container({ "target" => "topcomment" });
-        """<hr class="below-reply-container" />""";
-    }
-    else {
+    """<hr class="above-entry-interaction-links" />""";
+    $e->print_interaction_links("topcomment");
+    $this->print_reply_container({ "target" => "topcomment" });
+    """<hr class="below-reply-container" />""";
+}
+
+function Page::print_entry_footer(Entry e) {
+    $e->print_management_links();
         $e->print_interaction_links();
-    }
-    "</div>\n</div>\n";
-    $e->print_wrapper_end();
-
-}
-
+
+}
 function RecentPage::print_sticky_entry(StickyEntry s)
 "function to print the sticky entry. can be overrised by styles to print it differently than other entries."
 {
diff -r 7b31b791448e -r 891879298ff0 htdocs/preview/entry.bml
--- a/htdocs/preview/entry.bml	Wed Oct 13 12:37:28 2010 +0800
+++ b/htdocs/preview/entry.bml	Wed Oct 13 13:27:24 2010 +0800
@@ -57,6 +57,9 @@ _c?>
     my $r = BML::get_request();
     my $ctx;
 
+    # Get the preview message to hand to S2 or use in $ret. 
+    my $preview_warn_text = $ML{".entry.preview_warn_text"}; 
+    
     if ($u && $up) {
         $r->notes->{_journal} = $u->{user};
         $r->notes->{journalid} = $u->{userid};
@@ -193,6 +196,10 @@ _c?>
 
         $ret .= $event;
         $ret .= "</div>";
+        $ret .= "<hr/><?standout <div><p>\n";
+        $ret .= $preview_warn_text . "\n";
+        $ret .= "</p></div> standout?>";
+
 
         $ret .= "<br clear='all' /><hr width='100%' size='2' align='center' />";
         
@@ -210,11 +217,12 @@ _c?>
         $LJ::S2::CURR_CTX = $ctx;
 
         my $p = LJ::S2::Page($u, $opts);
-        $p->{'_type'} = "EntryPage";
+        $p->{'_type'} = "EntryPreviewPage";
         $p->{'view'} = "entry";
         $p->{'comment_pages'} = undef;
         $p->{'comments'} = [];
         $p->{'comment_pages'} = undef;
+        $p->{'preview_warn_text'} = $preview_warn_text;
 
         my $userlite_journal = LJ::S2::UserLite($u);
         my $userlite_poster  = LJ::S2::UserLite($up);
@@ -290,6 +298,15 @@ _c?>
                 left: -10000px;
                 top: auto;
             }
+            .standout .standout-inner, .standout-colors {
+                background-color: #ffafb6;
+                color: #111;
+                border: 1px solid #c1272d;
+            }
+
+            .standout-inner a:hover, .standout-inner a:active {
+                color: #000;
+            }
             </style>
         };
 
diff -r 7b31b791448e -r 891879298ff0 htdocs/preview/entry.bml.text
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/preview/entry.bml.text	Wed Oct 13 13:27:24 2010 +0800
@@ -0,0 +1,1 @@
+.entry.preview_warn_text=This is a preview only. To save this entry, close this popup and return to your main browser window.
--------------------------------------------------------------------------------