Problem der Objektsortierung in den Kategorien behoben (Ticket #1318)

git-svn-id: https://svn.libreccm.org/ccm/trunk@1839 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2012-08-29 13:30:56 +00:00
parent 1b69863fa6
commit dd864b7ed4
5 changed files with 102 additions and 71 deletions

View File

@ -71,7 +71,7 @@ public class BaseImage extends ResourceHandlerImpl {
CMS.getConfig().getImageCacheMaxSize()); CMS.getConfig().getImageCacheMaxSize());
} }
} }
private final bool IMAGE_CACHE_PREFETCH = CMS.getConfig().getImageCachePrefetchEnabled(); private final boolean IMAGE_CACHE_PREFETCH = CMS.getConfig().getImageCachePrefetchEnabled();
private static final Logger s_log = Logger.getLogger(BaseImage.class); private static final Logger s_log = Logger.getLogger(BaseImage.class);
/** /**

View File

@ -60,21 +60,26 @@ public class CategorizedObjectsList extends SortableCategoryList {
* This actually performs the sorting * This actually performs the sorting
*/ */
public void respond(PageState ps) throws ServletException { public void respond(PageState ps) throws ServletException {
String event = ps.getControlEventName(); final String event = ps.getControlEventName();
if (NEXT_EVENT.equals(event) || PREV_EVENT.equals(event)) { if (NEXT_EVENT.equals(event) || PREV_EVENT.equals(event)) {
BigDecimal selectedID = new BigDecimal(ps.getControlEventValue()); final BigDecimal selectedID = new BigDecimal(ps.getControlEventValue());
Category parent = getCategory(ps); final Category parent = getCategory(ps);
final ContentItem selectedItem = new ContentItem(selectedID); final ContentItem selectedItem = new ContentItem(selectedID);
final BigDecimal selectedDraftId = selectedItem.getDraftVersion().getID(); final BigDecimal selectedDraftId = selectedItem.getDraftVersion().getID();
if (CMS.getContext().getSecurityManager().canAccess(SecurityManager.CATEGORY_ADMIN)) { if (CMS.getContext().getSecurityManager().canAccess(SecurityManager.CATEGORY_ADMIN)) {
BigDecimal swapId = getSwapID(parent, selectedID, event); final BigDecimal swapId = getSwapID(parent, selectedID, event);
parent.swapSortKeys(selectedID, swapId); parent.swapSortKeys(selectedID, swapId);
final ContentItem draftSwapItem = new ContentItem(swapId); final ContentItem swapItem = new ContentItem(swapId);
final BigDecimal draftSwapId = selectedItem.getDraftVersion().getID(); final BigDecimal swapDraftId = swapItem.getDraftVersion().getID();
parent.swapSortKeys(selectedDraftId, draftSwapId);
final BigDecimal sortKey1 = parent.getSortKey(selectedItem);
final BigDecimal sortKey2 = parent.getSortKey(swapItem);
parent.setSortKey(new ContentItem(selectedDraftId), sortKey1);
parent.setSortKey(new ContentItem(swapDraftId), sortKey2);
} }
} else { } else {

View File

@ -169,6 +169,7 @@ public class OrderedCategorizedObjectsList extends CategorizedObjectsList {
} }
} }
parent.save(); parent.save();
} catch (DataObjectNotFoundException e) { } catch (DataObjectNotFoundException e) {
s_log.error("Trying to create categories with state = " + ps, e); s_log.error("Trying to create categories with state = " + ps, e);
throw new ServletException(e); throw new ServletException(e);

View File

@ -23,6 +23,7 @@ import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.parameters.BigDecimalParameter; import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.categorization.Category; import com.arsdigita.categorization.Category;
import com.arsdigita.cms.CMS; import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.SecurityManager; import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.ui.SortableList; import com.arsdigita.cms.ui.SortableList;

View File

@ -416,7 +416,8 @@ public class Category extends ACSObject {
public String getName(String locale) { public String getName(String locale) {
// Test for localized version // Test for localized version
if (locale != null && !locale.isEmpty() && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. if (locale != null && !locale.isEmpty() && m_categoryLocalizationCollection != null
&& m_categoryLocalizationCollection.
localizationExists(locale)) { localizationExists(locale)) {
// Return value of isEnabled from localized version, so categories could be disabled depending on locale // Return value of isEnabled from localized version, so categories could be disabled depending on locale
@ -602,7 +603,8 @@ public class Category extends ACSObject {
// Test for localized version // Test for localized version
// HACK // HACK
if (locale != null && !locale.isEmpty() && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. if (locale != null && !locale.isEmpty() && m_categoryLocalizationCollection != null
&& m_categoryLocalizationCollection.
localizationExists(locale)) { localizationExists(locale)) {
// Return value of isEnabled from localized version, so categories could be disabled depending on locale // Return value of isEnabled from localized version, so categories could be disabled depending on locale
@ -679,7 +681,8 @@ public class Category extends ACSObject {
public String getURL(String locale) { public String getURL(String locale) {
// Test for localized version // Test for localized version
if (locale != null && !locale.isEmpty() && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. if (locale != null && !locale.isEmpty() && m_categoryLocalizationCollection != null
&& m_categoryLocalizationCollection.
localizationExists(locale)) { localizationExists(locale)) {
// Return value of isEnabled from localized version, so categories could be disabled depending on locale // Return value of isEnabled from localized version, so categories could be disabled depending on locale
@ -751,7 +754,8 @@ public class Category extends ACSObject {
} }
// Test for localized version // Test for localized version
if (locale != null && !locale.isEmpty() && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. if (locale != null && !locale.isEmpty() && m_categoryLocalizationCollection != null
&& m_categoryLocalizationCollection.
localizationExists(locale)) { localizationExists(locale)) {
// Return value of isEnabled from localized version, so categories could be disabled depending on locale // Return value of isEnabled from localized version, so categories could be disabled depending on locale
@ -1640,6 +1644,24 @@ public class Category extends ACSObject {
} }
} }
public BigDecimal getSortKey(final ACSObject object) {
return getSortKey(object.getID());
}
public BigDecimal getSortKey(final BigDecimal objId) {
final DataAssociationCursor cursor = ((DataAssociation) get(CHILD_OBJECTS)).cursor();
cursor.addEqualsFilter(ID, objId);
if (cursor.next()) {
return (BigDecimal) cursor.getLink().get(SORT_KEY);
}
return null;
}
public void setSortKey(ACSObject object, int key) {
setSortKey(object, new BigDecimal(key));
}
/** /**
* Explicitly sets the sort key for this child object (category or * Explicitly sets the sort key for this child object (category or
* otherwise). * otherwise).
@ -1647,7 +1669,7 @@ public class Category extends ACSObject {
* @param child The child object or category to set the sortKey for * @param child The child object or category to set the sortKey for
* @param key The integer to use for the sortKey * @param key The integer to use for the sortKey
*/ */
public void setSortKey(ACSObject child, int key) { public void setSortKey(ACSObject child, BigDecimal key) {
if (isCategory(child)) { if (isCategory(child)) {
setSortKey((Category) child, key); setSortKey((Category) child, key);
return; return;
@ -1659,7 +1681,7 @@ public class Category extends ACSObject {
cursor.addEqualsFilter(ID, child.getID()); cursor.addEqualsFilter(ID, child.getID());
if (cursor.next()) { if (cursor.next()) {
DataObject link = cursor.getLink(); DataObject link = cursor.getLink();
link.set(SORT_KEY, new BigDecimal(key)); link.set(SORT_KEY, key);
} }
cursor.close(); cursor.close();
} }
@ -2053,6 +2075,7 @@ public class Category extends ACSObject {
public String getToken() { public String getToken() {
return m_token; return m_token;
} }
} }
@Override @Override
@ -2356,4 +2379,5 @@ public class Category extends ACSObject {
return false; return false;
} }
} }