merge edit_user and select_table to edit_table
This commit is contained in:
68
app/public/js/edit_table.js
Normal file
68
app/public/js/edit_table.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
//wait for html site to be ready before executing init()
|
||||||
|
if (document.readyState == "complete") {
|
||||||
|
init();
|
||||||
|
} else {
|
||||||
|
document.addEventListener("DOMContentLoaded", init);
|
||||||
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
if(document.getElementById('table') != null) {
|
||||||
|
highlight_row();
|
||||||
|
}
|
||||||
|
|
||||||
|
user_edit_button();
|
||||||
|
statistic_edit_button();
|
||||||
|
}
|
||||||
|
|
||||||
|
var selected = null;
|
||||||
|
|
||||||
|
function highlight_row() {
|
||||||
|
var table = document.getElementById('table');
|
||||||
|
var cells = table.getElementsByTagName('td');
|
||||||
|
|
||||||
|
for( var i = 0; i < cells.length; i++) {
|
||||||
|
var cell = cells[i];
|
||||||
|
cell.onclick = function() {
|
||||||
|
var rowId = this.parentNode.rowIndex;
|
||||||
|
var rowsNotSelected = table.getElementsByTagName('tr');
|
||||||
|
for ( var row = 0; row < rowsNotSelected.length; row++) {
|
||||||
|
rowsNotSelected[row].style.backgroundColor = "";
|
||||||
|
rowsNotSelected[row].classList.remove('selected');
|
||||||
|
}
|
||||||
|
var rowSelected = table.getElementsByTagName('tr')[rowId];
|
||||||
|
if (selected != null && selected == rowId) {
|
||||||
|
selected = null;
|
||||||
|
rowSelected.style.backgroundColor = "";
|
||||||
|
rowSelected.classList.remove('selected');
|
||||||
|
document.getElementsByClassName("edit")[0].disabled = true;
|
||||||
|
} else {
|
||||||
|
selected = rowId;
|
||||||
|
rowSelected.style.backgroundColor = "yellow";
|
||||||
|
rowSelected.className += " selected";
|
||||||
|
document.getElementsByClassName("edit")[0].disabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function user_edit_button() {
|
||||||
|
var button = document.getElementById("edit_user");
|
||||||
|
if(button != null) {
|
||||||
|
button.onclick = function() {
|
||||||
|
var row = document.getElementsByClassName("selected")[0];
|
||||||
|
document.getElementById('user_id_val').value = row.id;
|
||||||
|
this.form.submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function statistic_edit_button() {
|
||||||
|
var button = document.getElementById('edit_statistic');
|
||||||
|
if(button != null) {
|
||||||
|
button.onclick = function() {
|
||||||
|
var row = document.getElementsByClassName('row selected')[0];
|
||||||
|
document.getElementById('team_id').value = row.id;
|
||||||
|
this.form.submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user