3 <script src="{% static 'filex/fileupload/jquery.ui.widget.js' %}"></script>
4 <script src="{% static 'filex/fileupload/jquery.iframe-transport.js' %}"></script>
5 <script src="{% static 'filex/fileupload/jquery.fileupload.js' %}"></script>
6 <script src="{% static 'filex/underscore/underscore-min.js' %}"></script>
7 <script src="{% static 'filex/humanize/humanize-duration.js' %}"></script>
8 <script src="{% static 'qcg/moment/moment.min.js' %}"></script>
9 <script src="{% static 'qcg/moment/pl.js' %}"></script>
15 var host = '{{ host }}',
17 template = _.template($('#template').html()),
18 conflictTemplate = _.template($('#conflict-template').html()),
19 $conflictStack = $.when(),
20 $conflict = $('#conflict').modal({
27 function humanBytes(bytes, no_unit) {
28 function format(val, unit) {
32 return val + ' ' + unit;
36 return format('0', 'B');
39 sizes = ['B', 'KB', 'MB', 'GB', 'TB'],
40 i = Math.floor(Math.log(bytes) / Math.log(k));
42 return format((bytes / Math.pow(k, i)).toFixed(1), sizes[i]);
45 $('#files').fileupload({
46 sequentialUploads: true,
47 add: function (e, data) {
48 var file = data.files[0];
50 data.context = $(template(file));
51 $('#elements').append(data.context);
55 submit: function (e, data) {
56 var file = data.files[0],
59 data.context.find('.progress-info').text('Przetwarzanie');
61 function finish(action) {
62 if (action == 'replace')
63 data.jqXHR = $this.fileupload('send', data);
65 data.context.find('.progress-info').text('Pominięto');
68 $.getJSON('{% url 'filex:info' %}', {host: host, path: path + '/' + file.name}, function(response) {
69 if (applyToAll != undefined) {
74 $conflictStack = $conflictStack.then(function() {
75 if (applyToAll != undefined) {
80 var deferred = $.Deferred();
82 $conflict.one('hidden.bs.modal', function() {
86 $('#btn-skip').off().on('click', function() {
87 if ($('#apply-to-all').prop('checked')) {
91 $conflict.modal('hide');
94 $('#btn-replace').off().on('click', function() {
95 if ($('#apply-to-all').prop('checked')) {
96 applyToAll = 'replace';
99 $conflict.modal('hide');
103 $conflict.find('.modal-body').html(conflictTemplate({
105 srcDate: moment(file.lastModified),
106 srcSize: humanBytes(file.size),
107 dstDate: moment(response.date),
108 dstSize: humanBytes(response.size)
110 $conflict.modal('show');
112 return deferred.promise();
115 }).fail(function(xhr, textStatus) {
116 // if file does not exist we are good to go
117 if (xhr.status == 404)
120 data.context.find('.progress-info').text('Błąd');
121 console.error("Info query failed: " + textStatus);
127 progress: function (e, data) {
128 var progress = parseInt(data.loaded / data.total * 100, 10);
130 data.context.find('.progress-bar').css('width', progress+'%').attr('aria-valuenow', data.loaded);
131 data.context.find('.progress-bar span').text(progress+'%');
133 if (data.loaded < data.total) {
134 data.context.find('.bit-rate').text(humanBytes(data.bitrate / 8) + '/s');
135 data.context.find('.progress-info').text(humanBytes(data.loaded, true) + ' / ' + humanBytes(data.total));
138 progressall: function (e, data) {
139 var remaining = (data.total - data.loaded) / (data.bitrate / 8);
142 $('#btn-close').hide();
143 $('#status').text('Pozostało ' + (humanizeDuration(remaining * 1000, {language: 'pl', round: true}) || 'kilka sekund'));
146 $('#btn-close').show();
147 $('#status').text('');
150 done: function (e, data) {
151 data.context.find('.bit-rate').text('');
152 data.context.find('.progress-info').text('Zakończono');
154 fail: function (e, data) {
155 data.context.find('.progress-info').text((data.jqXHR.responseJSON || {}).error || 'Błąd');
160 $(window).on('beforeunload', function() {
161 var $files = $('#files');
162 if ($files.length && $files.fileupload('active'))
163 return 'Nie zakończono przesyłania wszystkich plików, czy chcesz kontynuować?';
166 $(window).on('dragenter dragleave drop', function() {
167 $('#drop-overlay').toggleClass('in');
173 <script type="text/template" id="template">
175 <div class="text clearfix">
176 <span class="name"><%= name %></span>
177 <span class="status pull-right">
178 <em class="small bit-rate" style="margin-right: 15px"></em>
179 <span class="text-muted progress-info">Oczekiwanie</span>
183 <div class="progress">
184 <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="<%= size %>" style="width: 0;">
185 <span class="sr-only">0%</span>
191 <script type="text/template" id="conflict-template">
192 <h4>W wybranej lokalizacji plik on nazwie <em><%= name %></em> już istnieje!</h4>
194 <table class="table">
204 <th scope="row">Data modyfikacji</th>
205 <td><%= srcDate.format('D MMM YYYY, h:mm') %></td>
206 <td><%= dstDate.format('D MMM YYYY, h:mm') %></td>
209 <th scope="row">Rozmiar</th>
210 <td><%= srcSize %></td>
211 <td><%= dstSize %></td>