X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=qcg%2Ftemplates%2Fqcg%2Fgridftp.html;h=dd24d7edfec9df350dcee8e970aea978b5dbb7e7;hb=67ec532d7a614cd39cf1e4d36a4ba963c9e166ee;hp=d0e77c14ee98de640f00e9ceb4767613255ccd0a;hpb=05260e5290c07e848090b9c3f69f03bf487a9fa0;p=qcg-portal.git diff --git a/qcg/templates/qcg/gridftp.html b/qcg/templates/qcg/gridftp.html index d0e77c1..dd24d7e 100644 --- a/qcg/templates/qcg/gridftp.html +++ b/qcg/templates/qcg/gridftp.html @@ -1,5 +1,5 @@ {% extends 'qcg/base.html' %} -{% load staticfiles %} +{% load staticfiles bootstrap3 %} {% block extra_css %} @@ -14,6 +14,45 @@ $(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(''); + }, 3000); + + $('#status').text(msg); + } + + function fail() { + status('Wystąpił błąd.'); + console.error(arguments); + filex.idle(); + } + + filex.files.on('change:checked reset', function() { + var selected = filex.selectedFiles().length; + + $('#btn-rename').toggleClass('disabled', selected != 1); + $('#btn-delete').toggleClass('disabled', selected == 0); + $('#btn-compress').toggleClass('disabled', selected == 0); + + 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() { var url = '{% url 'gridftp_upload' %}?' + $.param({host: filex.host, path: filex.path.full() + '/'}); @@ -57,24 +96,107 @@ filex.idle(); } else { - clearTimeout(statusTimeout); - statusTimeout = setTimeout(function() { - $('#status').text(''); - }, 3000); - - $('#status').text('Usuwanie zakończone pomyślnie'); + status('Usuwanie zakończone pomyślnie'); } if (response.done.length) filex.reloadFiles(); - }, 'json'); + }, 'json').fail(fail); $confirmModal.modal('hide'); }); $confirmModal.modal(); }); + + $('#mkdir-form').on('submit', function(e) { + var $this = $(this); + + e.preventDefault(); + filex.busy(); + $this.modal('hide'); + + $this.find('#id_host').val(filex.host); + $this.find('#id_path').val(filex.path.full()); + + $.post($this.attr('action'), $this.serialize(), function() { + status('Katalog utworzono pomyślnie'); + filex.reloadFiles(); + }, 'json').fail(fail); + }); + + $('#rename-form').on('show.bs.modal', function() { + var $this = $(this); + + var file = filex.selectedFiles()[0]; + + $this.find('#id_host').val(filex.host); + $this.find('#id_path').val(filex.path.full()); + $this.find('#id_src').val(file.get('name')); + $this.find('#id_dst').val(file.get('name')); + }).on('submit', function(e) { + var $this = $(this); + + e.preventDefault(); + filex.busy(); + $this.modal('hide'); + + $.post($this.attr('action'), $this.serialize(), function() { + status('Nazwę zmieniono pomyślnie'); + filex.reloadFiles(); + }, 'json').fail(fail); + }); + + $('#compress-form').on('submit', function(e) { + e.preventDefault(); + + var $this = $(this), + name = $this.find('#id_name').val(), + type = $this.find('#id_type').val(), + archive = name + (name.endsWith(type) ? '' : type), + data = { + host: filex.host, + path: filex.path.full(), + files: _.map(filex.selectedFiles(), function (item) { return item.get('name') }), + archive: archive + }; + + // check if maybe file with given name exists + if (filex.files.some(function(item) { return item.get('name') == archive })) { + $this.find('.alert').remove(); + + $('
', { + 'class': 'alert alert-danger', + html: ' Plik o podanej już nazwie istnieje!' + }).prependTo($this.find('.modal-body')); + + return; + } + + filex.busy(); + $this.modal('hide'); + + $.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 %} @@ -124,6 +246,69 @@
+ + + + + + {% endblock container %} {% block footer %} @@ -132,11 +317,15 @@