filebrowser/static/js/app.js

64 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-09-14 17:18:26 +00:00
$(document).ready(function() {
$('form').submit(function(event) {
var data = JSON.stringify($(this).serializeField())
var url = $(this).attr('action')
2015-09-14 21:36:15 +00:00
console.log(data)
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) {
// add publish and save
xhr.setRequestHeader('X-Save-Mode', 'publish');
}
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() {
$(this).find("> *").each(function() {
var $this = $(this);
var name = $this.attr("name");
2015-09-14 17:18:26 +00:00
if ($this.is("fieldset") && name) {
result[name] = $this.serializeField();
} else {
$.each($this.serializeArray(), function() {
result[this.name] = this.value;
});
}
2015-09-14 17:18:26 +00:00
});
});
return result;
};