1 {% extends 'qcg/base.html' %}
2 {% load staticfiles bootstrap3 %}
5 <link href="{% static 'qcg/selectize/selectize.bootstrap3.css' %}" rel="stylesheet">
9 <script src="{% static 'qcg/cookie/jquery.cookie.min.js' %}"></script>
10 <script src="{% static 'qcg/globals.js' %}"></script>
11 {% include 'filex/source.js.html' %}
14 var filex = filex || {};
23 String.prototype.endsWith = function(suffix) {
24 return this.indexOf(suffix, this.length - suffix.length) !== -1;
27 function status(msg) {
28 clearTimeout(statusTimeout);
29 statusTimeout = setTimeout(function() {
30 $('#status').text('');
33 $('#status').text(msg);
36 function failModal(msg) {
37 return function(xhr) {
38 var $errorModal = $('#error-modal');
40 $errorModal.find('#error-modal-label').text('Błąd serwera');
41 $errorModal.find('.modal-body').html($('<h4>', {text: msg}));
43 var error = (xhr.responseJSON || {}).error || undefined;
45 if (typeof error === 'string')
46 $errorModal.find('.modal-body').append($('<pre>', {text: error}));
51 console.error(arguments);
55 function conflictingName(name, modal) {
56 if (filex.files.some(function(item) { return item.get('name') == name })) {
58 'class': 'alert alert-danger',
59 html: '<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> Plik o podanej już nazwie istnieje!'
60 }).prependTo(modal.find('.modal-body'));
68 filex.files.on('change:checked reset', function() {
69 var selected = filex.selectedFiles().length;
71 $('#btn-rename').toggleClass('disabled', selected != 1);
72 $('#btn-delete').toggleClass('disabled', selected == 0);
73 $('#btn-compress').toggleClass('disabled', filex.host != 'moss.man.poznan.pl' || selected == 0);
75 if (filex.host == 'moss.man.poznan.pl' && selected == 1) {
76 var filename = filex.selectedFiles()[0].get('name'),
77 is_archive = _.some(['.zip', '.tar.gz', '.tgz', '.tar.bz2', 'tbz'], function(ext) {
78 return filename.endsWith(ext);
81 $('#btn-extract').toggleClass('disabled', !is_archive);
84 $('#btn-extract').addClass('disabled');
88 $('form').on('show.bs.modal', function() {
89 $(this).find('.alert').remove();
91 }).on('shown.bs.modal', function() {
92 $(this).find('input[type="text"]')[0].focus();
95 $('#btn-upload').on('click', function() {
96 var url = '{% url 'gridftp_upload' %}?' + $.param({host: filex.host, path: filex.path.full()});
98 var win = window.open(url, url, 'height=500,width=800');
102 $('#btn-delete').on('click', function() {
103 var selected = _.groupBy(filex.selectedFiles(), function(item) { return item.get('type') }),
104 path = filex.path.full() + '/',
105 dirs = _.map(selected.directory || [], function (item) { return path + item.get('name') }),
106 files = _.map(selected.file || [], function (item) { return path + item.get('name') }),
112 $confirmModal = $('#confirm-modal'),
113 $confirmList = $confirmModal.find('ul').html('');
115 _.each(filex.selectedFiles(), function(item) {
116 $('<li>', {text: item.get('name')}).appendTo($confirmList);
119 $('#btn-confirm').off().on('click', function() {
122 $.post('{% url 'filex:delete' %}', data, function(response) {
123 var keys = Object.keys(response.fail);
126 var $errorModal = $('#error-modal'),
127 $errorBody = $errorModal.find('.modal-body')
128 .html($('<h4>', {text: 'Wystąpiły problemy podczas usuwania:'})),
129 $errorList = $('<dl>', {'class': 'dl-horizontal'}).appendTo($errorBody);
131 $errorModal.find('#error-modal-label').text('Błąd');
133 for (var i in keys) {
134 if(keys.hasOwnProperty(i)) {
135 $('<dt>', {text: keys[i].replace(path, '')}).appendTo($errorList);
136 $('<dd>', {text: response.fail[keys[i]]}).appendTo($errorList);
144 status('Usuwanie zakończone pomyślnie');
147 if (response.done.length)
150 }, 'json').fail(failModal('Nie udało się usunąć plików'));
152 $confirmModal.modal('hide');
155 $confirmModal.modal();
158 $('#mkdir-form').on('submit', function(e) {
163 if (conflictingName($this.find('#id_name').val(), $this))
169 $this.find('#id_host').val(filex.host);
170 $this.find('#id_path').val(filex.path.full());
172 $.post($this.attr('action'), $this.serialize(), function() {
173 status('Katalog utworzono pomyślnie');
175 }, 'json').fail(failModal('Nie udało się utworzyć katalogu'));
178 $('#rename-form').on('show.bs.modal', function() {
179 $(this).find('#id_dst').val(filex.selectedFiles()[0].get('name'));
180 }).on('submit', function(e) {
184 path = filex.path.full() + '/',
185 newName = $this.find('#id_dst').val(),
188 src: path + filex.selectedFiles()[0].get('name'),
192 if (conflictingName(newName, $this))
198 $.post($this.attr('action'), data, function() {
199 status('Nazwę zmieniono pomyślnie');
201 }, 'json').fail(failModal('Nie udało się zmienić nazwy'));
204 $('#compress-form').on('submit', function(e) {
208 name = $this.find('#id_archive').val(),
209 type = $this.find('#id_type').val(),
210 path = filex.path.full(),
211 archive = name + (name.endsWith(type) ? '' : type),
215 files: _.map(filex.selectedFiles(), function (item) { return item.get('name') }),
216 archive: path + '/' + archive
219 if (conflictingName(archive, $this))
225 $.post($this.attr('action'), data, function() {
226 status('Archiwum utworzono pomyślnie');
228 }, 'json').fail(failModal('Nie udało się utworzyć archiwum'));
231 $('#btn-extract').on('click', function() {
236 path: filex.path.full() + '/' + filex.selectedFiles()[0].get('name'),
237 dst: filex.path.full()
240 $.post('{% url 'filex:extract' %}', data, function() {
241 status('Archiwum rozpakowano pomyślnie');
243 }, 'json').fail(failModal('Nie udało się rozpakować archiwum'));
247 {% endblock extra_js %}
249 {% block title %}Zarządzanie plikami GridFTP{% endblock %}
251 {% block container %}
252 {% include 'filex/source.html' %}
254 <div id="confirm-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="confirm-modal-label" aria-hidden="true">
255 <div class="modal-dialog">
256 <div class="modal-content">
257 <div class="modal-header">
258 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
259 <span aria-hidden="true">×</span>
261 <h4 class="modal-title" id="confirm-modal-label">Usuwanie plików</h4>
263 <div class="modal-body">
264 <h4>Czy na pewno usunąć następujące elementy?</h4>
267 <div class="modal-footer">
268 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
269 <button id="btn-confirm" type="button" class="btn btn-primary">OK</button>
275 <div id="error-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="error-modal-label" aria-hidden="true">
276 <div class="modal-dialog">
277 <div class="modal-content">
278 <div class="modal-header">
279 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
280 <span aria-hidden="true">×</span>
282 <h4 class="modal-title" id="error-modal-label"></h4>
284 <div class="modal-body">
286 <div class="modal-footer">
287 <button type="button" class="btn btn-primary" data-dismiss="modal">OK</button>
293 <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">
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="mkdir-modal-label">Nowy katalog</h4>
302 <div class="modal-body">
304 {% bootstrap_form new_dir_form layout='horizontal' %}
306 <div class="modal-footer">
307 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
308 <button type="submit" class="btn btn-primary">OK</button>
314 <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">
315 <div class="modal-dialog">
316 <div class="modal-content">
317 <div class="modal-header">
318 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
319 <span aria-hidden="true">×</span>
321 <h4 class="modal-title" id="rename-modal-label">Zmień nazwę</h4>
323 <div class="modal-body">
325 {% bootstrap_form rename_form layout='horizontal' %}
327 <div class="modal-footer">
328 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
329 <button type="submit" class="btn btn-primary">OK</button>
335 <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">
336 <div class="modal-dialog">
337 <div class="modal-content">
338 <div class="modal-header">
339 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
340 <span aria-hidden="true">×</span>
342 <h4 class="modal-title" id="compress-modal-label">Podaj nazwę archiwum</h4>
344 <div class="modal-body">
346 {% bootstrap_form archive_form layout='horizontal' %}
348 <div class="modal-footer">
349 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
350 <button type="submit" class="btn btn-primary">OK</button>
355 {% endblock container %}
358 <footer class="navbar navbar-default navbar-fixed-bottom" style="position:fixed">
359 <div class="container">
360 <div class="btn-toolbar" role="toolbar" style="float: left">
361 <div class="btn-group" role="group">
362 <button id="btn-upload" class="btn btn-default navbar-btn">Wgraj plik</button>
363 <button class="btn btn-default navbar-btn" data-toggle="modal" data-target="#mkdir-form">Utwórz katalog</button>
365 <div class="btn-group" role="group">
366 <button id="btn-rename" class="btn btn-default navbar-btn disabled" data-toggle="modal" data-target="#rename-form">Zmień nazwę</button>
367 <button id="btn-delete" class="btn btn-default navbar-btn disabled">Usuń</button>
369 <div class="btn-group" role="group">
370 <button id="btn-compress" class="btn btn-default navbar-btn disabled" data-toggle="modal" data-target="#compress-form">Spakuj</button>
371 <button id="btn-extract" class="btn btn-default navbar-btn disabled">Rozpakuj</button>
374 <p id="status" class="navbar-text"></p>
377 {% endblock footer %}