fixes in selecting files from grid ftp
[qcg-portal.git] / qcg / templates / qcg / job_new.html
index 37a4fc5..6f829d0 100644 (file)
@@ -3,19 +3,77 @@
 
 {% block extra_css %}
     <link href="{% static 'qcg/selectize/selectize.bootstrap3.css' %}" rel="stylesheet">
-    <link href="{% static 'qcg/datetimepicker/bootstrap-datetimepicker.min.css' %}" rel="stylesheet">
 {% endblock %}
 
 {% block extra_js %}
     <script src="{% static 'qcg/selectize/selectize.min.js' %}"></script>
     <script src="{% static 'qcg/formset/jquery.formset.js' %}"></script>
-    <script src="{% static 'qcg/moment/moment.min.js' %}"></script>
-    <script src="{% static 'qcg/moment/pl.js' %}"></script>
-    <script src="{% static 'qcg/datetimepicker/bootstrap-datetimepicker.min.js' %}"></script>
+
+    {% include 'filex/source.js.html' %}
 
     <script>
         $(function() {
-            $('#id_application, #id_host').selectize();
+            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'],
                 create: true,
@@ -33,7 +91,7 @@
                     }
                 }
             });
-            $('#id_modules').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']
             });
 
                 deleteCssClass: 'delete-btn btn btn-xs btn-danger'
             });
 
-            $('#id_not_before,#id_not_after').datetimepicker({
-                locale: 'pl',
-                minDate: moment()
-            });
-
             $('input[name="notify_type"],input[name="watch_output_type"],input[name="preprocess_type"],input[name="postprocess_type"]').on('change', function () {
                 $(this).tab('show');
             }).each(function() {
                 $('form .collapse').collapse('toggle');
                 $(this).find('span').text(this.text == "Pokaż zaawansowane" ? "Ukryj zaawansowane" : "Pokaż zaawansowane");
             });
-
-            $('#new-env').click(function(e) {
-                e.preventDefault();
-                $('#env-modal').modal('show');
-            });
-
-            $('#env-form').submit(function(e) {
-                e.preventDefault();
-                $('#env-modal').modal('hide');
-
-                $('#id_environment')[0].selectize.createItem($('#id_env_name').val() + '=' + $('#id_env_value').val());
-            });
         });
     </script>
 {% endblock %}
 {% block container %}
     <h1 class="page-header">{% block title %}Zleć zadanie{% endblock %}</h1>
 
+    {% if errors %}
+        <div class="alert alert-danger">
+            <strong>Uwaga!</strong> Formularz zawiera błędy.
+            {{ form.non_field_errors }}
+            {{ env_formset.non_field_errors }}
+        </div>
+    {% endif %}
+
     <form action="." method="post" class="form-horizontal">
         {% csrf_token %}
 
             <li role="presentation"><a href="#resources" data-toggle="tab">Zasoby</a></li>
             <li role="presentation"><a href="#files" data-toggle="tab">Pliki</a></li>
             <li role="presentation"><a href="#environment" data-toggle="tab">Środowisko</a></li>
-            <li role="presentation"><a href="#reservation" data-toggle="tab">Rezerwacja</a></li>
             <li role="presentation"><a href="#monitoring" data-toggle="tab">Powiadomienia</a></li>
             <li role="presentation"><a href="#other" data-toggle="tab">Inne</a></li>
         </ul>
         <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.executable layout="horizontal" form_group_class="form-group collapse"  %}
