Move js call of tasks/newCounter to js api file

This commit is contained in:
maxpozdeev 2025-02-15 20:37:54 +03:00
parent 30b08bd87c
commit b05f40f77c
2 changed files with 26 additions and 13 deletions

View file

@ -1,6 +1,6 @@
/*
This file is a part of myTinyTodo.
(C) Copyright 2009-2010,2020-2023 Max Pozdeev <maxpozdeev@gmail.com>
(C) Copyright 2009-2010,2020-2025 Max Pozdeev <maxpozdeev@gmail.com>
Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details.
*/
@ -2744,17 +2744,7 @@ function newTaskCounter()
});
});
fetch(_mtt.apiUrl + 'tasks/newCounter', {
method: 'POST',
credentials: 'same-origin', // old browsers
headers: {
'Content-Type': 'application/json',
'MTT-Token': _mtt.options.token,
},
body: JSON.stringify(params)
})
.then(response => response.json())
.then(json => {
_mtt.db.request("newTaskCounter", params, json => {
if (json && json.ok) {
let counters = {};
let curCounter = 0;

View file

@ -1,6 +1,6 @@
/*
This file is a part of myTinyTodo.
(C) Copyright 2010,2020-2023 Max Pozdeev <maxpozdeev@gmail.com>
(C) Copyright 2010,2020-2025 Max Pozdeev <maxpozdeev@gmail.com>
Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details.
*/
@ -227,6 +227,29 @@ MytinytodoAjaxApi.prototype = {
});
},
newTaskCounter(params, callback) {
fetch(mytinytodo.apiUrl + 'tasks/newCounter', {
method: 'POST',
credentials: 'same-origin', // old browsers
headers: {
'Content-Type': 'application/json',
'MTT-Token': mytinytodo.options.token,
},
body: JSON.stringify(params)
})
.then((response) => {
if (!response.ok) throw response;
return response.json();
})
.catch((e) => {
if (e instanceof Error) console.log("newTaskCounter fetch error: ", e);
else console.log("newTaskCounter fetch error, HTTP status code: " + e.status);
})
.then(json => {
callback(json)
});
},
// Lists
loadLists(params, callback) {