+ var filex = filex || {};
+
+ $(function () {
+ 'use strict';
+
+ var gridftpButton = $('<button/>', {
+ 'type': 'button',
+ 'class': 'btn btn-default pull-right',
+ 'text': 'Wybierz',
+ 'data-toggle': 'modal',
+ 'data-target': '#gridftp'
+ });
+
+ function fullPath(path, file) {
+ var res = path + file.get('name');
+
+ if (file.isDir())
+ res += '/';
+
+ return res;
+ }
+
+ $('#id_master_file,#id_executable,#id_input,#id_preprocess_script,#id_postprocess_script').before(function() {
+ var target = this;
+ return gridftpButton.clone().click(function() {
+ $('#select-btn').off().click(function() {
+ var selected = filex.selectedFiles();
+
+ if (selected.length != 1 || !selected[0].isFile()) {
+ alert('Wybierz dokładnie jeden plik.');
+ return;
+ }
+
+ var file = fullPath(filex.host + '/' + filex.path.full() + '/', selected[0]);
+
+ target.selectize.clear();
+ target.selectize.addOption({value: file, text: file});
+ target.selectize.addItem(file);
+ target.selectize.refreshItems();
+
+ $('#gridftp').modal('hide');
+ filex.clearSelection();
+ });
+ });
+ }).wrap('<div style="margin-right: 80px"></div>');
+
+ $('#id_stage_in').before(function() {
+ var target = this;
+ return gridftpButton.clone().click(function() {
+ $('#select-btn').off().click(function() {
+ var path = filex.host + '/' + filex.path.full() + '/';
+
+ _.each(filex.selectedFiles(), function(item) {
+ var file = fullPath(path, item);
+ target.selectize.addOption({value: file, text: file});
+ target.selectize.addItem(file);
+ });
+ target.selectize.refreshItems();
+
+ $('#gridftp').modal('hide');
+ filex.clearSelection();
+ });
+ });
+ }).wrap('<div style="margin-right: 80px"></div>');
+