gridftp: multiple fixes in handling and presenting errors
[qcg-portal.git] / qcg / templates / qcg / job_new.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     </script>
130 {% endblock %}
131
132 {% block container %}
133     <h1 class="page-header">{% block title %}Zleć zadanie{% endblock %}</h1>
134
135     {% if errors %}
136         <div class="alert alert-danger">
137             <strong>Uwaga!</strong> Formularz zawiera błędy.
138             {{ form.non_field_errors }}
139             {{ env_formset.non_field_errors }}
140         </div>
141     {% endif %}
142
143     <form action="." method="post" class="form-horizontal">
144         {% csrf_token %}
145
146         <!-- Nav tabs -->
147         <ul class="nav nav-tabs" style="margin-bottom: 20px">
148             <li role="presentation" class="active"><a href="#basic" data-toggle="tab">Podstawowe</a></li>
149             <li role="presentation"><a href="#resources" data-toggle="tab">Zasoby</a></li>
150             <li role="presentation"><a href="#files" data-toggle="tab">Pliki</a></li>
151             <li role="presentation"><a href="#environment" data-toggle="tab">Środowisko</a></li>
152             <li role="presentation"><a href="#monitoring" data-toggle="tab">Powiadomienia</a></li>
153             <li role="presentation"><a href="#other" data-toggle="tab">Inne</a></li>
154         </ul>
155
156         <div class="tab-content">
157             <fieldset id="basic" class="tab-pane active" role="tabpanel">
158                 {% bootstrap_field form.application layout="horizontal" %}
159                 {% bootstrap_field form.master_file layout="horizontal" %}
160                 {% bootstrap_field form.executable layout="horizontal" form_group_class="form-group collapse" %}
161                 {% bootstrap_field form.script layout="horizontal" form_group_class="form-group collapse" %}
162                 {% bootstrap_field form.arguments layout="horizontal" %}
163                 {% bootstrap_field form.note layout="horizontal" %}
164                 {% bootstrap_field form.grant layout="horizontal" form_group_class="form-group collapse" %}
165             </fieldset>
166
167             <fieldset id="resources" class="tab-pane" role="tabpanel">
168                 {% bootstrap_field form.hosts layout="horizontal" %}
169                 {% bootstrap_field form.queue layout="horizontal" %}
170                 {% bootstrap_field form.properties layout="horizontal" form_group_class="form-group collapse" %}
171                 {% bootstrap_field form.modules layout="horizontal" form_group_class="form-group collapse" %}
172                 {% bootstrap_field form.procs layout="horizontal" %}
173                 {% bootstrap_field form.nodes layout="horizontal" form_group_class="form-group collapse" %}
174                 {% bootstrap_field form.wall_time layout="horizontal" form_group_class="form-group timerange" %}
175                 {% bootstrap_field form.memory layout="horizontal" form_group_class="form-group collapse" %}
176                 {% bootstrap_field form.memory_per_slot layout="horizontal" form_group_class="form-group collapse" %}
177                 {% bootstrap_field form.reservation layout="horizontal" form_group_class="form-group collapse" %}
178             </fieldset>
179
180             <fieldset id="files" class="tab-pane" role="tabpanel">
181                 {% bootstrap_field form.input layout="horizontal" %}
182                 {% bootstrap_field form.stage_in layout="horizontal" %}
183 {#                {% bootstrap_field form.stage_out layout="horizontal" form_group_class="form-group collapse" %}#}
184             </fieldset>
185
186             <fieldset id="environment" class="tab-pane" role="tabpanel">
187                 {{ env_formset.management_form }}
188
189                 <div class="form-group">
190                     <label class="col-sm-3 col-md-4 control-label">Zmienne środowiskowe</label>
191                     <div class="col-sm-9 col-md-6">
192                         <div id="env-controls">
193                             {% for env_form in env_formset %}
194                                 <div>{% bootstrap_form env_form layout='inline' %}</div>
195                             {% endfor %}
196                         </div>
197                         <div id="add-env-form"></div>
198                         <div id="env-form-empty" style="display: none">
199                             {% bootstrap_form env_formset.empty_form layout='inline' %}
200                         </div>
201                     </div>
202                 </div>
203             </fieldset>
204
205             <fieldset id="monitoring" class="tab-pane" role="tabpanel">
206                 {% bootstrap_checkbox form.monitoring %}
207
208                 <div class="form-group">
209                     <label class="col-sm-3 col-md-4 control-label">Monitorowanie stanu</label>
210                     <div class="col-sm-9 col-md-6">
211                         <div class="btn-group" data-toggle="buttons">
212                             {% for option in form.notify_type %}
213                                 <label class="btn btn-default">
214                                     <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
215                                             {% if option.is_checked %}checked{% endif %}
216                                             data-target=".notify-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
217                                 </label>
218                             {% endfor %}
219                         </div>
220                     </div>
221                 </div>
222
223                 <div class="tab-content">
224                     <div class="tab-pane notify-type-0"></div>
225
226                     <div class="tab-pane notify-type-1 notify-type-2" style="margin-top: 15px">
227                         {% bootstrap_field form.notify_address layout="horizontal" %}
228                     </div>
229                 </div>
230
231                 <div class="collapse">
232                     <div class="form-group">
233                         <label class="col-sm-3 col-md-4 control-label">Monitorowanie wyjścia</label>
234                         <div class="col-sm-9 col-md-6">
235                             <div class="btn-group" data-toggle="buttons">
236                                 {% for option in form.watch_output_type %}
237                                     <label class="btn btn-default">
238                                         <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
239                                                 {% if option.is_checked %}checked{% endif %}
240                                                 data-target=".watch-output-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
241                                     </label>
242                                 {% endfor %}
243                             </div>
244                         </div>
245                     </div>
246
247                     <div class="tab-content">
248                         <div class="tab-pane watch-output-type-0"></div>
249
250                         <div class="tab-pane watch-output-type-1 watch-output-type-2" style="margin-top: 15px">
251                             {% bootstrap_field form.watch_output_address layout="horizontal" %}
252                             {% bootstrap_field form.watch_output_pattern layout="horizontal" %}
253                         </div>
254                     </div>
255                 </div>
256             </fieldset>
257
258             <fieldset id="other" class="tab-pane" role="tabpanel">
259                 <div class="form-group">
260                     <label class="col-sm-3 col-md-4 control-label">Preprocessing</label>
261                     <div class="col-sm-9 col-md-6">
262                         <div class="btn-group" data-toggle="buttons">
263                             {% for option in form.preprocess_type %}
264                                 <label class="btn btn-default">
265                                     <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
266                                             {% if option.is_checked %}checked{% endif %}
267                                             data-target=".preprocess-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
268                                 </label>
269                             {% endfor %}
270                         </div>
271                     </div>
272                 </div>
273
274                 <div class="tab-content">
275                     <div class="tab-pane preprocess-type-0"></div>
276
277                     <div class="tab-pane preprocess-type-1" style="margin-top: 15px">
278                         {% bootstrap_field form.preprocess_cmd layout="horizontal" %}
279                     </div>
280
281                     <div class="tab-pane preprocess-type-2" style="margin-top: 15px">
282                         {% bootstrap_field form.preprocess_script layout="horizontal" %}
283                     </div>
284                 </div>
285
286                 <div class="form-group">
287                     <label class="col-sm-3 col-md-4 control-label">Postprocessing</label>
288                     <div class="col-sm-9 col-md-6">
289                         <div class="btn-group" data-toggle="buttons">
290                             {% for option in form.postprocess_type %}
291                                 <label class="btn btn-default">
292                                     <input type="radio" autocomplete="off" name="{{ option.name }}" value="{{ option.choice_value }}"
293                                             {% if option.is_checked %}checked{% endif %}
294                                             data-target=".postprocess-type-{{ forloop.counter0 }}"> {{ option.choice_label }}
295                                 </label>
296                             {% endfor %}
297                         </div>
298                     </div>
299                 </div>
300
301                 <div class="tab-content">
302                     <div class="tab-pane postprocess-type-0"></div>
303
304                     <div class="tab-pane postprocess-type-1" style="margin-top: 15px">
305                         {% bootstrap_field form.postprocess_cmd layout="horizontal" %}
306                     </div>
307
308                     <div class="tab-pane postprocess-type-2" style="margin-top: 15px">
309                         {% bootstrap_field form.postprocess_script layout="horizontal" %}
310                     </div>
311                 </div>
312
313                 {% bootstrap_field form.native layout="horizontal" %}
314                 {% bootstrap_checkbox form.persistent %}
315             </fieldset>
316         </div>
317
318         <hr>
319
320         <div class="row">
321             <div class="col-sm-offset-3 col-md-offset-4 col-sm-9 col-md-6">
322                 <button type="submit" class="btn btn-primary">Zleć zadanie</button>
323                 <button type="reset" class="btn btn-warning">Resetuj</button>
324                 <a id="toggle-advanced" href="#"><span class="text-muted">Pokaż zaawansowane</span></a>
325             </div>
326         </div>
327     </form>
328
329     <div id="gridftp" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modal-label" aria-hidden="true">
330         <div class="modal-dialog modal-lg">
331             <div class="modal-content">
332                 <div class="modal-header">
333                     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
334                     <h4 class="modal-title" id="modal-label">Wybierz plik</h4>
335                 </div>
336                 <div class="modal-body">
337                     {% include 'filex/source.html' %}
338                 </div>
339                 <div class="modal-footer">
340                     <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
341                     <button id="select-btn" type="button" class="btn btn-primary">Wybierz</button>
342                 </div>
343             </div>
344         </div>
345     </div>
346
347 {% endblock %}