mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added callback notifications to edit functions
This commit is contained in:
parent
45ea7499b2
commit
6e8cbe6a57
@ -16,8 +16,17 @@ function toggleDeleteConfirm(element) {
|
||||
}
|
||||
|
||||
function deleteScrobble(id,element) {
|
||||
element.parentElement.parentElement.parentElement.classList.add('removed');
|
||||
neo.xhttpreq("/apis/mlj_1/delete_scrobble",data={'timestamp':id},method="POST",callback=(()=>null),json=true);
|
||||
var callback_func = function(req){
|
||||
if (req.status == 200) {
|
||||
element.parentElement.parentElement.parentElement.classList.add('removed');
|
||||
notifyCallback(req);
|
||||
}
|
||||
else {
|
||||
notifyCallback(req);
|
||||
}
|
||||
};
|
||||
|
||||
neo.xhttpreq("/apis/mlj_1/delete_scrobble",data={'timestamp':id},method="POST",callback=callback_func,json=true);
|
||||
}
|
||||
|
||||
|
||||
@ -77,11 +86,20 @@ function doneEditing() {
|
||||
var payload = {'id':entity_id,'title':newname}
|
||||
}
|
||||
|
||||
callback_func = function(req){
|
||||
if (req.status == 200) {
|
||||
window.location = "?" + searchParams.toString();
|
||||
}
|
||||
else {
|
||||
notifyCallback(req);
|
||||
}
|
||||
};
|
||||
|
||||
neo.xhttpreq(
|
||||
endpoint,
|
||||
data=payload,
|
||||
method="POST",
|
||||
callback=(()=>window.location = "?" + searchParams.toString()),
|
||||
callback=callback_func,
|
||||
json=true
|
||||
);
|
||||
}
|
||||
@ -97,6 +115,7 @@ function markForMerge() {
|
||||
current_stored.push(entity_id);
|
||||
current_stored = [...new Set(current_stored)];
|
||||
lcst.setItem(key,current_stored); //this already formats it correctly
|
||||
notify("Success","Marked " + entity_name + " for merge, currently " + current_stored.length + " marked!")
|
||||
}
|
||||
|
||||
function merge() {
|
||||
@ -105,6 +124,15 @@ function merge() {
|
||||
var current_stored = lcst.getItem(key).split(",");
|
||||
current_stored = current_stored.filter((x)=>x).map((x)=>parseInt(x));
|
||||
|
||||
callback_func = function(req){
|
||||
if (req.status == 200) {
|
||||
window.location.reload();
|
||||
}
|
||||
else {
|
||||
notifyCallback(req);
|
||||
}
|
||||
};
|
||||
|
||||
neo.xhttpreq(
|
||||
"/apis/mlj_1/merge_" + entity_type + "s",
|
||||
data={
|
||||
@ -112,7 +140,7 @@ function merge() {
|
||||
'target_id':entity_id
|
||||
},
|
||||
method="POST",
|
||||
callback=(()=>window.location.reload()),
|
||||
callback=callback_func,
|
||||
json=true
|
||||
);
|
||||
|
||||
|
@ -6,7 +6,7 @@ const colors = {
|
||||
}
|
||||
|
||||
const notification_template = info => `
|
||||
<div class="notification" style="background-color:${colors[type]};">
|
||||
<div class="notification" style="background-color:${colors[info.notification_type]};">
|
||||
<b>${info.title}</b><br/>
|
||||
<span>${info.body}</span>
|
||||
|
||||
@ -20,11 +20,11 @@ function htmlToElement(html) {
|
||||
return template.content.firstChild;
|
||||
}
|
||||
|
||||
function notify(title,msg,type='info',reload=false) {
|
||||
function notify(title,msg,notification_type='info',reload=false) {
|
||||
info = {
|
||||
'title':title,
|
||||
'body':msg,
|
||||
'type':type
|
||||
'notification_type':notification_type
|
||||
}
|
||||
|
||||
var element = htmlToElement(notification_template(info));
|
||||
@ -33,3 +33,19 @@ function notify(title,msg,type='info',reload=false) {
|
||||
|
||||
setTimeout(function(e){e.remove();},7000,element);
|
||||
}
|
||||
|
||||
function notifyCallback(request) {
|
||||
var body = request.response;
|
||||
var status = request.status;
|
||||
|
||||
|
||||
if (status == 200) {
|
||||
var notification_type = 'info';
|
||||
}
|
||||
else {
|
||||
var notification_type = 'warning';
|
||||
}
|
||||
|
||||
|
||||
notify(body.status,body.desc || "",notification_type);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user