+                {% 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" %}
-                {% bootstrap_field form.name layout="horizontal" %}
                 {% bootstrap_field form.note layout="horizontal" %}
-                {% bootstrap_field form.grant layout="horizontal" %}
+                {% bootstrap_field form.grant layout="horizontal" form_group_class="form-group collapse" %}
             </fieldset>
 
             <fieldset id="resources" class="tab-pane" role="tabpanel">
-                {% bootstrap_field form.host layout="horizontal" %}
+                {% bootstrap_field form.hosts layout="horizontal" %}
                 {% bootstrap_field form.queue layout="horizontal" %}
+                {% bootstrap_field form.properties layout="horizontal" form_group_class="form-group collapse" %}
+                {% bootstrap_field form.modules layout="horizontal" form_group_class="form-group collapse" %}
                 {% bootstrap_field form.procs layout="horizontal" %}
                 {% bootstrap_field form.nodes layout="horizontal" form_group_class="form-group collapse" %}
-                {% include 'qcg/time_range_field.html' with field_name='wall_time' field=form.wall_time %}
-                {% bootstrap_field form.memory layout="horizontal" %}
-                {% bootstrap_field form.memory_per_slot layout="horizontal" %}
+                {% bootstrap_field form.wall_time layout="horizontal" form_group_class="form-group timerange" %}
+                {% bootstrap_field form.memory layout="horizontal" form_group_class="form-group collapse" %}
+                {% bootstrap_field form.memory_per_slot layout="horizontal" form_group_class="form-group collapse" %}
+                {% bootstrap_field form.reservation layout="horizontal" form_group_class="form-group collapse" %}
             </fieldset>
 
             <fieldset id="files" class="tab-pane" role="tabpanel">
                 {% bootstrap_field form.input layout="horizontal" %}
-                {% bootstrap_field form.output layout="horizontal" %}
-                {% bootstrap_field form.error layout="horizontal" %}
                 {% bootstrap_field form.stage_in layout="horizontal" %}
-                {% bootstrap_field form.stage_out layout="horizontal" %}
+{#                {% bootstrap_field form.stage_out layout="horizontal" form_group_class="form-group collapse" %}#}
             </fieldset>
 
             <fieldset id="environment" class="tab-pane" role="tabpanel">
-                {% bootstrap_field form.properties layout="horizontal" %}
                 {{ env_formset.management_form }}
 
                 <div class="form-group">
                         </div>
                     </div>
                 </div>
-
-                {% bootstrap_field form.modules layout="horizontal" %}
-            </fieldset>
-
-            <fieldset id="reservation" class="tab-pane" role="tabpanel">
-                {% bootstrap_field form.not_before layout="horizontal" %}
-                {% bootstrap_field form.not_after layout="horizontal" %}
-                {% include 'qcg/time_range_field.html' with field_name='deadline' field=form.deadline %}
-                {% bootstrap_field form.reservation layout="horizontal" form_group_class="form-group collapse" %}
             </fieldset>
 
             <fieldset id="monitoring" class="tab-pane" role="tabpanel">
                                 <label class="btn btn-default">
                                     <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
                                             {% if option.is_checked %}checked{% endif %}
-                                            data-target=".notify-type-{{ option.choice_value }}"> {{ option.choice_label }}
+                                            data-target=".notify-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
                                 </label>
                             {% endfor %}
                         </div>
                     </div>
                 </div>
 
-                <div class="form-group">
-                    <label class="col-sm-3 col-md-4 control-label">Monitorowanie wyjścia</label>
-                    <div class="col-sm-9 col-md-6">
-                        <div class="btn-group" data-toggle="buttons">
-                            {% for option in form.watch_output_type %}
-                                <label class="btn btn-default">
-                                    <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
-                                            {% if option.is_checked %}checked{% endif %}
-                                            data-target=".watch-output-type-{{ option.choice_value }}"> {{ option.choice_label }}
-                                </label>
-                            {% endfor %}
+                <div class="collapse">
+                    <div class="form-group">
+                        <label class="col-sm-3 col-md-4 control-label">Monitorowanie wyjścia</label>
+                        <div class="col-sm-9 col-md-6">
+                            <div class="btn-group" data-toggle="buttons">
+                                {% for option in form.watch_output_type %}
+                                    <label class="btn btn-default">
+                                        <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
+                                                {% if option.is_checked %}checked{% endif %}
+                                                data-target=".watch-output-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
+                                    </label>
+                                {% endfor %}
+                            </div>
                         </div>
                     </div>
-                </div>
 
-                <div class="tab-content">
-                    <div class="tab-pane watch-output-type-0"></div>
+                    <div class="tab-content">
+                        <div class="tab-pane watch-output-type-0"></div>
 
-                    <div class="tab-pane watch-output-type-1 watch-output-type-2" style="margin-top: 15px">
-                        {% bootstrap_field form.watch_output_address layout="horizontal" %}
-                        {% bootstrap_field form.watch_output_pattern layout="horizontal" %}
+                        <div class="tab-pane watch-output-type-1 watch-output-type-2" style="margin-top: 15px">
+                            {% bootstrap_field form.watch_output_address layout="horizontal" %}
+                            {% bootstrap_field form.watch_output_pattern layout="horizontal" %}
+                        </div>
                     </div>
                 </div>
             </fieldset>
                                 <label class="btn btn-default">
                                     <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
                                             {% if option.is_checked %}checked{% endif %}
-                                            data-target=".preprocess-type-{{ option.choice_value }}"> {{ option.choice_label }}
+                                            data-target=".preprocess-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
                                 </label>
                             {% endfor %}
                         </div>
                                 <label class="btn btn-default">
                                     <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
                                             {% if option.is_checked %}checked{% endif %}
-                                            data-target=".postprocess-type-{{ option.choice_value }}"> {{ option.choice_label }}
+                                            data-target=".postprocess-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
                                 </label>
                             {% endfor %}
                         </div>
 
                 {% bootstrap_field form.native layout="horizontal" %}
                 {% bootstrap_checkbox form.persistent %}
-                {% bootstrap_checkbox form.use_scratch %}
             </fieldset>
         </div>
 
         </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 %}