Додані повідомлення та перепрацьована структура застосунку та api
This commit is contained in:
@@ -40,6 +40,8 @@ const SheepsEvents = {
|
||||
const sheepEditorButton = document.getElementById('sheep-editor-button');
|
||||
const form = event.target;
|
||||
const formData = new FormData(form);
|
||||
console.log(formData);
|
||||
|
||||
const uuidValue = form.elements["uuid"].value;
|
||||
const sheep = Sheeps.sheeps_list.list.find(item => item.uuid === uuidValue);
|
||||
|
||||
@@ -50,7 +52,7 @@ const SheepsEvents = {
|
||||
|
||||
sheep.name = form.elements["name"].value;
|
||||
sheep.group_id = Number(formData.get("group_id"));
|
||||
sheep.mode = formData.get("mode");
|
||||
sheep.mode = formData.get("mode") || sheep.mode;
|
||||
sheep.mode_title = ["Користувач", "Модератор", "Адміністратор"][sheep.mode] || "Користувач";
|
||||
|
||||
const permKeys = [
|
||||
@@ -59,8 +61,10 @@ const SheepsEvents = {
|
||||
"can_view_stand",
|
||||
"can_view_territory",
|
||||
"can_add_sheeps",
|
||||
"can_manager_sheeps",
|
||||
"can_add_territory",
|
||||
"can_manager_territory",
|
||||
"can_joint_territory",
|
||||
"can_add_stand",
|
||||
"can_manager_stand",
|
||||
"can_add_schedule"
|
||||
@@ -73,8 +77,7 @@ const SheepsEvents = {
|
||||
|
||||
try {
|
||||
const uuid = localStorage.getItem('uuid');
|
||||
const URL = `${CONFIG.api}sheep`;
|
||||
const response = await fetch(URL, {
|
||||
const response = await fetch(`${CONFIG.api}sheep`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -84,26 +87,23 @@ const SheepsEvents = {
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
sheepEditorButton.innerText = "Успішно збережено";
|
||||
sheepEditorButton.innerText = "Зберегти";
|
||||
Notifier.success("Успішно збережено!", {timeout: 2000})
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
|
||||
Sheeps.sheeps_list.list = [];
|
||||
await Sheeps.sheeps_list.setHTML();
|
||||
|
||||
setTimeout(() => {
|
||||
sheepEditorButton.innerText = "Зберегти";
|
||||
}, 3000);
|
||||
} else {
|
||||
sheepEditorButton.innerText = "Зберегти";
|
||||
console.error('Помилка збереження');
|
||||
sheepEditorButton.innerText = "Помилка збереження";
|
||||
Notifier.error("Помилка збереження!", {timeout: 3000});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
sheepEditorButton.innerText = "Помилка збереження";
|
||||
Notifier.error("Помилка збереження!", {timeout: 3000});
|
||||
}
|
||||
|
||||
// тот же код, что был в _onSheepEditorSubmit, но обращаемся к editorForm
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -120,8 +120,7 @@ const SheepsEvents = {
|
||||
|
||||
try {
|
||||
const uuid = localStorage.getItem('uuid');
|
||||
const URL = `${CONFIG.api}sheep`;
|
||||
const response = await fetch(URL, {
|
||||
const response = await fetch(`${CONFIG.api}sheep`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -131,7 +130,7 @@ const SheepsEvents = {
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
sheepAddedsButton.innerText = "Вісника додано";
|
||||
sheepAddedsButton.innerText = "Додати";
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
|
||||
@@ -141,17 +140,14 @@ const SheepsEvents = {
|
||||
|
||||
Sheeps.addeds.close();
|
||||
await Sheeps.editor.setHTML(data.id, randomNumber);
|
||||
|
||||
setTimeout(() => {
|
||||
sheepAddedsButton.innerText = "Додати";
|
||||
}, 3000);
|
||||
} else {
|
||||
sheepEditorButton.innerText = "Додати";
|
||||
console.error('Помилка додавання');
|
||||
sheepAddedsButton.innerText = "Помилка додавання";
|
||||
Notifier.error("Помилка додавання!", {timeout: 3000});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
sheepAddedsButton.innerText = "Помилка додавання";
|
||||
Notifier.error("Помилка додавання!", {timeout: 3000});
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -176,9 +172,7 @@ const Sheeps = {
|
||||
loadAPI: async () => {
|
||||
let uuid = localStorage.getItem("uuid");
|
||||
|
||||
const URL = `${CONFIG.api}sheeps/list`;
|
||||
|
||||
Sheeps.sheeps_list.list = await fetch(URL, {
|
||||
Sheeps.sheeps_list.list = await fetch(`${CONFIG.api}sheeps/list`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -238,9 +232,11 @@ const Sheeps = {
|
||||
if (p.can_view_territory) perms.push("View Territory");
|
||||
if (p.can_add_sheeps) perms.push("Create Sheeps");
|
||||
if (p.can_add_territory) perms.push("Create Territory");
|
||||
if (p.can_manager_sheeps) perms.push("Manager Sheeps");
|
||||
if (p.can_manager_territory) perms.push("Manager Territory");
|
||||
if (p.can_add_stand) perms.push("Create Stand");
|
||||
if (p.can_manager_stand) perms.push("Manager Stand");
|
||||
if (p.can_joint_territory) perms.push("Joint Territory");
|
||||
if (p.can_add_stand) perms.push("Create Stand");
|
||||
if (p.can_add_schedule) perms.push("Create Schedule");
|
||||
return perms.map(p => `<b>${p}</b>`).join('');
|
||||
};
|
||||
@@ -274,8 +270,7 @@ const Sheeps = {
|
||||
loadAPI: async (id) => {
|
||||
let uuid = localStorage.getItem("uuid");
|
||||
|
||||
const URL = `${CONFIG.api}sheep?id=${id}`;
|
||||
return await fetch(URL, {
|
||||
return await fetch(`${CONFIG.api}sheep?id=${id}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -327,8 +322,11 @@ const Sheeps = {
|
||||
|
||||
let sheep_editor_can_view_sheeps = document.getElementById('sheep-editor-can_view_sheeps');
|
||||
let sheep_editor_can_add_sheeps = document.getElementById('sheep-editor-can_add_sheeps');
|
||||
let sheep_editor_can_manager_sheeps = document.getElementById('sheep-editor-can_manager_sheeps');
|
||||
let sheep_editor_can_add_territory = document.getElementById('sheep-editor-can_add_territory');
|
||||
let sheep_editor_can_manager_territory = document.getElementById('sheep-editor-can_manager_territory');
|
||||
let sheep_editor_can_joint_territory = document.getElementById('sheep-editor-can_joint_territory');
|
||||
|
||||
let sheep_editor_can_add_stand = document.getElementById('sheep-editor-can_add_stand');
|
||||
let sheep_editor_can_manager_stand = document.getElementById('sheep-editor-can_manager_stand');
|
||||
let sheep_editor_can_add_schedule = document.getElementById('sheep-editor-can_add_schedule');
|
||||
@@ -367,8 +365,10 @@ const Sheeps = {
|
||||
|
||||
sheep_editor_can_view_sheeps.checked = sheep.possibilities.can_view_sheeps;
|
||||
sheep_editor_can_add_sheeps.checked = sheep.possibilities.can_add_sheeps;
|
||||
sheep_editor_can_manager_sheeps.checked = sheep.possibilities.can_manager_sheeps;
|
||||
sheep_editor_can_add_territory.checked = sheep.possibilities.can_add_territory;
|
||||
sheep_editor_can_manager_territory.checked = sheep.possibilities.can_manager_territory;
|
||||
sheep_editor_can_joint_territory.checked = sheep.possibilities.can_joint_territory;
|
||||
sheep_editor_can_add_stand.checked = sheep.possibilities.can_add_stand;
|
||||
sheep_editor_can_manager_stand.checked = sheep.possibilities.can_manager_stand;
|
||||
sheep_editor_can_add_schedule.checked = sheep.possibilities.can_add_schedule;
|
||||
@@ -387,6 +387,9 @@ const Sheeps = {
|
||||
if (USER.mode == 2) {
|
||||
document.getElementById('sheep-editor-button').style.display = "";
|
||||
sheep_editor_mode.disabled = false;
|
||||
} else if (USER.possibilities.can_manager_sheeps) {
|
||||
document.getElementById('sheep-editor-button').style.display = "";
|
||||
sheep_editor_mode.disabled = true;
|
||||
} else {
|
||||
sheep_editor_mode.disabled = true;
|
||||
}
|
||||
@@ -458,9 +461,9 @@ const Sheeps = {
|
||||
}
|
||||
},
|
||||
territory: {
|
||||
async loadAPI(URL) {
|
||||
async loadAPI(url) {
|
||||
const uuid = localStorage.getItem("uuid");
|
||||
const res = await fetch(URL, {
|
||||
const res = await fetch(url, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": uuid
|
||||
@@ -470,8 +473,7 @@ const Sheeps = {
|
||||
},
|
||||
|
||||
async house(id) {
|
||||
const URL = `${CONFIG.api}house/list?mode=admin&sheep_id=${id}`;
|
||||
const list = await Sheeps.territory.loadAPI(URL);
|
||||
const list = await Sheeps.territory.loadAPI(`${CONFIG.api}house/list?mode=admin&sheep_id=${id}`);
|
||||
|
||||
if ((USER.possibilities.can_view_territory || USER.mode == 2) && list.length > 0) {
|
||||
document.getElementById('editor-blocks-territory').style.display = "";
|
||||
@@ -480,8 +482,7 @@ const Sheeps = {
|
||||
},
|
||||
|
||||
async homestead(id) {
|
||||
const URL = `${CONFIG.api}homestead/list?mode=admin&sheep_id=${id}`;
|
||||
const list = await Sheeps.territory.loadAPI(URL);
|
||||
const list = await Sheeps.territory.loadAPI(`${CONFIG.api}homestead/list?mode=admin&sheep_id=${id}`);
|
||||
|
||||
if ((USER.possibilities.can_view_territory || USER.mode == 2) && list.length > 0) {
|
||||
document.getElementById('editor-blocks-territory').style.display = "";
|
||||
|
||||
Reference in New Issue
Block a user