$(function () {
var statusTimeout;
+ String.prototype.endsWith = function(suffix) {
+ return this.indexOf(suffix, this.length - suffix.length) !== -1;
+ };
+
function status(msg) {
clearTimeout(statusTimeout);
statusTimeout = setTimeout(function() {
$('#status').text(msg);
}
- function fail(xhr) {
- status('Wystąpił błąd: ' + ((xhr.responseJSON || {}).msg || "Server error"));
- console.error(xhr);
+ function fail() {
+ status('Wystąpił błąd.');
+ console.error(arguments);
filex.idle();
}
$('#btn-rename').toggleClass('disabled', selected != 1);
$('#btn-delete').toggleClass('disabled', selected == 0);
$('#btn-compress').toggleClass('disabled', selected == 0);
- $('#btn-extract').toggleClass('disabled', selected != 1);
+
+ if (selected == 1) {
+ var filename = filex.selectedFiles()[0].get('name'),
+ is_archive = _.some(['.zip', '.tar.gz', '.tgz', '.tar.bz2', 'tbz'], function(ext) {
+ return filename.endsWith(ext);
+ });
+
+ $('#btn-extract').toggleClass('disabled', !is_archive);
+ }
+ else {
+ $('#btn-extract').toggleClass('disabled', true);
+ }
});
$('#btn-upload').on('click', function() {
$this.find('#id_host').val(filex.host);
$this.find('#id_path').val(filex.path.full());
- $.post($this.attr('action'), $this.serialize(), function(response) {
+ $.post($this.attr('action'), $this.serialize(), function() {
status('Katalog utworzono pomyślnie');
filex.reloadFiles();
}, 'json').fail(fail);
filex.busy();
$this.modal('hide');
- $.post($this.attr('action'), $this.serialize(), function(response) {
+ $.post($this.attr('action'), $this.serialize(), function() {
status('Nazwę zmieniono pomyślnie');
filex.reloadFiles();
}, 'json').fail(fail);
var $this = $(this),
name = $this.find('#id_name').val(),
type = $this.find('#id_type').val(),
- archive = name + (name.indexOf(type, name.length - type.length) === -1 ? type : ''),
+ archive = name + (name.endsWith(type) ? '' : type),
data = {
host: filex.host,
path: filex.path.full(),
filex.busy();
$this.modal('hide');
- $.post($this.attr('action'), data, function(response) {
+ $.post($this.attr('action'), data, function() {
status('Archiwum utworzono pomyślnie');
filex.reloadFiles();
}, 'json').fail(fail);
});
+
+ $('#btn-extract').on('click', function() {
+ filex.busy();
+
+ var data = {
+ host: filex.host,
+ archive: filex.path.full() + '/' + filex.selectedFiles()[0].get('name'),
+ dst: filex.path.full()
+ };
+
+ $.post('{% url 'filex:extract' %}', data, function() {
+ status('Archiwum rozpakowano pomyślnie');
+ filex.reloadFiles();
+ }, 'json').fail(fail);
+ });
})
</script>
{% endblock extra_js %}