fixed some problems with the new asset manager. restored functionality to search with the hope of making the asset data table an API we can use in all the places we display tables of assets

This commit is contained in:
Doug Bell 2008-06-12 08:58:51 +00:00
parent f786ad7ce4
commit 36bea30cd6
6 changed files with 229 additions and 148 deletions

View file

@ -935,6 +935,16 @@ sub www_edit {
$session->errorHandler->error("Couldn't demote asset '$assetId' because we couldn't instantiate it.");
}
}
elsif ( $form->get("delete") ) {
my $assetId = $form->get("delete");
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
if ( $asset ) {
$asset->purge;
}
else {
$session->errorHandler->error( "Couldn't delete asset '$assetId' because we couldn't instanciate it.");
}
}
# Generate the form
if ($form->get("func") eq "add") {
@ -972,6 +982,7 @@ sub www_edit {
= WebGUI::Form::submit( $session, {
name => "cancel",
value => $i18n->get("cancel"),
extras => 'onclick="history.go(-1)"',
});
}
$var->{ form_start }
@ -1016,21 +1027,31 @@ sub www_edit {
# Raw HTML here to provide proper value for the image
$file->{ form_promote }
= qq{<button type="submit" name="promote" class="promote" value="$file->{assetId}">}
= qq{<button type="submit" name="promote" class="promote" value="$file->{assetId}" onclick="this.setAttribute('innerHTML','$file->{assetId}')">}
. $session->icon->moveUp( undef, undef, "disabled" )
. qq{</button>}
;
$file->{ form_demote }
= qq{<button type="submit" name="demote" class="demote" value="$file->{assetId}">}
= qq{<button type="submit" name="demote" class="demote" value="$file->{assetId}" onclick="this.setAttribute('innerHTML','$file->{assetId}')">}
. $session->icon->moveDown( undef, undef, "disabled" )
. qq{</button>}
;
my $deleteConfirm = $i18n->get( 'template delete message' );
$file->{ form_delete }
= qq!<button onclick="if ( confirm('$deleteConfirm') ) { this.setAttribute('innerHTML','$file->{assetId}'); return true; } else { return false };" type="submit" name="delete" class="delete" value="$file->{assetId}">!
. $session->icon->delete( undef, undef, "disabled" )
. qq{</button>}
;
$file->{ form_synopsis }
= WebGUI::Form::text( $session, {
= WebGUI::Form::HTMLArea( $session, {
name => "fileSynopsis_$file->{assetId}",
value => $form->get( "fileSynopsis_$file->{assetId}" ) || $file->{ synopsis },
richEditId => $self->getParent->get( 'richEditIdFile' ),
height => 150,
width => 400,
});
}

View file

@ -162,6 +162,8 @@ sub getMoreMenu {
### The More menu
my @more_fields = ();
# FIXME: Add a show callback with the record as first argument. If it
# returns true, the URL will be shown.
# These links are shown based on UI level
if ( $userUiLevel >= $toolbarUiLevel->{ "changeUrl" } ) {
push @more_fields, {
@ -391,7 +393,7 @@ sub www_manage {
YAHOO.util.Event.onDOMReady( WebGUI.AssetManager.initManager );
</script>
ENDHTML
my $output = '<div id="assetManager">' . getHeader( $session );
my $output = '<div class="yui-skin-sam" id="assetManager">' . getHeader( $session );
### Crumbtrail
my $crumb_markup = '<li><a href="%s">%s</a> &gt;</li>';
@ -413,7 +415,7 @@ ENDHTML
$output .= '</ol>';
### The page of assets
$output .= q{<div class="yui-skin-sam" id="assetManager" >}
$output .= q{<div>}
. q{<form>}
. q{<input type="hidden" name="op" value="assetManager" />}
. q{<input type="hidden" name="method" value="manage" />}
@ -514,8 +516,6 @@ ENDHTML
;
$output .= <<'ENDJS';
// Initialize the datatable and datasource
YAHOO.util.Event.onDOMReady(function () {
// Start the data source
WebGUI.AssetManager.DataSource
= new YAHOO.util.DataSource( '?op=assetManager;method=ajaxGetManagerPage' );
@ -540,14 +540,8 @@ YAHOO.util.Event.onDOMReady(function () {
]
};
var assetPaginator = new YAHOO.widget.Paginator({
containers : ['pagination'],
pageLinks : 7,
rowsPerPage : 15,
template : "<strong>{CurrentPageReport}</strong> {PreviousPageLink} {PageLinks} {NextPageLink}"
});
function buildQueryString( state, dt ) {
WebGUI.AssetManager.BuildQueryString
= function ( state, dt ) {
var query = ";recordOffset=" + state.pagination.recordOffset
+ ';orderByDirection=' + ((state.sorting.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "DESC" : "ASC")
+ ';rowsPerPage=' + state.pagination.rowsPerPage
@ -556,35 +550,6 @@ YAHOO.util.Event.onDOMReady(function () {
return query;
};
// Custom function to handle pagination requests
var handlePagination = function (state,dt) {
var sortedBy = dt.get('sortedBy');
// Define the new state
var newState = {
startIndex: state.recordOffset,
sorting: {
key: sortedBy.key,
dir: ((sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "desc" : "asc")
},
pagination : { // Pagination values
recordOffset: state.recordOffset, // Default to first page when sorting
rowsPerPage: dt.get("paginator").getRowsPerPage() // Keep current setting
}
};
// Create callback object for the request
var oCallback = {
success: dt.onDataReturnSetRows,
failure: dt.onDataReturnSetRows,
scope: dt,
argument: newState // Pass in new state as data payload for callback function to use
};
// Send the request
dt.getDataSource().sendRequest(buildQueryString(newState), oCallback);
};
ENDJS
$output .= q(
@ -602,55 +567,8 @@ ENDJS
);
$output .= <<'ENDJS';
WebGUI.AssetManager.DataTable
= new YAHOO.widget.DataTable( 'dataTableContainer',
WebGUI.AssetManager.ColumnDefs,
WebGUI.AssetManager.DataSource,
{
initialRequest : ';recordOffset=0',
generateRequest : buildQueryString,
paginationEventHandler : handlePagination,
paginator : assetPaginator,
sortedBy : { key : "lineage", dir : YAHOO.widget.DataTable.CLASS_ASC }
}
);
// Override function for custom server-side sorting
WebGUI.AssetManager.DataTable.sortColumn = function(oColumn) {
// Default ascending
var sDir = "asc";
// If already sorted, sort in opposite direction
if(oColumn.key === this.get("sortedBy").key) {
sDir = (this.get("sortedBy").dir === YAHOO.widget.DataTable.CLASS_ASC) ?
"desc" : "asc";
}
// Define the new state
var newState = {
startIndex: 0,
sorting: { // Sort values
key: oColumn.key,
dir: (sDir === "desc") ? YAHOO.widget.DataTable.CLASS_DESC : YAHOO.widget.DataTable.CLASS_ASC
},
pagination : { // Pagination values
recordOffset: 0, // Default to first page when sorting
rowsPerPage: this.get("paginator").getRowsPerPage() // Keep current setting
}
};
// Create callback object for the request
var oCallback = {
success: this.onDataReturnSetRows,
failure: this.onDataReturnSetRows,
scope: this,
argument: newState // Pass in new state as data payload for callback function to use
};
// Send the request
this.getDataSource().sendRequest(buildQueryString(newState), oCallback);
};
} );
YAHOO.util.Event.onDOMReady( WebGUI.AssetManager.initManager );
</script>
ENDJS
@ -669,7 +587,7 @@ sub www_search {
my $session = shift;
my $ac = WebGUI::AdminConsole->new( $session, "assets" );
my $i18n = WebGUI::International->new( $session, "Asset" );
my $output = '<div id="assetManager">' . getHeader( $session );
my $output = '<div id="assetSearch">' . getHeader( $session );
$session->style->setLink( $session->url->extras( 'yui-webgui/build/assetManager/assetManager.css' ), { rel => "stylesheet", type => 'text/css' } );
$session->style->setScript( $session->url->extras( 'yui/build/yahoo-dom-event/yahoo-dom-event.js' ) );
@ -749,11 +667,11 @@ ENDHTML
$output .= q{<input type="hidden" name="class" value="} . $class . q{" />};
}
$output .= q{<table class="assetManager" border="0">}
$output .= q{<table class="assetSearch" border="0">}
. q{<thead>}
. q{<tr>}
. q{<th class="center"><input type="checkbox" onclick="WebGUI.Form.toggleAllCheckboxesInForm( this.form, 'assetId' )" /></th>} # Checkbox column
. q{<th class="center">&nbsp;</th>} # Edit / More
. q{<th class="center">&nbsp;</th>} # Edit
. q{<th>} . $i18n->get( '99' ) . q{</th>} # Title
. q{<th>} . $i18n->get( "type" ) . q{</th>} # Type
. q{<th class="center">} . $i18n->get( "last updated" ) . q{</th>} # Revision Date
@ -767,7 +685,7 @@ ENDHTML
# The markup for a single asset
my $row_markup = q{<tr %s ondblclick="WebGUI.AssetManager.toggleRow( this )">}
. q{<td class="center"><input type="checkbox" name="assetId" value="%s" onchange="WebGUI.AssetManager.toggleHighlightForRow( this )" /></td>}
. q{<td class="center">%s %s</td>}
. q{<td class="center">%s</td>}
. q{<td>%s</td>}
. q{<td><img src="%s" /> %s</td>}
. q{<td class="center">%s</td>}
@ -780,7 +698,7 @@ ENDHTML
my @row_fields = qw(
alt
assetId
editLink moreMenu
editLink
title
iconUrl type
revisionDate
@ -795,7 +713,7 @@ ENDHTML
# Populate the required fields to fill in
my %fields = (
alt => ( $count % 3 == 0 ? 'class="alt"' : '' ),
alt => ( $count % 2 == 0 ? 'class="alt"' : '' ),
assetId => $asset->getId,
url => $asset->getUrl,
title => $asset->get( "title" ),
@ -832,14 +750,11 @@ ENDHTML
# The edit link
if ( !$asset->lockedBy || $asset->canEditIfLocked ) {
$fields{ editLink }
= sprintf '<a href="%s">' . $i18n->get( "edit" ) . '</a> |',
= sprintf '<a href="%s">' . $i18n->get( "edit" ) . '</a>',
$asset->getUrl( 'func=edit' )
;
}
# The More menu
$fields{ moreMenu } = getMoreMenu( $session, $i18n->get( "menu label" ) );
$output .= sprintf $row_markup, @fields{ @row_fields };
}

View file

@ -295,6 +295,22 @@ our $HELP = {
name => 'isAlbumThumbnail',
description => 'helpvar isAlbumThumbnail',
},
{
name => 'form_promote',
description => 'helpvar form_promote',
},
{
name => 'form_demote',
description => 'helpvar form_demote',
},
{
name => 'form_synopsis',
description => 'helpvar form_synopsis',
},
{
name => 'form_delete',
description => 'helpvar form_delete',
},
],
},
],

View file

@ -490,6 +490,30 @@ our $I18N = {
context => q{Description of template variable},
},
'helpvar form_promote' => {
message => q{A button to promote the image in the ranking. Use these to move images in the order.},
lastUpdated => 0,
context => q{Description of template variable},
},
'helpvar form_demote' => {
message => q{A button to demote the image in the ranking. Use these to move images in the order.},
lastUpdated => 0,
context => q{Description of template variable},
},
'helpvar form_delete' => {
message => q{A button to delete the image.},
lastUpdated => 0,
context => q{Description of template variable},
},
'helpvar form_synopsis' => {
message => q{An HTML Area for the image thumbnail.},
lastUpdated => 0,
context => q{Description of template variable},
},
};
1;

View file

@ -107,3 +107,58 @@ tr.highlight td {
.functionPane a {
vertical-align: bottom;
}
/** Asset Search table
NOTE: These will be removed when the search uses the Asset Data Table API **/
.assetSearch {
clear: both;
width: 100%;
}
.assetSearch th {
border: solid #666;
border-width: 0 1px 2px 0;
background-color: #eee;
}
.assetSearch th, .assetSearch td {
padding: 0 0.8em;
}
#assetSearch th, #assetSearch td, .assetManager {
font-size: 0.8em;
}
.assetSearch .center, .assetSearch th {
text-align: center;
}
.assetSearch .right {
text-align: right;
}
.assetSearch a:link, .assetSearch a:visited, .assetSearch a:active, .assetSearch a:hover {
font-size: 8pt;
}
.assetSearch tr.alt td {
background-color: #ddd;
}
.assetSearch tr.highlight td {
background-color: #CCF;
}
/** Page stats **/
#pageStats {
float: right;
text-align: right;
}
#pageLinks {
float: right;
text-align: right;
}

View file

@ -59,6 +59,12 @@ WebGUI.AssetManager.formatActions
more.appendChild( document.createTextNode( 'More' ) );
more.href = '#';
// Delete the old menu
if ( document.getElementById( 'moreMenu' + oRecord.getData( 'assetId' ) ) ) {
var oldMenu = document.getElementById( 'moreMenu' + oRecord.getData( 'assetId' ) );
oldMenu.parentNode.removeChild( oldMenu );
}
// Build a more menu
var rawItems = WebGUI.AssetManager.MoreMenuItems;
var menuItems = [];
@ -67,22 +73,20 @@ WebGUI.AssetManager.formatActions
? rawItems[i].url.replace( "<url>", oRecord.getData( 'url' ) )
: oRecord.getData( 'url' ) + rawItems[i].url
;
menuItems.push( '<li><a href="' + itemUrl + '">' + rawItems[i].label + "</a></li>" );
menuItems.push( { "url" : itemUrl, "text" : rawItems[i].label } );
}
var options = {
"zindex" : 100,
"zindex" : 1000,
"clicktohide" : true,
"constraintoviewport" : true,
"position" : "dynamic",
"xy" : [ more.clientLeft, more.clientTop ],
"context" : [ more, "tl", "bl" ],
"itemdata" : menuItems
};
var menu = new YAHOO.widget.Menu( "moreMenu" + oRecord.getData( 'assetId' ), options );
menu.render( document.getElementById( 'assetManager' ) );
YAHOO.util.Event.addListener( more, "click", menu.show, null, menu );
YAHOO.util.Event.onDOMReady( function () { menu.render( document.getElementById( 'assetManager' ) ) } );
YAHOO.util.Event.addListener( more, "click", function () { menu.show(); menu.focus(); }, null, menu );
};
/*---------------------------------------------------------------------------
@ -178,16 +182,93 @@ WebGUI.AssetManager.formatTitle
Initialize the www_manage page
*/
WebGUI.AssetManager.initManager
= function () {
= function (o) {
var assetPaginator = new YAHOO.widget.Paginator({
containers : ['pagination'],
pageLinks : 7,
rowsPerPage : 15,
template : "<strong>{CurrentPageReport}</strong> {PreviousPageLink} {PageLinks} {NextPageLink}"
});
};
/*---------------------------------------------------------------------------
WebGUI.AssetManager.initSearch ( )
Initialize the www_search page
*/
WebGUI.AssetManager.initSearch
= function () {
// Custom function to handle pagination requests
var handlePagination = function (state,dt) {
var sortedBy = dt.get('sortedBy');
// Define the new state
var newState = {
startIndex: state.recordOffset,
sorting: {
key: sortedBy.key,
dir: ((sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "desc" : "asc")
},
pagination : { // Pagination values
recordOffset: state.recordOffset, // Default to first page when sorting
rowsPerPage: dt.get("paginator").getRowsPerPage() // Keep current setting
}
};
// Create callback object for the request
var oCallback = {
success: dt.onDataReturnSetRows,
failure: dt.onDataReturnSetRows,
scope: dt,
argument: newState // Pass in new state as data payload for callback function to use
};
// Send the request
dt.getDataSource().sendRequest(WebGUI.AssetManager.BuildQueryString(newState), oCallback);
};
// Initialize the data table
WebGUI.AssetManager.DataTable
= new YAHOO.widget.DataTable( 'dataTableContainer',
WebGUI.AssetManager.ColumnDefs,
WebGUI.AssetManager.DataSource,
{
initialRequest : ';recordOffset=0',
generateRequest : WebGUI.AssetManager.BuildQueryString,
paginationEventHandler : handlePagination,
paginator : assetPaginator,
sortedBy : WebGUI.AssetManager.DefaultSortedBy
}
);
// Override function for custom server-side sorting
WebGUI.AssetManager.DataTable.sortColumn = function(oColumn) {
// Default ascending
var sDir = "asc";
// If already sorted, sort in opposite direction
if(oColumn.key === this.get("sortedBy").key) {
sDir = (this.get("sortedBy").dir === YAHOO.widget.DataTable.CLASS_ASC) ?
"desc" : "asc";
}
// Define the new state
var newState = {
startIndex: 0,
sorting: { // Sort values
key: oColumn.key,
dir: (sDir === "desc") ? YAHOO.widget.DataTable.CLASS_DESC : YAHOO.widget.DataTable.CLASS_ASC
},
pagination : { // Pagination values
recordOffset: 0, // Default to first page when sorting
rowsPerPage: this.get("paginator").getRowsPerPage() // Keep current setting
}
};
// Create callback object for the request
var oCallback = {
success: this.onDataReturnSetRows,
failure: this.onDataReturnSetRows,
scope: this,
argument: newState // Pass in new state as data payload for callback function to use
};
// Send the request
this.getDataSource().sendRequest(WebGUI.AssetManager.BuildQueryString(newState), oCallback);
};
};
@ -224,37 +305,6 @@ WebGUI.AssetManager.selectRow
}
};
/*---------------------------------------------------------------------------
WebGUI.AssetManager.showMoreMenu ( event, url )
Show the more menu located inside element.
*/
WebGUI.AssetManager.showMoreMenu
= function ( event, url ) {
var rawItems = WebGUI.AssetManager.MoreMenuItems;
var menuItems = [];
for ( var i = 0; i < rawItems.length; i++ ) {
var itemUrl = rawItems[i].url.match( /<url>/ )
? rawItems[i].url.replace( "<url>", url )
: url + rawItems[i].url
;
menuItems.push( '<li><a href="' + itemUrl + '">' + rawItems[i].label + "</a></li>" );
}
var options = {
"zindex" : 1000,
"clicktohide" : true,
"constraintoviewport" : true,
"xy" : [ event.clientX, event.clientY ],
"itemdata" : menuItems
};
var menu = new YAHOO.widget.Menu( "moreMenu", options );
menu.render( document.getElementById( 'assetManager' ) );
menu.show();
menu.focus();
};
/*---------------------------------------------------------------------------
WebGUI.AssetManager.toggleHighlightForRow ( checkbox )
Toggle the highlight for the row based on the state of the checkbox