mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2024-11-30 12:36:03 +00:00
textarea line breaks, bootswatch, etc. I don't fucking remember
This commit is contained in:
parent
eca6598fdf
commit
6eadbcfebb
@ -33,38 +33,39 @@ if ($cmd == "getTable") {
|
||||
|
||||
// Iterate over the rows
|
||||
foreach ($rows as $row) {
|
||||
$tableMarkup .= '<tr class="row-' . $row['rowid'] . '">';
|
||||
$string = str_replace('\n', " ", $row['String']);
|
||||
|
||||
$tableMarkup .= "<tr class='row-{$row['rowid']}'>";
|
||||
|
||||
$tableMarkup .= "<td>{$row['rowid']}</td>";
|
||||
|
||||
// Display the Key column as a text input with Bootstrap form-control class
|
||||
$tableMarkup .= '<td><input type="text" value="' . $row['Key'] . '" class="form-control"></td>';
|
||||
$tableMarkup .= "<td><input type='text' value='{$row['Key']}' class='form-control'><span style='visibility: hidden;'>{$row['Key']}</span></td>";
|
||||
|
||||
// Display the String column as a textarea with Bootstrap form-control class
|
||||
$tableMarkup .= '<td><textarea class="form-control">' . $row['String'] . '</textarea></td>';
|
||||
$tableMarkup .= "<td><textarea class='form-control'>{$string}</textarea></td>";
|
||||
|
||||
// Add the Update and Delete links within a single td element
|
||||
$tableMarkup .= '<td><div>';
|
||||
$tableMarkup .= "<td><div>";
|
||||
|
||||
// Add the Update link with Bootstrap btn and btn-primary classes
|
||||
$tableMarkup .= '<a href="#" class="update-link btn btn-primary" data-rowid="' . $row['rowid'] . '">Update</a>';
|
||||
$tableMarkup .= "<a href='#' class='update-link btn btn-primary' data-rowid='{$row['rowid']}'>Update</a>";
|
||||
|
||||
// Add the Delete link with Bootstrap btn and btn-danger classes
|
||||
$tableMarkup .= '<a href="#" class="delete-link btn btn-danger" data-rowid="' . $row['rowid'] . '">Delete</a>';
|
||||
$tableMarkup .= "<a style='float:right' href='#' class='delete-link btn btn-danger' data-rowid='{$row['rowid']}'>Delete</a>";
|
||||
|
||||
$tableMarkup .= '</div></td>';
|
||||
$tableMarkup .= "</div></td>";
|
||||
|
||||
$tableMarkup .= '</tr>';
|
||||
$tableMarkup .= "</tr>";
|
||||
}
|
||||
|
||||
|
||||
// Return the table markup
|
||||
echo $tableMarkup;
|
||||
}
|
||||
|
||||
|
||||
if ($cmd == "update") {
|
||||
$query = "UPDATE patchstring SET Key = ?, String = ? WHERE ROWID = ?";
|
||||
$query = "UPDATE $tableName SET Key = ?, String = ? WHERE ROWID = ?";
|
||||
PDO_Execute($query, [$_REQUEST['key'], $_REQUEST['string'], $_REQUEST['rowid']]);
|
||||
|
||||
echo $_REQUEST['key'] . " updated";
|
||||
@ -87,13 +88,10 @@ if ($cmd == "add") {
|
||||
|
||||
// Execute the insert statement
|
||||
$result = PDO_Execute($query, $params);
|
||||
|
||||
|
||||
|
||||
// Retrieve the last inserted rowid from the table
|
||||
$query = "SELECT last_insert_rowid() AS rowid";
|
||||
$result = PDO_FetchOne($query);
|
||||
|
||||
|
||||
|
||||
echo $result;
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ foreach (glob($tbl . "*.tbl") as $filename) {
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<!-- CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.min.css">
|
||||
|
||||
|
||||
<!-- JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>
|
||||
@ -51,6 +51,7 @@ foreach (glob($tbl . "*.tbl") as $filename) {
|
||||
<!-- Bootstrap DataTables JS -->
|
||||
<script src="https://cdn.datatables.net/1.11.4/js/dataTables.bootstrap4.min.js"></script>
|
||||
<title>Editable Tables</title>
|
||||
<link rel="stylesheet" href="https://bootswatch.com/4/lumen/bootstrap.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
@ -115,6 +116,8 @@ foreach (glob($tbl . "*.tbl") as $filename) {
|
||||
|
||||
// Select element change event handler
|
||||
$('#tableName').change(function () {
|
||||
$('.table').DataTable().destroy();
|
||||
|
||||
var selectedTable = $(this).val();
|
||||
|
||||
// Send GET request to TblEditor.php?getTable with selected table name
|
||||
@ -172,6 +175,9 @@ foreach (glob($tbl . "*.tbl") as $filename) {
|
||||
// Get the updated values from the corresponding input and textarea
|
||||
var key = $('.row-' + rowid + ' input').val();
|
||||
var string = $('.row-' + rowid + ' textarea').val();
|
||||
string = string.replace(/ /g, '\\n');
|
||||
string = string.replace(/\n/g, '\\n');
|
||||
|
||||
|
||||
// Send POST request to TblEditor.php with the updated values
|
||||
$.post('TblEditor.php', {cmd: 'update', tableName: selectedTable, rowid: rowid, key: key, string: string}, function (response) {
|
||||
@ -179,8 +185,6 @@ foreach (glob($tbl . "*.tbl") as $filename) {
|
||||
|
||||
// Optional: Update any UI elements if needed
|
||||
|
||||
// Update DataTable
|
||||
$('.table').DataTable().draw();
|
||||
});
|
||||
});
|
||||
|
||||
@ -195,23 +199,23 @@ foreach (glob($tbl . "*.tbl") as $filename) {
|
||||
// Handle the response here
|
||||
rowid = response;
|
||||
// Create the HTML markup for the new row
|
||||
var newRow = '<tr class="row-' + rowid + '">' +
|
||||
'<td>' + rowid + '</td>' +
|
||||
'<td><input type="text" value="' + key + '" class="form-control"></td>' +
|
||||
'<td><textarea class="form-control">' + string + '</textarea></td>' +
|
||||
'<td><div>' +
|
||||
'<a href="#" class="update-link btn btn-primary" data-rowid="' + rowid + '">Update</a>' +
|
||||
'<a href="#" class="delete-link btn btn-danger" data-rowid="' + rowid + '">Delete</a>' +
|
||||
'</div></td>' +
|
||||
'</tr>';
|
||||
;
|
||||
var newRow = '<tr class="row-' + rowid + '">' +
|
||||
'<td>' + rowid + '</td>' +
|
||||
'<td><input type="text" value="' + key + '" class="form-control"></td>' +
|
||||
'<td><textarea class="form-control">' + string + '</textarea></td>' +
|
||||
'<td><div>' +
|
||||
'<a href="#" class="update-link btn btn-primary" data-rowid="' + rowid + '">Update</a>' +
|
||||
'<a href="#" class="delete-link btn btn-danger" data-rowid="' + rowid + '">Delete</a>' +
|
||||
'</div></td>' +
|
||||
'</tr>';
|
||||
;
|
||||
|
||||
|
||||
// Append the new row to the table
|
||||
$('.table').DataTable().destroy();
|
||||
|
||||
|
||||
$('.table tbody').append(newRow);
|
||||
|
||||
|
||||
$('.table').DataTable();
|
||||
});
|
||||
});
|
||||
@ -220,7 +224,18 @@ var newRow = '<tr class="row-' + rowid + '">' +
|
||||
});
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
// Iterate over each div with the form-control class
|
||||
$('.form-control').each(function () {
|
||||
// Get the text content of the div
|
||||
var text = $(this).val();
|
||||
|
||||
// Set the height of the div to fit the text content
|
||||
$(this).height('auto'); // Reset the height to auto
|
||||
var contentHeight = $(this).prop('scrollHeight');
|
||||
$(this).height(contentHeight);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user