mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2024-11-30 12:36:03 +00:00
TBL Editor working
This commit is contained in:
parent
2362e336f6
commit
90cd6b6cd8
@ -72,7 +72,7 @@ if ($cmd == "getTable") {
|
|||||||
foreach ($fileLines as $line) {
|
foreach ($fileLines as $line) {
|
||||||
$row = explode("\t", $line);
|
$row = explode("\t", $line);
|
||||||
$key = $row[0];
|
$key = $row[0];
|
||||||
$string = trim($row[1]);
|
$string = ($row[1]);
|
||||||
|
|
||||||
$rowData = [
|
$rowData = [
|
||||||
'rowid' => $rowid,
|
'rowid' => $rowid,
|
||||||
@ -90,9 +90,9 @@ if ($cmd == "getTable") {
|
|||||||
|
|
||||||
// Iterate over the rows
|
// Iterate over the rows
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
|
|
||||||
$row['String'] = str_replace('}', ' ', $row['String']);
|
$row['String'] = trim(str_replace('}', ' ', $row['String']));
|
||||||
|
|
||||||
$tableMarkup .= "<tr class='row-{$row['rowid']}'>";
|
$tableMarkup .= "<tr class='row-{$row['rowid']}'>";
|
||||||
|
|
||||||
$tableMarkup .= "<td style='width: 64px;'>{$row['rowid']}</td>";
|
$tableMarkup .= "<td style='width: 64px;'>{$row['rowid']}</td>";
|
||||||
@ -123,10 +123,9 @@ if ($cmd == "getTable") {
|
|||||||
|
|
||||||
|
|
||||||
if ($cmd == "update") {
|
if ($cmd == "update") {
|
||||||
|
|
||||||
$string = str_replace('\n', '}', $_REQUEST['string']);
|
$string = str_replace('\n', '}', $_REQUEST['string']);
|
||||||
|
|
||||||
|
|
||||||
$query = "UPDATE $tableName SET Key = ?, String = ? WHERE Key = ?";
|
$query = "UPDATE $tableName SET Key = ?, String = ? WHERE Key = ?";
|
||||||
PDO_Execute($query, [$_REQUEST['key'], $string, $_REQUEST['key']]);
|
PDO_Execute($query, [$_REQUEST['key'], $string, $_REQUEST['key']]);
|
||||||
|
|
||||||
@ -150,7 +149,7 @@ if ($cmd == "update") {
|
|||||||
shell_exec($processCommand);
|
shell_exec($processCommand);
|
||||||
|
|
||||||
rename(getcwd() . "\ModString.tbl", "{$_SESSION['tbl']}/$tableName.tbl");
|
rename(getcwd() . "\ModString.tbl", "{$_SESSION['tbl']}/$tableName.tbl");
|
||||||
|
|
||||||
// Remove empty lines from end of file
|
// Remove empty lines from end of file
|
||||||
// Read the file contents into an array of lines
|
// Read the file contents into an array of lines
|
||||||
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
@ -172,6 +171,7 @@ if ($cmd == "delete") {
|
|||||||
$filePath = "{$_SESSION['tbl']}/$tableName.txt";
|
$filePath = "{$_SESSION['tbl']}/$tableName.txt";
|
||||||
// Calculate the line number to delete based on the rowid
|
// Calculate the line number to delete based on the rowid
|
||||||
$lineNumber = $rowid - 1; // Assuming zero-indexed line numbers
|
$lineNumber = $rowid - 1; // Assuming zero-indexed line numbers
|
||||||
|
|
||||||
// Read the lines of the text file into an array
|
// Read the lines of the text file into an array
|
||||||
$fileLines = file($filePath, FILE_IGNORE_NEW_LINES);
|
$fileLines = file($filePath, FILE_IGNORE_NEW_LINES);
|
||||||
|
|
||||||
@ -182,16 +182,15 @@ if ($cmd == "delete") {
|
|||||||
|
|
||||||
// Save the updated content back to the text file
|
// Save the updated content back to the text file
|
||||||
file_put_contents($filePath, implode("\n", $fileLines));
|
file_put_contents($filePath, implode("\n", $fileLines));
|
||||||
|
|
||||||
// Convert TXT to TBL
|
// Convert TXT to TBL
|
||||||
$executablePath = "bin\EnquettarM.exe";
|
$executablePath = "bin\EnquettarM.exe";
|
||||||
$processCommand = "{$executablePath} -i \"{$_SESSION['tbl']}/$tableName.txt\"";
|
$processCommand = "{$executablePath} -i \"{$_SESSION['tbl']}/$tableName.txt\"";
|
||||||
|
|
||||||
shell_exec($processCommand);
|
shell_exec($processCommand);
|
||||||
|
|
||||||
rename(getcwd() . "\ModString.tbl", "{$_SESSION['tbl']}/$tableName.tbl");
|
rename(getcwd() . "\ModString.tbl", "{$_SESSION['tbl']}/$tableName.tbl");
|
||||||
|
|
||||||
|
|
||||||
echo $_REQUEST['rowid'] . " deleted";
|
echo $_REQUEST['rowid'] . " deleted";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +198,7 @@ if ($cmd == "add") {
|
|||||||
$tableName = $_POST['tableName'];
|
$tableName = $_POST['tableName'];
|
||||||
$key = $_POST['Key'];
|
$key = $_POST['Key'];
|
||||||
$string = $_POST['String'];
|
$string = $_POST['String'];
|
||||||
|
$filePath = "{$_SESSION['tbl']}/$tableName.txt";
|
||||||
// Create your insert statement using the provided values
|
// Create your insert statement using the provided values
|
||||||
$query = "INSERT INTO $tableName (Key, String) VALUES (?, ?)";
|
$query = "INSERT INTO $tableName (Key, String) VALUES (?, ?)";
|
||||||
$params = array($key, $string);
|
$params = array($key, $string);
|
||||||
@ -208,17 +207,24 @@ if ($cmd == "add") {
|
|||||||
$result = PDO_Execute($query, $params);
|
$result = PDO_Execute($query, $params);
|
||||||
|
|
||||||
// Retrieve the last inserted rowid from the table
|
// Retrieve the last inserted rowid from the table
|
||||||
$query = "SELECT last_insert_rowid() AS rowid";
|
// $query = "SELECT last_insert_rowid() AS rowid";
|
||||||
$result = PDO_FetchOne($query);
|
// $result = PDO_FetchOne($query);
|
||||||
|
|
||||||
// Append the new row to the text file
|
// Append the new row to the text file
|
||||||
$newLine = "{$key}\t{$string}";
|
$newLine = "{$key}\t{$string}";
|
||||||
file_put_contents($filePath, $newLine . PHP_EOL, FILE_APPEND);
|
file_put_contents($filePath, $newLine . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
|
// Get the line number of the newly inserted line
|
||||||
|
$fileContents = file_get_contents($filePath);
|
||||||
|
$linesArray = explode(PHP_EOL, $fileContents);
|
||||||
|
$result = count($linesArray) - 1;
|
||||||
|
|
||||||
|
// Convert TXT to TBL
|
||||||
|
$executablePath = "bin\EnquettarM.exe";
|
||||||
|
$processCommand = "{$executablePath} -i \"{$_SESSION['tbl']}/$tableName.txt\"";
|
||||||
|
|
||||||
|
shell_exec($processCommand);
|
||||||
|
|
||||||
|
rename(getcwd() . "\ModString.tbl", "{$_SESSION['tbl']}/$tableName.tbl");
|
||||||
|
|
||||||
echo $result;
|
echo $result;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,266 +28,282 @@ foreach (glob($tbl . "*.tbl") as $filename) {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<!-- CSS -->
|
<!-- CSS -->
|
||||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.min.css">
|
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.min.css">
|
||||||
|
|
||||||
<!-- JS -->
|
<!-- JS -->
|
||||||
<!-- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>-->
|
<!-- <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>
|
<script src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>
|
||||||
<!-- Bootstrap CSS (if not already included) -->
|
<!-- Bootstrap CSS (if not already included) -->
|
||||||
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css">-->
|
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css">-->
|
||||||
|
|
||||||
<!-- Bootstrap DataTables CSS -->
|
<!-- Bootstrap DataTables CSS -->
|
||||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/dataTables.bootstrap4.min.css">
|
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/dataTables.bootstrap4.min.css">
|
||||||
|
|
||||||
<!-- Bootstrap JS (if not already included) -->
|
<!-- Bootstrap JS (if not already included) -->
|
||||||
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>-->
|
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>-->
|
||||||
|
|
||||||
<!-- Bootstrap DataTables JS -->
|
<!-- Bootstrap DataTables JS -->
|
||||||
<script src="https://cdn.datatables.net/1.11.4/js/dataTables.bootstrap4.min.js"></script>
|
<script src="https://cdn.datatables.net/1.11.4/js/dataTables.bootstrap4.min.js"></script>
|
||||||
|
|
||||||
<div style="padding:10px; border: 1px solid #eee;">
|
<div style="padding:10px; border: 1px solid #eee;">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<select name="tableName" id="tableName" class="form-control">
|
<select name="tableName" id="tableName" class="form-control">
|
||||||
<option value="" disabled selected></option>
|
<option value="" disabled selected></option>
|
||||||
<?php foreach ($tableNames as $tableName): ?>
|
<?php foreach ($tableNames as $tableName): ?>
|
||||||
<option value="<?php echo $tableName; ?>" <?php echo ($tableName == "") ? "selected" : ""; ?>><?php echo $tableName; ?></option>
|
<option value="<?php echo $tableName; ?>" <?php echo ($tableName == "") ? "selected" : ""; ?>><?php echo $tableName; ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
|
||||||
<div class="col-md-6">
|
|
||||||
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseForm" aria-expanded="false" aria-controls="collapseForm">
|
|
||||||
Add new String Key
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
<div class="collapse" id="collapseForm">
|
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseForm" aria-expanded="false" aria-controls="collapseForm">
|
||||||
<div class="form-group">
|
Add new String Key
|
||||||
<label for="inputKey">Key</label>
|
</button>
|
||||||
<input type="text" class="form-control" id="inputKey" placeholder="Enter Key">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="inputString">String</label>
|
|
||||||
<textarea class="form-control" id="inputString" placeholder="Enter String"></textarea>
|
|
||||||
</div>
|
|
||||||
<button type="button" class="btn btn-primary" id="addLink">Add</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br>
|
<div class="collapse" id="collapseForm">
|
||||||
<hr>
|
<div class="form-group">
|
||||||
|
<label for="inputKey">Key</label>
|
||||||
<div class="tablediv">
|
<input type="text" class="form-control" id="inputKey" placeholder="Enter Key">
|
||||||
<table class="table">
|
</div>
|
||||||
<thead>
|
<div class="form-group">
|
||||||
<tr>
|
<label for="inputString">String</label>
|
||||||
<th style="width: 64px;">ID</th>
|
<textarea class="form-control" id="inputString" placeholder="Enter String"></textarea>
|
||||||
<th style='width: 20%;'>Key</th>
|
</div>
|
||||||
<th>String</th>
|
<button type="button" class="btn btn-primary" id="addLink">Add</button>
|
||||||
<th style="width: 100px;"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<!-- Additional rows -->
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="loading-spinner" style="display: none; text-align:center;">
|
|
||||||
<img src="img/loading.gif" alt="Loading...">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<br>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div class="tablediv">
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="width: 64px;">ID</th>
|
||||||
|
<th style='width: 20%;'>Key</th>
|
||||||
|
<th>String</th>
|
||||||
|
<th style="width: 100px;"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<!-- Additional rows -->
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div id="loading-spinner" style="display: none; text-align:center;">
|
||||||
|
<img src="img/loading.gif" alt="Loading...">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function resizeTextarea() {
|
||||||
|
this.style.height = 'auto';
|
||||||
|
this.style.height = (this.scrollHeight) + 'px';
|
||||||
|
}
|
||||||
|
function showLoadingSpinner() {
|
||||||
|
$('#loading-spinner').show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide the loading spinner
|
||||||
|
function hideLoadingSpinner() {
|
||||||
|
$('#loading-spinner').hide();
|
||||||
|
}
|
||||||
|
$(document).ready(function () {
|
||||||
|
// Function to resize textarea based on content
|
||||||
function resizeTextarea() {
|
function resizeTextarea() {
|
||||||
this.style.height = 'auto';
|
this.style.height = 'auto';
|
||||||
this.style.height = (this.scrollHeight) + 'px';
|
this.style.height = (this.scrollHeight) + 'px';
|
||||||
}
|
}
|
||||||
function showLoadingSpinner() {
|
|
||||||
$('#loading-spinner').show();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hide the loading spinner
|
// Select element change event handler
|
||||||
function hideLoadingSpinner() {
|
$('#tableName').change(function () {
|
||||||
$('#loading-spinner').hide();
|
$('.table').DataTable().destroy();
|
||||||
}
|
$('.table tbody').html('');
|
||||||
$(document).ready(function () {
|
showLoadingSpinner();
|
||||||
// Function to resize textarea based on content
|
var selectedTable = $(this).val();
|
||||||
function resizeTextarea() {
|
if (selectedTable !== '') {
|
||||||
this.style.height = 'auto';
|
|
||||||
this.style.height = (this.scrollHeight) + 'px';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select element change event handler
|
// Send GET request to TblEditor.php?getTable with selected table name
|
||||||
$('#tableName').change(function () {
|
var request = $.get('TblEditor.php', {cmd: 'getTable', tableName: selectedTable});
|
||||||
$('.table').DataTable().destroy();
|
|
||||||
$('.table tbody').html('');
|
|
||||||
showLoadingSpinner();
|
|
||||||
var selectedTable = $(this).val();
|
|
||||||
if (selectedTable !== '') {
|
|
||||||
|
|
||||||
// Send GET request to TblEditor.php?getTable with selected table name
|
request.done(function (response) {
|
||||||
var request = $.get('TblEditor.php', {cmd: 'getTable', tableName: selectedTable});
|
hideLoadingSpinner();
|
||||||
|
// Handle the response here
|
||||||
|
$('.tablediv tbody').html(response).promise().done(function () {
|
||||||
|
// Callback function after HTML content is loaded
|
||||||
|
|
||||||
request.done(function (response) {
|
// Initialize DataTables on the table
|
||||||
hideLoadingSpinner();
|
$('.table').DataTable();
|
||||||
// Handle the response here
|
|
||||||
$('.tablediv tbody').html(response).promise().done(function () {
|
|
||||||
// Callback function after HTML content is loaded
|
|
||||||
|
|
||||||
// Initialize DataTables on the table
|
// Resize textareas on page load
|
||||||
$('.table').DataTable();
|
$('textarea').each(resizeTextarea);
|
||||||
|
|
||||||
// Resize textareas on page load
|
// Resize textareas on input
|
||||||
|
$('textarea').on('input', resizeTextarea);
|
||||||
|
|
||||||
|
// Resize textareas on custom select change
|
||||||
|
$('.custom-select').change(function () {
|
||||||
|
$('textarea').each(resizeTextarea);
|
||||||
|
});
|
||||||
|
$('.page-link').click(function () {
|
||||||
$('textarea').each(resizeTextarea);
|
$('textarea').each(resizeTextarea);
|
||||||
|
|
||||||
// Resize textareas on input
|
|
||||||
$('textarea').on('input', resizeTextarea);
|
|
||||||
|
|
||||||
// Resize textareas on custom select change
|
|
||||||
$('.custom-select').change(function () {
|
|
||||||
$('textarea').each(resizeTextarea);
|
|
||||||
});
|
|
||||||
$('.page-link').click(function () {
|
|
||||||
$('textarea').each(resizeTextarea);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Delete link click event handler
|
||||||
|
$(document).on('click', '.delete-link', function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
var selectedTable = $('select[name="tableName"]').val();
|
||||||
|
|
||||||
|
// Get the rowid from the custom attribute data-rowid
|
||||||
|
var rowid = $(this).data('rowid');
|
||||||
|
|
||||||
|
// Remove the deleted row from the table
|
||||||
|
$('.row-' + rowid).remove();
|
||||||
|
|
||||||
|
var key = $(this).parent().parent().parent().find('input').val();
|
||||||
|
|
||||||
|
// Send GET request to TblEditor.php?cmd=delete&rowid={rowid}
|
||||||
|
$.get('TblEditor.php?key=' + key + '&', {cmd: 'delete', tableName: selectedTable, rowid: rowid}, function (response) {
|
||||||
|
// Handle the response here
|
||||||
|
|
||||||
|
// Wait until the response is loaded, then remove the row
|
||||||
|
$(response).ready(function () {
|
||||||
|
|
||||||
|
// Update DataTable
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Update link click event handler
|
||||||
|
$(document).on('click', '.update-link', function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
var selectedTable = $('select[name="tableName"]').val();
|
||||||
|
|
||||||
|
// Get the rowid from the custom attribute data-rowid
|
||||||
|
var rowid = $(this).data('rowid');
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
// Handle the response here
|
||||||
|
|
||||||
|
// Optional: Update any UI elements if needed
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add link click event handler
|
||||||
|
$('#addLink').click(function () {
|
||||||
|
var selectedTable = $('#tableName').val();
|
||||||
|
var key = $('#inputKey').val();
|
||||||
|
var string = $('#inputString').val();
|
||||||
|
|
||||||
|
// Send POST request to TblEditor.php with parameters
|
||||||
|
$.post('TblEditor.php', {cmd: 'add', tableName: selectedTable, Key: key, String: string}, function (response) {
|
||||||
|
// Handle the response here
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.table').DataTable().destroy();
|
||||||
|
$('.table tbody').html('');--
|
||||||
|
// Send GET request to TblEditor.php?getTable with selected table name
|
||||||
|
var request = $.get('TblEditor.php', {cmd: 'getTable', tableName: selectedTable});
|
||||||
|
|
||||||
|
request.done(function (response) {
|
||||||
|
hideLoadingSpinner();
|
||||||
|
// Handle the response here
|
||||||
|
$('.tablediv tbody').html(response).promise().done(function () {
|
||||||
|
// Callback function after HTML content is loaded
|
||||||
|
|
||||||
|
// Initialize DataTables on the table
|
||||||
|
$('.table').DataTable();
|
||||||
|
|
||||||
|
var table = $('.table').DataTable();
|
||||||
|
table.page( 'last' ).draw( 'page' );
|
||||||
|
|
||||||
// Delete link click event handler
|
// Resize textareas on page load
|
||||||
$(document).on('click', '.delete-link', function (event) {
|
$('textarea').each(resizeTextarea);
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
var selectedTable = $('select[name="tableName"]').val();
|
// Resize textareas on input
|
||||||
|
$('textarea').on('input', resizeTextarea);
|
||||||
// Get the rowid from the custom attribute data-rowid
|
|
||||||
var rowid = $(this).data('rowid');
|
|
||||||
|
|
||||||
// Remove the deleted row from the table
|
|
||||||
$('.row-' + rowid).remove();
|
|
||||||
|
|
||||||
// Send GET request to TblEditor.php?cmd=delete&rowid={rowid}
|
|
||||||
$.get('TblEditor.php', {cmd: 'delete', tableName: selectedTable, rowid: rowid}, function (response) {
|
|
||||||
// Handle the response here
|
|
||||||
|
|
||||||
// Wait until the response is loaded, then remove the row
|
|
||||||
$(response).ready(function () {
|
|
||||||
|
|
||||||
// Update DataTable
|
|
||||||
|
|
||||||
|
// Resize textareas on custom select change
|
||||||
|
$('.custom-select').change(function () {
|
||||||
|
$('textarea').each(resizeTextarea);
|
||||||
|
});
|
||||||
|
$('.page-link').click(function () {
|
||||||
|
$('textarea').each(resizeTextarea);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Update link click event handler
|
|
||||||
$(document).on('click', '.update-link', function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
var selectedTable = $('select[name="tableName"]').val();
|
|
||||||
|
|
||||||
// Get the rowid from the custom attribute data-rowid
|
|
||||||
var rowid = $(this).data('rowid');
|
|
||||||
|
|
||||||
// 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) {
|
|
||||||
// Handle the response here
|
|
||||||
|
|
||||||
// Optional: Update any UI elements if needed
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add link click event handler
|
|
||||||
$('#addLink').click(function () {
|
|
||||||
var selectedTable = $('#tableName').val();
|
|
||||||
var key = $('#inputKey').val();
|
|
||||||
var string = $('#inputString').val();
|
|
||||||
|
|
||||||
// Send POST request to TblEditor.php with parameters
|
|
||||||
$.post('TblEditor.php', {cmd: 'add', tableName: selectedTable, Key: key, String: string}, function (response) {
|
|
||||||
// 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 style="float:right" 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);
|
|
||||||
|
|
||||||
// Initialize DataTables on the table
|
|
||||||
var table = $('.table').DataTable();
|
|
||||||
|
|
||||||
// Go to the last page after loading the table
|
|
||||||
table.page('last').draw('page');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function () {
|
});
|
||||||
$('textarea').each(function () {
|
|
||||||
this.style.height = 'auto';
|
|
||||||
this.style.height = (this.scrollHeight) + 'px';
|
$(document).ready(function () {
|
||||||
});
|
$('textarea').each(function () {
|
||||||
setInterval(function () {
|
this.style.height = 'auto';
|
||||||
$('textarea').each(resizeTextarea);
|
this.style.height = (this.scrollHeight) + 'px';
|
||||||
}, 4000);
|
|
||||||
});
|
});
|
||||||
|
setInterval(function () {
|
||||||
|
$('textarea').each(resizeTextarea);
|
||||||
|
}, 4000);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background: #f8f8f8;
|
background: #f8f8f8;
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
border: 1px solid #eee;
|
border: 1px solid #eee;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
div.dataTables_wrapper div.dataTables_length select {
|
div.dataTables_wrapper div.dataTables_length select {
|
||||||
width: 75px !important;
|
width: 75px !important;
|
||||||
}
|
}
|
||||||
textarea {
|
textarea {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
resize: none;
|
resize: none;
|
||||||
scrollbar-width: none; /* For Firefox */
|
scrollbar-width: none; /* For Firefox */
|
||||||
-ms-overflow-style: none; /* For Internet Explorer and Edge */
|
-ms-overflow-style: none; /* For Internet Explorer and Edge */
|
||||||
}
|
}
|
||||||
#loading-spinner {
|
#loading-spinner {
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user