305 lines
12 KiB
HTML
305 lines
12 KiB
HTML
{# vim: set filetype=html: #}
|
|
|
|
{% extends "base" %}
|
|
{% block pagename %}Table{% endblock pagename %}
|
|
|
|
{% block script %}
|
|
<script type="text/javascript">
|
|
let ncol = 1;
|
|
let edit_mode = false;
|
|
let column_names = [{% for col in column_names %} '{{ col }}', {% endfor %}];
|
|
let column_types = [{% for col in column_types %} {{ col }}, {% endfor %}];
|
|
|
|
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_tname').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;
|
|
}
|
|
</script>
|
|
{% endblock script %}
|
|
{% block body %}
|
|
<div class="row justify-content-between">
|
|
<div class="col-auto">
|
|
<h1><div class='input-group'><span id="tname">{{ tblname }}</span><button class="btn" type="button" onclick="toggle_edit_tname();" id="pencil_button_edit_tname"><i class="bi bi-pencil"></i></button></div></h1>
|
|
</div>
|
|
<div class="col-auto">
|
|
<div class="btn-toolbar mt-2" role="toolbar">
|
|
<div class="btn-group me-2">
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#new_item"><i class="bi bi-plus-lg"></i></button>
|
|
</div>
|
|
<form method="get" action="/table/{{ tblid }}">
|
|
<div class="input-group">
|
|
<div class="input-group-text dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-table"></i>
|
|
</div>
|
|
<input id="input_search_value" name="search_value" type="text" placeholder="Search" value="{{ search_value }}" class="form-control">
|
|
<button class="btn btn-outline-primary" type="submit"><i class="bi bi-search"></i></button>
|
|
<ul class="dropdown-menu">
|
|
<select name="search_fields" class="form-select" multiple>
|
|
<li><option disabled class="dropdown-header">Search in</option></li>
|
|
{% for column in column_names %}
|
|
<li><option class="dropdown-option" value="{{ loop.index - 1 }}" {% if (loop.index - 1) in search_fields %}selected{% endif %}>{{ column }}</option></li>
|
|
{% endfor %}
|
|
</select>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<br>
|
|
<table id="content_table" class="table table-striped table-hover table-responsive table-bordered mt-2">
|
|
<thead>
|
|
<tr>
|
|
<th style="width:7%">
|
|
<div class="row justify-content-between">
|
|
<div class="col-auto">
|
|
#
|
|
</div>
|
|
<div class="col-auto">
|
|
<div class="btn-toolbar">
|
|
<form method="GET" action="/table/{{ tblid }}">
|
|
<input value="0" name="sort_field" hidden />
|
|
<input value="{% if sort_field == 0 %}{{ (sort_dir + 1) % 2}}{% else %}0{% endif %}" name="sort_dir" hidden />
|
|
{% if sort_field == 0 and sort_dir == 0 %}
|
|
{% set dir='up' %}
|
|
{% else %}
|
|
{% set dir='down' %}
|
|
{% endif %}
|
|
<button class="btn p-0" type="submit"><i class="bi bi-sort-{{ dir }}"></i></button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</th>
|
|
{% for column in column_names %}
|
|
<th>
|
|
<div class="row justify-content-between">
|
|
<div class="col-auto">
|
|
{{ column }}
|
|
</div>
|
|
<div class="col-auto">
|
|
<div class="btn-toolbar">
|
|
<button class="btn p-0 me-2" type="button" data-bs-toggle="modal" data-bs-target="#edit_column_modal" onclick="edit_column({{ loop.index0 }});"><i class="bi bi-pencil"></i></button>
|
|
<form method="GET" action="/table/{{ tblid }}">
|
|
<input value="{{ loop.index }}" name="sort_field" hidden />
|
|
<input value="{% if sort_field == loop.index %}{{ (sort_dir + 1) % 2}}{% else %}0{% endif %}" name="sort_dir" hidden />
|
|
{% if sort_field == loop.index and sort_dir == 0 %}
|
|
{% set dir='up' %}
|
|
{% else %}
|
|
{% set dir='down'%}
|
|
{% endif %}
|
|
<button class="btn p-0" type="submit"><i class="bi bi-sort-{{ dir }}"></i></button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</th>
|
|
{% endfor %}
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for row in rows %}
|
|
<tr>
|
|
{% for column in row %}
|
|
<td>{{ column }}</td>
|
|
{% endfor %}
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
{% endblock body %}
|
|
|
|
{% block more_modals %}
|
|
<!-- Add new item -->
|
|
<div class="modal fade" id="new_item" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h1 class="modal-title fs-5">Add entry</h1>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<h5>Cell values:</h5>
|
|
<br>
|
|
<form id="form_add_entry" action="/row/new" method="post">
|
|
<input name="tblid" value="{{ tblid }}" hidden />
|
|
{% for column in column_names %}
|
|
<div class="mb-3">
|
|
<div class="row">
|
|
<div class="col-auto">
|
|
<label for="entry_value_{{ column }}" class="form-label" >{{ column }}:</label>
|
|
</div>
|
|
<div class="col-auto">
|
|
<input type="text" class="form-control" name="cells" id="entry_value_{{column}}" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<div class="container row justify-content-between">
|
|
<div class="col-auto">
|
|
</div>
|
|
<div class="col-auto">
|
|
<button class="btn btn-secondary" data-bs-dismiss="modal" type="button" onclick="document.getElementById('form_add_entry').reset();"><i class="bi bi-x"></i></button>
|
|
<button class="btn btn-primary" type="button" onclick="document.getElementById('form_add_entry').submit().reset();"><i class="bi bi-check-lg"></i></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Edit entry -->
|
|
<div class="modal fade" id="edit_entry_modal" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h1 class="modal-title fs-5"><div class="row"><div class="col-auto">Row <span id="modal_caller"></span></div><div class="col-auto"><i class="bi bi-pencil-fill"></i></div></div></h1>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form action="/row/edit" method="post" id="form_edit_entry">
|
|
<input name="tblid" value="{{ tblid }}" hidden>
|
|
<input name="row_pos" id="form_edit_entry_rowpos" hidden>
|
|
{% for column in column_names %}
|
|
<div class="mb-3">
|
|
<div class="row">
|
|
<div class="col-auto">
|
|
<label for="form_edit_entry_{{ loop.index }}" class="form-label">{{ column }}</label>
|
|
</div>
|
|
<div class="col-auto">
|
|
<input type="text" class="form-control" name="cells" id="form_edit_entry_{{ loop.index }}" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<div class="container row justify-content-between">
|
|
<div class="col-auto">
|
|
<form action="/row/delete" method="post" id="form_delete_entry">
|
|
<input name="tblid" value="{{ tblid }}" hidden>
|
|
<input id="form_delete_entry_rowpos" name="row_pos" hidden>
|
|
<button class="btn btn-danger" data-bs-dismiss="modal" type="button" onclick="confirm_delete('entry');"><i class="bi bi-trash3-fill"></i></button>
|
|
</form>
|
|
</div>
|
|
<div class="col-auto">
|
|
<button class="btn btn-secondary" data-bs-dismiss="modal" type="button" onclick="document.getElementById('form_edit_entry').reset();"><i class="bi bi-x"></i></button>
|
|
<button class="btn btn-primary" type="button" onclick="document.getElementById('form_edit_entry').submit().reset();"><i class="bi bi-check-lg"></i></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Edit column -->
|
|
<div class="modal fade" id="edit_column_modal" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h1 class="modal-title fs-5"><div class="row"><div class="col-auto"><span id="modal_caller"></span></div><div class="col-auto"><i class="bi bi-pencil-fill"></i></div></div></h1>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form action="/column/edit" method="post" id="form_edit_column">
|
|
<input name="tblid" value="{{ tblid }}" hidden>
|
|
<div class="mb-3">
|
|
<div class="row">
|
|
<div class="col-auto">
|
|
<label for="form_edit_column_name" class="form-label">Name:</label>
|
|
<input type="text" class="form-control" name="name" id="form_edit_column_name" />
|
|
</div>
|
|
<div class="col-auto">
|
|
<label for="form_edit_column_type" class="form-label">Type</label>
|
|
<select class="form-select" name="column_type" id="form_edit_column_type">
|
|
<option value="0">Text</option>
|
|
<option value="1">Number</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<div class="container row justify-content-between">
|
|
<div class="col-auto">
|
|
<form action="/column/delete" method="post" id="form_delete_column">
|
|
<input name="id_in_table" id="form_delete_column_idintbl" hidden>
|
|
<input name="tblid" value="{{ tblid }}" hidden>
|
|
<button class="btn btn-danger" data-bs-dismiss="modal" type="button" onclick="confirm_delete('column');"><i class="bi bi-trash3-fill"></i></button>
|
|
</form>
|
|
</div>
|
|
<div class="col-auto">
|
|
<button class="btn btn-secondary" data-bs-dismiss="modal" type="button" onclick="document.getElementById('form_edit_column').reset();"><i class="bi bi-x"></i></button>
|
|
<button class="btn btn-primary" type="button" onclick="document.getElementById('form_edit_column').submit().reset();"><i class="bi bi-check-lg"></i></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock more_modals %}
|