[pLog-svn] r3366 - in plog/trunk: class/action/admin js/tinymce js/ui locale templates/admin

mark at devel.lifetype.net mark at devel.lifetype.net
Mon May 8 14:54:19 GMT 2006


Author: mark
Date: 2006-05-08 14:54:18 +0000 (Mon, 08 May 2006)
New Revision: 3366

Modified:
   plog/trunk/class/action/admin/adminaddpostaction.class.php
   plog/trunk/js/tinymce/tiny_mce-plog.js
   plog/trunk/js/ui/plogui.js
   plog/trunk/locale/locale_en_UK.php
   plog/trunk/locale/locale_zh_TW.php
   plog/trunk/templates/admin/header.template
   plog/trunk/templates/admin/newpost.template
Log:
Autosvae done. Now, user don't need to worry about system crash, browser crash ...or even session time out ...

All data saved in cookie, if something wrong. It will come out when you click newpost link next time.

** I only implement it in newPost, I think it should be enough.

Modified: plog/trunk/class/action/admin/adminaddpostaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminaddpostaction.class.php	2006-05-08 14:14:46 UTC (rev 3365)
+++ plog/trunk/class/action/admin/adminaddpostaction.class.php	2006-05-08 14:54:18 UTC (rev 3366)
@@ -122,7 +122,9 @@
 			
         	// once we have built the object, we can add it to the database
         	if( $artId ) {
-			
+	            // clear autosave cookie
+	            $this->clearAutoSaveCookie();
+
                 $this->_view = new AdminPostsListView( $this->_blogInfo );
             	//$article->setId( $artId );
                 $message = $this->_locale->tr("post_added_ok");
@@ -204,9 +206,15 @@
         	}
 
             $this->setCommonData();
-
+            
             // better to return true if everything fine
             return true;
         }
+        
+        function clearAutoSaveCookie()
+        {
+        	// set the auto save cookie as false
+	    	setcookie( 'LTpostNotSaved', '0', -1, '/' );	
+        }
     }
 ?>
\ No newline at end of file

Modified: plog/trunk/js/tinymce/tiny_mce-plog.js
===================================================================
--- plog/trunk/js/tinymce/tiny_mce-plog.js	2006-05-08 14:14:46 UTC (rev 3365)
+++ plog/trunk/js/tinymce/tiny_mce-plog.js	2006-05-08 14:54:18 UTC (rev 3366)
@@ -18,6 +18,7 @@
 	theme_advanced_path_location : "bottom",
 	theme_advanced_resizing : true,
 	theme_advanced_resize_horizontal : false,
+	onchange_callback : "tinyMCEOnChangeEvent",
 	extended_valid_elements : "a[class|name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
 	verify_html : true,
 	valid_elements : ""

Modified: plog/trunk/js/ui/plogui.js
===================================================================
--- plog/trunk/js/ui/plogui.js	2006-05-08 14:14:46 UTC (rev 3365)
+++ plog/trunk/js/ui/plogui.js	2006-05-08 14:54:18 UTC (rev 3366)
@@ -1,4 +1,76 @@
 /**
+ * functions for auto save
+ */
+
+function initialAutoSave()
+{
+	LTpostNotSaved = getCookie( 'LTpostNotSaved' );
+	if ( LTpostNotSaved == 1 )
+	{
+		$('autoSaveMessage').innerHTML = msgAutoSaveMessage;
+		Element.show($('autoSaveMessage'));
+	}
+	else
+	{
+		deleteCookie( 'LTpostNotSaved' );
+		deleteCookie( 'LTpostText' );
+		deleteCookie( 'LTpostExtendedText' );
+	}
+}
+
+function restoreAutoSave()
+{
+	if( htmlAreaEnabled )
+	{
+		tinyMCE.getInstanceById('postText').getBody().innerHTML  = decodeURIComponent( getCookie( 'LTpostText' ) );
+		tinyMCE.getInstanceById('postExtendedText').getBody().innerHTML  = decodeURIComponent( getCookie( 'LTpostExtendedText' ) );
+	}
+	else
+	{
+		$('postText').value = decodeURIComponent( getCookie( 'LTpostText' ) );
+		$('postExtendedText').value = decodeURIComponent( getCookie( 'LTpostExtendedText' ) );
+	}
+	
+	$('autoSaveMessage').innerHTML = '';
+	Element.hide($('autoSaveMessage'));
+}
+
+function eraseAutoSave()
+{
+	deleteCookie( 'LTpostNotSaved' );
+	deleteCookie( 'LTpostText' );
+	deleteCookie( 'LTpostExtendedText' );
+	
+	$('autoSaveMessage').innerHTML = '';
+	Element.hide($('autoSaveMessage'));
+}
+
+function tinyMCEOnChangeEvent( inst ) {
+	// set the postNotSaved ture
+	setCookie( 'LTpostNotSaved', 1, 7);
+	
+	// postText
+	if( inst.editorId == 'mce_editor_0' )
+		cookieId = 'LTpostText';
+	else
+		cookieId = 'LTpostExtendedText';
+	
+	setCookie( cookieId, encodeURIComponent( inst.getBody().innerHTML ), 7 );
+}
+
+function plogEditorOnChangeEvent( editor ) {
+	setCookie( 'LTpostNotSaved', 1, 7);
+	
+	// postText
+	if( editor.id == 'postText' )
+		cookieId = 'LTpostText';
+	else
+		cookieId = 'LTpostExtendedText';
+		
+	setCookie( cookieId, encodeURIComponent( editor.value ), 7 );
+}
+
+/**
  * when adding a new form, checks that there is at least one category selected
  */
 function submitNewPost(form)

Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php	2006-05-08 14:14:46 UTC (rev 3365)
+++ plog/trunk/locale/locale_en_UK.php	2006-05-08 14:54:18 UTC (rev 3366)
@@ -1024,4 +1024,6 @@
 
 $messages['change_album'] = 'Change Album';
 
