From 4549fd580154faebc975efe19d2f15451539cdeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Viguier?= Date: Wed, 23 Nov 2022 19:09:19 +0100 Subject: [PATCH] add upload date changer (#353) * add upload date changer --- scripts/main/lychee_locale.js | 2 + scripts/main/photo.js | 69 ++++++++++++++++++++++++++++++++++- scripts/main/sidebar.js | 9 ++++- scripts/main/view.js | 7 ++++ 4 files changed, 84 insertions(+), 3 deletions(-) diff --git a/scripts/main/lychee_locale.js b/scripts/main/lychee_locale.js index c8ce0df7..d1701eb9 100644 --- a/scripts/main/lychee_locale.js +++ b/scripts/main/lychee_locale.js @@ -284,6 +284,8 @@ lychee.locale = { "Because this photo is located in a public album, it inherits that album’s visibility settings. Its current visibility is shown below for informational purposes only.", PHOTO_EDIT_GLOBAL_SHARING_TEXT: "The visibility of this photo can be fine-tuned using global Lychee settings. Its current visibility is shown below for informational purposes only.", + PHOTO_NEW_CREATED_AT: "Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]", + PHOTO_SET_CREATED_AT: "Set upload date", LOADING: "Loading", ERROR: "Error", diff --git a/scripts/main/photo.js b/scripts/main/photo.js index ca91ca5b..48ff564e 100644 --- a/scripts/main/photo.js +++ b/scripts/main/photo.js @@ -735,7 +735,7 @@ photo.setDescription = function (photoID) { }; const setPhotoDescriptionDialogBody = ` -

+

`; @@ -746,7 +746,7 @@ photo.setDescription = function (photoID) { * @returns {void} */ const initSetPhotoDescriptionDialog = function (formElements, dialog) { - dialog.querySelector("p").textContent = lychee.locale["PHOTO_NEW_DESCRIPTION"]; + dialog.querySelector("p#ppp_dialog_description_expl").textContent = lychee.locale["PHOTO_NEW_DESCRIPTION"]; formElements.description.placeholder = lychee.locale["PHOTO_DESCRIPTION"]; formElements.description.value = photo.json.description ? photo.json.description : ""; }; @@ -767,6 +767,71 @@ photo.setDescription = function (photoID) { }); }; +/** + * Edits the upload date of a photo. + * + * This method is a misnomer, it does not only set the description, it also creates and handles the edit dialog + * + * @param {string} photoID + * @returns {void} + */ +photo.setCreatedAt = function (photoID) { + /** + * @param {{date: string}} data + */ + const action = function (data) { + basicModal.close(); + + const created_at = data.created_at ? data.created_at.concat(":", data.tz) : null; + + if (visible.photo()) { + photo.json.created_at = created_at; + view.photo.uploaded(); + } + + api.post("Photo::setUploadDate", { + photoID: photoID, + date: created_at, + }); + }; + + const setPhotoCreatedAtDialogBody = ` +

+
+
+ +
+
`; + + /** + * @param {ModalDialogFormElements} formElements + * @param {HTMLDivElement} dialog + * @returns {void} + */ + const initSetPhotoCreatedAtDialog = function (formElements, dialog) { + dialog.querySelector("p#ppp_dialog_uploaddate_expl").textContent = lychee.locale["PHOTO_NEW_CREATED_AT"]; + formElements.created_at.value = photo.json.created_at ? photo.json.created_at.slice(0, 16) : ""; + formElements.tz.value = photo.json.created_at ? photo.json.created_at.slice(17) : ""; + }; + + basicModal.show({ + body: setPhotoCreatedAtDialogBody, + readyCB: initSetPhotoCreatedAtDialog, + buttons: { + action: { + title: lychee.locale["PHOTO_SET_CREATED_AT"], + fn: action, + }, + cancel: { + title: lychee.locale["CANCEL"], + fn: basicModal.close, + }, + }, + }); +}; + /** * @param {string[]} photoIDs * @returns {void} diff --git a/scripts/main/sidebar.js b/scripts/main/sidebar.js index c395869d..a79e2a28 100644 --- a/scripts/main/sidebar.js +++ b/scripts/main/sidebar.js @@ -51,6 +51,13 @@ sidebar.bind = function () { else if (visible.album()) album.setDescription(album.getID()); }); + sidebar + .dom("#edit_uploaded") + .off(eventName) + .on(eventName, function () { + if (visible.photo()) photo.setCreatedAt(photo.getID()); + }); + sidebar .dom("#edit_showtags") .off(eventName) @@ -277,7 +284,7 @@ sidebar.createStructure.photo = function (data) { type: sidebar.types.DEFAULT, rows: [ { title: lychee.locale["PHOTO_TITLE"], kind: "title", value: data.title, editable }, - { title: lychee.locale["PHOTO_UPLOADED"], kind: "uploaded", value: lychee.locale.printDateTime(data.created_at) }, + { title: lychee.locale["PHOTO_UPLOADED"], kind: "uploaded", value: lychee.locale.printDateTime(data.created_at), editable }, { title: lychee.locale["PHOTO_DESCRIPTION"], kind: "description", value: data.description ? data.description : "", editable }, ], }; diff --git a/scripts/main/view.js b/scripts/main/view.js index 0d78d6c6..61489cbe 100644 --- a/scripts/main/view.js +++ b/scripts/main/view.js @@ -853,6 +853,13 @@ view.photo = { if (photo.json.init) sidebar.changeAttr("description", photo.json.description ? photo.json.description : ""); }, + /** + * @returns {void} + */ + uploaded: function () { + if (photo.json.init) sidebar.changeAttr("uploaded", photo.json.created_at ? lychee.locale.printDateTime(photo.json.created_at) : ""); + }, + /** * @returns {void} */