Fixed Advanced Config reset

This commit is contained in:
Julian Prieber 2023-12-15 00:30:57 +01:00
parent ce60ce8c17
commit 9796c09eaa
2 changed files with 28 additions and 31 deletions

View File

@ -422,9 +422,11 @@ public function SendTestMail(Request $request)
//Saves advanced config //Saves advanced config
public function editAC(request $request) public function editAC(request $request)
{ {
$AdvancedConfig = $request->AdvancedConfig; if ($request->ResetAdvancedConfig == 'RESET_DEFAULTS') {
copy(base_path('storage/templates/advanced-config.php'), base_path('config/advanced-config.php'));
file_put_contents('config/advanced-config.php', $AdvancedConfig); } else {
file_put_contents('config/advanced-config.php', $request->AdvancedConfig);
}
return redirect('/admin/config#2'); return redirect('/admin/config#2');
} }

View File

@ -1,40 +1,35 @@
<p>{{__('messages.AC.description')}}</p> <p>{{__('messages.AC.description')}}</p>
<form action="{{ route('editAC') }}" method="post"> <form action="{{ route('editAC') }}" method="post" id="editForm">
@csrf @csrf
<div class="form-group"> <div class="form-group">
<label>{{__('messages.Advanced Configuration file.')}}</label> <label>{{__('messages.Advanced Configuration file.')}}</label>
<textarea style="width:100%;display:none;" class="form-control" name="AdvancedConfig" rows="280">{{ file_get_contents('config/advanced-config.php') }}</textarea> <textarea style="width:100%;display:none;" class="form-control" name="AdvancedConfig" rows="280">{{ file_get_contents('config/advanced-config.php') }}</textarea>
<div id="editor" style="width:100%; height:<?php echo count(file('config/advanced-config.php')) * 24 + 15;?>px; background-color:transparent !important;" class="form-control border-1 border-light" name="AdvancedConfig" rows="280">{{ file_get_contents('config/advanced-config.php') }}</div> <div id="editor" style="width:100%; height:<?php echo count(file('config/advanced-config.php')) * 24 + 15;?>px; background-color:transparent !important;" class="form-control border-1 border-light" name="AdvancedConfig" rows="280">{{ file_get_contents('config/advanced-config.php') }}</div>
</div> </div>
<button type="submit" class="btn btn-primary">{{__('messages.Save')}}</button> <button type="submit" class="btn btn-primary" id="saveBtn">{{__('messages.Save')}}</button>
<a class="btn btn-danger confirmation" href="{{url('/admin/advanced-config?restore-defaults')}}">{{__('messages.Restore defaults')}}</a> <a class="btn btn-danger confirmation" href="#" id="restoreDefaultsBtn">{{__('messages.Restore defaults')}}</a>
<script type="text/javascript">
var elems = document.getElementsByClassName('confirmation');
var confirmIt = function (e) {
if (!confirm('Are you sure?')) e.preventDefault();
};
for (var i = 0, l = elems.length; i < l; i++) {
elems[i].addEventListener('click', confirmIt, false);
}
</script>
</form> </form>
<script src="{{ asset('assets/external-dependencies/ace.js') }}" type="text/javascript" charset="utf-8"></script> <script src="{{ asset('assets/external-dependencies/ace.js') }}" type="text/javascript" charset="utf-8"></script>
<script> <script>
var editor = ace.edit("editor"); var editor = ace.edit("editor");
//if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
if(!$('#toggle-switch').is(':checked')){ editor.getSession().on('change', function(e) {
// dark mode $('textarea[name=AdvancedConfig]').val(editor.getSession().getValue());
editor.setTheme("ace/theme/tomorrow_night"); });
} else {
editor.setTheme("ace/theme/xcode"); $('#restoreDefaultsBtn').on('click', function(e) {
} e.preventDefault();
editor.getSession().setMode("ace/mode/javascript");
editor.session.setUseWorker(false); var isAdvancedConfig = $(this).hasClass('confirmation');
</script> var confirmationMessage = "Are you sure?";
<script>
editor.getSession().on('change', function(e) { if (isAdvancedConfig) {
$('textarea[name=AdvancedConfig]').val(editor.getSession().getValue()); $('#editForm').append('<input type="hidden" name="ResetAdvancedConfig" value="RESET_DEFAULTS">');
}); }
if (confirm(confirmationMessage)) {
$('#editForm').submit();
}
});
</script> </script>