Delete and Undo works from Lightbox and Thumbnail

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2018-10-17 21:23:05 -07:00
parent 60d738a55f
commit 13f1fe3233
2 changed files with 85 additions and 26 deletions

View File

@ -1282,7 +1282,7 @@
this.processing = false;
},
_removeImageAfterFetch: function(thumbnail, callback, error, xhr) {
_removeImageAfterFetch: function(thumbnail, callback, error) {
thumbnail.disabled = false;
if (error) {
console.log("Unable to take action on photo: " + error);
@ -1350,10 +1350,38 @@
},
undoAction: function(thumbnail) {
var params = {};
thumbnail.disabled = true;
window.fetch("api/v1/photos/" + thumbnail.item.id + "?a=undelete",
this._removeImageAfterFetch.bind(this, thumbnail, null), {}, "PUT");
window.fetch("api/v1/photos/" + thumbnail.item.id + "?a=undelete", function(thumbnail, error) {
thumbnail.disabled = false;
if (error) {
console.log("Unable to take action on photo: " + error);
return;
}
/* If we are in the lightbox mode, then reload the corresponing
* thumb in the main view as well */
if (thumbnail.tagName == "PHOTO-LIGHTBOX") {
console.log("Undo from lightbox");
this.$.lightbox.close();
var match = null;
for (var i = 0; i < this.thumbnails.length; i++) {
if (this.thumbnails[i].item.id == thumbnail.item.id) {
match = this.thumbnails[i];
break;
}
}
if (!match) {
return;
}
thumbnail = match;
} else {
console.log("Undo from thumbnail");
}
this._removeImageAfterFetch(thumbnail);
}.bind(this, thumbnail), {}, "PUT");
},
deleteAction: function(thumbnail) {
@ -1363,10 +1391,39 @@
console.log("TODO: Prompt user 'Are you sure?' ?");
query += "?permanent=1";
}
window.fetch("api/v1/photos/" + thumbnail.item.id + query,
this._removeImageAfterFetch.bind(this, thumbnail, function() {
/* If there is a lightbox, close the lightbox */
function(thumbnail, error) {
thumbnail.disabled = false;
if (error) {
console.log("Unable to take action on photo: " + error);
return;
}
/* If we are in the lightbox mode, then reload the corresponing
* thumb in the main view as well */
if (thumbnail.tagName == "PHOTO-LIGHTBOX") {
console.log("Delete from lightbox");
this.$.lightbox.close();
var match = null;
for (var i = 0; i < this.thumbnails.length; i++) {
if (this.thumbnails[i].item.id == thumbnail.item.id) {
match = this.thumbnails[i];
break;
}
}
if (!match) {
return;
}
thumbnail = match;
} else {
console.log("Delete from thumbnail");
}
this._removeImageAfterFetch(thumbnail, function() {
/* If there is a lightbox, close the lightbox */
/* In duplicates mode, if an image is deleted it has the same
* effect as renaming it since it removes it from the view */
if (this.mode != "duplicates") {
@ -1384,9 +1441,10 @@
}
}
if (orphan) {
this._removeImageAfterFetch(orphan, null);
this._removeImageAfterFetch(orphan);
}
}.bind(this)), {}, "DELETE");
}.bind(this));
}.bind(this, thumbnail), {}, "DELETE");
},
renameAction: function(thumbnail) {
@ -1405,7 +1463,7 @@
}
}
if (orphan) {
this._removeImageAfterFetch(orphan, null);
this._removeImageAfterFetch(orphan);
}
}.bind(this)), {}, "PUT");
},
@ -1415,7 +1473,7 @@
thumbnail.loading = true;
window.fetch("api/v1/photos/" + thumbnail.item.id + "?a=rotate&direction=" + direction,
function(thumbnail, error, xhr) {
function(thumbnail, error) {
thumbnail.disabled = false;
thumbnail.loading = false;
@ -1426,6 +1484,7 @@
}
thumbnail.reload();
/* If we are in the lightbox mode, then reload the corresponing
* thumb in the main view as well */
if (thumbnail.tagName == "PHOTO-LIGHTBOX") {