[pLog-svn] r4904 - in plog/trunk: class/action/admin js/ui templates/admin
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Thu Mar 1 09:51:19 EST 2007
Author: oscar
Date: 2007-03-01 09:51:19 -0500 (Thu, 01 Mar 2007)
New Revision: 4904
Modified:
plog/trunk/class/action/admin/adminsavedraftarticleajaxaction.class.php
plog/trunk/js/ui/common.js
plog/trunk/js/ui/plogui.js
plog/trunk/templates/admin/newpost.template
Log:
Moved the "save draft" functionality to the new framework, both in the PHP side and the javascript side.
Modified: plog/trunk/class/action/admin/adminsavedraftarticleajaxaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminsavedraftarticleajaxaction.class.php 2007-03-01 14:25:25 UTC (rev 4903)
+++ plog/trunk/class/action/admin/adminsavedraftarticleajaxaction.class.php 2007-03-01 14:51:19 UTC (rev 4904)
@@ -1,7 +1,7 @@
<?php
- lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
- lt_include( PLOG_CLASS_PATH."class/view/admin/adminxmlview.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/action/admin/ajax/adminajaxaction.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/view/admin/ajax/adminajaxview.class.php" );
lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php");
lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
@@ -9,7 +9,7 @@
* \ingroup Action
* @private
*/
- class AdminSaveDraftArticleAjaxAction extends AdminAction
+ class AdminSaveDraftArticleAjaxAction extends AdminAjaxAction
{
var $_postText;
@@ -17,7 +17,7 @@
function AdminSaveDraftArticleAjaxAction( $actionInfo, $request )
{
- $this->AdminAction( $actionInfo, $request );
+ $this->AdminAjaxAction( $actionInfo, $request );
}
function validate()
@@ -28,11 +28,7 @@
// if there is no text, extended text or topic there is no point in saving anything
if( $this->_postText == "" && $this->_postTopic == "" ) {
// nothing to do yet, so let's quit
- $this->_view = new AdminXmlView( $this->_blogInfo, "response" );
- $this->_view->setValue( "method", "saveDraftArticleAjax" );
- $this->_view->setValue( "success", "0" );
- $this->_view->setValue( "message", $this->_locale->tr( "error_saving_draft" ) );
-
+ $this->_view = $this->getErrorView( $this->_locale->tr( "error_saving_draft" ));
return false;
}
@@ -120,20 +116,15 @@
}
// once we have built the object, we can add it to the database
- $this->_view = new AdminXmlView( $this->_blogInfo, "response" );
- $this->_view->setValue( "method", "saveDraftArticleAjax" );
- if( $artId )
- {
- $this->_view->setValue( "success", "1" );
- $this->_view->setValue( "message", $this->_locale->pr( "draft_saved_ok", $this->_postTopic ) );
-
- $result = '<id>'.$artId.'</id>';
- $this->_view->setValue( "result", $result );
+ $this->_view = new AdminAjaxView( $this->_blogInfo, "saveDraftArticleAjax" );
+ if( $artId ) {
+ $this->_view->setSuccess( true );
+ $this->_view->setMessage( $this->_locale->pr( "draft_saved_ok", $this->_postTopic ) );
+ $this->_view->setResult( $article );
}
- else
- {
- $this->_view->setValue( "success", "0" );
- $this->_view->setValue( "message", $this->_locale->tr( "error_saving_draft" ) );
+ else {
+ $this->_view->setSuccess( false );
+ $this->_view->setMessage( $this->_locale->tr( "error_saving_draft" ));
}
return true;
Modified: plog/trunk/js/ui/common.js
===================================================================
--- plog/trunk/js/ui/common.js 2007-03-01 14:25:25 UTC (rev 4903)
+++ plog/trunk/js/ui/common.js 2007-03-01 14:51:19 UTC (rev 4904)
@@ -302,53 +302,4 @@
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
-}
-
-function getPostEditFormElements( formId )
-{
- var formData = '';
-
- form = document.getElementById( formId );
-
- for(i = 0; i < form.elements.length; i++ ) {
- itemName = form.elements[i].name;
- itemValue = form.elements[i].value;
-
- if( itemName != "op" ) {
- // we don't want to send more than one "op" parameter... do we?
- if( itemName == "postCategories[]" ) {
- // we need to have a special case for this one because it's a list that
- // allows multiple selection... only using the "value" attribute will
- // return one of the items and we would like to have them all
- for (var j = 0; j < form.elements[i].options.length; j++) {
- if (form.elements[i].options[j].selected)
- formData = formData + itemName + "=" + form.elements[i].options[j].value + "&";
- }
- }
- else if( itemName == "postText" && htmlAreaEnabled ) {
- if ( blogLocale == "UTF-8" ) {
- formData = formData + itemName + "=" + encodeURIComponent(tinyMCE.getContent('postText')) + "&";
- } else {
- formData = formData + itemName + "=" + escape(tinyMCE.getContent('postText')) + "&";
- }
- }
- else if( itemName == "postExtendedText" && htmlAreaEnabled ) {
- if ( blogLocale == "UTF-8" ) {
- formData = formData + itemName + "=" + encodeURIComponent(tinyMCE.getContent('postExtendedText')) + "&";
- } else {
- formData = formData + itemName + "=" + escape(tinyMCE.getContent('postExtendedText')) + "&";
- }
- }
- else {
- // for all other elements, normal handling
- if ( blogLocale == "UTF-8" ) {
- formData = formData + itemName + "=" + encodeURIComponent(itemValue) + "&";
- } else {
- formData = formData + itemName + "=" + escape(itemValue) + "&";
- }
- }
- }
- }
-
- return formData;
-}
+}
\ No newline at end of file
Modified: plog/trunk/js/ui/plogui.js
===================================================================
--- plog/trunk/js/ui/plogui.js 2007-03-01 14:25:25 UTC (rev 4903)
+++ plog/trunk/js/ui/plogui.js 2007-03-01 14:51:19 UTC (rev 4904)
@@ -13,53 +13,6 @@
}
/**
- * The following functions are called when clicking the "save draft and continue" button
- */
-function saveDraftArticleAjax()
-{
- // if there is no category selected, then we won't save a draft!
- form = document.getElementById( "newPost" );
-
- if( form.postTopic.value == '' ) {
- window.alert( msgErrorPostTopic );
- return false;
- }
-
- // Can't use form.postText.value, becasue the form.postText.value still "null"
- if( htmlAreaEnabled ) {
- postText = tinyMCE.getContent('postText');
- } else {
- postText = form.postText.value;
- }
-
- if (postText == '') {
- window.alert( msgErrorPostText );
- return false;
- }
-
- if( !submitNewPost( form ))
- return false;
-
- var formData = getPostEditFormElements( "newPost" );
- var url = plogAdminBaseUrl;
- var params = 'op=saveDraftArticleAjax&'+formData;
- var myAjax = new Ajax.Request(
- url,
- {method: 'post', parameters: params, onComplete: saveDraftArticleResponse}
- );
-}
-
-function saveDraftArticleResponse(originalRequest)
-{
- //put returned XML in the textarea
- var xmldoc = originalRequest.responseXML;
- var id = xmldoc.getElementsByTagName('id')[0].firstChild.nodeValue;
- var message = xmldoc.getElementsByTagName('message')[0].firstChild.nodeValue;
- $( 'postId' ).value = id;
- window.alert(message);
-}
-
-/**
* this function is the one called when clicking the "add category" button
*/
function switchOptionPanel()
@@ -265,6 +218,9 @@
}
}
+/**
+ * Callback for the 'add category' feature
+ */
Lifetype.UI.Pages.NewPost.addArticleCategoryOption = function(originalRequest)
{
//put returned XML in the textarea
@@ -290,4 +246,109 @@
$( 'newArticleCategory' ).value = '';
$( 'addArticleCategory' ).disabled = 0;
}
+}
+
+/**
+ * Save the article via Ajax in the background
+ */
+/**
+ * The following functions are called when clicking the "save draft and continue" button
+ */
+Lifetype.UI.Pages.NewPost.saveDraftArticleAjax = function()
+{
+ // if there is no category selected, then we won't save a draft!
+ form = document.getElementById( "newPost" );
+
+ if( form.postTopic.value == '' ) {
+ window.alert( msgErrorPostTopic );
+ return false;
+ }
+
+ // Can't use form.postText.value, becasue the form.postText.value still "null"
+ if( htmlAreaEnabled ) {
+ postText = tinyMCE.getContent('postText');
+ } else {
+ postText = form.postText.value;
+ }
+
+ if (postText == '') {
+ window.alert( msgErrorPostText );
+ return false;
+ }
+
+ if( !submitNewPost( form ))
+ return false;
+
+ var formData = Lifetype.UI.Pages.NewPost.getPostEditFormElements( "newPost" );
+
+ var params = 'op=saveDraftArticleAjax&'+formData;
+ var url = plogAdminBaseUrl + "?" + params;
+
+ var transaction = YAHOO.util.Connect.asyncRequest( 'GET', url, { success:Lifetype.UI.Pages.NewPost.saveDraftArticleResponse });
+}
+
+/**
+ * Callback for the "save draft" functionality
+ */
+Lifetype.UI.Pages.NewPost.saveDraftArticleResponse = function(originalRequest)
+{
+ // fetcth the json response
+ var msg = Lifetype.JSon.decode( originalRequest.responseText );
+
+ var id = msg.result._id;
+ var message = msg.message;
+ $( 'postId' ).value = id;
+ window.alert(message);
+}
+
+/**
+ * Gets all the fields from the "new post" form
+ */
+Lifetype.UI.Pages.NewPost.getPostEditFormElements = function( formId )
+{
+ var formData = '';
+
+ form = document.getElementById( formId );
+
+ for(i = 0; i < form.elements.length; i++ ) {
+ itemName = form.elements[i].name;
+ itemValue = form.elements[i].value;
+
+ if( itemName != "op" ) {
+ // we don't want to send more than one "op" parameter... do we?
+ if( itemName == "postCategories[]" ) {
+ // we need to have a special case for this one because it's a list that
+ // allows multiple selection... only using the "value" attribute will
+ // return one of the items and we would like to have them all
+ for (var j = 0; j < form.elements[i].options.length; j++) {
+ if (form.elements[i].options[j].selected)
+ formData = formData + itemName + "=" + form.elements[i].options[j].value + "&";
+ }
+ }
+ else if( itemName == "postText" && htmlAreaEnabled ) {
+ if ( blogLocale == "UTF-8" ) {
+ formData = formData + itemName + "=" + encodeURIComponent(tinyMCE.getContent('postText')) + "&";
+ } else {
+ formData = formData + itemName + "=" + escape(tinyMCE.getContent('postText')) + "&";
+ }
+ }
+ else if( itemName == "postExtendedText" && htmlAreaEnabled ) {
+ if ( blogLocale == "UTF-8" ) {
+ formData = formData + itemName + "=" + encodeURIComponent(tinyMCE.getContent('postExtendedText')) + "&";
+ } else {
+ formData = formData + itemName + "=" + escape(tinyMCE.getContent('postExtendedText')) + "&";
+ }
+ }
+ else {
+ // for all other elements, normal handling
+ if ( blogLocale == "UTF-8" ) {
+ formData = formData + itemName + "=" + encodeURIComponent(itemValue) + "&";
+ } else {
+ formData = formData + itemName + "=" + escape(itemValue) + "&";
+ }
+ }
+ }
+ }
+
+ return formData;
}
\ No newline at end of file
Modified: plog/trunk/templates/admin/newpost.template
===================================================================
--- plog/trunk/templates/admin/newpost.template 2007-03-01 14:25:25 UTC (rev 4903)
+++ plog/trunk/templates/admin/newpost.template 2007-03-01 14:51:19 UTC (rev 4904)
@@ -215,7 +215,7 @@
</div>
</fieldset>
<div class="buttons">
- <input type="button" name="saveDraftAndContinue" value="{$locale->tr("save_draft_and_continue")}" onclick="javascript:saveDraftArticleAjax()" />
+ <input type="button" name="saveDraftAndContinue" value="{$locale->tr("save_draft_and_continue")}" onclick="Lifetype.UI.Pages.NewPost.saveDraftArticleAjax()" />
<input type="submit" name="previewPost" value="{$locale->tr("preview")}" onClick="preview=true"/>
<input type="submit" name="addPost" value="{$locale->tr("add_post")}" onClick="preview=false" />
<input type="hidden" name="isDraft" value="" />
@@ -228,4 +228,4 @@
startAutoSave();
</script>
{include file="$admintemplatepath/footernavigation.template"}
-{include file="$admintemplatepath/footer.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file
More information about the pLog-svn
mailing list