2022-07-17 18:16:00 +00:00
|
|
|
<!--
|
2023-11-04 09:54:52 +00:00
|
|
|
Copyright (C) 2023 Nicola Murino
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
This WebUI uses the KeenThemes Mega Bundle, a proprietary theme:
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
https://keenthemes.com/products/templates-mega-bundle
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
KeenThemes HTML/CSS/JS components are allowed for use only within the
|
|
|
|
SFTPGo product and restricted to be used in a resealable HTML template
|
|
|
|
that can compete with KeenThemes products anyhow.
|
|
|
|
|
|
|
|
This WebUI is allowed for use only within the SFTPGo product and
|
|
|
|
therefore cannot be used in derivative works/products without an
|
|
|
|
explicit grant from the SFTPGo Team (support@sftpgo.com).
|
2022-07-17 18:16:00 +00:00
|
|
|
-->
|
2021-10-09 12:17:28 +00:00
|
|
|
{{template "base" .}}
|
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- define "extra_css"}}
|
2023-11-17 20:42:22 +00:00
|
|
|
<style {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}}>
|
2021-10-09 12:17:28 +00:00
|
|
|
.shortcut {font-family: monospace; color: #666;}
|
2023-11-04 09:54:52 +00:00
|
|
|
.cm-editor {
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
2021-10-09 12:17:28 +00:00
|
|
|
</style>
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- end}}
|
|
|
|
|
|
|
|
{{- define "additionalnavitems"}}
|
|
|
|
<div class="d-flex align-items-center ms-2 ms-lg-3" id="kt_header_user_menu_toggle">
|
|
|
|
<div class="btn btn-icon btn-active-light-primary w-35px h-35px w-md-40px h-md-40px" data-bs-toggle="modal" data-bs-target="#info_modal">
|
|
|
|
<i class="ki-duotone ki-information-2 fs-2">
|
|
|
|
<i class="path1"></i>
|
|
|
|
<i class="path2"></i>
|
|
|
|
<i class="path3"></i>
|
|
|
|
</i>
|
|
|
|
</div>
|
2021-10-09 12:17:28 +00:00
|
|
|
</div>
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- end}}
|
|
|
|
|
|
|
|
{{- define "page_body"}}
|
|
|
|
{{- template "errmsg" ""}}
|
|
|
|
<div class="card shadow-sm">
|
2021-10-09 12:17:28 +00:00
|
|
|
<div class="card-header">
|
2023-12-26 07:59:52 +00:00
|
|
|
<h6 id="card_title" class="card-title section-title"></h6>
|
2023-11-04 09:54:52 +00:00
|
|
|
<div class="card-toolbar">
|
2023-12-10 15:40:13 +00:00
|
|
|
<a data-i18n="general.back" class="btn btn-light-primary px-10 me-5" href='{{.FilesURL}}?path={{.CurrentDir}}' role="button">Back</a>
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- if not .ReadOnly}}
|
2023-11-14 18:41:20 +00:00
|
|
|
<a id="save_button" type="button" class="btn btn-primary px-10" href="#" role="button">
|
2023-12-10 15:40:13 +00:00
|
|
|
<span data-i18n="general.submit" class="indicator-label">Save</span>
|
|
|
|
<span data-i18n="general.wait" class="indicator-progress">
|
|
|
|
Please wait...
|
2023-11-04 09:54:52 +00:00
|
|
|
<span class="spinner-border spinner-border-sm align-middle ms-2"></span>
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
{{- end}}
|
|
|
|
</div>
|
2021-10-09 12:17:28 +00:00
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
2023-11-04 09:54:52 +00:00
|
|
|
<div id="editor" class="col-sm-12 border border-light-primary"></div>
|
2021-10-09 12:17:28 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- end}}
|
2021-10-09 12:17:28 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- define "modals"}}
|
|
|
|
<div class="modal fade" id="info_modal" tabindex="-1">
|
|
|
|
<div class="modal-dialog">
|
2021-10-09 12:17:28 +00:00
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
2023-12-10 15:40:13 +00:00
|
|
|
<h3 data-i18n="editor.keybinding" class="modal-title">Editor keybindings</h3>
|
2023-12-26 07:59:52 +00:00
|
|
|
<div data-i18n="[aria-label]general.close" class="btn btn-icon btn-sm btn-active-light-primary" data-bs-dismiss="modal" aria-label="Close">
|
|
|
|
<i class="ki-solid ki-cross fs-2x text-gray-700"></i>
|
2023-11-04 09:54:52 +00:00
|
|
|
</div>
|
2021-10-09 12:17:28 +00:00
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
|
|
<p>
|
2023-12-10 15:40:13 +00:00
|
|
|
<span class="shortcut">Ctrl-F / Cmd-F</span> => <span data-i18n="editor.search" class="fw-semibold">Open search panel</span>
|
2021-10-09 12:17:28 +00:00
|
|
|
</p>
|
|
|
|
<p>
|
2023-12-10 15:40:13 +00:00
|
|
|
<span class="shortcut">Alt-G</span> => <span data-i18n="editor.goto" class="fw-semibold">Jump to line</span>
|
2021-10-09 12:17:28 +00:00
|
|
|
</p>
|
|
|
|
<p>
|
2023-12-10 15:40:13 +00:00
|
|
|
<span class="shortcut">Tab</span> => <span data-i18n="editor.indent_more" class="fw-semibold">Indent more</span>
|
2021-10-09 12:17:28 +00:00
|
|
|
</p>
|
|
|
|
<p>
|
2023-12-10 15:40:13 +00:00
|
|
|
<span class="shortcut">Shift-Tab</span> => <span data-i18n="editor.indent_less" class="fw-semibold">Indent less</span>
|
2021-10-09 12:17:28 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
2023-12-10 15:40:13 +00:00
|
|
|
<button data-i18n="general.ok" class="btn btn-primary" type="button" data-bs-dismiss="modal">OK</button>
|
2021-10-09 12:17:28 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- end}}
|
|
|
|
|
|
|
|
{{- define "extra_js"}}
|
2023-11-21 15:24:43 +00:00
|
|
|
<script {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}} src="{{.StaticURL}}/vendor/codemirror/cm6.bundle.min.js"></script>
|
2023-11-16 17:55:14 +00:00
|
|
|
<script type="text/javascript" {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}}>
|
2023-11-04 09:54:52 +00:00
|
|
|
var cmView;
|
2021-10-09 12:17:28 +00:00
|
|
|
|
|
|
|
function keepAlive() {
|
2023-11-06 18:58:39 +00:00
|
|
|
axios.get('{{.PingURL}}',{
|
|
|
|
timeout: 15000,
|
|
|
|
responseType: 'text'
|
2023-11-04 09:54:52 +00:00
|
|
|
}).catch(function (error){});
|
2021-10-09 12:17:28 +00:00
|
|
|
}
|
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
//{{- if not .ReadOnly}}
|
2021-10-09 12:17:28 +00:00
|
|
|
function saveFile() {
|
2023-11-04 09:54:52 +00:00
|
|
|
$('#errorMsg').addClass("d-none");
|
|
|
|
let saveButton = document.querySelector('#save_button');
|
|
|
|
saveButton.setAttribute('data-kt-indicator', 'on');
|
|
|
|
saveButton.disabled = true;
|
|
|
|
|
|
|
|
let uploadPath = '{{.FileURL}}?path='+encodeURIComponent('{{.CurrentDir}}/{{.Name}}');
|
|
|
|
let blob = new Blob([cmView.state.doc.toString()]);
|
|
|
|
|
|
|
|
axios.post(uploadPath, blob, {
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-TOKEN': '{{.CSRFToken}}'
|
|
|
|
},
|
|
|
|
timeout: 600000,
|
|
|
|
validateStatus: function (status) {
|
|
|
|
return status == 201;
|
|
|
|
}
|
|
|
|
}).then(function (response) {
|
|
|
|
window.location.replace('{{.FilesURL}}?path='+encodeURIComponent('{{.CurrentDir}}'));
|
|
|
|
}).catch(function (error) {
|
|
|
|
saveButton.removeAttribute('data-kt-indicator');
|
|
|
|
saveButton.disabled = false;
|
2023-12-10 15:40:13 +00:00
|
|
|
|
|
|
|
let errorMessage = "";
|
2023-11-04 09:54:52 +00:00
|
|
|
if (error && error.response) {
|
2023-12-10 15:40:13 +00:00
|
|
|
switch (error.response.status) {
|
|
|
|
case 403:
|
|
|
|
errorMessage = "fs.save.err403";
|
|
|
|
break;
|
|
|
|
case 429:
|
|
|
|
errorMessage = "fs.save.err429";
|
|
|
|
break;
|
2021-10-09 12:17:28 +00:00
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
}
|
2023-12-10 15:40:13 +00:00
|
|
|
if (!errorMessage){
|
|
|
|
errorMessage = "fs.save.err_generic";
|
|
|
|
}
|
|
|
|
setI18NData($('#errorTxt'), errorMessage);
|
2023-11-04 09:54:52 +00:00
|
|
|
$('#errorMsg').removeClass("d-none");
|
2021-12-08 18:25:22 +00:00
|
|
|
});
|
2021-10-09 12:17:28 +00:00
|
|
|
}
|
2023-11-04 09:54:52 +00:00
|
|
|
//{{- end}}
|
|
|
|
|
2023-12-10 15:40:13 +00:00
|
|
|
$(document).on("i18nload", function(){
|
2023-12-12 17:04:14 +00:00
|
|
|
let message = 'fs.edit_file';
|
2023-12-10 15:40:13 +00:00
|
|
|
//{{- if .ReadOnly}}
|
2023-12-12 17:04:14 +00:00
|
|
|
message = 'fs.view_file';
|
2023-12-10 15:40:13 +00:00
|
|
|
//{{- end}}
|
2023-12-12 17:04:14 +00:00
|
|
|
setI18NData($('#card_title'), message, { path: '{{.Path}}'});
|
2023-12-10 15:40:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on("i18nshow", function(){
|
2023-11-18 13:17:28 +00:00
|
|
|
let filename = "{{.Name}}";
|
|
|
|
let extension = filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
|
2023-11-04 09:54:52 +00:00
|
|
|
let options = {
|
2023-11-18 13:17:28 +00:00
|
|
|
oneDark: KTThemeMode.getMode() == "dark",
|
|
|
|
fileExt: extension
|
2023-11-04 09:54:52 +00:00
|
|
|
};
|
|
|
|
//{{- if .ReadOnly}}
|
|
|
|
options.readOnly = true;
|
|
|
|
//{{- end}}
|
2023-11-18 10:18:31 +00:00
|
|
|
//{{- if .CSPNonce}}
|
|
|
|
options.cspNonce = "{{.CSPNonce}}";
|
|
|
|
//{{- end}}
|
|
|
|
let editorState = cm6.createEditorState("{{.Data}}", options);
|
|
|
|
cmView = cm6.createEditorView(editorState, document.getElementById("editor"));
|
2023-11-04 09:54:52 +00:00
|
|
|
|
2023-11-14 18:41:20 +00:00
|
|
|
var saveBtn = $('#save_button');
|
|
|
|
if (saveBtn){
|
|
|
|
saveBtn.on("click", function(){
|
|
|
|
saveFile();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
setInterval(keepAlive, 300000);
|
|
|
|
});
|
2021-10-09 12:17:28 +00:00
|
|
|
</script>
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- end}}
|