List<Album> getAlbums();
/**
- * Moves the given album up in this album’s albums. If the album is already the
- * first album, nothing happens.
- *
- * @param album
- * The album to move up
- * @return The album that the given album swapped the place with, or
- * <code>null</code> if the album did not change its place
- */
- Album moveAlbumUp(Album album);
-
- /**
- * Moves the given album down in this album’s albums. If the album is already
- * the last album, nothing happens.
- *
- * @param album
- * The album to move down
- * @return The album that the given album swapped the place with, or
- * <code>null</code> if the album did not change its place
- */
- Album moveAlbumDown(Album album);
-
- /**
* Returns the images in this album.
*
* @return The images in this album
*/
Modifier modify() throws IllegalStateException;
+ void moveUp();
+
+ void moveDown();
+
void remove() throws IllegalStateException;
/**
}
@Override
- public Album moveAlbumUp(Album album) {
- checkNotNull(album, "album must not be null");
- checkArgument(album.getSone().equals(sone), "album must belong to the same Sone as this album");
- checkArgument(equals(album.getParent()), "album must belong to this album");
- int oldIndex = albums.indexOf(album);
- if (oldIndex <= 0) {
- return null;
- }
- albums.remove(oldIndex);
- albums.add(oldIndex - 1, album);
- return albums.get(oldIndex);
- }
-
- @Override
- public Album moveAlbumDown(Album album) {
- checkNotNull(album, "album must not be null");
- checkArgument(album.getSone().equals(sone), "album must belong to the same Sone as this album");
- checkArgument(equals(album.getParent()), "album must belong to this album");
- int oldIndex = albums.indexOf(album);
- if ((oldIndex < 0) || (oldIndex >= (albums.size() - 1))) {
- return null;
- }
- albums.remove(oldIndex);
- albums.add(oldIndex + 1, album);
- return albums.get(oldIndex);
- }
-
- @Override
public List<Image> getImages() {
return new ArrayList<Image>(Collections2.filter(Collections2.transform(imageIds, new Function<String, Image>() {
}
@Override
+ public void moveUp() {
+ int oldIndex = parent.albums.indexOf(this);
+ parent.albums.remove(this);
+ parent.albums.add(Math.max(0, oldIndex - 1), this);
+ }
+
+ @Override
+ public void moveDown() {
+ int oldIndex = parent.albums.indexOf(this);
+ parent.albums.remove(this);
+ parent.albums.add(Math.min(parent.albums.size(), oldIndex + 1), this);
+ }
+
+ @Override
public void remove() throws IllegalStateException {
checkState(!isRoot(), "can not remove root album");
removeAllAlbums();
throw new RedirectException("noPermission.html");
}
if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveLeft", 4))) {
- album.get().getParent().moveAlbumUp(album.get());
+ album.get().moveUp();
webInterface.getCore().touchConfiguration();
throw new RedirectException("imageBrowser.html?album=" + album.get().getParent().getId());
} else if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveRight", 4))) {
- album.get().getParent().moveAlbumDown(album.get());
+ album.get().moveDown();
webInterface.getCore().touchConfiguration();
throw new RedirectException("imageBrowser.html?album=" + album.get().getParent().getId());
}
return createErrorJsonObject("not-authorized");
}
if ("true".equals(request.getHttpRequest().getParam("moveLeft"))) {
- Album swappedAlbum = album.get().getParent().moveAlbumUp(album.get());
+ album.get().moveUp();
webInterface.getCore().touchConfiguration();
- return createSuccessJsonObject().put("sourceAlbumId", album.get().getId()).put("destinationAlbumId", swappedAlbum.getId());
+ return createSuccessJsonObject(); // TODO - fix javascript!
}
if ("true".equals(request.getHttpRequest().getParam("moveRight"))) {
- Album swappedAlbum = album.get().getParent().moveAlbumDown(album.get());
+ album.get().moveDown();
webInterface.getCore().touchConfiguration();
- return createSuccessJsonObject().put("sourceAlbumId", album.get().getId()).put("destinationAlbumId", swappedAlbum.getId());
+ return createSuccessJsonObject(); // TODO - fix javascript!
}
String title = request.getHttpRequest().getParam("title").trim();
String description = request.getHttpRequest().getParam("description").trim();