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) {
38 var $errorModal = $('#error-modal');
40 $errorModal.find('#error-modal-label').text('Błąd serwera');
41 $errorModal.find('.modal-body').html($('<h4>', {text: msg}));
46 console.error(arguments);
50 filex.files.on('change:checked reset', function() {
51 var selected = filex.selectedFiles().length;
53 $('#btn-rename').toggleClass('disabled', selected != 1);
54 $('#btn-delete').toggleClass('disabled', selected == 0);
55 $('#btn-compress').toggleClass('disabled', selected == 0);
58 var filename = filex.selectedFiles()[0].get('name'),
59 is_archive = _.some(['.zip', '.tar.gz', '.tgz', '.tar.bz2', 'tbz'], function(ext) {
60 return filename.endsWith(ext);
63 $('#btn-extract').toggleClass('disabled', !is_archive);
66 $('#btn-extract').addClass('disabled');
70 $('#btn-upload').on('click', function() {
71 var url = '{% url 'gridftp_upload' %}?' + $.param({host: filex.host, path: filex.path.full() + '/'});
73 var win = window.open(url, url, 'height=500,width=800');
77 $('#btn-delete').on('click', function() {
78 var selected = _.groupBy(filex.selectedFiles(), function(item) { return item.get('type') }),
79 dirs = _.map(selected.directory || [], function (item) { return item.get('name') }),
80 files = _.map(selected.file || [], function (item) { return item.get('name') }),
83 path: filex.path.full() + '/',
87 $confirmModal = $('#confirm-modal'),
88 $confirmList = $confirmModal.find('ul').html('');
90 _.each(filex.selectedFiles(), function(item) {
91 $('<li>', {text: item.get('name')}).appendTo($confirmList);
94 $('#btn-confirm').off().on('click', function() {
97 $.post('{% url 'filex:delete' %}', data, function(response) {
98 var keys = Object.keys(response.fail);
101 var $errorModal = $('#error-modal'),
102 $errorBody = $errorModal.find('.modal-body')
103 .html($('<h4>', {text: 'Wystąpiły problemy podczas usuwania:'})),
104 $errorList = $('<dl>', {'class': 'dl-horizontal'}).appendTo($errorBody);
106 $errorModal.find('#error-modal-label').text('Błąd');
108 for (var i in keys) {
109 $('<dt>', {text: keys[i]}).appendTo($errorList);
110 $('<dd>', {text: response.fail[keys[i]]}).appendTo($errorList);
117 status('Usuwanie zakończone pomyślnie');
120 if (response.done.length)
123 }, 'json').fail(failModal('Nie udało się usunąć plików'));
125 $confirmModal.modal('hide');
128 $confirmModal.modal();
131 $('#mkdir-form').on('submit', function(e) {
138 $this.find('#id_host').val(filex.host);
139 $this.find('#id_path').val(filex.path.full());
141 $.post($this.attr('action'), $this.serialize(), function() {
142 status('Katalog utworzono pomyślnie');
144 }, 'json').fail(failModal('Nie udało się utworzyć katalogu'));
147 $('#rename-form').on('show.bs.modal', function() {
150 var file = filex.selectedFiles()[0];
152 $this.find('#id_host').val(filex.host);
153 $this.find('#id_path').val(filex.path.full());
154 $this.find('#id_src').val(file.get('name'));
155 $this.find('#id_dst').val(file.get('name'));
156 }).on('submit', function(e) {
163 $.post($this.attr('action'), $this.serialize(), function() {
164 status('Nazwę zmieniono pomyślnie');
166 }, 'json').fail(failModal('Nie udało się zmienić nazwy'));
169 $('#compress-form').on('submit', function(e) {
173 name = $this.find('#id_name').val(),
174 type = $this.find('#id_type').val(),
175 archive = name + (name.endsWith(type) ? '' : type),
178 path: filex.path.full(),
179 files: _.map(filex.selectedFiles(), function (item) { return item.get('name') }),
183 // check if maybe file with given name exists
184 if (filex.files.some(function(item) { return item.get('name') == archive })) {
185 $this.find('.alert').remove();
188 'class': 'alert alert-danger',
189 html: '<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> Plik o podanej już nazwie istnieje!'
190 }).prependTo($this.find('.modal-body'));
198 $.post($this.attr('action'), data, function() {
199 status('Archiwum utworzono pomyślnie');
201 }, 'json').fail(failModal('Nie udało się utworzyć archiwum'));
204 $('#btn-extract').on('click', function() {
209 archive: filex.path.full() + '/' + filex.selectedFiles()[0].get('name'),
210 dst: filex.path.full()
213 $.post('{% url 'filex:extract' %}', data, function() {
214 status('Archiwum rozpakowano pomyślnie');
216 }, 'json').fail(failModal('Nie udało się rozpakować archiwum'));
220 {% endblock extra_js %}
222 {% block title %}Zarządzanie plikami GridFTP{% endblock %}
224 {% block container %}
225 {% include 'filex/source.html' %}
227 <div id="confirm-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="confirm-modal-label" aria-hidden="true">
228 <div class="modal-dialog">
229 <div class="modal-content">
230 <div class="modal-header">
231 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
232 <span aria-hidden="true">×</span>
234 <h4 class="modal-title" id="confirm-modal-label">Usuwanie plików</h4>
236 <div class="modal-body">
237 <h4>Czy na pewno usunąć następujące elementy?</h4>
240 <div class="modal-footer">
241 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
242 <button id="btn-confirm" type="button" class="btn btn-primary">OK</button>
248 <div id="error-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="error-modal-label" aria-hidden="true">
249 <div class="modal-dialog">
250 <div class="modal-content">
251 <div class="modal-header">
252 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
253 <span aria-hidden="true">×</span>
255 <h4 class="modal-title" id="error-modal-label"></h4>
257 <div class="modal-body">
259 <div class="modal-footer">
260 <button type="button" class="btn btn-primary" data-dismiss="modal">OK</button>
266 <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">
267 <div class="modal-dialog">
268 <div class="modal-content">
269 <div class="modal-header">
270 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
271 <span aria-hidden="true">×</span>
273 <h4 class="modal-title" id="mkdir-modal-label">Nowy katalog</h4>
275 <div class="modal-body">
277 {% bootstrap_form new_dir_form layout='horizontal' %}
279 <div class="modal-footer">
280 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
281 <button type="submit" class="btn btn-primary">OK</button>
287 <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">
288 <div class="modal-dialog">
289 <div class="modal-content">
290 <div class="modal-header">
291 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
292 <span aria-hidden="true">×</span>
294 <h4 class="modal-title" id="rename-modal-label">Zmień nazwę</h4>
296 <div class="modal-body">
298 {% bootstrap_form rename_form layout='horizontal' %}
300 <div class="modal-footer">
301 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
302 <button type="submit" class="btn btn-primary">OK</button>
308 <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">
309 <div class="modal-dialog">
310 <div class="modal-content">
311 <div class="modal-header">
312 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
313 <span aria-hidden="true">×</span>
315 <h4 class="modal-title" id="compress-modal-label">Podaj nazwę archiwum</h4>
317 <div class="modal-body">
319 {% bootstrap_form archive_form layout='horizontal' %}
321 <div class="modal-footer">
322 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
323 <button type="submit" class="btn btn-primary">OK</button>
328 {% endblock container %}
331 <footer class="navbar navbar-default navbar-fixed-bottom" style="position:fixed">
332 <div class="container">
333 <div class="btn-toolbar" role="toolbar" style="float: left">
334 <div class="btn-group" role="group">
335 <button id="btn-upload" class="btn btn-default navbar-btn">Wgraj plik</button>
336 <button class="btn btn-default navbar-btn" data-toggle="modal" data-target="#mkdir-form">Utwórz katalog</button>
338 <div class="btn-group" role="group">
339 <button id="btn-rename" class="btn btn-default navbar-btn disabled" data-toggle="modal" data-target="#rename-form">Zmień nazwę</button>
340 <button id="btn-delete" class="btn btn-default navbar-btn disabled">Usuń</button>
342 <div class="btn-group" role="group">
343 <button id="btn-compress" class="btn btn-default navbar-btn disabled" data-toggle="modal" data-target="#compress-form">Spakuj</button>
344 <button id="btn-extract" class="btn btn-default navbar-btn disabled">Rozpakuj</button>
347 <p id="status" class="navbar-text"></p>
350 {% endblock footer %}