[pLog-svn] r6076 - in plog/trunk: class/action/admin class/view/admin js/ui/pages templates/admin
mark at devel.lifetype.net
mark at devel.lifetype.net
Fri Nov 23 12:35:34 EST 2007
Author: mark
Date: 2007-11-23 12:35:34 -0500 (Fri, 23 Nov 2007)
New Revision: 6076
Modified:
plog/trunk/class/action/admin/adminresourceinfoaction.class.php
plog/trunk/class/action/admin/adminupdateresourceaction.class.php
plog/trunk/class/view/admin/admineditresourceview.class.php
plog/trunk/js/ui/pages/resources.js
plog/trunk/templates/admin/resourceinfo_form.template
plog/trunk/templates/admin/resources_table.template
Log:
Finally, editResourceInfo and updateResourceInfo works.
TODO:
1. The resources.js and resourcealbums.js may need some reorganize...
2. Upload resource with swfupload
Modified: plog/trunk/class/action/admin/adminresourceinfoaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminresourceinfoaction.class.php 2007-11-23 15:42:38 UTC (rev 6075)
+++ plog/trunk/class/action/admin/adminresourceinfoaction.class.php 2007-11-23 17:35:34 UTC (rev 6076)
@@ -1,12 +1,4 @@
<?php
-
-
-
-
-
-
-
-
/**
* \ingroup Action
* @private
@@ -23,16 +15,16 @@
* class, BlogAction with the same parameters
*/
function AdminResourceInfoAction( $actionInfo, $request )
- {
+ {
$this->AdminAction( $actionInfo, $request );
-
+
// data validation
$this->registerFieldValidator( "resourceId", new IntegerValidator());
$view = new AdminResourcesListView( $this->_blogInfo );
$view->setErrorMessage( $this->_locale->tr( "error_fetching_resource" ));
$this->setValidationErrorView( $view );
-
- $this->requirePermission( "update_resource" );
+
+ $this->requirePermission( "update_resource" );
}
function loadResource()
@@ -42,7 +34,7 @@
$resources = new GalleryResources();
$resource = $resources->getResource( $this->_resourceId, $this->_blogInfo->getId());
if( $resource )
- $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$resource ));
+ $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$resource ));
return( $resource );
}
@@ -54,18 +46,24 @@
{
$resource = $this->loadResource();
if( !$resource ) {
- $this->_view = new AdminResourcesListView( $this->_blogInfo );
- $this->_view->setErrorMessage( $this->_locale->tr("error_fetching_resource"));
+
+ if( $this->_request->isXHR())
+ $this->_view = new AdminErrorDialogView( $this->_blogInfo );
+ else
+ $this->_view = new AdminResourcesListView( $this->_blogInfo );
+
+ $this->_view->setErrorMessage( $this->_locale->tr("error_fetching_resource" ));
+ $this->setCommonData();
+ return false;
}
- else {
- $this->_view = new AdminEditResourceView( $this->_blogInfo );
- $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$resource ));
- $this->_view->setValue( "resource", $resource );
- // export some useful information
- $this->_view->setValue( "resourceDescription", $resource->getDescription());
- $this->_view->setValue( "albumId", $resource->getAlbumId());
- }
-
+
+ $this->_view = new AdminEditResourceView( $this->_blogInfo );
+ $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$resource ));
+ $this->_view->setValue( "resource", $resource );
+ // export some useful information
+ $this->_view->setValue( "resourceDescription", $resource->getDescription());
+ $this->_view->setValue( "albumId", $resource->getAlbumId());
+
$this->setCommonData();
// better to return true if everything fine
@@ -74,19 +72,7 @@
function performAjax()
{
-
- $this->_view = new AdminAjaxView( $this->_blogInfo );
- $resource = $this->loadResource();
- if( !$resource ) {
- $this->_view->setErrorMessage( $this->_locale->tr("error_fetching_resource"));
- }
- else {
- $this->_view->setResult( $resource );
- $this->_view->setSuccess( true );
- }
-
- // better to return true if everything fine
- return true;
+ return( $this->perform() );
}
}
?>
Modified: plog/trunk/class/action/admin/adminupdateresourceaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminupdateresourceaction.class.php 2007-11-23 15:42:38 UTC (rev 6075)
+++ plog/trunk/class/action/admin/adminupdateresourceaction.class.php 2007-11-23 17:35:34 UTC (rev 6076)
@@ -1,12 +1,4 @@
<?php
-
-
-
-
-
-
-
-
/**
* \ingroup Action
* @private
@@ -27,79 +19,89 @@
function AdminUpdateResourceAction( $actionInfo, $request )
{
$this->AdminAction( $actionInfo, $request );
-
+
// data validation
- $this->registerFieldValidator( "albumId", new IntegerValidator());
- $this->registerFieldValidator( "resourceId", new IntegerValidator());
+ $this->registerFieldValidator( "albumId", new IntegerValidator(), false, $this->_locale->tr("error_empty_album_id" ));
+ $this->registerFieldValidator( "resourceId", new IntegerValidator(), false, $this->_locale->tr("error_empty_resource_id" ));
$this->registerField( "resourceDescription" );
$view = new AdminEditResourceView( $this->_blogInfo );
$view->setErrorMessage( $this->_locale->tr("error_updating_resource" ));
$this->setValidationErrorView( $view );
-
-
}
-
- function validate()
- {
- if( !parent::validate()) {
- $resources = new GalleryResources();
- $resource = $resources->getResource( $this->_request->getValue("resourceId"), $this->_blogInfo->getId());
- if( !$resource ) {
- $this->setValidationErrorView( new AdminResourcesListView( $this->_blogInfo ));
- $this->setCommonData();
- return false;
- }
- $this->_view->setValue( "resource", $resource );
-
- return false;
- }
-
- return true;
- }
- /**
- * Carries out the specified action
- */
- function perform()
+ function updateResource()
{
- // load the resource
$this->_resourceDescription = Textfilter::filterAllHTML($this->_request->getValue( "resourceDescription" ));
$this->_albumId = $this->_request->getValue( "albumId" );
$this->_resourceId = $this->_request->getValue( "resourceId" );
$resources = new GalleryResources();
$resource = $resources->getResource( $this->_resourceId, $this->_blogInfo->getId());
+
+ if( !$resource ) {
+ $this->_message = $this->_locale->tr("error_fetching_resource" );
+ return false;
+ }
+
// update the fields we'd like to update
$resource->setAlbumId( $this->_albumId );
$resource->setDescription( $this->_resourceDescription );
// location data, if any
- $resource->setLocationId( $this->getLocationFromRequest());
+ $resource->setLocationId( $this->getLocationFromRequest());
// send the event
- $this->notifyEvent( EVENT_PRE_RESOURCE_UPDATE, Array( "resource" => &$resource ));
+ $this->notifyEvent( EVENT_PRE_RESOURCE_UPDATE, Array( "resource" => &$resource ));
// and update it in the db
$result = $resources->updateResource( $resource );
if( !$result ) {
- $this->_view = new AdminResourcesListView( $this->_blogInfo );
- $this->_view->setErrorMessage( $this->_locale->tr("error_updating_resource"));
+ $this->_message = $this->_locale->tr("error_updating_resource");
+ return false;
}
- else {
- // check which submit button was pressed
- if($this->_request->getValue("regenerate" ) != ""){
- return Controller::setForwardAction( "regeneratePreview" );
- }
- $this->_view = new AdminResourcesListView( $this->_blogInfo );
- $this->_view->setSuccessMessage( $this->_locale->pr("resource_updated_ok", $resource->getFileName()));
- $this->notifyEvent( EVENT_POST_RESOURCE_UPDATE, Array( "resource" => &$resource ));
-
- // clear the cache
- CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );
- }
+ $this->_message = $this->_locale->pr( "resource_updated_ok", $resource->getFileName() );
+ $this->notifyEvent( EVENT_POST_RESOURCE_UPDATE, Array( "resource" => &$resource ));
+ // clear the cache
+ CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );
+
+ return $resource;
+ }
+
+ /**
+ * Carries out the specified action
+ */
+ function perform()
+ {
+ $resource = $this->updateResource();
+
+ $this->_view = new AdminResourcesListView( $this->_blogInfo );
+ if( !$resource ) {
+ $this->_view->setErrorMessage( $this->_message );
+ }
+ else {
+ // and go back to the view with the list of links
+ $this->_view->setSuccessMessage( $this->_message );
+ }
+
$this->setCommonData();
- // better to return true if everything fine
return true;
}
+
+ function performAjax()
+ {
+ $resource = $this->updateResource();
+
+ $this->_view = new AdminAjaxView( $this->_blogInfo );
+ if( $resource ) {
+ $this->_view->setSuccess( true );
+ $this->_view->setResult( $resource );
+ }
+ else {
+ $this->_view->setSuccess( false );
+ }
+ $this->_view->setMessage( $this->_message );
+
+ return( true );
+ }
}
?>
Modified: plog/trunk/class/view/admin/admineditresourceview.class.php
===================================================================
--- plog/trunk/class/view/admin/admineditresourceview.class.php 2007-11-23 15:42:38 UTC (rev 6075)
+++ plog/trunk/class/view/admin/admineditresourceview.class.php 2007-11-23 17:35:34 UTC (rev 6076)
@@ -1,29 +1,32 @@
<?php
-
-
-
-
+
+
+
+
/**
* \ingroup View
* @private
- *
+ *
* shows the view that allows to see more information of a resource
*/
class AdminEditResourceView extends AdminTemplatedView
{
var $_resourceId;
-
+
function AdminEditResourceView( $blogInfo )
{
- $this->AdminTemplatedView( $blogInfo, "resourceinfo" );
+ if( Request::isXHR() )
+ $this->AdminTemplatedView( $blogInfo, "resourceinfo_form" );
+ else
+ $this->AdminTemplatedView( $blogInfo, "resourceinfo" );
}
-
+
function getResourceId( $resourceId )
{
return( $this->_resourceId );
}
-
+
function render()
{
// load the nested list of albums
@@ -32,11 +35,11 @@
$blogAlbums = $albums->getNestedAlbumList( $this->_blogInfo->getId());
$this->notifyEvent( EVENT_ALBUMS_LOADED, Array( "albums" => &$blogAlbums ));
$this->setValue( "albums", $blogAlbums );
-
+
// load the list of locations
$locations = new Locations();
$this->setValue( "locations", $locations->getBlogLocations( $this->_blogInfo->getId()));
-
+
parent::render();
}
}
Modified: plog/trunk/js/ui/pages/resources.js
===================================================================
--- plog/trunk/js/ui/pages/resources.js 2007-11-23 15:42:38 UTC (rev 6075)
+++ plog/trunk/js/ui/pages/resources.js 2007-11-23 17:35:34 UTC (rev 6076)
@@ -95,4 +95,9 @@
document.getElementById("Resources").op.value = op;
document.getElementById("Resources").submit();
+}
+
+Lifetype.UI.Pages.Resources.updateSubmitHook = function( form )
+{
+ Lifetype.Forms.AjaxFormProcessor(form.id,'?op=updateResource&output=json', {} );
}
\ No newline at end of file
Modified: plog/trunk/templates/admin/resourceinfo_form.template
===================================================================
--- plog/trunk/templates/admin/resourceinfo_form.template 2007-11-23 15:42:38 UTC (rev 6075)
+++ plog/trunk/templates/admin/resourceinfo_form.template 2007-11-23 17:35:34 UTC (rev 6076)
@@ -1,5 +1,5 @@
{if $resource->isImage()}
- {assign var=imgPath value=$url->resourceMediumSizePreviewLink($resource)}
+ {assign var=imgPath value=$url->resourcePreviewLink($resource)}
{elseif $resource->isSound()}
{assign var=imgPath value="imgs/admin/icon_sound-48.png"}
{elseif $resource->isVideo()}
@@ -9,87 +9,99 @@
{else}
{assign var=imgPath value="imgs/admin/icon_file-48.png"}
{/if}
-<form name="updateResourceInfo" method="post" action="admin.php">
+<form id="updateResourceInfo" name="updateResourceInfo" method="post" action="admin.php" onSubmit="Lifetype.UI.Pages.Resources.updateSubmitHook(this);return(false);">
<fieldset class="inputField">
<legend>{$locale->tr("editResource")}</legend>
- <div class="field">
- <img src="{$imgPath}" alt="Preview" style="display:block;" />
- <span id="resourceLink"><a target="_blank" href="{$url->resourceLink($resource)}">{$resource->getFileName()}</a></span>
+ {include file="$admintemplatepath/formvalidateajax.template"}
+
+ <div style="float:left;width:30%">
+
+ <div class="field">
+ <img src="{$imgPath}" alt="Preview" style="display:block;" />
+ <span id="resourceLink"><a target="_blank" href="{$url->resourceLink($resource)}">{$resource->getFileName()}</a></span>
+ </div>
+
</div>
+
+ <div style="float:right;width:70%">
+
<div class="field">
- <label for="resourceInformation">{$locale->tr("information")}</label>
- <div class="formHelp">{$locale->tr("resource_information_help")}</div>
- {assign var=metadata value=$resource->getMetadataReader()}
- <span id="resourceInformation">
- {if $resource->isImage()}
- {assign var=imgPath value=$url->resourcePreviewLink($resource)}
- {$locale->tr("size")}: {$metadata->getFileSize()|round:$locale} ({$metadata->getFileSize()} {$locale->tr("bytes")})<br/>
- {$locale->tr("format")}: {$metadata->getFormat()|upper}<br/>
- {$locale->tr("dimensions")}: {$metadata->getWidth()} x {$metadata->getHeight()}<br/>
- {$locale->tr("bits_per_sample")}: {$metadata->getBitsPerSample()}<br/>
- {assign var=thumbnailformat value=$resource->getThumbnailFormat()}
- {$locale->tr("thumbnail_format")}: {$locale->tr($thumbnailformat)}<br/>
- {elseif $resource->isSound()}
- {assign var=imgPath value="imgs/admin/icon_sound-48.png"}
- {$locale->tr("format")}: {$metadata->getFormat()|upper}<br/>
- {$locale->tr("size")}: {$metadata->getFileSize()|round:$locale} ({$metadata->getFileSize()} {$locale->tr("bytes")})<br/>
- {$locale->tr("length")}: {$metadata->getLengthString()}<br/>
- {$locale->tr("sample_rate")}: {$metadata->getSampleRate()} Khz<br/>
- {$locale->tr("number_of_channels")}: {$metadata->getChannels()|upper}<br/>
- {elseif $resource->isVideo()}
- {assign var=imgPath value="imgs/admin/icon_video-48.png"}
- {$locale->tr("size")}: {$metadata->getFileSize()|round:$locale} ({$metadata->getFileSize()} {$locale->tr("bytes")})<br/>
- {$locale->tr("format")}: {$metadata->getFormat()|upper}<br/>
- {$locale->tr("length")}: {$metadata->getLengthString()}<br/>
- {$locale->tr("video_codec")}: {$metadata->getVideoCodec()}<br/>
- {$locale->tr("audio_codec")}: {$metadata->getAudioCodec()}<br/>
- {$locale->tr("dimensions")}: {$metadata->getWidth()} x {$metadata->getHeight()}<br/>
- {$locale->tr("bits_per_sample")}: {$metadata->getBitsPerSample()}<br/>
- {elseif $resource->isZip()}
- {assign var=imgPath value="imgs/admin/icon_compressed-48.png"}
- {$locale->tr("size")}: {$metadata->getFileSize()|round:$locale} ({$metadata->getFileSize()} {$locale->tr("bytes")})<br/>
- {$locale->tr("number_of_files")}: {$metadata->getTotalFiles()}<br/>
- {$locale->tr("uncompressed_size")}: {$metadata->getUncompressedSize()} {$locale->tr("bytes")}<br/>
- {else}
- {assign var=imgPath value="imgs/admin/icon_file-48.png"}
- {$locale->tr("size")}: {$metadata->getFileSize()|round:$locale} ({$metadata->getFileSize()} {$locale->tr("bytes")})<br/>
- {/if}
- {if $resource->hasLocationData()}
- {assign var=loc value=$resource->getLocation()}
- {$locale->tr("location")}: {location_chooser locations=$locations addNewString=$locale->tr("add_new") showDisplayLink=1 default=$loc}
- {/if}
- </span>
+ <label for="resourceInformation">{$locale->tr("information")}</label>
+ <div class="formHelp">{$locale->tr("resource_information_help")}</div>
+ {assign var=metadata value=$resource->getMetadataReader()}
+ <span id="resourceInformation">
+ {if $resource->isImage()}
+ {assign var=imgPath value=$url->resourcePreviewLink($resource)}
+ {$locale->tr("size")}: {$metadata->getFileSize()|round:$locale} ({$metadata->getFileSize()} {$locale->tr("bytes")})<br/>
+ {$locale->tr("format")}: {$metadata->getFormat()|upper}<br/>
+ {$locale->tr("dimensions")}: {$metadata->getWidth()} x {$metadata->getHeight()}<br/>
+ {$locale->tr("bits_per_sample")}: {$metadata->getBitsPerSample()}<br/>
+ {assign var=thumbnailformat value=$resource->getThumbnailFormat()}
+ {$locale->tr("thumbnail_format")}: {$locale->tr($thumbnailformat)}<br/>
+ {elseif $resource->isSound()}
+ {assign var=imgPath value="imgs/admin/icon_sound-48.png"}
+ {$locale->tr("format")}: {$metadata->getFormat()|upper}<br/>
+ {$locale->tr("size")}: {$metadata->getFileSize()|round:$locale} ({$metadata->getFileSize()} {$locale->tr("bytes")})<br/>
+ {$locale->tr("length")}: {$metadata->getLengthString()}<br/>
+ {$locale->tr("sample_rate")}: {$metadata->getSampleRate()} Khz<br/>
+ {$locale->tr("number_of_channels")}: {$metadata->getChannels()|upper}<br/>
+ {elseif $resource->isVideo()}
+ {assign var=imgPath value="imgs/admin/icon_video-48.png"}
+ {$locale->tr("size")}: {$metadata->getFileSize()|round:$locale} ({$metadata->getFileSize()} {$locale->tr("bytes")})<br/>
+ {$locale->tr("format")}: {$metadata->getFormat()|upper}<br/>
+ {$locale->tr("length")}: {$metadata->getLengthString()}<br/>
+ {$locale->tr("video_codec")}: {$metadata->getVideoCodec()}<br/>
+ {$locale->tr("audio_codec")}: {$metadata->getAudioCodec()}<br/>
+ {$locale->tr("dimensions")}: {$metadata->getWidth()} x {$metadata->getHeight()}<br/>
+ {$locale->tr("bits_per_sample")}: {$metadata->getBitsPerSample()}<br/>
+ {elseif $resource->isZip()}
+ {assign var=imgPath value="imgs/admin/icon_compressed-48.png"}
+ {$locale->tr("size")}: {$metadata->getFileSize()|round:$locale} ({$metadata->getFileSize()} {$locale->tr("bytes")})<br/>
+ {$locale->tr("number_of_files")}: {$metadata->getTotalFiles()}<br/>
+ {$locale->tr("uncompressed_size")}: {$metadata->getUncompressedSize()} {$locale->tr("bytes")}<br/>
+ {else}
+ {assign var=imgPath value="imgs/admin/icon_file-48.png"}
+ {$locale->tr("size")}: {$metadata->getFileSize()|round:$locale} ({$metadata->getFileSize()} {$locale->tr("bytes")})<br/>
+ {/if}
+ {if $resource->hasLocationData()}
+ {assign var=loc value=$resource->getLocation()}
+ {$locale->tr("location")}: {location_chooser locations=$locations addNewString=$locale->tr("add_new") showDisplayLink=1 default=$loc}
+ {/if}
+ </span>
+ </div>
+
+ <div class="field">
+ <label for="albumId">{$locale->tr("album")}</label>
+ <span class="required">*</span>
+ <div class="formHelp">{$locale->tr("resource_album_help")}</div>
+ <select name="albumId" id="albumId">
+ {foreach from=$albums item=albumItem}
+ <option value="{$albumItem->getId()}" {if $albumItem->getId()==$albumId}selected="selected"{/if}>
+ {assign var=indentLevel value=$albumItem->getValue("level")}
+ {textformat indent=$indentLevel indent_char=" "}{$albumItem->getName()}{/textformat}
+ </option>
+ {/foreach}
+ </select>
+ </div>
+
+ <div class="field">
+ <label for="resourceDescription">{$locale->tr("description")}</label>
+ <div class="formHelp">{$locale->tr("resource_description_help")}</div>
+ <span class="required"></span>
+ <textarea name="resourceDescription" id="resourceDescription" rows="7" cols="60">{$resourceDescription}</textarea>
+ </div>
+
</div>
- <div class="field">
- <label for="albumId">{$locale->tr("album")}</label>
- <span class="required">*</span>
- <div class="formHelp">{$locale->tr("resource_album_help")}</div>
- <select name="albumId" id="albumId">
- {foreach from=$albums item=albumItem}
- <option value="{$albumItem->getId()}" {if $albumItem->getId()==$albumId}selected="selected"{/if}>
- {assign var=indentLevel value=$albumItem->getValue("level")}
- {textformat indent=$indentLevel indent_char=" "}{$albumItem->getName()}{/textformat}
- </option>
- {/foreach}
- </select>
- </div>
- <div class="field">
- <label for="resourceDescription">{$locale->tr("description")}</label>
- <div class="formHelp">{$locale->tr("resource_description_help")}</div>
- <span class="required"></span>
- <textarea name="resourceDescription" id="resourceDescription" rows="7" cols="60">{$resourceDescription}</textarea>
- </div>
- </div>
-</fieldset>
-<div class="buttons">
- {if $resource->isImage()}
- {** this should only appear for images... **}
- <input type="submit" name="regenerate" value="{$locale->tr("regenerate_preview")}" />
- {/if}
- <input type="reset" name="resetButton" value="{$locale->tr("reset")}" />
- <input type="hidden" name="op" value="updateResource" />
- <input type="hidden" name="resourceId" value="{$resource->getId()}" />
- <input type="submit" name="Update" value="{$locale->tr("update")}" />
-</div>
+ </fieldset>
+ <div class="buttons">
+ {if $resource->isImage()}
+ {** this should only appear for images... **}
+ <input type="submit" name="regenerate" value="{$locale->tr("regenerate_preview")}" />
+ {/if}
+ <input type="reset" name="resetButton" value="{$locale->tr("reset")}" />
+ <input type="hidden" name="op" value="updateResource" />
+ <input type="hidden" name="resourceId" value="{$resource->getId()}" />
+ <input type="submit" name="Update" value="{$locale->tr("update")}" />
+ </div>
</form>
\ No newline at end of file
Modified: plog/trunk/templates/admin/resources_table.template
===================================================================
--- plog/trunk/templates/admin/resources_table.template 2007-11-23 15:42:38 UTC (rev 6075)
+++ plog/trunk/templates/admin/resources_table.template 2007-11-23 17:35:34 UTC (rev 6076)
@@ -38,7 +38,7 @@
{if $resource->hasPreview()}
<div class="pictureFrame">
<div class="picture">
- <a href="?op=resourceInfo&resourceId={$resource->getId()}">
+ <a rel="overlay" href="?op=resourceInfo&resourceId={$resource->getId()}">
<img alt="{$resource->getDescription()}" id="resource_img_{$resource->getId()}" url="{$url->resourcePreviewLink($resource)}" />
</a>
</div>
More information about the pLog-svn
mailing list