+$messages['warning_autosave_message'] = '<img src="imgs/admin/icon_warning-16.png" alt="Error" class="InfoIcon"/><p class="ErrorText">You seem to have left here without saving your post. If so, you may <a href="#" onclick="restoreAutoSave();">click here to restore it</a> or <a href="#" onclick="eraseAutoSave();">delete it</a>.</p>';
+
 ?>
\ No newline at end of file

Modified: plog/trunk/locale/locale_zh_TW.php
===================================================================
--- plog/trunk/locale/locale_zh_TW.php	2006-05-08 14:14:46 UTC (rev 3365)
+++ plog/trunk/locale/locale_zh_TW.php	2006-05-08 14:54:18 UTC (rev 3366)
@@ -1022,6 +1022,8 @@
 $messages['enable_pull_down_menu'] = '下拉式選單';
 $messages['enable_pull_down_menu_help'] = '啟用或關閉下拉式選單。';
 
-$messages['change_album'] = '修改檔案夾';
-
+$messages['change_album'] = '修改檔案夾';
 
+
+$messages['warning_autosave_message'] = '<img src="imgs/admin/icon_warning-16.png" alt="Error" class="InfoIcon"/><p class="ErrorText">你好像有之前尚未存檔的文章。如果你還想繼續編輯,你可以 <a href="#" onclick="restoreAutoSave();">取回未存檔文章繼續編輯</a> 或是 <a href="#" onclick="eraseAutoSave();">把他刪除</a> 。</p>';
+
 ?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/header.template
===================================================================
--- plog/trunk/templates/admin/header.template	2006-05-08 14:14:46 UTC (rev 3365)
+++ plog/trunk/templates/admin/header.template	2006-05-08 14:54:18 UTC (rev 3366)
@@ -16,6 +16,7 @@
 <![endif] -->
 <script type="text/javascript" src="js/ui/default.js"></script>
 <script type="text/javascript" src="js/ui/common.js"></script>
+<script type="text/javascript" src="js/cookie/cookie.js"></script>
 <script type="text/javascript">
     var blogLocale = '{$locale->getCharset()|upper}';
 </script>

Modified: plog/trunk/templates/admin/newpost.template
===================================================================
--- plog/trunk/templates/admin/newpost.template	2006-05-08 14:14:46 UTC (rev 3365)
+++ plog/trunk/templates/admin/newpost.template	2006-05-08 14:54:18 UTC (rev 3366)
@@ -24,7 +24,8 @@
   var msgErrorPostText = "{$locale->tr("error_missing_post_text")}";
   var msgSaving = "{$locale->tr("saving_message")}";
   var msgShowOptionPanel = "{$locale->tr("show_option_panel")}";
-  var msgHideOptionPanel = "{$locale->tr("hide_option_panel")}";  
+  var msgHideOptionPanel = "{$locale->tr("hide_option_panel")}";
+  var msgAutoSaveMessage = '{$locale->tr("warning_autosave_message")}';
   
   var todayDay = '{$today->getDay()}';
   var todayMonth = '{$today->getMonth()}';
@@ -43,6 +44,7 @@
    </div> 
 
    <div id="mainPanel" style="float:left; width: 73%; border-right: 1px solid #DEDEDE;">
+	   <div id="autoSaveMessage" style="display: none;"></div>
 	   {include file="$admintemplatepath/formvalidate.template" message=$locale->tr("error_adding_post")}  
 	   <div class="field">
 	     <label for="postTopic">{$locale->tr("topic")}</label>
@@ -60,7 +62,7 @@
 		 <span class="required">*</span>
 		 <div class="formHelp">{$locale->tr("text_help")}</div>
 	     {if !$htmlarea}<script type="text/javascript">var ed1 = new pLogEditor('postText','ed1');</script>{/if}
-	     <textarea {if $htmlarea==1}rows="20"{else}rows="15"{/if} id="postText" name="postText" style="width:100%">{$postText}</textarea>
+	     <textarea {if $htmlarea==1}rows="20"{else}rows="15"{/if} id="postText" name="postText" style="width:100%" {if !$htmlarea}onChange="javascript:plogEditorOnChangeEvent(this);"{/if}>{$postText}</textarea>
 	     {include file="$admintemplatepath/validate.template" field=postText message=$locale->tr("error_missing_post_text")}   
 	   </div>
 	   
@@ -68,7 +70,7 @@
 	     <label for="postExtendedText">{$locale->tr("extended_text")}</label>
 		 <div class="formHelp">{$locale->tr("extended_text_help")}</div>
 	     {if !$htmlarea}<script type="text/javascript">var ed2 = new pLogEditor('postExtendedText','ed2');</script>{/if}
-	     <textarea {if $htmlarea}rows="25"{else}rows="20"{/if} id="postExtendedText" name="postExtendedText" style="width:100%">{$postExtendedText}</textarea>
+	     <textarea {if $htmlarea}rows="25"{else}rows="20"{/if} id="postExtendedText" name="postExtendedText" style="width:100%" {if !$htmlarea}onChange="javascript:plogEditorOnChangeEvent(this);"{/if}>{$postExtendedText}</textarea>
 	   </div>
 
 	   <div class="field">
@@ -192,5 +194,10 @@
 		<input type="hidden" name="postId" id="postId" value="{$postId}" />
     </div>
   </form>
+  {literal}
+  <script type="text/javascript">
+    initialAutoSave();
+  </script>
+  {/literal}
 {include file="$admintemplatepath/footernavigation.template"}
 {include file="$admintemplatepath/footer.template"}
\ No newline at end of file



More information about the pLog-svn mailing list