[pLog-svn] r3360 - in plog/trunk: class/action/admin
class/controller js/ui templates/admin
mark at devel.lifetype.net
mark at devel.lifetype.net
Mon May 8 05:08:24 GMT 2006
Author: mark
Date: 2006-05-08 05:08:22 +0000 (Mon, 08 May 2006)
New Revision: 3360
Added:
plog/trunk/class/action/admin/adminchangegalleryitemsalbumaction.class.php
Modified:
plog/trunk/class/controller/admincontrollermap.properties.php
plog/trunk/js/ui/plogui.js
plog/trunk/templates/admin/resources.template
Log:
Now, we have massive option for resource. User can easily change thier resource or albums to another album massively.
Added: plog/trunk/class/action/admin/adminchangegalleryitemsalbumaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminchangegalleryitemsalbumaction.class.php 2006-05-08 03:55:46 UTC (rev 3359)
+++ plog/trunk/class/action/admin/adminchangegalleryitemsalbumaction.class.php 2006-05-08 05:08:22 UTC (rev 3360)
@@ -0,0 +1,157 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresource.class.php" );
+ include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
+ include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminresourceslistview.class.php" );
+
+ /**
+ * \ingroup Action
+ * @private
+ *
+ * Massive changes resources and albums to another Album
+ */
+ class AdminChangeGalleryItemsAlbumAction extends AdminAction
+ {
+
+ var $_resourceIds;
+ var $_albumIds;
+ var $_galleryAlbumId;
+
+ var $_successMessage;
+ var $_errorMessage;
+ var $_totalOk;
+
+ /**
+ * Constructor. If nothing else, it also has to call the constructor of the parent
+ * class, BlogAction with the same parameters
+ */
+ function AdminChangeGalleryItemsAlbumAction( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+
+ $this->_totalOk = 0;
+ $this->_successMessage = "";
+ $this->_errorMessage = "";
+
+ // data validation
+ $this->registerFieldValidator( "resourceIds", new ArrayValidator(), true );
+ $this->registerFieldValidator( "albumIds", new ArrayValidator(), true );
+ $this->registerFieldValidator( "galleryAlbumId", new IntegerValidator(), true );
+ $view = new AdminResourcesListView( $this->_blogInfo );
+ $view->setErrorMessage( $this->_locale->tr("error_no_resources_selected"));
+ $this->setValidationErrorView( $view );
+ }
+
+ function perform()
+ {
+ // create the view
+ $this->_view = new AdminResourcesListView( $this->_blogInfo );
+
+ // fetch the parameters
+ $this->_resourceIds = $this->_request->getValue( "resourceIds" );
+ $this->_albumIds = $this->_request->getValue( "albumIds" );
+ $this->_galleryAlbumId = $this->_request->getValue( "galleryAlbumId" );
+
+ // make sure that we're dealing with arrays!
+ if( !is_array( $this->_resourceIds)) $this->_resourceIds = Array();
+ if( !is_array( $this->_albumIds)) $this->_albumIds = Array();
+
+ // update the items, if any
+ $this->_updateAlbums();
+ $this->_updateResources();
+
+ // put error and success messages (if any) into the view
+ if( $this->_successMessage != "" ) $this->_view->setSuccessMessage( $this->_successMessage );
+ if( $this->_errorMessage != "" ) $this->_view->setErrorMessage( $this->_errorMessage );
+ $this->setCommonData();
+
+ // clear the cache
+ CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );
+
+ // better to return true if everything fine
+ return true;
+ }
+
+ /**
+ * updates resources from the list
+ */
+ function _updateResources()
+ {
+ // Chanages the resource album field by selection
+ $resources = new GalleryResources();
+
+ foreach( $this->_resourceIds as $resourceId ) {
+ // get the resource
+ $resource = $resources->getResource( $resourceId, $this->_blogInfo->getId());
+
+ if( $resource ) {
+ // fire the event
+ $this->notifyEvent( EVENT_PRE_RESOURCE_UPDATE, Array( "resource" => &$resource ));
+
+ // update the resource album
+ $resource->setAlbumId( $this->_galleryAlbumId );
+ $result = $resources->updateResource( $resource );
+
+ if( !$result ) {
+ $this->_errorMessage .= $this->_locale->pr("error_deleting_resource", $resource->getFileName())."<br/>";
+ }
+ else {
+ $this->_totalOk++;
+ if( $this->_totalOk < 2 )
+ $this->_successMessage .= $this->_locale->pr("item_updated_ok", $resource->getFileName());
+ else
+ $this->_successMessage = $this->_locale->pr("items_updated_ok", $this->_totalOk );
+ // fire the post event
+ $this->notifyEvent( EVENT_POST_RESOURCE_UPDATE, Array( "article" => &$post ));
+ }
+ }
+ else {
+ $this->_errorMessage .= $this->_locale->pr("error_deleting_resource2", $resourceId )."<br/>";
+ }
+ }
+ }
+
+ /**
+ * update resources from the list
+ */
+ function _updateAlbums()
+ {
+ // Chanages the album's parent album field by selection
+ $albums = new GalleryAlbums();
+
+ foreach( $this->_albumIds as $albumId => $value ) {
+ // get the album
+ $album = $albums->getAlbum( $albumId, $this->_blogInfo->getId());
+
+ if( $album )
+ {
+ // fire the event
+ $this->notifyEvent( EVENT_PRE_ALBUM_UPDATE, Array( "album" => &$album ));
+
+ // update the resource album
+ $album->setParentId( $this->_galleryAlbumId );
+ $result = $albums->updateAlbum( $album );
+
+ if( !$result ) {
+ $this->_errorMessage .= $this->_locale->pr("error_deleting_album", $album->getName())."<br/>";
+ }
+ else {
+ $this->_totalOk++;
+ if( $this->_totalOk < 2 )
+ $this->_successMessage = $this->_locale->pr("item_updated_ok", $album->getName());
+ else
+ $this->_successMessage = $this->_locale->pr("items_updated_ok", $this->_totalOk );
+ // fire the post event
+ $this->notifyEvent( EVENT_POST_ALBUM_UPDATE, Array( "album" => &$album ));
+ }
+ } else {
+ $this->_errorMessage .= $this->_locale->pr( "error_deleting_album2", $albumId )."<br/>";
+ }
+ }
+ }
+ }
+?>
Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php 2006-05-08 03:55:46 UTC (rev 3359)
+++ plog/trunk/class/controller/admincontrollermap.properties.php 2006-05-08 05:08:22 UTC (rev 3360)
@@ -211,6 +211,8 @@
// removes albums
$actions["deleteResourceAlbum"] = "AdminDeleteResourceAlbumAction";
$actions["deleteResourceItems"] = "AdminDeleteGalleryItemsAction";
+ // massive change gallery items album
+ $actions["changeGalleryItemsAlbum"] = "AdminChangeGalleryItemsAlbumAction";
// mark as spam
$actions["markComment"] = "AdminMarkCommentAction";
$actions["markTrackback"] = "AdminMarkTrackbackAction";
Modified: plog/trunk/js/ui/plogui.js
===================================================================
--- plog/trunk/js/ui/plogui.js 2006-05-08 03:55:46 UTC (rev 3359)
+++ plog/trunk/js/ui/plogui.js 2006-05-08 05:08:22 UTC (rev 3360)
@@ -193,6 +193,12 @@
}
}
+function submitGalleryItemsList(op)
+{
+ document.getElementById("Resources").op.value = op;
+ document.getElementById("Resources").submit();
+}
+
function switchMassiveOption()
{
if ( $('massiveChangeOption').style.display == 'none' )
Modified: plog/trunk/templates/admin/resources.template
===================================================================
--- plog/trunk/templates/admin/resources.template 2006-05-08 03:55:46 UTC (rev 3359)
+++ plog/trunk/templates/admin/resources.template 2006-05-08 05:08:22 UTC (rev 3360)
@@ -1,7 +1,12 @@
{include file="$admintemplatepath/header.template"}
{include file="$admintemplatepath/navigation.template" showOpt=resources title=$locale->tr("resources")}
- <div id="list_nav_bar">
- <div id="list_nav_select">
+ <script type="text/javascript" src="js/ui/plogui.js"></script>
+ <script type="text/javascript">
+ var showMassiveChangeOption = '{$locale->tr("show_massive_change_option")}';
+ var hideMassiveChangeOption = '{$locale->tr("hide_massive_change_option")}';
+ </script>
+<div id="list_nav_bar">
+<div id="list_nav_select">
<form id="viewResources" action="admin.php" method="post">
<fieldset>
<legend>{$locale->tr("show_by")}</legend>
@@ -35,6 +40,9 @@
</div>
<form id="Resources" method="post" action="admin.php">
+<div class="optionIcon">
+ <a id="optionIconLink" href="#" title="{$locale->tr("show_massive_change_option")}" onclick="switchMassiveOption()">{$locale->tr("show_massive_change_option")}</a>
+</div>
<div id="list">
{include file="$admintemplatepath/successmessage.template"}
{include file="$admintemplatepath/errormessage.template"}
@@ -115,6 +123,22 @@
{if $quota > 0 }, {$locale->tr("quota")}: <strong>{$quota|round}</strong>{/if}
<input type="submit" name="delete" value="{$locale->tr("delete")}" class="submit" />
<input type="hidden" name="op" value="deleteResourceItems" />
+ <div id="massiveChangeOption" style="display: none">
+ <fieldset>
+ <legend>{$locale->tr("messave_change_option")}</legend>
+ <label for="galleryAlbumId">{$locale->tr("album")}</label>
+ <select name="galleryAlbumId" id="galleryAlbumId">
+ <option value="0">{$locale->tr("root_album")}</option>
+ {foreach from=$albumsList item=albumItem}
+ {assign var=indentLevel value=$albumItem->getValue("level")}
+ <option value="{$albumItem->getId()}">
+ {textformat indent=$indentLevel indent_char=" "}{$albumItem->getName()}{/textformat}
+ </option>
+ {/foreach}
+ </select>
+ <input type="button" name="changeGalleryItemsAlbum" value="{$locale->tr("change_album")}" class="submit" onClick="javascript:submitGalleryItemsList('changeGalleryItemsAlbum');" />
+ </fieldset>
+ </div>
</div>
</form>
{include file="$admintemplatepath/footernavigation.template"}
More information about the pLog-svn
mailing list