X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=qcg%2Ftemplates%2Fqcg%2Fgridftp.html;fp=qcg%2Ftemplates%2Fqcg%2Fgridftp.html;h=dd24d7edfec9df350dcee8e970aea978b5dbb7e7;hb=273c0546c3f3154497c6554efeba805d9bbde526;hp=9b354de3b8f4633e965a0dd208cc580ad2c87ebf;hpb=2e226ed0e2a8bbf0cedbcaf5fff9e2906e858588;p=qcg-portal.git diff --git a/qcg/templates/qcg/gridftp.html b/qcg/templates/qcg/gridftp.html index 9b354de..dd24d7e 100644 --- a/qcg/templates/qcg/gridftp.html +++ b/qcg/templates/qcg/gridftp.html @@ -14,6 +14,10 @@ $(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() { @@ -23,9 +27,9 @@ $('#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(); } @@ -35,7 +39,18 @@ $('#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() { @@ -105,7 +120,7 @@ $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); @@ -127,7 +142,7 @@ 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); @@ -139,7 +154,7 @@ 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(), @@ -162,11 +177,26 @@ 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); + }); }) {% endblock extra_js %}