Delete and Undo works from Lightbox and Thumbnail
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
60d738a55f
commit
13f1fe3233
@ -145,8 +145,8 @@
|
|||||||
thumbChanged: function(thumbpath, visible) {
|
thumbChanged: function(thumbpath, visible) {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
this.style.backgroundImage = "url(" +
|
this.style.backgroundImage = "url(" +
|
||||||
encodeURI(thumbpath).replace(/'/g, "\\'").replace(/([\(\)])/g, "\\$1") +
|
encodeURI(thumbpath).replace(/'/g, "\\'").replace(/([\(\)])/g, "\\$1") +
|
||||||
")";
|
")";
|
||||||
} else {
|
} else {
|
||||||
this.style.backgroundImage = "";
|
this.style.backgroundImage = "";
|
||||||
}
|
}
|
||||||
|
@ -1282,7 +1282,7 @@
|
|||||||
this.processing = false;
|
this.processing = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
_removeImageAfterFetch: function(thumbnail, callback, error, xhr) {
|
_removeImageAfterFetch: function(thumbnail, callback, error) {
|
||||||
thumbnail.disabled = false;
|
thumbnail.disabled = false;
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log("Unable to take action on photo: " + error);
|
console.log("Unable to take action on photo: " + error);
|
||||||
@ -1350,10 +1350,38 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
undoAction: function(thumbnail) {
|
undoAction: function(thumbnail) {
|
||||||
var params = {};
|
|
||||||
thumbnail.disabled = true;
|
thumbnail.disabled = true;
|
||||||
window.fetch("api/v1/photos/" + thumbnail.item.id + "?a=undelete",
|
window.fetch("api/v1/photos/" + thumbnail.item.id + "?a=undelete", function(thumbnail, error) {
|
||||||
this._removeImageAfterFetch.bind(this, thumbnail, null), {}, "PUT");
|
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) {
|
deleteAction: function(thumbnail) {
|
||||||
@ -1363,30 +1391,60 @@
|
|||||||
console.log("TODO: Prompt user 'Are you sure?' ?");
|
console.log("TODO: Prompt user 'Are you sure?' ?");
|
||||||
query += "?permanent=1";
|
query += "?permanent=1";
|
||||||
}
|
}
|
||||||
|
|
||||||
window.fetch("api/v1/photos/" + thumbnail.item.id + query,
|
window.fetch("api/v1/photos/" + thumbnail.item.id + query,
|
||||||
this._removeImageAfterFetch.bind(this, thumbnail, function() {
|
function(thumbnail, error) {
|
||||||
/* If there is a lightbox, close the lightbox */
|
thumbnail.disabled = false;
|
||||||
this.$.lightbox.close();
|
|
||||||
/* In duplicates mode, if an image is deleted it has the same
|
if (error) {
|
||||||
* effect as renaming it since it removes it from the view */
|
console.log("Unable to take action on photo: " + error);
|
||||||
if (this.mode != "duplicates") {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* If there is now only one item with this thumbnail's name,
|
|
||||||
* remove it from the view */
|
/* If we are in the lightbox mode, then reload the corresponing
|
||||||
var orphan = null;
|
* thumb in the main view as well */
|
||||||
for (var i = 0; i < this.thumbnails.length; i++) {
|
if (thumbnail.tagName == "PHOTO-LIGHTBOX") {
|
||||||
if (this.thumbnails[i].item.filename == thumbnail.item.filename) {
|
console.log("Delete from lightbox");
|
||||||
if (orphan) {
|
this.$.lightbox.close();
|
||||||
return;
|
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;
|
||||||
}
|
}
|
||||||
orphan = this.thumbnails[i];
|
|
||||||
}
|
}
|
||||||
|
if (!match) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
thumbnail = match;
|
||||||
|
} else {
|
||||||
|
console.log("Delete from thumbnail");
|
||||||
}
|
}
|
||||||
if (orphan) {
|
|
||||||
this._removeImageAfterFetch(orphan, null);
|
this._removeImageAfterFetch(thumbnail, function() {
|
||||||
}
|
/* If there is a lightbox, close the lightbox */
|
||||||
}.bind(this)), {}, "DELETE");
|
/* 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") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* If there is now only one item with this thumbnail's name,
|
||||||
|
* remove it from the view */
|
||||||
|
var orphan = null;
|
||||||
|
for (var i = 0; i < this.thumbnails.length; i++) {
|
||||||
|
if (this.thumbnails[i].item.filename == thumbnail.item.filename) {
|
||||||
|
if (orphan) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
orphan = this.thumbnails[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (orphan) {
|
||||||
|
this._removeImageAfterFetch(orphan);
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
}.bind(this, thumbnail), {}, "DELETE");
|
||||||
},
|
},
|
||||||
|
|
||||||
renameAction: function(thumbnail) {
|
renameAction: function(thumbnail) {
|
||||||
@ -1405,7 +1463,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (orphan) {
|
if (orphan) {
|
||||||
this._removeImageAfterFetch(orphan, null);
|
this._removeImageAfterFetch(orphan);
|
||||||
}
|
}
|
||||||
}.bind(this)), {}, "PUT");
|
}.bind(this)), {}, "PUT");
|
||||||
},
|
},
|
||||||
@ -1415,7 +1473,7 @@
|
|||||||
thumbnail.loading = true;
|
thumbnail.loading = true;
|
||||||
|
|
||||||
window.fetch("api/v1/photos/" + thumbnail.item.id + "?a=rotate&direction=" + direction,
|
window.fetch("api/v1/photos/" + thumbnail.item.id + "?a=rotate&direction=" + direction,
|
||||||
function(thumbnail, error, xhr) {
|
function(thumbnail, error) {
|
||||||
|
|
||||||
thumbnail.disabled = false;
|
thumbnail.disabled = false;
|
||||||
thumbnail.loading = false;
|
thumbnail.loading = false;
|
||||||
@ -1426,6 +1484,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
thumbnail.reload();
|
thumbnail.reload();
|
||||||
|
|
||||||
/* If we are in the lightbox mode, then reload the corresponing
|
/* If we are in the lightbox mode, then reload the corresponing
|
||||||
* thumb in the main view as well */
|
* thumb in the main view as well */
|
||||||
if (thumbnail.tagName == "PHOTO-LIGHTBOX") {
|
if (thumbnail.tagName == "PHOTO-LIGHTBOX") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user