add commands to the front end; inject json user data; close #24

pull/144/head
Henrique Dias 2016-08-21 20:44:28 +01:00
parent 408fa2e86f
commit 7c3a55c386
3 changed files with 24 additions and 15 deletions

View File

@ -443,13 +443,20 @@ var searchEvent = function(event) {
let box = document.querySelector('#search div');
if (value.length == 0) {
box.innerHTML = "Write your git, mercurial or svn command and press enter.";
box.innerHTML = "Write one of yours suported commands: " + user.Commands.join(", ") + ".";
return;
}
let pieces = value.split(' ');
let supported = false;
if (pieces[0] != "git" && pieces[0] != "hg" && pieces[0] != "svn") {
user.Commands.forEach(function(cmd) {
if (cmd == pieces[0]) {
supported = true;
}
});
if (!supported) {
box.innerHTML = "Command not supported."
return;
}
@ -509,7 +516,7 @@ document.addEventListener('listing', event => {
}
});
if (document.getElementById('search')) {
if (user.AllowCommands) {
document.querySelector('#search input').addEventListener('focus', event => {
document.getElementById('search').classList.add('active');
});
@ -519,31 +526,27 @@ document.addEventListener('listing', event => {
document.querySelector('#search input').value = '';
});
document.querySelector('#search div').innerHTML = "Write one of yours suported commands: " + user.Commands.join(", ") + ".";
document.querySelector('#search input').addEventListener('keyup', searchEvent);
}
if (document.getElementById("upload")) {
if (user.AllowEdit) {
// Enables rename button
document.getElementById("rename").addEventListener("click", renameEvent);
}
if (user.AllowNew) {
// Enables upload button
document.getElementById("upload").addEventListener("click", (event) => {
document.getElementById("upload-input").click();
});
}
if (document.getElementById("rename")) {
// Enables rename button
document.getElementById("rename").addEventListener("click", renameEvent);
}
if (document.getElementById('new')) {
document.getElementById('new').addEventListener('click', event => {
let newdir = document.getElementById('newdir');
newdir.classList.add('enabled');
newdir.focus();
});
}
if (document.getElementById('newdir')) {
document.getElementById('newdir').addEventListener('blur', event => {
document.getElementById('newdir').classList.remove('enabled');
});
@ -845,7 +848,7 @@ document.addEventListener("DOMContentLoaded", function(event) {
// Enables open, delete and download buttons
document.getElementById("open").addEventListener("click", openEvent);
if (document.getElementById("delete")) {
if (user.AllowEdit) {
document.getElementById("delete").addEventListener("click", deleteEvent);
}

View File

@ -121,6 +121,8 @@
</footer>
<!-- SCRIPTS -->
<!-- User Data and Permissions -->
<script>var user = JSON.parse('{{ Marshal .User }}');</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js"></script>
<script src="{{ .Config.AbsoluteURL }}/_filemanagerinternal/js/form2js.js"></script>
<script src="{{ .Config.AbsoluteURL }}/_filemanagerinternal/js/application.js"></script>

View File

@ -80,6 +80,10 @@ func (p Page) PrintAsHTML(w http.ResponseWriter, templates ...string) (int, erro
"CSS": func(s string) template.CSS {
return template.CSS(s)
},
"Marshal": func(v interface{}) template.JS {
a, _ := json.Marshal(v)
return template.JS(a)
},
}
if p.Minimal {