86 lines
3.6 KiB
JavaScript
86 lines
3.6 KiB
JavaScript
/* This file is part of inventur.
|
|
* inventur is a simple web app using rocket to help maintain inventory data.
|
|
* Copyright (C) 2024 Johannes Randerath
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
let edit_mode = false;
|
|
|
|
document.addEventListener("DOMContentLoaded", (event) => {
|
|
let rows = document.getElementById("content_table").getElementsByTagName('tbody')[0].rows;
|
|
for (let i = 0; i < rows.length; i++)
|
|
{
|
|
let row = rows[i];
|
|
let createClickHandler = function(r)
|
|
{
|
|
return function()
|
|
{
|
|
$('#edit_entry_modal').modal('show');
|
|
document.getElementById('modal_caller').innerHTML = i+1;
|
|
document.getElementById('form_edit_entry_rowpos').value = i+1;
|
|
document.getElementById('form_delete_entry_rowpos').value = i+1;
|
|
let cells = row.cells;
|
|
for (let j = 1; j < cells.length; j++) {
|
|
document.getElementById(`form_edit_entry_${j}`).value = cells[j].innerHTML;
|
|
}
|
|
};
|
|
};
|
|
row.onclick = createClickHandler(row);
|
|
}
|
|
});
|
|
|
|
function toggle_edit_tname() {
|
|
let span = document.getElementById('tname');
|
|
if (!edit_mode) {
|
|
span.innerHTML = `
|
|
<div class='row'>
|
|
<div class='col-auto ml-1 p-2'>
|
|
<form id='form_edit_table' action='/table/name/edit' method='post'>
|
|
<input name='tblid' value='${tblid}' hidden />
|
|
<input type='text' class='form-control' id='tname_edit' name='new_name' value='${tblname}' />
|
|
</form>
|
|
</div>
|
|
<div class='col-auto mt-0 pt-0 pr-1'>
|
|
<div class="btn-group" role="group">
|
|
<button class="btn btn-secondary" onclick="toggle_edit_tname();" type="button"><i class="bi bi-x"></i></button>
|
|
<button class='btn btn-success' type='button' onclick='edit_tname()'>
|
|
<i class='bi bi-check'></i>
|
|
</button>
|
|
</div>
|
|
<button class='btn btn-danger' type="button" onclick='confirm_delete("table");'><i class="bi bi-trash3-fill"></i></button>
|
|
</div>
|
|
<form id="form_delete_table" action="/table/delete" method="post">
|
|
<input value="${tblid}" name="tblid" hidden />
|
|
</form>`;
|
|
edit_mode = true;
|
|
document.getElementById('pencil_button_edit_tname').hidden = true;
|
|
} else {
|
|
document.getElementById('pencil_button_edit_tname').hidden = false;
|
|
span.innerHTML = `${tblname}`;
|
|
edit_mode = false;
|
|
}
|
|
}
|
|
function edit_tname() {
|
|
document.getElementById('form_edit_table').submit();
|
|
toggle_edit_tname();
|
|
}
|
|
function edit_column(clmn_index) {
|
|
document.getElementById('form_edit_column_name').value = column_names[clmn_index];
|
|
document.getElementById('form_edit_column_type').value = column_types[clmn_index];
|
|
document.getElementById('modal_caller').innerHTML = column_names[clmn_index];
|
|
document.getElementById('form_delete_column_idintbl').value = clmn_index + 1;
|
|
document.getElementById('form_edit_column_idintbl').value = clmn_index + 1;
|
|
}
|