Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
add upload date changer (#353)
Browse files Browse the repository at this point in the history
* add upload date changer
  • Loading branch information
ildyria authored Nov 23, 2022
1 parent 2cfbce0 commit 4549fd5
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
2 changes: 2 additions & 0 deletions scripts/main/lychee_locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
69 changes: 67 additions & 2 deletions scripts/main/photo.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ photo.setDescription = function (photoID) {
};

const setPhotoDescriptionDialogBody = `
<p></p>
<p id="ppp_dialog_description_expl"></p>
<form>
<div class="input-group stacked"><input class='text' name='description' type='text' maxlength='800'></div>
</form>`;
Expand All @@ -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 : "";
};
Expand All @@ -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 = `
<p id="ppp_dialog_uploaddate_expl"></p>
<form>
<div class="input-group stacked"><input class='text' name='created_at' type='datetime-local'
pattern='[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}'
>
<input name='tz' type='hidden'>
</div>
</form>`;

/**
* @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}
Expand Down
9 changes: 8 additions & 1 deletion scripts/main/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 },
],
};
Expand Down
7 changes: 7 additions & 0 deletions scripts/main/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down

0 comments on commit 4549fd5

Please sign in to comment.