X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=qcg%2Ftemplates%2Fqcg%2Fgridftp.html;h=12fe644abf3e119bcec9dac38159f72474d61b1b;hb=5456abffdf1fee64a216e7a8a6d09ba3fd01b3bd;hp=52e482664b1763f5913160f2e2444beaf9430ac3;hpb=a5eea24f30969c1434c7743516f0195aa4bc53ae;p=qcg-portal.git diff --git a/qcg/templates/qcg/gridftp.html b/qcg/templates/qcg/gridftp.html index 52e4826..12fe644 100644 --- a/qcg/templates/qcg/gridftp.html +++ b/qcg/templates/qcg/gridftp.html @@ -16,6 +16,8 @@ $(function () { 'use strict'; + filex.initialLoad(); + var statusTimeout; String.prototype.endsWith = function(suffix) { @@ -32,12 +34,17 @@ } function failModal(msg) { - return function() { + return function(xhr) { var $errorModal = $('#error-modal'); $errorModal.find('#error-modal-label').text('Błąd serwera'); $errorModal.find('.modal-body').html($('

', {text: msg})); + var error = (xhr.responseJSON || {}).error || undefined; + + if (typeof error === 'string') + $errorModal.find('.modal-body').append($('
', {text: error}));
+
                     filex.idle();
                     $errorModal.modal();
 
@@ -45,6 +52,19 @@
                 };
             }
 
+            function conflictingName(name, modal) {
+                if (filex.files.some(function(item) { return item.get('name') == name })) {
+                    $('
', { + 'class': 'alert alert-danger', + html: ' Plik o podanej już nazwie istnieje!' + }).prependTo(modal.find('.modal-body')); + + return true; + } + + return false; + } + filex.files.on('change:checked reset', function() { var selected = filex.selectedFiles().length; @@ -61,12 +81,19 @@ $('#btn-extract').toggleClass('disabled', !is_archive); } else { - $('#btn-extract').toggleClass('disabled', true); + $('#btn-extract').addClass('disabled'); } }); + $('form').on('show.bs.modal', function() { + $(this).find('.alert').remove(); + this.reset(); + }).on('shown.bs.modal', function() { + $(this).find('input[type="text"]')[0].focus(); + }); + $('#btn-upload').on('click', function() { - var url = '{% url 'gridftp_upload' %}?' + $.param({host: filex.host, path: filex.path.full() + '/'}); + var url = '{% url 'gridftp_upload' %}?' + $.param({host: filex.host, path: filex.path.full()}); var win = window.open(url, url, 'height=500,width=800'); win.focus(); @@ -74,11 +101,11 @@ $('#btn-delete').on('click', function() { var selected = _.groupBy(filex.selectedFiles(), function(item) { return item.get('type') }), - dirs = _.map(selected.directory || [], function (item) { return item.get('name') }), - files = _.map(selected.file || [], function (item) { return item.get('name') }), + path = filex.path.full() + '/', + dirs = _.map(selected.directory || [], function (item) { return path + item.get('name') }), + files = _.map(selected.file || [], function (item) { return path + item.get('name') }), data = { host: filex.host, - path: filex.path.full() + '/', dirs: dirs, files: files }, @@ -104,8 +131,10 @@ $errorModal.find('#error-modal-label').text('Błąd'); for (var i in keys) { - $('
', {text: keys[i]}).appendTo($errorList); - $('
', {text: response.fail[keys[i]]}).appendTo($errorList); + if(keys.hasOwnProperty(i)) { + $('
', {text: keys[i].replace(path, '')}).appendTo($errorList); + $('
', {text: response.fail[keys[i]]}).appendTo($errorList); + } } $errorModal.modal(); @@ -130,6 +159,10 @@ var $this = $(this); e.preventDefault(); + + if (conflictingName($this.find('#id_name').val(), $this)) + return; + filex.busy(); $this.modal('hide'); @@ -143,22 +176,26 @@ }); $('#rename-form').on('show.bs.modal', function() { - var $this = $(this); + $(this).find('#id_dst').val(filex.selectedFiles()[0].get('name')); + }).on('submit', function(e) { + e.preventDefault(); - var file = filex.selectedFiles()[0]; + var $this = $(this), + path = filex.path.full() + '/', + newName = $this.find('#id_dst').val(), + data = { + host: filex.host, + src: path + filex.selectedFiles()[0].get('name'), + dst: path + newName + }; - $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); + if (conflictingName(newName, $this)) + return; - e.preventDefault(); filex.busy(); $this.modal('hide'); - $.post($this.attr('action'), $this.serialize(), function() { + $.post($this.attr('action'), data, function() { status('Nazwę zmieniono pomyślnie'); filex.reloadFiles(); }, 'json').fail(failModal('Nie udało się zmienić nazwy')); @@ -168,27 +205,19 @@ e.preventDefault(); var $this = $(this), - name = $this.find('#id_name').val(), + name = $this.find('#id_archive').val(), type = $this.find('#id_type').val(), + path = filex.path.full(), archive = name + (name.endsWith(type) ? '' : type), data = { host: filex.host, - path: filex.path.full(), + path: path, files: _.map(filex.selectedFiles(), function (item) { return item.get('name') }), - archive: archive + archive: path + '/' + 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')); - + if (conflictingName(archive, $this)) return; - } filex.busy(); $this.modal('hide'); @@ -204,7 +233,7 @@ var data = { host: filex.host, - archive: filex.path.full() + '/' + filex.selectedFiles()[0].get('name'), + path: filex.path.full() + '/' + filex.selectedFiles()[0].get('name'), dst: filex.path.full() };