[pLog-svn] r5723 - in plog/trunk: class/action/admin js/ui js/ui/pages templates/admin
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Wed Jul 25 10:25:18 EDT 2007
Author: oscar
Date: 2007-07-25 10:25:18 -0400 (Wed, 25 Jul 2007)
New Revision: 5723
Modified:
plog/trunk/class/action/admin/adminchangepostscategoryaction.class.php
plog/trunk/class/action/admin/adminchangepostslocationaction.class.php
plog/trunk/class/action/admin/adminchangepostsstatusaction.class.php
plog/trunk/js/ui/forms.js
plog/trunk/js/ui/pages/posts.js
plog/trunk/templates/admin/editposts.template
Log:
Implemented background bulk processing operations for posts.
Modified: plog/trunk/class/action/admin/adminchangepostscategoryaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminchangepostscategoryaction.class.php 2007-07-25 14:24:46 UTC (rev 5722)
+++ plog/trunk/class/action/admin/adminchangepostscategoryaction.class.php 2007-07-25 14:25:18 UTC (rev 5723)
@@ -30,7 +30,9 @@
$this->registerFieldValidator( "postCategories", new ArrayValidator( new IntegerValidator()));
$view = new AdminPostsListView( $this->_blogInfo );
$view->setErrorMessage( $this->_locale->tr("error_incorrect_article_id"));
- $this->setValidationErrorView( $view );
+ $this->setValidationErrorView( $view );
+
+ $this->requirePermission( "update_post" );
}
/**
@@ -38,6 +40,11 @@
*/
function _changePostsCategory()
{
+ // prepare the parameters.. If there's only one category id, then add it to
+ // an array.
+ $this->_postIds = $this->_request->getValue( "postIds" );
+ $this->_postCategories = $this->_request->getValue( "postCategories" );
+
// Chanages the post category field by selection
$articles = new Articles();
$errorMessage = "";
@@ -75,27 +82,36 @@
}
// clean up the cache
- CacheControl::resetBlogCache( $this->_blogInfo->getId());
+ if( $totalOk > 0 )
+ CacheControl::resetBlogCache( $this->_blogInfo->getId());
- $this->_view = new AdminPostsListView( $this->_blogInfo );
- if( $errorMessage != "" )
- $this->_view->setErrorMessage( $errorMessage );
- if( $successMessage != "" )
- $this->_view->setSuccessMessage( $successMessage );
-
- $this->setCommonData();
-
- return true;
+
+ return( Array( "errorMessage" => $errorMessage, "successMessage" => $successMessage ));
}
function perform()
{
- // prepare the parameters.. If there's only one category id, then add it to
- // an array.
- $this->_postIds = $this->_request->getValue( "postIds" );
- $this->_postCategories = $this->_request->getValue( "postCategories" );
-
- $this->_changePostsCategory();
+ $results = $this->_changePostsCategory();
+
+ $this->_view = new AdminPostsListView( $this->_blogInfo );
+ if( $results["errorMessage"] != "" ) $this->_view->setErrorMessage( $results["errorMessage"] );
+ if( $results["successMessage"] != "" ) $this->_view->setSuccessMessage( $results["successMessage"] );
+ $this->setCommonData();
}
+
+ /**
+ * Ajax-specific behaviour
+ */
+ function performAjax()
+ {
+ $results = $this->_changePostsCategory();
+
+ lt_include( PLOG_CLASS_PATH."class/view/admin/ajax/adminajaxview.class.php" );
+ $this->_view = new AdminAjaxView( $this->_blogInfo );
+ $this->_view->setResult( $results );
+
+ // better to return true if everything fine
+ return true;
+ }
}
?>
\ No newline at end of file
Modified: plog/trunk/class/action/admin/adminchangepostslocationaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminchangepostslocationaction.class.php 2007-07-25 14:24:46 UTC (rev 5722)
+++ plog/trunk/class/action/admin/adminchangepostslocationaction.class.php 2007-07-25 14:25:18 UTC (rev 5723)
@@ -31,14 +31,21 @@
$this->registerFieldValidator( "postLocation", new IntegerValidator() );
$view = new AdminPostsListView( $this->_blogInfo );
$view->setErrorMessage( $this->_locale->tr("error_incorrect_article_id"));
- $this->setValidationErrorView( $view );
+ $this->setValidationErrorView( $view );
+
+ $this->requirePermission( "update_post" );
}
/**
* Carries out the specified action
*/
- function _changePostsStatus()
+ function _changePostsLocation()
{
+ // prepare the parameters.. If there's only one category id, then add it to
+ // an array.
+ $this->_postIds = $this->_request->getValue( "postIds" );
+ $this->_postLocation = $this->_request->getValue( "postLocation" );
+
// Chanages the post status field by selection
$articles = new Articles();
$errorMessage = "";
@@ -76,27 +83,37 @@
}
// clean up the cache
- CacheControl::resetBlogCache( $this->_blogInfo->getId());
+ if( $totalOk > 0 )
+ CacheControl::resetBlogCache( $this->_blogInfo->getId());
- $this->_view = new AdminPostsListView( $this->_blogInfo );
- if( $errorMessage != "" )
- $this->_view->setErrorMessage( $errorMessage );
- if( $successMessage != "" )
- $this->_view->setSuccessMessage( $successMessage );
-
- $this->setCommonData();
-
- return true;
+ return( Array( "errorMessage" => $errorMessage, "successMessage" => $successMessage ));
}
function perform()
{
- // prepare the parameters.. If there's only one category id, then add it to
- // an array.
- $this->_postIds = $this->_request->getValue( "postIds" );
- $this->_postLocation = $this->_request->getValue( "postLocation" );
-
- $this->_changePostsStatus();
+ $results = $this->_changePostsLocation();
+
+ $this->_view = new AdminPostsListView( $this->_blogInfo );
+ if( $results["errorMessage"] != "" ) $this->_view->setErrorMessage( $results["errorMessage"] );
+ if( $results["successMessage"] != "" ) $this->_view->setSuccessMessage( $results["successMessage"] );
+ $this->setCommonData();
+
+ return( true );
}
+
+ /**
+ * Ajax-specific behaviour
+ */
+ function performAjax()
+ {
+ $results = $this->_changePostsLocation();
+
+ lt_include( PLOG_CLASS_PATH."class/view/admin/ajax/adminajaxview.class.php" );
+ $this->_view = new AdminAjaxView( $this->_blogInfo );
+ $this->_view->setResult( $results );
+
+ // better to return true if everything fine
+ return true;
+ }
}
?>
\ No newline at end of file
Modified: plog/trunk/class/action/admin/adminchangepostsstatusaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminchangepostsstatusaction.class.php 2007-07-25 14:24:46 UTC (rev 5722)
+++ plog/trunk/class/action/admin/adminchangepostsstatusaction.class.php 2007-07-25 14:25:18 UTC (rev 5723)
@@ -30,7 +30,9 @@
$this->registerFieldValidator( "postStatus", new IntegerValidator());
$view = new AdminPostsListView( $this->_blogInfo );
$view->setErrorMessage( $this->_locale->tr("error_incorrect_article_id"));
- $this->setValidationErrorView( $view );
+ $this->setValidationErrorView( $view );
+
+ $this->requirePermission( "update_post" );
}
/**
@@ -38,6 +40,9 @@
*/
function _changePostsStatus()
{
+ $this->_postIds = $this->_request->getValue( "postIds" );
+ $this->_postStatus = $this->_request->getValue( "postStatus" );
+
// Chanages the post status field by selection
$articles = new Articles();
$errorMessage = "";
@@ -75,27 +80,38 @@
}
// clean up the cache
- CacheControl::resetBlogCache( $this->_blogInfo->getId());
+ if( $totalOk > 0 )
+ CacheControl::resetBlogCache( $this->_blogInfo->getId());
- $this->_view = new AdminPostsListView( $this->_blogInfo );
- if( $errorMessage != "" )
- $this->_view->setErrorMessage( $errorMessage );
- if( $successMessage != "" )
- $this->_view->setSuccessMessage( $successMessage );
-
- $this->setCommonData();
-
- return true;
+ return( Array( "errorMessage" => $errorMessage, "successMessage" => $successMessage ));
}
function perform()
{
// prepare the parameters.. If there's only one category id, then add it to
// an array.
- $this->_postIds = $this->_request->getValue( "postIds" );
- $this->_postStatus = $this->_request->getValue( "postStatus" );
+
- $this->_changePostsStatus();
+ $results = $this->_changePostsStatus();
+ $this->_view = new AdminPostsListView( $this->_blogInfo );
+ if( $results["errorMessage"] != "" ) $this->_view->setErrorMessage( $results["errorMessage"] );
+ if( $results["successMessage"] != "" ) $this->_view->setSuccessMessage( $results["successMessage"] );
+ $this->setCommonData();
}
+
+ /**
+ * Ajax-specific behaviour
+ */
+ function performAjax()
+ {
+ $results = $this->_changePostsStatus();
+
+ lt_include( PLOG_CLASS_PATH."class/view/admin/ajax/adminajaxview.class.php" );
+ $this->_view = new AdminAjaxView( $this->_blogInfo );
+ $this->_view->setResult( $results );
+
+ // better to return true if everything fine
+ return true;
+ }
}
?>
\ No newline at end of file
Modified: plog/trunk/js/ui/forms.js
===================================================================
--- plog/trunk/js/ui/forms.js 2007-07-25 14:24:46 UTC (rev 5722)
+++ plog/trunk/js/ui/forms.js 2007-07-25 14:25:18 UTC (rev 5723)
@@ -128,6 +128,31 @@
}
/**
+ * Checks that there is at least one element selected
+ * in a list
+ *
+ * @param box The drop-down list
+ * @return True if there is at least one element selected
+ * or false otherwise
+ */
+Lifetype.Forms.List.atLeastOneSelected = function( listId )
+{
+ list = Lifetype.Dom.$( listId );
+ if( list == undefined )
+ return( false );
+
+ var found = false;
+ for( var i = 0; i < list.options.length; i++ ) {
+ if( list.options[i].selected == true ) {
+ found = true;
+ break;
+ }
+ }
+
+ return( found );
+}
+
+/**
* Toggles all checkboxes within a form
*/
Lifetype.Forms.toggleAllChecks = function(formName, prefix)
@@ -436,4 +461,4 @@
{
element = dest.getElementById( fieldName );
element.value = value;
-}
\ No newline at end of file
+}
Modified: plog/trunk/js/ui/pages/posts.js
===================================================================
--- plog/trunk/js/ui/pages/posts.js 2007-07-25 14:24:46 UTC (rev 5722)
+++ plog/trunk/js/ui/pages/posts.js 2007-07-25 14:25:18 UTC (rev 5723)
@@ -10,10 +10,16 @@
{
if ( op == 'changePostsStatus' ) {
if ( document.getElementById("postsList").postStatus.value == -1 )
- window.alert(errorLocationMsg);
+ window.alert(errorPostStatusMsg);
else {
document.getElementById("postsList").op.value = op;
- document.getElementById("postsList").submit();
+
+ // it's actually a bit annoying that calling form.submit() via
+ // Javascript will not execute our event handler in the
+ // form's onSubmit event, so we'll have to do it
+ // manually
+ Lifetype.Forms.performRequest(Lifetype.Dom.$( 'postsList' ));
+ return( false );
}
}
else if( op == 'changePostsLocation' ) {
@@ -22,9 +28,25 @@
}
else {
document.getElementById("postsList").op.value = op;
- document.getElementById("postsList").submit();
+
+ // same thing here with the form submit
+ Lifetype.Forms.performRequest(Lifetype.Dom.$( 'postsList' ));
+ return( false );
}
}
+ else if( op == 'changePostsCategory' ) {
+ //if ( document.getElementById("postsList").postLocation.value == -1 ) {
+ if( !Lifetype.Forms.List.atLeastOneSelected( "postCategories" )) {
+ window.alert(errorPostCategoryMsg);
+ }
+ else {
+ document.getElementById("postsList").op.value = op;
+
+ // same thing here with the form submit
+ Lifetype.Forms.performRequest(Lifetype.Dom.$( 'postsList' ));
+ return( false );
+ }
+ }
}
YAHOO.util.Event.addListener( window, "load", function() {
@@ -35,4 +57,4 @@
// reload the list when successfully deleting an item and processing one of the forms
Lifetype.Forms.Events.performRequestSuccessEvent.subscribe( Lifetype.UI.AjaxPager.reload );
Lifetype.Forms.Events.formProcessorSuccessEvent.subscribe( Lifetype.UI.AjaxPager.reload );
-});
\ No newline at end of file
+});
Modified: plog/trunk/templates/admin/editposts.template
===================================================================
--- plog/trunk/templates/admin/editposts.template 2007-07-25 14:24:46 UTC (rev 5722)
+++ plog/trunk/templates/admin/editposts.template 2007-07-25 14:25:18 UTC (rev 5723)
@@ -5,7 +5,8 @@
<script type="text/javascript" src="js/ui/plogui.js"></script>
<script type="text/javascript">
var errorPostStatusMsg = '{$locale->tr("error_post_status")}';
- var errorLocationMsg = '{$locale->tr("error_post_location")}';
+ var errorPostLocationMsg = '{$locale->tr("error_post_location")}';
+ var errorPostCategoryMsg = '{$locale->tr("error_no_category_selected")}';
var showMassiveChangeOption = '{$locale->tr("show_massive_change_option")}';
var hideMassiveChangeOption = '{$locale->tr("hide_massive_change_option")}';
</script>
More information about the pLog-svn
mailing list