Duplicate photos by right-clicking them (#186)

This commit is contained in:
Tobias Reich 2014-08-22 23:31:09 +02:00
parent c291ab35bf
commit d686a2b083
5 changed files with 75 additions and 10 deletions

View File

@ -164,6 +164,7 @@ contextMenu = {
function() { photo.setStar([photoID]) },
function() { photo.editTags([photoID]) },
function() { photo.setTitle([photoID]) },
function() { photo.duplicate([photoID]) },
function() { contextMenu.move([photoID], e, "right") },
function() { photo.delete([photoID]) }
];
@ -173,8 +174,9 @@ contextMenu = {
["<a class='icon-tags'></a> Tags", 1],
["separator", -1],
["<a class='icon-edit'></a> Rename", 2],
["<a class='icon-folder-open'></a> Move", 3],
["<a class='icon-trash'></a> Delete", 4]
["<a class='icon-copy'></a> Duplicate", 3],
["<a class='icon-folder-open'></a> Move", 4],
["<a class='icon-trash'></a> Delete", 5]
];
contextMenu.show(items, mouse_x, mouse_y, "right");
@ -195,6 +197,7 @@ contextMenu = {
function() { photo.setStar(photoIDs) },
function() { photo.editTags(photoIDs) },
function() { photo.setTitle(photoIDs) },
function() { photo.duplicate(photoIDs) },
function() { contextMenu.move(photoIDs, e, "right") },
function() { photo.delete(photoIDs) }
];
@ -204,8 +207,9 @@ contextMenu = {
["<a class='icon-tags'></a> Tag All", 1],
["separator", -1],
["<a class='icon-edit'></a> Rename All", 2],
["<a class='icon-folder-open'></a> Move All", 3],
["<a class='icon-trash'></a> Delete All", 4]
["<a class='icon-copy'></a> Duplicate All", 3],
["<a class='icon-folder-open'></a> Move All", 4],
["<a class='icon-trash'></a> Delete All", 5]
];
contextMenu.show(items, mouse_x, mouse_y, "right");

View File

@ -117,6 +117,23 @@ photo = {
},
duplicate: function(photoIDs) {
var params;
if (!photoIDs) return false;
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
params = "duplicatePhoto&photoIDs=" + photoIDs;
lychee.api(params, function(data) {
if (data!==true) lychee.error(null, params, data);
else album.load(album.getID(), false);
});
},
delete: function(photoIDs) {
var params,

File diff suppressed because one or more lines are too long

View File

@ -32,6 +32,7 @@ class Admin extends Access {
case 'setPhotoPublic': $this->setPhotoPublic(); break;
case 'setPhotoAlbum': $this->setPhotoAlbum(); break;
case 'setPhotoTags': $this->setPhotoTags(); break;
case 'duplicatePhoto': $this->duplicatePhoto(); break;
case 'deletePhoto': $this->deletePhoto(); break;
# Add functions
@ -181,6 +182,14 @@ class Admin extends Access {
}
private function duplicatePhoto() {
Module::dependencies(isset($_POST['photoIDs']));
$photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
echo $photo->duplicate();
}
private function deletePhoto() {
Module::dependencies(isset($_POST['photoIDs']));

View File

@ -818,6 +818,41 @@ class Photo extends Module {
}
public function duplicate() {
# Check dependencies
self::dependencies(isset($this->database, $this->photoIDs));
# Call plugins
$this->plugins(__METHOD__, 0, func_get_args());
# Get photos
$photos = $this->database->query("SELECT id, checksum FROM lychee_photos WHERE id IN ($this->photoIDs);");
if (!$photos) {
Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
return false;
}
# For each photo
while ($photo = $photos->fetch_object()) {
# Generate id
$id = str_replace('.', '', microtime(true));
while(strlen($id)<14) $id .= 0;
# Duplicate entry
$duplicate = $this->database->query("INSERT INTO lychee_photos(id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star, checksum) SELECT '$id' AS id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star, checksum FROM lychee_photos WHERE id = '$photo->id';");
if (!$duplicate) {
Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
return false;
}
}
return true;
}
public function delete() {
# Check dependencies