1 {% extends 'qcg/base.html' %}
2 {% load staticfiles bootstrap3 %}
5 <link href="{% static 'qcg/selectize/selectize.bootstrap3.css' %}" rel="stylesheet">
18 height: calc(100% - 122px);
25 <script src="{% static 'qcg/cookie/jquery.cookie.min.js' %}"></script>
26 <script src="{% static 'qcg/globals.js' %}"></script>
27 {% include 'filex/source.js.html' %}
30 var filex = filex || {},
31 hostArchiveSupport = ['moss.man.poznan.pl', 'ui.plgrid.wcss.wroc.pl'];
40 String.prototype.endsWith = function(suffix) {
41 return this.indexOf(suffix, this.length - suffix.length) !== -1;
44 function status(msg) {
45 clearTimeout(statusTimeout);
46 statusTimeout = setTimeout(function() {
47 $('#status').text('');
50 $('#status').text(msg);
53 function failModal(msg) {
54 return function(xhr) {
55 var $errorModal = $('#error-modal');
57 $errorModal.find('#error-modal-label').text('Błąd serwera');
58 $errorModal.find('.modal-body').html($('<h4>', {text: msg}));
60 var error = (xhr.responseJSON || {}).error || undefined;
62 if (typeof error === 'string')
63 $errorModal.find('.modal-body').append($('<pre>', {text: error}));
68 console.error(arguments);
72 function conflictingName(name, modal) {
73 if (filex.files.some(function(item) { return item.get('name') == name })) {
75 'class': 'alert alert-danger',
76 html: '<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> Plik o podanej nazwie już istnieje!'
77 }).prependTo(modal.find('.modal-body'));
85 filex.files.on('change:checked reset', function() {
86 var selected = filex.selectedFiles().length,
87 supportsArchive = hostArchiveSupport.indexOf(filex.host) != -1;
89 $('#btn-rename').toggleClass('disabled', selected != 1);
90 $('#btn-delete').toggleClass('disabled', selected == 0);
91 $('#btn-compress').toggleClass('disabled', !supportsArchive || selected == 0);
93 if (supportsArchive && selected == 1) {
94 var filename = filex.selectedFiles()[0].get('name'),
95 is_archive = _.some(['.zip', '.tar.gz', '.tgz', '.tar.bz2', 'tbz'], function(ext) {
96 return filename.endsWith(ext);
99 $('#btn-extract').toggleClass('disabled', !is_archive);
102 $('#btn-extract').addClass('disabled');
106 $('form').on('show.bs.modal', function() {
107 $(this).find('.alert').remove();
109 }).on('shown.bs.modal', function() {
110 $(this).find('input[type="text"]')[0].focus();
113 $('#btn-upload').on('click', function() {
114 var url = '{% url 'gridftp_upload' %}?' + $.param({host: filex.host, path: filex.path.full()});
116 var win = window.open(url, url, 'height=500,width=800');
120 $('#btn-delete').on('click', function() {
121 var selected = _.groupBy(filex.selectedFiles(), function(item) { return item.get('type') }),
122 path = filex.path.full() + '/',
123 dirs = _.map(selected.directory || [], function (item) { return path + item.get('name') }),
124 files = _.map(selected.file || [], function (item) { return path + item.get('name') }),
130 $confirmModal = $('#confirm-modal'),
131 $confirmList = $confirmModal.find('ul').html('');
133 _.each(filex.selectedFiles(), function(item) {
134 $('<li>', {text: item.get('name')}).appendTo($confirmList);
137 $('#btn-confirm').off().on('click', function() {
140 $.post('{% url 'filex:delete' %}', data, function(response) {
141 var keys = Object.keys(response.fail);
144 var $errorModal = $('#error-modal'),
145 $errorBody = $errorModal.find('.modal-body')
146 .html($('<h4>', {text: 'Wystąpiły problemy podczas usuwania:'})),
147 $errorList = $('<dl>', {'class': 'dl-horizontal'}).appendTo($errorBody);
149 $errorModal.find('#error-modal-label').text('Błąd');
151 for (var i in keys) {
152 if(keys.hasOwnProperty(i)) {
153 $('<dt>', {text: keys[i].replace(path, '')}).appendTo($errorList);
154 $('<dd>', {text: response.fail[keys[i]]}).appendTo($errorList);
162 status('Usuwanie zakończone pomyślnie');
165 if (response.done.length)
168 }, 'json').fail(failModal('Nie udało się usunąć plików'));
170 $confirmModal.modal('hide');
173 $confirmModal.modal();
176 $('#mkdir-form').on('submit', function(e) {
181 if (conflictingName($this.find('#id_name').val(), $this))
187 $this.find('#id_host').val(filex.host);
188 $this.find('#id_path').val(filex.path.full());
190 $.post($this.attr('action'), $this.serialize(), function() {
191 status('Katalog utworzono pomyślnie');
193 }, 'json').fail(failModal('Nie udało się utworzyć katalogu'));
196 $('#rename-form').on('show.bs.modal', function() {
197 $(this).find('#id_dst').val(filex.selectedFiles()[0].get('name'));
198 }).on('submit', function(e) {
202 path = filex.path.full() + '/',
203 newName = $this.find('#id_dst').val(),
206 src: path + filex.selectedFiles()[0].get('name'),
210 if (conflictingName(newName, $this))
216 $.post($this.attr('action'), data, function() {
217 status('Nazwę zmieniono pomyślnie');
219 }, 'json').fail(failModal('Nie udało się zmienić nazwy'));
222 $('#compress-form').on('submit', function(e) {
226 name = $this.find('#id_archive').val(),
227 type = $this.find('#id_type').val(),
228 path = filex.path.full(),
229 archive = name + (name.endsWith(type) ? '' : type),
233 files: _.map(filex.selectedFiles(), function (item) { return item.get('name') }),
234 archive: path + '/' + archive
237 if (conflictingName(archive, $this))
243 $.post($this.attr('action'), data, function() {
244 status('Archiwum utworzono pomyślnie');
246 }, 'json').fail(failModal('Nie udało się utworzyć archiwum'));
249 $('#btn-extract').on('click', function() {
254 path: filex.path.full() + '/' + filex.selectedFiles()[0].get('name'),
255 dst: filex.path.full()
258 $.post('{% url 'filex:extract' %}', data, function() {
259 status('Archiwum rozpakowano pomyślnie');
261 }, 'json').fail(failModal('Nie udało się rozpakować archiwum'));
265 {% endblock extra_js %}
267 {% block title %}Zarządzanie plikami GridFTP{% endblock %}
269 {% block container %}
270 {% include 'filex/source.html' %}
272 <div id="confirm-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="confirm-modal-label" aria-hidden="true">
273 <div class="modal-dialog">
274 <div class="modal-content">
275 <div class="modal-header">
276 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
277 <span aria-hidden="true">×</span>
279 <h4 class="modal-title" id="confirm-modal-label">Usuwanie plików</h4>
281 <div class="modal-body">
282 <h4>Czy na pewno usunąć następujące elementy?</h4>
285 <div class="modal-footer">
286 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
287 <button id="btn-confirm" type="button" class="btn btn-primary">OK</button>
293 <div id="error-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="error-modal-label" aria-hidden="true">
294 <div class="modal-dialog">
295 <div class="modal-content">
296 <div class="modal-header">
297 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
298 <span aria-hidden="true">×</span>
300 <h4 class="modal-title" id="error-modal-label"></h4>
302 <div class="modal-body">
304 <div class="modal-footer">
305 <button type="button" class="btn btn-primary" data-dismiss="modal">OK</button>
311 <form id="mkdir-form" action="{% url 'filex:mkdir' %}" class="modal fade form-horizontal" tabindex="-1" role="dialog" aria-labelledby="mkdir-modal-label" aria-hidden="true">
312 <div class="modal-dialog">
313 <div class="modal-content">
314 <div class="modal-header">
315 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
316 <span aria-hidden="true">×</span>
318 <h4 class="modal-title" id="mkdir-modal-label">Nowy katalog</h4>
320 <div class="modal-body">
322 {% bootstrap_form new_dir_form layout='horizontal' %}
324 <div class="modal-footer">
325 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
326 <button type="submit" class="btn btn-primary">OK</button>
332 <form id="rename-form" action="{% url 'filex:move' %}" class="modal fade form-horizontal" tabindex="-1" role="dialog" aria-labelledby="rename-modal-label" aria-hidden="true">
333 <div class="modal-dialog">
334 <div class="modal-content">
335 <div class="modal-header">
336 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
337 <span aria-hidden="true">×</span>
339 <h4 class="modal-title" id="rename-modal-label">Zmień nazwę</h4>
341 <div class="modal-body">
343 {% bootstrap_form rename_form layout='horizontal' %}
345 <div class="modal-footer">
346 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
347 <button type="submit" class="btn btn-primary">OK</button>
353 <form id="compress-form" action="{% url 'filex:compress' %}" class="modal fade form-horizontal" tabindex="-1" role="dialog" aria-labelledby="compress-modal-label" aria-hidden="true">
354 <div class="modal-dialog">
355 <div class="modal-content">
356 <div class="modal-header">
357 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
358 <span aria-hidden="true">×</span>
360 <h4 class="modal-title" id="compress-modal-label">Podaj nazwę archiwum</h4>
362 <div class="modal-body">
364 {% bootstrap_form archive_form layout='horizontal' %}
366 <div class="modal-footer">
367 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
368 <button type="submit" class="btn btn-primary">OK</button>
373 {% endblock container %}
376 <footer class="navbar navbar-default navbar-fixed-bottom">
377 <div class="container">
378 <div class="btn-toolbar" role="toolbar" style="float: left">
379 <div class="btn-group" role="group">
380 <button id="btn-upload" class="btn btn-default navbar-btn">Wgraj plik</button>
381 <button class="btn btn-default navbar-btn" data-toggle="modal" data-target="#mkdir-form">Utwórz katalog</button>
383 <div class="btn-group" role="group">
384 <button id="btn-rename" class="btn btn-default navbar-btn disabled" data-toggle="modal" data-target="#rename-form">Zmień nazwę</button>
385 <button id="btn-delete" class="btn btn-default navbar-btn disabled">Usuń</button>
387 <div class="btn-group" role="group">
388 <button id="btn-compress" class="btn btn-default navbar-btn disabled" data-toggle="modal" data-target="#compress-form">Spakuj</button>
389 <button id="btn-extract" class="btn btn-default navbar-btn disabled">Rozpakuj</button>
392 <p id="status" class="navbar-text"></p>
395 {% endblock footer %}