+ var win = window.open(url, url, 'height=500,width=800');
+ win.focus();
+ });
+
+ $('#btn-delete').on('click', function() {
+ var selected = _.groupBy(filex.selectedFiles(), function(item) { return item.get('type') }),
+ dirs = _.map(selected.directory || [], function (item) { return item.get('name') }),
+ files = _.map(selected.file || [], function (item) { return item.get('name') }),
+ data = {
+ host: filex.host,
+ path: filex.path.full() + '/',
+ dirs: dirs,
+ files: files
+ },
+ $confirmModal = $('#confirm-modal'),
+ $confirmList = $confirmModal.find('ul').html('');
+
+ _.each(filex.selectedFiles(), function(item) {
+ $('<li>', {text: item.get('name')}).appendTo($confirmList);
+ });
+
+ $('#btn-confirm').off().on('click', function() {
+ filex.busy();
+
+ $.post('{% url 'filex:delete' %}', data, function(response) {
+ var keys = Object.keys(response.fail);
+
+ if (keys.length) {
+ var $errorModal = $('#error-modal'),
+ $errorBody = $errorModal.find('.modal-body')
+ .html($('<h4>', {text: 'Wystąpiły problemy podczas usuwania:'})),
+ $errorList = $('<dl>', {'class': 'dl-horizontal'}).appendTo($errorBody);
+
+ $errorModal.find('#error-modal-label').text('Błąd');
+
+ for (var i in keys) {
+ $('<dt>', {text: keys[i]}).appendTo($errorList);
+ $('<dd>', {text: response.fail[keys[i]]}).appendTo($errorList);
+ }
+
+ $errorModal.modal();
+ filex.idle();
+ }
+ else {
+ status('Usuwanie zakończone pomyślnie');
+ }
+
+ if (response.done.length)
+ filex.reloadFiles();
+
+ }, 'json').fail(failModal('Nie udało się usunąć plików'));
+
+ $confirmModal.modal('hide');
+ });
+
+ $confirmModal.modal();
+ });
+
+ $('#mkdir-form').on('submit', function(e) {
+ var $this = $(this);
+
+ e.preventDefault();
+ filex.busy();
+ $this.modal('hide');
+
+ $this.find('#id_host').val(filex.host);
+ $this.find('#id_path').val(filex.path.full());
+
+ $.post($this.attr('action'), $this.serialize(), function() {
+ status('Katalog utworzono pomyślnie');
+ filex.reloadFiles();
+ }, 'json').fail(failModal('Nie udało się utworzyć katalogu'));
+ });
+
+ $('#rename-form').on('show.bs.modal', function() {
+ var $this = $(this);
+
+ var file = filex.selectedFiles()[0];
+
+ $this.find('#id_host').val(filex.host);
+ $this.find('#id_path').val(filex.path.full());
+ $this.find('#id_src').val(file.get('name'));
+ $this.find('#id_dst').val(file.get('name'));
+ }).on('submit', function(e) {
+ var $this = $(this);
+
+ e.preventDefault();
+ filex.busy();
+ $this.modal('hide');
+
+ $.post($this.attr('action'), $this.serialize(), function() {
+ status('Nazwę zmieniono pomyślnie');
+ filex.reloadFiles();
+ }, 'json').fail(failModal('Nie udało się zmienić nazwy'));
+ });