2016-02-06 16:08:48 +00:00
|
|
|
$(document).on('page:browse', function() {
|
2016-02-08 08:24:12 +00:00
|
|
|
var foreground = '#foreground';
|
2016-02-07 21:12:01 +00:00
|
|
|
|
|
|
|
/* DELETE FILE */
|
|
|
|
|
|
|
|
var remove = new Object();
|
2016-02-08 08:24:12 +00:00
|
|
|
remove.selector = 'form#delete';
|
|
|
|
remove.form = $(remove.selector);
|
2016-02-07 21:12:01 +00:00
|
|
|
remove.row = '';
|
|
|
|
remove.button = '';
|
|
|
|
remove.url = '';
|
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$('#content').on('click', '.delete', function(event) {
|
2016-02-07 21:12:01 +00:00
|
|
|
event.preventDefault();
|
|
|
|
remove.button = $(this);
|
|
|
|
remove.row = $(this).parent().parent();
|
2016-02-08 08:24:12 +00:00
|
|
|
$(foreground).fadeIn(200);
|
2016-02-07 21:12:01 +00:00
|
|
|
remove.url = remove.row.find('.filename').text();
|
2016-02-08 08:24:12 +00:00
|
|
|
remove.form.find('span').text(remove.url);
|
2016-02-07 21:12:01 +00:00
|
|
|
remove.form.fadeIn(200);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$('#content').on('submit', remove.selector, function(event) {
|
2016-02-07 21:12:01 +00:00
|
|
|
event.preventDefault();
|
|
|
|
|
2016-03-06 12:39:36 +00:00
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.open("DELETE", remove.button.data("file"));
|
|
|
|
request.send();
|
|
|
|
request.onreadystatechange = function() {
|
|
|
|
if (request.readyState == 4) {
|
2016-03-06 15:39:03 +00:00
|
|
|
var response = JSON.parse(request.responseText),
|
|
|
|
type = "success",
|
|
|
|
timeout = 5000;
|
|
|
|
|
|
|
|
$(foreground).fadeOut(200);
|
|
|
|
remove.form.fadeOut(200);
|
|
|
|
remove.row.fadeOut(200);
|
|
|
|
|
|
|
|
if (request.status != 200) {
|
|
|
|
type = "error";
|
|
|
|
timeout = false;
|
2016-03-06 12:39:36 +00:00
|
|
|
}
|
2016-03-06 15:39:03 +00:00
|
|
|
|
|
|
|
notification({
|
|
|
|
text: response.message,
|
|
|
|
type: type,
|
|
|
|
timeout: timeout
|
|
|
|
});
|
2016-03-06 12:39:36 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-07 21:12:01 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
2016-02-06 17:18:30 +00:00
|
|
|
|
2016-02-07 19:37:01 +00:00
|
|
|
/* FILE UPLOAD */
|
2016-02-06 17:18:30 +00:00
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$('#content').on('change', 'input[type="file"]', function(event) {
|
2016-02-07 19:37:01 +00:00
|
|
|
event.preventDefault();
|
|
|
|
files = event.target.files;
|
2016-02-06 17:18:30 +00:00
|
|
|
|
2016-02-07 19:37:01 +00:00
|
|
|
// Create a formdata object and add the files
|
|
|
|
var data = new FormData();
|
|
|
|
$.each(files, function(key, value) {
|
|
|
|
data.append(key, value);
|
|
|
|
});
|
2016-02-06 17:18:30 +00:00
|
|
|
|
|
|
|
$.ajax({
|
2016-02-07 19:37:01 +00:00
|
|
|
url: window.location.pathname,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
cache: false,
|
2016-02-06 17:18:30 +00:00
|
|
|
dataType: 'json',
|
2016-02-07 19:37:01 +00:00
|
|
|
headers: {
|
|
|
|
'X-Upload': 'true',
|
|
|
|
},
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
2016-02-06 17:18:30 +00:00
|
|
|
}).done(function(data) {
|
|
|
|
notification({
|
2016-02-07 19:37:01 +00:00
|
|
|
text: "File(s) uploaded successfully.",
|
2016-02-06 17:18:30 +00:00
|
|
|
type: 'success',
|
|
|
|
timeout: 5000
|
|
|
|
});
|
2016-02-07 19:37:01 +00:00
|
|
|
|
|
|
|
$.pjax({
|
|
|
|
url: window.location.pathname,
|
|
|
|
container: '#content'
|
|
|
|
})
|
2016-02-06 17:18:30 +00:00
|
|
|
}).fail(function(data) {
|
|
|
|
notification({
|
|
|
|
text: 'Something went wrong.',
|
|
|
|
type: 'error'
|
|
|
|
});
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-02-08 08:25:38 +00:00
|
|
|
$('#content').on('click', '#upload', function(event) {
|
2016-02-06 16:08:48 +00:00
|
|
|
event.preventDefault();
|
2016-02-07 19:37:01 +00:00
|
|
|
$('.actions input[type="file"]').click();
|
2016-02-06 16:08:48 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-02-07 19:37:01 +00:00
|
|
|
/* NEW FILE */
|
|
|
|
|
|
|
|
var create = new Object();
|
2016-02-08 08:24:12 +00:00
|
|
|
create.selector = 'form#new';
|
|
|
|
create.form = $(create.selector);
|
|
|
|
create.input = create.selector + ' input[type="text"]';
|
2016-02-07 19:37:01 +00:00
|
|
|
create.button = '';
|
|
|
|
create.url = '';
|
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$('#content').on('click', '.new', function(event) {
|
2016-02-06 16:08:48 +00:00
|
|
|
event.preventDefault();
|
2016-02-07 19:37:01 +00:00
|
|
|
create.button = $(this);
|
2016-02-08 08:24:12 +00:00
|
|
|
$(foreground).fadeIn(200);
|
2016-02-07 21:12:01 +00:00
|
|
|
create.form.fadeIn(200);
|
2016-02-06 16:08:48 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$('#content').on('keypress', create.input, function(event) {
|
2016-02-07 17:49:20 +00:00
|
|
|
if (event.keyCode == 13) {
|
|
|
|
event.preventDefault();
|
2016-02-07 19:37:01 +00:00
|
|
|
$(create.form).submit();
|
2016-02-07 17:49:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$('#content').on('submit', create.selector, function(event) {
|
2016-02-07 17:16:09 +00:00
|
|
|
event.preventDefault();
|
2016-02-07 19:37:01 +00:00
|
|
|
|
|
|
|
var value = create.form.find('input[type="text"]').val(),
|
2016-02-07 17:16:09 +00:00
|
|
|
splited = value.split(":"),
|
|
|
|
filename = "",
|
|
|
|
archetype = "";
|
|
|
|
|
|
|
|
if (value == "") {
|
|
|
|
notification({
|
|
|
|
text: "You have to write something. If you want to close the box, click the button again.",
|
|
|
|
type: 'warning',
|
|
|
|
timeout: 5000
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} else if (splited.length == 1) {
|
|
|
|
filename = value;
|
|
|
|
} else if (splited.length == 2) {
|
|
|
|
filename = splited[0];
|
|
|
|
archetype = splited[1];
|
|
|
|
} else {
|
|
|
|
notification({
|
|
|
|
text: "Hmm... I don't understand you. Try writing something like 'name[:archetype]'.",
|
|
|
|
type: 'error'
|
2016-02-06 16:08:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-07 17:16:09 +00:00
|
|
|
|
2016-03-06 12:39:36 +00:00
|
|
|
var content = {
|
|
|
|
filename: filename,
|
|
|
|
archetype: archetype
|
|
|
|
}
|
2016-02-07 17:16:09 +00:00
|
|
|
|
2016-03-06 12:39:36 +00:00
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.open("POST", window.location.pathname);
|
|
|
|
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
|
request.send(JSON.stringify(content));
|
|
|
|
request.onreadystatechange = function() {
|
|
|
|
if (request.readyState == 4) {
|
2016-03-06 15:56:53 +00:00
|
|
|
var response = JSON.parse(request.responseText);
|
|
|
|
var type = "success";
|
|
|
|
var timeout = 5000;
|
2016-03-06 12:39:36 +00:00
|
|
|
|
2016-03-06 15:56:53 +00:00
|
|
|
if (request.status != 200) {
|
|
|
|
type = "error";
|
|
|
|
timeout = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
notification({
|
|
|
|
text: response.message,
|
|
|
|
type: type,
|
|
|
|
timeout: timeout
|
|
|
|
});
|
|
|
|
|
|
|
|
if (request.status == 200) {
|
2016-03-06 12:39:36 +00:00
|
|
|
$.pjax({
|
|
|
|
url: data.Location,
|
|
|
|
container: '#content'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-07 17:16:09 +00:00
|
|
|
|
|
|
|
return false;
|
2016-02-06 16:08:48 +00:00
|
|
|
});
|
|
|
|
|
2016-02-07 19:37:01 +00:00
|
|
|
/* RENAME FILE */
|
|
|
|
|
|
|
|
var rename = new Object();
|
2016-02-08 08:24:12 +00:00
|
|
|
rename.selector = 'form#rename';
|
|
|
|
rename.form = $(rename.selector);
|
|
|
|
rename.input = rename.selector + ' input[type="text"]';
|
2016-02-07 19:37:01 +00:00
|
|
|
rename.button = '';
|
|
|
|
rename.url = '';
|
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$('#content').on('click', '.rename', function(event) {
|
2016-02-06 16:08:48 +00:00
|
|
|
event.preventDefault();
|
2016-02-07 19:37:01 +00:00
|
|
|
rename.button = $(this);
|
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$(foreground).fadeIn(200);
|
2016-02-07 21:12:01 +00:00
|
|
|
rename.url = $(this).parent().parent().find('.filename').text();
|
|
|
|
rename.form.fadeIn(200);
|
|
|
|
rename.form.find('span').text(rename.url);
|
|
|
|
rename.form.find('input[type="text"]').val(rename.url);
|
2016-02-07 19:37:01 +00:00
|
|
|
|
2016-02-06 16:08:48 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$('#content').on('keypress', rename.input, function(event) {
|
2016-02-07 19:37:01 +00:00
|
|
|
if (event.keyCode == 13) {
|
|
|
|
event.preventDefault();
|
|
|
|
$(rename.form).submit();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$('#content').on('submit', rename.selector, function(event) {
|
2016-02-06 16:08:48 +00:00
|
|
|
event.preventDefault();
|
|
|
|
|
2016-02-07 19:37:01 +00:00
|
|
|
var filename = rename.form.find('input[type="text"]').val();
|
|
|
|
if (filename === "") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filename.substring(0, 1) != "/") {
|
|
|
|
filename = window.location.pathname.replace("/admin/browse/", "") + '/' + filename;
|
|
|
|
}
|
|
|
|
|
2016-03-06 13:01:03 +00:00
|
|
|
var content = {
|
|
|
|
filename: filename
|
|
|
|
};
|
2016-02-06 16:08:48 +00:00
|
|
|
|
2016-03-06 13:01:03 +00:00
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.open("PUT", rename.url);
|
|
|
|
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
|
request.send(JSON.stringify(content));
|
|
|
|
request.onreadystatechange = function() {
|
|
|
|
if (request.readyState == 4) {
|
2016-03-06 15:39:03 +00:00
|
|
|
var response = JSON.parse(request.responseText),
|
|
|
|
type = "success",
|
|
|
|
timeout = 5000;
|
|
|
|
|
|
|
|
if (request.status != 200) {
|
|
|
|
type = "error";
|
|
|
|
timeout = false;
|
2016-03-06 13:01:03 +00:00
|
|
|
}
|
2016-03-06 15:39:03 +00:00
|
|
|
|
|
|
|
$.pjax({
|
|
|
|
url: window.location.pathname,
|
|
|
|
container: '#content'
|
|
|
|
});
|
|
|
|
|
|
|
|
notification({
|
|
|
|
text: response.message,
|
|
|
|
type: type,
|
|
|
|
timeout: timeout
|
|
|
|
});
|
2016-03-06 13:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-06 16:08:48 +00:00
|
|
|
|
2016-02-07 19:37:01 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-03-06 12:39:36 +00:00
|
|
|
/* GIT ACTIONS */
|
|
|
|
|
|
|
|
var git = new Object();
|
|
|
|
git.selector = 'form#git';
|
|
|
|
git.form = $(git.selector);
|
|
|
|
git.input = git.selector + ' input[type="text"]';
|
|
|
|
|
|
|
|
$('#content').on('click', 'button.git', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
$(foreground).fadeIn(200);
|
|
|
|
git.form.fadeIn(200);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#content').on('keypress', git.input, function(event) {
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
event.preventDefault();
|
|
|
|
$(git.form).submit();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#content').on('submit', git.selector, function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var value = git.form.find('input[type="text"]').val();
|
|
|
|
|
|
|
|
if (value == "") {
|
|
|
|
notification({
|
|
|
|
text: "You have to write something. If you want to close the box, click outside of the box.",
|
|
|
|
type: 'warning',
|
|
|
|
timeout: 5000
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.open("POST", "/admin/git");
|
|
|
|
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
|
request.send(JSON.stringify({
|
|
|
|
command: value
|
|
|
|
}));
|
2016-03-06 13:01:03 +00:00
|
|
|
request.onreadystatechange = function() {
|
|
|
|
if (request.readyState == 4) {
|
2016-03-06 14:23:37 +00:00
|
|
|
var data = JSON.parse(request.responseText);
|
|
|
|
|
2016-03-06 13:01:03 +00:00
|
|
|
if (request.status == 200) {
|
|
|
|
notification({
|
2016-03-06 14:23:37 +00:00
|
|
|
text: data.message,
|
2016-03-06 15:39:03 +00:00
|
|
|
type: "success"
|
2016-03-06 13:01:03 +00:00
|
|
|
});
|
2016-03-06 14:23:37 +00:00
|
|
|
} else {
|
2016-03-06 15:39:03 +00:00
|
|
|
notification({
|
|
|
|
text: data.message,
|
|
|
|
type: "error"
|
|
|
|
});
|
2016-03-06 13:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-06 12:39:36 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
/* $(foreground) AND STUFF */
|
2016-02-07 19:37:01 +00:00
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$('#content').on('click', '.close', function(event) {
|
2016-02-07 21:12:01 +00:00
|
|
|
event.preventDefault();
|
|
|
|
$(this).parent().parent().fadeOut(200);
|
2016-02-08 08:24:12 +00:00
|
|
|
$(foreground).click();
|
2016-02-06 16:08:48 +00:00
|
|
|
return false;
|
|
|
|
});
|
2016-02-07 19:37:01 +00:00
|
|
|
|
2016-02-08 08:24:12 +00:00
|
|
|
$('#content').on('click', foreground, function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
$(foreground).fadeOut(200);
|
2016-02-07 19:37:01 +00:00
|
|
|
create.form.fadeOut(200);
|
|
|
|
rename.form.fadeOut(200);
|
2016-02-07 21:12:01 +00:00
|
|
|
remove.form.fadeOut(200);
|
2016-03-06 12:39:36 +00:00
|
|
|
git.form.fadeOut(200);
|
2016-02-08 08:24:12 +00:00
|
|
|
return false;
|
2016-02-07 19:37:01 +00:00
|
|
|
});
|
2016-03-06 15:56:53 +00:00
|
|
|
});
|