1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Added client logic for merging

This commit is contained in:
krateng 2022-04-17 17:24:23 +02:00
parent 0d985ff706
commit 57e66fdafd

View File

@ -1,19 +1,6 @@
// JS for all web interface editing / deletion of scrobble data // JS for all web interface editing / deletion of scrobble data
// HELPERS
function toggleDeleteConfirm(element) {
element.parentElement.parentElement.classList.toggle('active');
}
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);
}
function selectAll(e) { function selectAll(e) {
// https://stackoverflow.com/a/6150060/6651341 // https://stackoverflow.com/a/6150060/6651341
var range = document.createRange(); var range = document.createRange();
@ -23,6 +10,18 @@ function selectAll(e) {
sel.addRange(range); sel.addRange(range);
} }
// DELETION
function toggleDeleteConfirm(element) {
element.parentElement.parentElement.classList.toggle('active');
}
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);
}
// EDIT NAME
function editEntity() { function editEntity() {
var namefield = document.getElementById('main_entity_name'); var namefield = document.getElementById('main_entity_name');
@ -40,20 +39,18 @@ function editEntity() {
namefield.textContent = entity_name; namefield.textContent = entity_name;
namefield.blur(); namefield.blur();
} }
}) })
// emergency, not pretty because it will move cursor // emergency, not pretty because it will move cursor
namefield.addEventListener('input',function(e){ namefield.addEventListener('input',function(e){
if (namefield.textContent.includes("\n")) { if (namefield.textContent.includes("\n")) {
namefield.textContent = namefield.textContent.replace("\n",""); namefield.textContent = namefield.textContent.replace("\n","");
} }
}) })
// manually clicking away OR enter // manually clicking away OR enter
namefield.addEventListener('blur',function(e){ namefield.addEventListener('blur',function(e){
doneEditing(); doneEditing();
}) })
namefield.focus(); namefield.focus();
@ -88,6 +85,36 @@ function doneEditing() {
json=true json=true
); );
} }
}
// MERGING
function markForMerge() {
const lcst = window.localStorage;
var key = "marked_for_merge_" + entity_type;
var current_stored = (lcst.getItem(key) || '').split(",");
current_stored = current_stored.filter((x)=>x).map((x)=>parseInt(x));
current_stored.push(entity_id);
current_stored = [...new Set(current_stored)];
lcst.setItem(key,current_stored); //this already formats it correctly
}
function merge() {
const lcst = window.localStorage;
var key = "marked_for_merge_" + entity_type;
var current_stored = lcst.getItem(key).split(",");
current_stored = current_stored.filter((x)=>x).map((x)=>parseInt(x));
neo.xhttpreq(
"/apis/mlj_1/merge_" + entity_type + "s",
data={
'source_ids':current_stored,
'target_id':entity_id
},
method="POST",
callback=(()=>window.location.reload()),
json=true
);
lcst.removeItem(key);
} }