fixes in selecting files from grid ftp
[qcg-portal.git] / qcg / templates / qcg / job_new.html
index cf00b20..6f829d0 100644 (file)
@@ -9,8 +9,70 @@
     <script src="{% static 'qcg/selectize/selectize.min.js' %}"></script>
     <script src="{% static 'qcg/formset/jquery.formset.js' %}"></script>
 
+    {% include 'filex/source.js.html' %}
+
     <script>
         $(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 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>');
+
             $('#id_application').selectize();
             $('#id_arguments,#id_properties,#id_native').selectize({
                 plugins: ['remove_button'],
@@ -29,7 +91,7 @@
                     }
                 }
             });
-            $('#id_modules, #id_hosts').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>
     </form>
 
+    <div id="gridftp" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modal-label" aria-hidden="true">
+        <div class="modal-dialog modal-lg">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+                    <h4 class="modal-title" id="modal-label">Wybierz plik</h4>
+                </div>
+                <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>
+
 {% endblock %}