560bd99c70e27ef8aeda8d80abafa378f3e70608
[qcg-portal.git] / qcg / templates / qcg / job_submit.html
1 {% extends 'qcg/base.html' %}
2 {% load staticfiles bootstrap3 qcg_utils %}
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                 $(this).parent().toggleClass('active', this.checked);
118
119                 if (this.checked)
120                     $(this).tab('show');
121             });
122
123             $('#toggle-advanced').click(function(e) {
124                 e.preventDefault();
125                 $('form .collapse').collapse('toggle');
126                 $(this).find('span').text(this.text == "Pokaż zaawansowane" ? "Ukryj zaawansowane" : "Pokaż zaawansowane");
127             });
128
129             $('#gridftp').one('show.bs.modal', function() {
130                 filex.initialLoad();
131             });
132
133             $('#template').on('show.bs.modal', function() {
134                 $(this).find('.alert').remove();
135                 this.reset();
136             }).on('shown.bs.modal', function() {
137                 $(this).find('input[type="text"]')[0].focus();
138             }).on('submit', function(e) {
139                 e.preventDefault();
140
141                 var $this = $(this),
142                     $btn = $this.find('[type="submit"]');
143
144                 $this.find('.alert-danger').remove();
145                 $btn.button('loading');
146
147                 $.post(this.action, $('#description,#template').serializeArray(), function(response) {
148                     // FIXME url after redirection
149                     document.open();
150                     document.write(response);
151                     document.close();
152                 }).fail(function(xhr) {
153                     var error = (xhr.responseJSON || {}).error || 'Błąd serwera';
154
155                     $('<div>', {
156                         'class': 'alert alert-danger',
157                         html: '<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> ' + error
158                     }).prependTo($this.find('.modal-body'));
159
160                     $btn.button('reset');
161                 });
162             });
163         });
164     </script>
165 {% endblock %}
166
167 {% block container %}
168     <div class="pull-right">
169         {% if template %}
170             <button class="btn btn-default" data-toggle="modal" data-target="#template">Zapisz</button>
171             <button class="btn btn-default" data-toggle="modal" data-target="#delete-modal">Usuń</button>
172         {% else %}
173             <button class="btn btn-default" data-toggle="modal" data-target="#template">Zapisz jako szablon</button>
174         {% endif %}
175     </div>
176
177     <h1 class="page-header">{% block title %}Zleć zadanie{% endblock %} <small>{{ template.name }}</small></h1>
178
179     {% if errors %}
180         <div class="alert alert-danger">
181             <strong>Uwaga!</strong> Formularz zawiera błędy.
182             {{ form.non_field_errors }}
183             {{ env_formset.non_field_errors }}
184             {{ template_form.non_field_errors }}
185         </div>
186     {% endif %}
187
188     <form id="description" action="." method="post" class="form-horizontal">
189         {% csrf_token %}
190
191         <!-- Nav tabs -->
192         <ul class="nav nav-tabs" style="margin-bottom: 20px">
193             <li role="presentation" class="active"><a href="#basic" data-toggle="tab">Podstawowe</a></li>
194             <li role="presentation"><a href="#resources" data-toggle="tab">Zasoby</a></li>
195             <li role="presentation"><a href="#files" data-toggle="tab">Pliki</a></li>
196             <li role="presentation"><a href="#environment" data-toggle="tab">Środowisko</a></li>
197             <li role="presentation"><a href="#monitoring" data-toggle="tab">Powiadomienia</a></li>
198             <li role="presentation"><a href="#other" data-toggle="tab">Inne</a></li>
199         </ul>
200
201         <div class="tab-content">
202             <fieldset id="basic" class="tab-pane active" role="tabpanel">
203                 {% bootstrap_field form.application layout="horizontal" %}
204                 {% bootstrap_field form.master_file layout="horizontal" %}
205                 {% bootstrap_field form.executable layout="horizontal" form_group_class="form-group collapse" %}
206                 {% bootstrap_field form.script layout="horizontal" form_group_class="form-group collapse" %}
207                 {% bootstrap_field form.arguments layout="horizontal" %}
208                 {% bootstrap_field form.note layout="horizontal" %}
209                 {% bootstrap_field form.grant layout="horizontal" form_group_class="form-group collapse" %}
210             </fieldset>
211
212             <fieldset id="resources" class="tab-pane" role="tabpanel">
213                 {% bootstrap_field form.hosts layout="horizontal" %}
214                 {% bootstrap_field form.queue layout="horizontal" %}
215                 {% bootstrap_field form.properties layout="horizontal" form_group_class="form-group collapse" %}
216                 {% bootstrap_field form.modules layout="horizontal" form_group_class="form-group collapse" %}
217                 {% bootstrap_field form.procs layout="horizontal" %}
218                 {% bootstrap_field form.nodes layout="horizontal" form_group_class="form-group collapse" %}
219                 {% bootstrap_field form.wall_time layout="horizontal" form_group_class="form-group timerange" %}
220                 {% bootstrap_field form.memory layout="horizontal" form_group_class="form-group collapse" %}
221                 {% bootstrap_field form.memory_per_slot layout="horizontal" form_group_class="form-group collapse" %}
222                 {% bootstrap_field form.reservation layout="horizontal" form_group_class="form-group collapse" %}
223             </fieldset>
224
225             <fieldset id="files" class="tab-pane" role="tabpanel">
226                 {% bootstrap_field form.input layout="horizontal" %}
227                 {% bootstrap_field form.stage_in layout="horizontal" %}
228             </fieldset>
229
230             <fieldset id="environment" class="tab-pane" role="tabpanel">
231                 {{ env_formset.management_form }}
232
233                 <div class="form-group">
234                     <label class="col-sm-3 col-md-4 control-label">Zmienne środowiskowe</label>
235                     <div class="col-sm-9 col-md-6">
236                         <div id="env-controls">
237                             {% for env_form in env_formset %}
238                                 <div>{% bootstrap_form env_form layout='inline' %}</div>
239                             {% endfor %}
240                         </div>
241                         <div id="add-env-form"></div>
242                         <div id="env-form-empty" style="display: none">
243                             {% bootstrap_form env_formset.empty_form layout='inline' %}
244                         </div>
245                     </div>
246                 </div>
247             </fieldset>
248
249             <fieldset id="monitoring" class="tab-pane" role="tabpanel">
250                 {% bootstrap_checkbox form.monitoring %}
251
252                 <div class="form-group">
253                     <label class="col-sm-3 col-md-4 control-label">Monitorowanie stanu</label>
254                     <div class="col-sm-9 col-md-6">
255                         <div class="btn-group" data-toggle="buttons">
256                             {% for option in form.notify_type %}
257                                 <label class="btn btn-default">
258                                     <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
259                                             {% if option.is_checked %}checked{% endif %}
260                                             data-target=".notify-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
261                                 </label>
262                             {% endfor %}
263                         </div>
264                     </div>
265                 </div>
266
267                 <div class="tab-content">
268                     <div class="tab-pane notify-type-0"></div>
269
270                     <div class="tab-pane notify-type-1 notify-type-2" style="margin-top: 15px">
271                         {% bootstrap_field form.notify_address layout="horizontal" %}
272                     </div>
273                 </div>
274
275                 <div class="collapse">
276                     <div class="form-group">
277                         <label class="col-sm-3 col-md-4 control-label">Monitorowanie wyjścia</label>
278                         <div class="col-sm-9 col-md-6">
279                             <div class="btn-group" data-toggle="buttons">
280                                 {% for option in form.watch_output_type %}
281                                     <label class="btn btn-default">
282                                         <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
283                                                 {% if option.is_checked %}checked{% endif %}
284                                                 data-target=".watch-output-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
285                                     </label>
286                                 {% endfor %}
287                             </div>
288                         </div>
289                     </div>
290
291                     <div class="tab-content">
292                         <div class="tab-pane watch-output-type-0"></div>
293
294                         <div class="tab-pane watch-output-type-1 watch-output-type-2" style="margin-top: 15px">
295                             {% bootstrap_field form.watch_output_address layout="horizontal" %}
296                             {% bootstrap_field form.watch_output_pattern layout="horizontal" %}
297                         </div>
298                     </div>
299                 </div>
300             </fieldset>
301
302             <fieldset id="other" class="tab-pane" role="tabpanel">
303                 <div class="form-group">
304                     <label class="col-sm-3 col-md-4 control-label">Preprocessing</label>
305                     <div class="col-sm-9 col-md-6">
306                         <div class="btn-group" data-toggle="buttons">
307                             {% for option in form.preprocess_type %}
308                                 <label class="btn btn-default">
309                                     <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
310                                             {% if option.is_checked %}checked{% endif %}
311                                             data-target=".preprocess-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
312                                 </label>
313                             {% endfor %}
314                         </div>
315                     </div>
316                 </div>
317
318                 <div class="tab-content">
319                     <div class="tab-pane preprocess-type-0"></div>
320
321                     <div class="tab-pane preprocess-type-1" style="margin-top: 15px">
322                         {% bootstrap_field form.preprocess_cmd layout="horizontal" %}
323                     </div>
324
325                     <div class="tab-pane preprocess-type-2" style="margin-top: 15px">
326                         {% bootstrap_field form.preprocess_script layout="horizontal" %}
327                     </div>
328                 </div>
329
330                 <div class="form-group">
331                     <label class="col-sm-3 col-md-4 control-label">Postprocessing</label>
332                     <div class="col-sm-9 col-md-6">
333                         <div class="btn-group" data-toggle="buttons">
334                             {% for option in form.postprocess_type %}
335                                 <label class="btn btn-default">
336                                     <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
337                                             {% if option.is_checked %}checked{% endif %}
338                                             data-target=".postprocess-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
339                                 </label>
340                             {% endfor %}
341                         </div>
342                     </div>
343                 </div>
344
345                 <div class="tab-content">
346                     <div class="tab-pane postprocess-type-0"></div>
347
348                     <div class="tab-pane postprocess-type-1" style="margin-top: 15px">
349                         {% bootstrap_field form.postprocess_cmd layout="horizontal" %}
350                     </div>
351
352                     <div class="tab-pane postprocess-type-2" style="margin-top: 15px">
353                         {% bootstrap_field form.postprocess_script layout="horizontal" %}
354                     </div>
355                 </div>
356
357                 {% bootstrap_field form.native layout="horizontal" %}
358                 {% bootstrap_checkbox form.persistent %}
359             </fieldset>
360         </div>
361
362         <hr>
363
364         <div class="row">
365             <div class="col-sm-offset-3 col-md-offset-4 col-sm-9 col-md-6">
366                 <button type="submit" class="btn btn-primary">Zleć zadanie</button>
367                 <button type="reset" class="btn btn-warning">Resetuj</button>
368                 <a id="toggle-advanced" href="#"><span class="text-muted">Pokaż zaawansowane</span></a>
369             </div>
370         </div>
371     </form>
372
373     <div id="gridftp" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridftp-modal-label" aria-hidden="true">
374         <div class="modal-dialog modal-lg">
375             <div class="modal-content">
376                 <div class="modal-header">
377                     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
378                     <h4 class="modal-title" id="gridftp-modal-label">Wybierz plik</h4>
379                 </div>
380                 <div class="modal-body">
381                     {% include 'filex/source.html' %}
382                 </div>
383                 <div class="modal-footer">
384                     <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
385                     <button id="select-btn" type="button" class="btn btn-primary">Wybierz</button>
386                 </div>
387             </div>
388         </div>
389     </div>
390
391     <form id="template" action="." method="post" class="modal fade form-horizontal" tabindex="-1"
392           role="dialog" aria-labelledby="template-modal-label" aria-hidden="true">
393         <div class="modal-dialog">
394             <div class="modal-content">
395                 <div class="modal-header">
396                     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
397                     <h4 class="modal-title" id="template-modal-label">Podaj nazwę szablonu</h4>
398                 </div>
399                 <div class="modal-body">
400                     {% csrf_token %}
401                     <input type="hidden" name="save-template" value="1">
402                     {% bootstrap_field template_form.name layout="horizontal" %}
403                 </div>
404                 <div class="modal-footer">
405                     <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
406                     <button type="submit" class="btn btn-primary" data-loading-text="Zapisywanie...">Zapisz</button>
407                 </div>
408             </div>
409         </div>
410     </form>
411
412     {% if template %}
413         <form id="delete-modal" action="{% url 'template_delete' template.id %}" method="post" class="modal fade" tabindex="-1"
414               role="dialog" aria-labelledby="delete-modal-label" aria-hidden="true">
415             <div class="modal-dialog">
416                 <div class="modal-content">
417                     <div class="modal-header">
418                         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
419                         <h4 class="modal-title" id="delete-modal-label">Usuwanie szablonu</h4>
420                     </div>
421                     <div class="modal-body">
422                         {% csrf_token %}
423                         <p>Czy na pewno usunąć szablon <em>{{ template.name }}</em>?</p>
424                     </div>
425                     <div class="modal-footer">
426                         <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
427                         <button type="submit" class="btn btn-danger">Usuń</button>
428                     </div>
429                 </div>
430             </div>
431         </form>
432     {% endif %}
433 {% endblock %}