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 })) {
57 modal.find('.alert').remove();
60 'class': 'alert alert-danger',
61 html: '<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> Plik o podanej już nazwie istnieje!'
62 }).prependTo(modal.find('.modal-body'));
70 filex.files.on('change:checked reset', function() {
71 var selected = filex.selectedFiles().length;
73 $('#btn-rename').toggleClass('disabled', selected != 1);
74 $('#btn-delete').toggleClass('disabled', selected == 0);
75 $('#btn-compress').toggleClass('disabled', selected == 0);
78 var filename = filex.selectedFiles()[0].get('name'),
79 is_archive = _.some(['.zip', '.tar.gz', '.tgz', '.tar.bz2', 'tbz'], function(ext) {
80 return filename.endsWith(ext);
83 $('#btn-extract').toggleClass('disabled', !is_archive);
86 $('#btn-extract').addClass('disabled');
90 $('#btn-upload').on('click', function() {
91 var url = '{% url 'gridftp_upload' %}?' + $.param({host: filex.host, path: filex.path.full()});
93 var win = window.open(url, url, 'height=500,width=800');
97 $('#btn-delete').on('click', function() {
98 var selected = _.groupBy(filex.selectedFiles(), function(item) { return item.get('type') }),
99 path = filex.path.full() + '/',
100 dirs = _.map(selected.directory || [], function (item) { return path + item.get('name') }),
101 files = _.map(selected.file || [], function (item) { return path + item.get('name') }),
107 $confirmModal = $('#confirm-modal'),
108 $confirmList = $confirmModal.find('ul').html('');
110 _.each(filex.selectedFiles(), function(item) {
111 $('<li>', {text: item.get('name')}).appendTo($confirmList);
114 $('#btn-confirm').off().on('click', function() {
117 $.post('{% url 'filex:delete' %}', data, function(response) {
118 var keys = Object.keys(response.fail);
121 var $errorModal = $('#error-modal'),
122 $errorBody = $errorModal.find('.modal-body')
123 .html($('<h4>', {text: 'Wystąpiły problemy podczas usuwania:'})),
124 $errorList = $('<dl>', {'class': 'dl-horizontal'}).appendTo($errorBody);
126 $errorModal.find('#error-modal-label').text('Błąd');
128 for (var i in keys) {
129 if(keys.hasOwnProperty(i)) {
130 $('<dt>', {text: keys[i].replace(path, '')}).appendTo($errorList);
131 $('<dd>', {text: response.fail[keys[i]]}).appendTo($errorList);
139 status('Usuwanie zakończone pomyślnie');
142 if (response.done.length)
145 }, 'json').fail(failModal('Nie udało się usunąć plików'));
147 $confirmModal.modal('hide');
150 $confirmModal.modal();
153 $('#mkdir-form').on('submit', function(e) {
158 if (conflictingName($this.find('#id_name').val(), $this))
164 $this.find('#id_host').val(filex.host);
165 $this.find('#id_path').val(filex.path.full());
167 $.post($this.attr('action'), $this.serialize(), function() {
168 status('Katalog utworzono pomyślnie');
170 }, 'json').fail(failModal('Nie udało się utworzyć katalogu'));
173 $('#rename-form').on('show.bs.modal', function() {
174 $(this).find('#id_dst').val(filex.selectedFiles()[0].get('name'));
175 }).on('submit', function(e) {
179 path = filex.path.full() + '/',
180 newName = $this.find('#id_dst').val(),
183 src: path + filex.selectedFiles()[0].get('name'),
187 if (conflictingName(newName, $this))
193 $.post($this.attr('action'), data, function() {
194 status('Nazwę zmieniono pomyślnie');
196 }, 'json').fail(failModal('Nie udało się zmienić nazwy'));
199 $('#compress-form').on('submit', function(e) {
203 name = $this.find('#id_archive').val(),
204 type = $this.find('#id_type').val(),
205 path = filex.path.full(),
206 archive = name + (name.endsWith(type) ? '' : type),
210 files: _.map(filex.selectedFiles(), function (item) { return item.get('name') }),
211 archive: path + '/' + archive
214 if (conflictingName(archive, $this))
220 $.post($this.attr('action'), data, function() {
221 status('Archiwum utworzono pomyślnie');
223 }, 'json').fail(failModal('Nie udało się utworzyć archiwum'));
226 $('#btn-extract').on('click', function() {
231 path: filex.path.full() + '/' + filex.selectedFiles()[0].get('name'),
232 dst: filex.path.full()
235 $.post('{% url 'filex:extract' %}', data, function() {
236 status('Archiwum rozpakowano pomyślnie');
238 }, 'json').fail(failModal('Nie udało się rozpakować archiwum'));
242 {% endblock extra_js %}
244 {% block title %}Zarządzanie plikami GridFTP{% endblock %}
246 {% block container %}
247 {% include 'filex/source.html' %}
249 <div id="confirm-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="confirm-modal-label" aria-hidden="true">
250 <div class="modal-dialog">
251 <div class="modal-content">
252 <div class="modal-header">
253 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
254 <span aria-hidden="true">×</span>
256 <h4 class="modal-title" id="confirm-modal-label">Usuwanie plików</h4>
258 <div class="modal-body">
259 <h4>Czy na pewno usunąć następujące elementy?</h4>
262 <div class="modal-footer">
263 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
264 <button id="btn-confirm" type="button" class="btn btn-primary">OK</button>
270 <div id="error-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="error-modal-label" aria-hidden="true">
271 <div class="modal-dialog">
272 <div class="modal-content">
273 <div class="modal-header">
274 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
275 <span aria-hidden="true">×</span>
277 <h4 class="modal-title" id="error-modal-label"></h4>
279 <div class="modal-body">
281 <div class="modal-footer">
282 <button type="button" class="btn btn-primary" data-dismiss="modal">OK</button>
288 <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">
289 <div class="modal-dialog">
290 <div class="modal-content">
291 <div class="modal-header">
292 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
293 <span aria-hidden="true">×</span>
295 <h4 class="modal-title" id="mkdir-modal-label">Nowy katalog</h4>
297 <div class="modal-body">
299 {% bootstrap_form new_dir_form layout='horizontal' %}
301 <div class="modal-footer">
302 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
303 <button type="submit" class="btn btn-primary">OK</button>
309 <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">
310 <div class="modal-dialog">
311 <div class="modal-content">
312 <div class="modal-header">
313 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
314 <span aria-hidden="true">×</span>
316 <h4 class="modal-title" id="rename-modal-label">Zmień nazwę</h4>
318 <div class="modal-body">
320 {% bootstrap_form rename_form layout='horizontal' %}
322 <div class="modal-footer">
323 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
324 <button type="submit" class="btn btn-primary">OK</button>
330 <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">
331 <div class="modal-dialog">
332 <div class="modal-content">
333 <div class="modal-header">
334 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
335 <span aria-hidden="true">×</span>
337 <h4 class="modal-title" id="compress-modal-label">Podaj nazwę archiwum</h4>
339 <div class="modal-body">
341 {% bootstrap_form archive_form layout='horizontal' %}
343 <div class="modal-footer">
344 <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
345 <button type="submit" class="btn btn-primary">OK</button>
350 {% endblock container %}
353 <footer class="navbar navbar-default navbar-fixed-bottom" style="position:fixed">
354 <div class="container">
355 <div class="btn-toolbar" role="toolbar" style="float: left">
356 <div class="btn-group" role="group">
357 <button id="btn-upload" class="btn btn-default navbar-btn">Wgraj plik</button>
358 <button class="btn btn-default navbar-btn" data-toggle="modal" data-target="#mkdir-form">Utwórz katalog</button>
360 <div class="btn-group" role="group">
361 <button id="btn-rename" class="btn btn-default navbar-btn disabled" data-toggle="modal" data-target="#rename-form">Zmień nazwę</button>
362 <button id="btn-delete" class="btn btn-default navbar-btn disabled">Usuń</button>
364 <div class="btn-group" role="group">
365 <button id="btn-compress" class="btn btn-default navbar-btn disabled" data-toggle="modal" data-target="#compress-form">Spakuj</button>
366 <button id="btn-extract" class="btn btn-default navbar-btn disabled">Rozpakuj</button>
369 <p id="status" class="navbar-text"></p>
372 {% endblock footer %}