mirror of
https://github.com/hkalexling/Mango.git
synced 2026-03-20 00:00:48 -04:00
Set and load display names in frontend
This commit is contained in:
@@ -15,7 +15,10 @@ function showModal(encodedPath, pages, percentage, encodedeTitle, encodedEntryTi
|
||||
if (percentage === 100) {
|
||||
$('#read-btn').attr('hidden', '');
|
||||
}
|
||||
$('#modal-title').text(entry);
|
||||
$('#modal-title').find('span').text(entry);
|
||||
$('#modal-title').next().attr('data-id', titleID);
|
||||
$('#modal-title').next().attr('data-entry-id', entryID);
|
||||
$('#modal-title').next().find('.title-rename-field').val(entry);
|
||||
$('#path-text').text(zipPath);
|
||||
$('#pages-text').text(pages + ' pages');
|
||||
|
||||
@@ -43,3 +46,60 @@ function updateProgress(titleID, entryID, page) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const rename = ele => {
|
||||
const h2 = $(ele).parent();
|
||||
|
||||
$(h2).attr('hidden', true);
|
||||
$(h2).next().removeAttr('hidden');
|
||||
};
|
||||
|
||||
const renameSubmit = ele => {
|
||||
const group = $(ele).closest('.title-rename');
|
||||
const id = $(group).attr('data-id');
|
||||
const eid = $(group).attr('data-entry-id');
|
||||
const name = $(ele).next().val();
|
||||
|
||||
console.log(name);
|
||||
|
||||
$(group).attr('hidden', true);
|
||||
$(group).prev().removeAttr('hidden');
|
||||
|
||||
if (name.length === 0) {
|
||||
alert('danger', 'The display name should not be empty');
|
||||
return;
|
||||
}
|
||||
|
||||
$(group).prev().find('span').text(name);
|
||||
|
||||
const query = $.param({ entry: eid });
|
||||
let url = `/api/admin/display_name/${id}/${name}`;
|
||||
if (eid)
|
||||
url += `?${query}`;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: url,
|
||||
contentType: "application/json",
|
||||
dataType: 'json'
|
||||
})
|
||||
.done(data => {
|
||||
console.log(data);
|
||||
if (data.error) {
|
||||
alert('danger', `Failed to update display name. Error: ${data.error}`);
|
||||
return;
|
||||
}
|
||||
location.reload();
|
||||
})
|
||||
.fail((jqXHR, status) => {
|
||||
alert('danger', `Failed to update display name. Error: [${jqXHR.status}] ${jqXHR.statusText}`);
|
||||
});
|
||||
};
|
||||
|
||||
$(() => {
|
||||
$('.uk-input.title-rename-field').keyup(event => {
|
||||
if (event.keyCode === 13) {
|
||||
renameSubmit($(event.currentTarget).prev());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user