83e90254b4ec4f2d747370e4247ff61c29ecca0b
[qcg-portal.git] / qcg / templates / qcg / job_submit.html
1 {% extends 'qcg/base.html' %}
2 {% load staticfiles bootstrap3 %}
3
4 {% block extra_css %}
5     <link href="{% static 'qcg/selectize/selectize.bootstrap3.css' %}" rel="stylesheet">
6 {% endblock %}
7
8 {% block extra_js %}
9     <script src="{% static 'qcg/selectize/selectize.min.js' %}"></script>
10     <script src="{% static 'qcg/formset/jquery.formset.js' %}"></script>
11
12     {% include 'filex/source.js.html' %}
13
14     <script>
15         var filex = filex || {};
16
17         $(function () {
18             'use strict';
19
20             var gridftpButton = $('<button/>', {
21                 'type': 'button',
22                 'class': 'btn btn-default pull-right',
23                 'text': 'Wybierz',
24                 'data-toggle': 'modal',
25                 'data-target': '#gridftp'
26             });
27
28             function fullPath(path, file) {
29                 var res = path + file.get('name');
30
31                 if (file.isDir())
32                     res += '/';
33
34                 return res;
35             }
36
37             $('#id_master_file,#id_executable,#id_input,#id_preprocess_script,#id_postprocess_script').before(function() {
38                 var target = this;
39                 return gridftpButton.clone().click(function() {
40                     $('#select-btn').off().click(function() {
41                         var selected = filex.selectedFiles();
42
43                         if (selected.length != 1 || !selected[0].isFile()) {
44                             alert('Wybierz dokładnie jeden plik.');
45                             return;
46                         }
47
48                         var file = fullPath(filex.host + '/' + filex.path.full() + '/', selected[0]);
49
50                         target.selectize.clear();
51                         target.selectize.addOption({value: file, text: file});
52                         target.selectize.addItem(file);
53                         target.selectize.refreshItems();
54
55                         $('#gridftp').modal('hide');
56                         filex.clearSelection();
57                     });
58                 });
59             }).wrap('<div style="margin-right: 80px"></div>');
60
61             $('#id_stage_in').before(function() {
62                 var target = this;
63                 return gridftpButton.clone().click(function() {
64                     $('#select-btn').off().click(function() {
65                         var path = filex.host + '/' + filex.path.full() + '/';
66
67                         _.each(filex.selectedFiles(), function(item) {
68                             var file = fullPath(path, item);
69                             target.selectize.addOption({value: file, text: file});
70                             target.selectize.addItem(file);
71                         });
72                         target.selectize.refreshItems();
73
74                         $('#gridftp').modal('hide');
75                         filex.clearSelection();
76                     });
77                 });
78             }).wrap('<div style="margin-right: 80px"></div>');
79
80             $('#id_application').selectize();
81             $('#id_arguments,#id_properties,#id_native').selectize({
82                 plugins: ['remove_button'],
83                 create: true,
84                 render: {
85                     option_create: function(data, escape) {
86                         return '<div class="create">Dodaj <strong>' + escape(data.input) + '</strong>&hellip;</div>';
87                     }
88                 }
89             });
90             $('#id_queue').selectize({
91                 create: true,
92                 render: {
93                     option_create: function(data, escape) {
94                         return '<div class="create">Wybierz <strong>' + escape(data.input) + '</strong>&hellip;</div>';
95                     }
96                 }
97             });
98             $('#id_modules,#id_hosts,#id_master_file,#id_executable,#id_input,#id_stage_in,#id_preprocess_script,#id_postprocess_script').selectize({
99                 plugins: ['remove_button']
100             });
101
102             // hide delete checkbox in empty env form
103             $('#env-form-empty').find('div.form-group:last-of-type').hide();
104             $('#env-controls').find('> div').formset({
105                 formTemplate: '#env-form-empty',
106                 parent: '#env-controls',
107                 addLinkParent: '#add-env-form',
108                 addText: 'dodaj »',
109                 addCssClass: 'add-btn',
110                 deleteText: 'Usuń',
111                 deleteCssClass: 'delete-btn btn btn-xs btn-danger'
112             });
113
114             $('input[name="notify_type"],input[name="watch_output_type"],input[name="preprocess_type"],input[name="postprocess_type"]').on('change', function () {
115                 $(this).tab('show');
116             }).each(function() {
117                 if (this.checked)
118                     $(this).tab('show');
119             });
120
121             $('#toggle-advanced').click(function(e) {
122                 e.preventDefault();
123                 $('form .collapse').collapse('toggle');
124                 $(this).find('span').text(this.text == "Pokaż zaawansowane" ? "Ukryj zaawansowane" : "Pokaż zaawansowane");
125             });
126
127             $('#gridftp').one('show.bs.modal', function() {
128                 filex.initialLoad();
129             });
130
131             $('#template').on('show.bs.modal', function() {
132                 this.reset();
133             }).on('shown.bs.modal', function() {
134                 $(this).find('input[type="text"]')[0].focus();
135             }).on('submit', function(e) {
136                 e.preventDefault();
137
138                 // copy this form's fields to description form and send it
139                 $('#description').append($(this).find('input').clone().attr('type', 'hidden')).submit();
140             });
141         });
142     </script>
143 {% endblock %}
144
145 {% block container %}
146     <div class="pull-right">
147         {% if template %}
148             <button class="btn btn-default" data-toggle="modal" data-target="#template">Zapisz</button>
149             <button class="btn btn-default" data-toggle="modal" data-target="#delete-modal">Usuń</button>
150         {% else %}
151             <button class="btn btn-default" data-toggle="modal" data-target="#template">Zapisz jako szablon</button>
152         {% endif %}
153     </div>
154
155     <h1 class="page-header">{% block title %}Zleć zadanie{% endblock %} <small>{{ template.name }}</small></h1>
156
157     {% if errors %}
158         <div class="alert alert-danger">
159             <strong>Uwaga!</strong> Formularz zawiera błędy.
160             {{ form.non_field_errors }}
161             {{ env_formset.non_field_errors }}
162             {{ template_form.non_field_errors }}
163         </div>
164     {% endif %}
165
166     <form id="description" action="." method="post" class="form-horizontal">
167         {% csrf_token %}
168
169         {% include 'qcg/job_submit_form.html' %}
170
171         <hr>
172
173         <div class="row">
174             <div class="col-sm-offset-3 col-md-offset-4 col-sm-9 col-md-6">
175                 <button type="submit" class="btn btn-primary">Zleć zadanie</button>
176                 <button type="reset" class="btn btn-warning">Resetuj</button>
177                 <a id="toggle-advanced" href="#"><span class="text-muted">Pokaż zaawansowane</span></a>
178             </div>
179         </div>
180     </form>
181
182     <div id="gridftp" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridftp-modal-label" aria-hidden="true">
183         <div class="modal-dialog modal-lg">
184             <div class="modal-content">
185                 <div class="modal-header">
186                     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
187                     <h4 class="modal-title" id="gridftp-modal-label">Wybierz plik</h4>
188                 </div>
189                 <div class="modal-body">
190                     {% include 'filex/source.html' %}
191                 </div>
192                 <div class="modal-footer">
193                     <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
194                     <button id="select-btn" type="button" class="btn btn-primary">Wybierz</button>
195                 </div>
196             </div>
197         </div>
198     </div>
199
200     <form id="template" action="." method="post" class="modal fade form-horizontal" tabindex="-1"
201           role="dialog" aria-labelledby="template-modal-label" aria-hidden="true">
202         <div class="modal-dialog">
203             <div class="modal-content">
204                 <div class="modal-header">
205                     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
206                     <h4 class="modal-title" id="template-modal-label">Podaj nazwę szablonu</h4>
207                 </div>
208                 <div class="modal-body">
209                     {% csrf_token %}
210                     <input type="hidden" name="save-template" value="1">
211                     {% bootstrap_field template_form.name layout="horizontal" %}
212                 </div>
213                 <div class="modal-footer">
214                     <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
215                     <button type="submit" class="btn btn-primary" data-loading-text="Zapisywanie...">Zapisz</button>
216                 </div>
217             </div>
218         </div>
219     </form>
220
221     {% if template %}
222         <form id="delete-modal" action="{% url 'template_delete' template.id %}" method="post" class="modal fade" tabindex="-1"
223               role="dialog" aria-labelledby="delete-modal-label" aria-hidden="true">
224             <div class="modal-dialog">
225                 <div class="modal-content">
226                     <div class="modal-header">
227                         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
228                         <h4 class="modal-title" id="delete-modal-label">Usuwanie szablonu</h4>
229                     </div>
230                     <div class="modal-body">
231                         {% csrf_token %}
232                         <p>Czy na pewno usunąć szablon <em>{{ template.name }}</em>?</p>
233                     </div>
234                     <div class="modal-footer">
235                         <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
236                         <button type="submit" class="btn btn-danger">Usuń</button>
237                     </div>
238                 </div>
239             </div>
240         </form>
241     {% endif %}
242 {% endblock %}