113 lines
3.7 KiB
PHP
113 lines
3.7 KiB
PHP
<?php
|
|
|
|
use yii\helpers\Html;
|
|
use yii\bootstrap4\ActiveForm;
|
|
|
|
/* @var $this yii\web\View */
|
|
/* @var $filename string */
|
|
/* @var $content string */
|
|
|
|
$this->title = 'แก้ไขไฟล์: ' . $filename;
|
|
$this->params['breadcrumbs'][] = ['label' => 'Administrator', 'url' => ['/administrator/default/index']];
|
|
$this->params['breadcrumbs'][] = ['label' => 'จัดการไฟล์ธีม', 'url' => ['index']];
|
|
$this->params['breadcrumbs'][] = $this->title;
|
|
|
|
// Register Ace Editor from CDN
|
|
$this->registerJsFile('https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js', ['position' => \yii\web\View::POS_HEAD]);
|
|
?>
|
|
|
|
<style>
|
|
#editor {
|
|
width: 100%;
|
|
height: 600px;
|
|
border-radius: 8px;
|
|
border: 1px solid #ddd;
|
|
font-size: 14px;
|
|
}
|
|
.editor-container {
|
|
position: relative;
|
|
}
|
|
.file-header {
|
|
background: #f8f9fa;
|
|
padding: 15px 20px;
|
|
border-radius: 8px 8px 0 0;
|
|
border: 1px solid #ddd;
|
|
border-bottom: none;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
</style>
|
|
|
|
<div class="theme-editor-edit">
|
|
<div class="file-header">
|
|
<div class="file-info">
|
|
<h5 class="mb-0"><i class="fa fa-file-code-o text-warning"></i> <?= Html::encode($filename) ?></h5>
|
|
<small class="text-muted">กำลังแก้ไขไฟล์ในโฟลเดอร์ธีม Mali</small>
|
|
</div>
|
|
<div class="actions">
|
|
<?= Html::a('<i class="fa fa-chevron-left"></i> ย้อนกลับ', ['index'], ['class' => 'btn btn-light btn-sm']) ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php $form = ActiveForm::begin(['id' => 'theme-edit-form']); ?>
|
|
<div class="editor-container">
|
|
<div id="editor"><?= Html::encode($content) ?></div>
|
|
<input type="hidden" name="content" id="content-input">
|
|
</div>
|
|
|
|
<div class="form-group mt-4 text-right">
|
|
<button type="button" id="save-btn" class="btn btn-success btn-lg px-5">
|
|
<i class="fa fa-save"></i> บันทึกไฟล์
|
|
</button>
|
|
</div>
|
|
<?php ActiveForm::end(); ?>
|
|
</div>
|
|
|
|
<?php
|
|
$js = <<<JS
|
|
// Initialize Ace Editor
|
|
var editor = ace.edit("editor");
|
|
editor.setTheme("ace/theme/monokai"); // Dark theme for coding
|
|
|
|
// Set mode based on file extension
|
|
var filename = "$filename";
|
|
if (filename.endsWith('.php')) {
|
|
editor.session.setMode("ace/mode/php");
|
|
} else if (filename.endsWith('.css')) {
|
|
editor.session.setMode("ace/mode/css");
|
|
} else if (filename.endsWith('.js')) {
|
|
editor.session.setMode("ace/mode/javascript");
|
|
}
|
|
|
|
editor.setOptions({
|
|
enableBasicAutocompletion: true,
|
|
enableLiveAutocompletion: true,
|
|
showPrintMargin: false,
|
|
useSoftTabs: true,
|
|
tabSize: 4
|
|
});
|
|
|
|
// Handle Save Button
|
|
document.getElementById('save-btn').addEventListener('click', function() {
|
|
var content = editor.getValue();
|
|
document.getElementById('content-input').value = content;
|
|
|
|
if (confirm('คุณแน่ใจหรือไม่ว่าต้องการบันทึกการเปลี่ยนแปลงนี้? กรุณาตรวจสอบโค้ดให้ถูกต้องเพื่อป้องกัน Error')) {
|
|
document.getElementById('theme-edit-form').submit();
|
|
}
|
|
});
|
|
|
|
// Keyboard shortcut (Ctrl+S or Cmd+S)
|
|
editor.commands.addCommand({
|
|
name: 'save',
|
|
bindKey: {win: 'Ctrl-S', mac: 'Command-S'},
|
|
exec: function(editor) {
|
|
document.getElementById('save-btn').click();
|
|
},
|
|
readOnly: false
|
|
});
|
|
JS;
|
|
$this->registerJs($js);
|
|
?>
|