115 lines
4.4 KiB
HTML
115 lines
4.4 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;
|
|
document.addEventListener("DOMContentLoaded", (event) => {
|
|
for (let row of document.getElementById("content_table").getElementsByTagName('tbody')[0].rows) {
|
|
let createClickHandler = function(r) {
|
|
return function() {
|
|
$('#edit_item').modal('show');
|
|
};
|
|
};
|
|
row.onclick = createClickHandler(row);
|
|
}
|
|
});
|
|
function add_column() {
|
|
ncol += 1;
|
|
document.getElementById('dynamic_columns').innerHTML += "<div class='row mt-3' id='columns'><div class='col-auto align-bottom'><div class='form-text me-1' id='field_index'><strong>" + ncol + "</strong></div></div><div class='col-auto'><input type='text' class='form-control' id='field_name' aria-describedby='field_name_label'></div><div class='col-auto'><select class='form-select' aria-label='data type'><option value='text' selected>Text</option><option value='number'>Number</option><option value='date'>Date</option></select></div></div>"
|
|
}
|
|
function create_table() {
|
|
let form = document.getElementById('create-table');
|
|
form.submit();
|
|
document.getElementById('dynamic_columns').innerHTML = "";
|
|
ncol = 1;
|
|
}
|
|
function set_modal_target(modal_target) {
|
|
document.getElementById('modal_caller').innerHTML = modal_target;
|
|
}
|
|
function toggle_edit_tname() {
|
|
let span = document.getElementById('tname');
|
|
if (!edit_mode) {
|
|
span.innerHTML = "<form><input type='text' class='form-control' id='tname_edit' value='{{ tname }}' /><button class='btn btn-success' type='submit'><i class='bi bi-check'></i></button></form>";
|
|
edit_mode = true;
|
|
} else {
|
|
span.innerHTML = '{{ tname }}';
|
|
edit_mode = false;
|
|
}
|
|
}
|
|
</script>
|
|
{% endblock script %}
|
|
{% block body %}
|
|
<div class="row justify-content-between">
|
|
<div class="col-auto">
|
|
<h1><div class='input-group'><span id="tname">{{ tname }}</span><button class="btn" type="button" onclick="toggle_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>
|
|
<div class="input-group">
|
|
<div class="input-group-text dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-search"></i>
|
|
</div>
|
|
<ul class="dropdown-menu">
|
|
<select class="form-select" multiple>
|
|
<li><option disabled class="dropdown-header">Search in</option></li>
|
|
<li><option class="dropdown-item" value="1" selected>1</option></li>
|
|
<li><option class="dropdown-item" value="2" selected>2</option></li>
|
|
</select>
|
|
</ul>
|
|
<input type="text" placeholder="Search" class="form-control">
|
|
</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">
|
|
<button class="btn p-0 me-2 mdl" type="button" data-bs-toggle="modal" data-bs-target="#filter"><i class="bi bi-filter"></i></button>
|
|
<button class="btn p-0" type="button" onclick="console.log('click');"><i class="bi bi-sort-down"></i></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</th>
|
|
{% for column in columns %}
|
|
<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="#filter" onclick="set_modal_target('{{ column }}');"><i class="bi bi-filter"></i></button>
|
|
<button class="btn p-0" type="button" onclick="console.log('click');"><i class="bi bi-sort-down"></i></button>
|
|
</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 %}
|