filebrowser/static/js/app.js

75 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-09-14 17:18:26 +00:00
$(document).ready(function() {
2015-09-15 10:59:48 +00:00
$('.scroll').perfectScrollbar();
2015-09-14 17:18:26 +00:00
$('form').submit(function(event) {
var data = JSON.stringify($(this).serializeField())
var url = $(this).attr('action')
2015-09-15 10:59:48 +00:00
var action = $(this).find("input[type=submit]:focus").val();
2015-09-14 17:18:26 +00:00
2015-09-15 10:59:48 +00:00
console.log(data);
2015-09-14 21:36:15 +00:00
2015-09-14 17:18:26 +00:00
$.ajax({
type: 'POST',
url: url,
data: data,
2015-09-14 21:36:15 +00:00
beforeSend: function(xhr) {
2015-09-15 10:59:48 +00:00
xhr.setRequestHeader('X-Save-Mode', action);
},
dataType: 'json',
encode: true,
2015-09-14 17:18:26 +00:00
}).done(function(data) {
2015-09-14 17:41:49 +00:00
alert("it workss");
}).fail(function(data) {
alert("it failed");
2015-09-14 17:18:26 +00:00
});
event.preventDefault();
});
$("#logout").click(function(e) {
e.preventDefault();
jQuery.ajax({
type: "GET",
url: "/admin",
async: false,
username: "logmeout",
password: "123456",
headers: {
"Authorization": "Basic xxx"
}
})
.fail(function() {
window.location = "/";
});
return false;
});
2015-09-14 17:18:26 +00:00
});
2015-09-14 17:18:26 +00:00
$.fn.serializeField = function() {
var result = {};
this.each(function() {
2015-09-15 10:59:48 +00:00
$(this).find(".container > *").each(function() {
var $this = $(this);
var name = $this.attr("name");
2015-09-14 17:18:26 +00:00
if ($this.is("fieldset") && name) {
2015-09-15 10:59:48 +00:00
if ($this.attr("type") == "array") {
result[this.name] = [];
$.each($this.serializeArray(), function() {
result[this.name].push(this.value);
});
} else {
result[name] = $this.serializeField();
}
} else {
$.each($this.serializeArray(), function() {
result[this.name] = this.value;
});
}
2015-09-14 17:18:26 +00:00
});
});
return result;
};