fixes in selecting files from grid ftp
[qcg-portal.git] / qcg / templates / qcg / job_new.html
index fca86fe..6f829d0 100644 (file)
 
     <script>
         $(function() {
-            $('#id_executable,#id_input,#id_stage_in,#id_preprocess_script,#id_postprocess_script').before(function() {
+            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 $('<button/>', {
-                    'type': 'button',
-                    'class': 'btn btn-default pull-right',
-                    'text': 'Wybierz',
-                    'data-toggle': 'modal',
-                    'data-target': '#gridftp'
-                }).click(function() {
-                    filex.once('selected:file', function(file) {
+                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>');
@@ -49,7 +91,7 @@
                     }
                 }
             });
-            $('#id_modules,#id_hosts,#id_executable,#id_input,#id_stage_in,#id_preprocess_script,#id_postprocess_script').selectize({
+            $('#id_modules,#id_hosts,#id_master_file,#id_executable,#id_input,#id_stage_in,#id_preprocess_script,#id_postprocess_script').selectize({
                 plugins: ['remove_button']
             });
 
         <div class="tab-content">
             <fieldset id="basic" class="tab-pane active" role="tabpanel">
                 {% bootstrap_field form.application layout="horizontal" %}
-                <div class="row" style="margin-top: -15px; margin-bottom: 15px">
-                    <div class="col-sm-offset-3 col-md-offset-4 col-sm-9 col-md-6">
-                        {# TODO grid ftp #}
-                        <a id="add-main-file" href="#">wybierz plik główny &raquo;</a>
-                    </div>
-                </div>
-
+                {% bootstrap_field form.master_file layout="horizontal" %}
                 {% bootstrap_field form.executable layout="horizontal" form_group_class="form-group collapse" %}
                 {% bootstrap_field form.script layout="horizontal" form_group_class="form-group collapse" %}
                 {% bootstrap_field form.arguments layout="horizontal" %}
             <fieldset id="files" class="tab-pane" role="tabpanel">
                 {% bootstrap_field form.input layout="horizontal" %}
                 {% bootstrap_field form.stage_in layout="horizontal" %}
-                {% bootstrap_field form.stage_out layout="horizontal" form_group_class="form-group collapse" %}
+{#                {% bootstrap_field form.stage_out layout="horizontal" form_group_class="form-group collapse" %}#}
             </fieldset>
 
             <fieldset id="environment" class="tab-pane" role="tabpanel">
                 <div class="modal-body">
                     {% include 'filex/source.html' %}
                 </div>
+                <div class="modal-footer">
+                    <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
+                    <button id="select-btn" type="button" class="btn btn-primary">Wybierz</button>
+                </div>
             </div>
         </div>
     </div>