diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 531748901..3c03b8a10 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -12,6 +12,7 @@ - fixed #12119: Locale setting for paypal - fixed #12156: Asset Manager performance - fixed #12158: Shop credit cannot be used to pay for Shipping on PayPal + - rfe #12159: Asset Manager sort preferences 7.10.17 - fixed: Forced to use a PayDriver even with a balance of 0 in the cart. diff --git a/docs/upgrades/upgrade_7.10.17-7.10.18.pl b/docs/upgrades/upgrade_7.10.17-7.10.18.pl index 930fb9550..bfb99781f 100644 --- a/docs/upgrades/upgrade_7.10.17-7.10.18.pl +++ b/docs/upgrades/upgrade_7.10.17-7.10.18.pl @@ -31,10 +31,59 @@ my $quiet; # this line required my $session = start(); # this line required # upgrade functions go here +addAssetManagerSortPreferences($session); finish($session); # this line required +#---------------------------------------------------------------------------- +sub addAssetManagerSortPreferences { + my $cn = 'assetManagerSortColumn'; + my $on = 'assetManagerSortDirection'; + unless (WebGUI::ProfileField->new($session, $cn)) { + print 'Adding Asset Manager Sort Column profile field...' + unless $quiet; + + WebGUI::ProfileField->create($session, $cn => { + label => + "WebGUI::International::get('$cn label', 'Account_Profile')", + protected => 1, + fieldType => 'selectBox', + dataDefault => 'lineage', + possibleValues => <<'VALUES', +{ + lineage => WebGUI::International::get('rank', 'Asset'), + title => WebGUI::International::get(99, 'Asset'), + className => WebGUI::International::get('type', 'Asset'), + revisionDate => WebGUI::International::get('revision date', 'Asset'), + assetSize => WebGUI::International::get('size', 'Asset'), + lockedBy => WebGUI::International::get('locked', 'Asset'), +} +VALUES + }, 4); + print "Done!\n" unless $quiet; + } + unless (WebGUI::ProfileField->new($session, $on)) { + print 'Adding Asset Manager Sort Direction profile field...' + unless $quiet; + + WebGUI::ProfileField->create($session, $on => { + label => + "WebGUI::International::get('$on label', 'Account_Profile')", + protected => 1, + fieldType => 'selectBox', + dataDefault => 'asc', + possibleValues => <<'VALUES', +{ + asc => WebGUI::International::get('ascending', 'Account_Profile'), + desc => WebGUI::International::get('descending', 'Account_Profile'), +} +VALUES + }, 4); + print "Done!\n" unless $quiet; + } +} + #---------------------------------------------------------------------------- # Describe what our function does #sub exampleFunction { diff --git a/lib/WebGUI/Content/AssetManager.pm b/lib/WebGUI/Content/AssetManager.pm index c26c30806..1a1de24cd 100644 --- a/lib/WebGUI/Content/AssetManager.pm +++ b/lib/WebGUI/Content/AssetManager.pm @@ -100,15 +100,26 @@ filled with asset IDs. sub getManagerPaginator { my $session = shift; + my $user = $session->user; my $asset = getCurrentAsset( $session ); + my %update; - my $orderByColumn = $session->form->get( 'orderByColumn' ) - || "lineage" - ; - my $orderByDirection = lc $session->form->get( 'orderByDirection' ) eq "desc" - ? "DESC" - : "ASC" - ; + my $orderByColumn = $session->form->get( 'orderByColumn' ); + if ($orderByColumn) { + $update{assetManagerSortColumn} = $orderByColumn; + } + else { + $orderByColumn = $user->get( 'assetManagerSortColumn' ) || 'lineage'; + } + my $orderByDirection = lc $session->form->get( 'orderByDirection' ); + if ($orderByDirection) { + $update{assetManagerSortDirection} = $orderByDirection; + } + else { + $orderByDirection = $user->get( 'assetManagerSortDirection' ); + } + $orderByDirection = $orderByDirection eq 'desc' ? 'DESC' : 'ASC'; + $user->update( \%update ) if ( keys %update ); my $recordOffset = $session->form->get( 'recordOffset' ) || 1; my $rowsPerPage = $session->form->get( 'rowsPerPage' ) || 100; @@ -119,7 +130,11 @@ sub getManagerPaginator { my $orderBy = $session->db->dbh->quote_identifier( $orderByColumn ) . ' ' . $orderByDirection; $p->setDataByArrayRef( $asset->getLineage( ['children'], { orderByClause => $orderBy } ) ); - return $p; + return { + paginator => $p, + sortColumn => $orderByColumn, + sortDirection => lc $orderByDirection, + }; } #---------------------------------------------------------------------------- @@ -288,7 +303,8 @@ sub www_ajaxGetManagerPage { my $session = shift; my $i18n = WebGUI::International->new( $session, "Asset" ); my $assetInfo = { assets => [] }; - my $p = getManagerPaginator( $session ); + my $pageInfo = getManagerPaginator( $session ); + my $p = $pageInfo->{paginator}; for my $assetId ( @{ $p->getPageData } ) { my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId ); @@ -319,8 +335,8 @@ sub www_ajaxGetManagerPage { } $assetInfo->{ totalAssets } = $p->getRowCount; - $assetInfo->{ sort } = $session->form->get( 'orderByColumn' ); - $assetInfo->{ dir } = lc $session->form->get( 'orderByDirection' ); + $assetInfo->{ sort } = $pageInfo->{sortColumn}; + $assetInfo->{ dir } = $pageInfo->{sortDirection}; $session->http->setMimeType( 'application/json' ); diff --git a/lib/WebGUI/i18n/English/Account_Profile.pm b/lib/WebGUI/i18n/English/Account_Profile.pm index cf54fb29e..1b9b46a65 100644 --- a/lib/WebGUI/i18n/English/Account_Profile.pm +++ b/lib/WebGUI/i18n/English/Account_Profile.pm @@ -169,6 +169,24 @@ our $I18N = { message => q{required }, lastUpdated => 1225724810, }, + 'assetManagerSortDirection label' => { + message => 'Asset Manager Sort Direction', + lastUpdated => 1307982524, + }, + 'assetManagerSortColumn label' => { + message => 'Asset Manager Sort Column', + lastUpdated => 1307982524, + }, + 'ascending' => { + message => 'Ascending', + lastUpdated => 1307982524, + context => 'Ascending sort order (lowest to highest)', + }, + 'descending' => { + message => 'Descending', + lastUpdated => 1307982524, + context => 'Descending sort order (highest to lowest)', + }, }; 1; diff --git a/www/extras/yui-webgui/build/assetManager/assetManager.js b/www/extras/yui-webgui/build/assetManager/assetManager.js index 4844d1159..b4d06a2d2 100644 --- a/www/extras/yui-webgui/build/assetManager/assetManager.js +++ b/www/extras/yui-webgui/build/assetManager/assetManager.js @@ -203,14 +203,6 @@ WebGUI.AssetManager.onMoreClick = function (e, a) { menu.focus(); }; -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.DefaultSortedBy ( ) -*/ -WebGUI.AssetManager.DefaultSortedBy = { - "key" : "lineage", - "dir" : YAHOO.widget.DataTable.CLASS_ASC -}; - /*--------------------------------------------------------------------------- WebGUI.AssetManager.BuildQueryString ( ) */ @@ -314,7 +306,9 @@ WebGUI.AssetManager.initDataTable = function (o) { { key: 'childCount' } ], metaFields: { - totalRecords: "totalAssets" // Access to value in the server response + totalRecords : 'totalAssets', + sortColumn : 'sort', + sortDirection : 'dir' } }; @@ -329,13 +323,19 @@ WebGUI.AssetManager.initDataTable = function (o) { initialRequest : 'recordOffset=0', dynamicData : true, paginator : assetPaginator, - sortedBy : WebGUI.AssetManager.DefaultSortedBy, generateRequest : WebGUI.AssetManager.BuildQueryString } ); WebGUI.AssetManager.DataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) { - oPayload.totalRecords = oResponse.meta.totalRecords; + var m = oResponse.meta; + oPayload.totalRecords = m.totalRecords; + this.set('sortedBy', { + key: m.sortColumn, + dir: m.sortDirection === 'desc' ? + YAHOO.widget.DataTable.CLASS_DESC : + YAHOO.widget.DataTable.CLASS_ASC + }); return oPayload; };