gridftp ui: limit archive functionality only to moss
[qcg-portal.git] / qcg / templates / qcg / job_new.html
index eb3d973..966c5d2 100644 (file)
     {% include 'filex/source.js.html' %}
 
     <script>
-        $(function() {
-            $('#id_master_file,#id_executable,#id_input,#id_stage_in,#id_preprocess_script,#id_postprocess_script').before(function() {
+        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 $('<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>');
             <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>