work in progress
[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_pdb_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,#id_force_field').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
99             $('#id_modules,#id_hosts,#id_pdb_file,#id_master_file,#id_executable,#id_input,#id_stage_in,#id_preprocess_script,#id_postprocess_script').selectize({
100                 plugins: ['remove_button']
101             });
102
103             $('#id_sequence').on("click keyup", function(){
104                 $(this).val($(this).val().toUpperCase());
105             });
106             
107             // hide delete checkbox in empty env form
108             $('#env-form-empty').find('div.form-group:last-of-type').hide();
109             $('#env-controls').find('> div').formset({
110                 formTemplate: '#env-form-empty',
111                 parent: '#env-controls',
112                 addLinkParent: '#add-env-form',
113                 addText: 'dodaj »',
114                 addCssClass: 'add-btn',
115                 deleteText: 'Usuń',
116                 deleteCssClass: 'delete-btn btn btn-xs btn-danger'
117             });
118
119             $('input[name="notify_type"],input[name="watch_output_type"],input[name="preprocess_type"],input[name="postprocess_type"]').on('change', function () {
120                 $(this).tab('show');
121             }).each(function() {
122                 if (this.checked)
123                     $(this).tab('show');
124             });
125
126             $('#toggle-advanced').click(function(e) {
127                 e.preventDefault();
128                 $('form .collapse').collapse('toggle');
129                 $(this).find('span').text(this.text == "Pokaż zaawansowane" ? "Ukryj zaawansowane" : "Pokaż zaawansowane");
130             });
131
132             $('#gridftp').one('show.bs.modal', function() {
133                 filex.initialLoad();
134                 $(this).find('.modal-body').css('height', window.innerHeight - 200 + 'px');
135             });
136
137             $('#template').on('show.bs.modal', function() {
138                 this.reset();
139             }).on('shown.bs.modal', function() {
140                 $(this).find('input[type="text"]')[0].focus();
141             }).on('submit', function(e) {
142                 e.preventDefault();
143
144                 // copy this form's fields to description form and send it
145                 $('#description').append($(this).find('input').clone().attr('type', 'hidden')).submit();
146             });
147         });
148     </script>
149 {% endblock %}
150
151 {% block container %}
152     <div class="pull-right">
153         {% if template %}
154             <button class="btn btn-default" data-toggle="modal" data-target="#template">Zapisz</button>
155             <button class="btn btn-default" data-toggle="modal" data-target="#delete-modal">Usuń</button>
156         {% else %}
157             <button class="btn btn-default" data-toggle="modal" data-target="#template">Zapisz jako szablon</button>
158         {% endif %}
159     </div>
160
161     <h1 class="page-header">{% block title %}Zleć zadanie{% endblock %} <small>{{ template.name }}</small></h1>
162
163     {% if errors %}
164         <div class="alert alert-danger">
165             <strong>Uwaga!</strong> Formularz zawiera błędy.
166             {{ form.non_field_errors }}
167             {{ env_formset.non_field_errors }}
168             {{ template_form.non_field_errors }}
169         </div>
170     {% endif %}
171
172     <form id="description" action="." method="post" class="form-horizontal">
173         {% csrf_token %}
174
175         {% include 'qcg/job_submit_form.html' %}
176
177         <hr>
178
179         <div class="row">
180             <div class="col-sm-offset-3 col-md-offset-4 col-sm-9 col-md-6">
181                 <button type="submit" class="btn btn-primary">Zleć zadanie</button>
182                 <button type="reset" class="btn btn-warning">Resetuj</button>
183                 <a id="toggle-advanced" href="#"><span class="text-muted">Pokaż zaawansowane</span></a>
184             </div>
185         </div>
186     </form>
187
188     <div id="gridftp" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridftp-modal-label" aria-hidden="true">
189         <div class="modal-dialog modal-lg">
190             <div class="modal-content">
191                 <div class="modal-header">
192                     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
193                     <h4 class="modal-title" id="gridftp-modal-label">Wybierz plik</h4>
194                 </div>
195                 <div class="modal-body">
196                     {% include 'filex/source.html' %}
197                 </div>
198                 <div class="modal-footer">
199                     <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
200                     <button id="select-btn" type="button" class="btn btn-primary">Wybierz</button>
201                 </div>
202             </div>
203         </div>
204     </div>
205
206     <form id="template" action="." method="post" class="modal fade form-horizontal" tabindex="-1"
207           role="dialog" aria-labelledby="template-modal-label" aria-hidden="true">
208         <div class="modal-dialog">
209             <div class="modal-content">
210                 <div class="modal-header">
211                     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
212                     <h4 class="modal-title" id="template-modal-label">Podaj nazwę szablonu</h4>
213                 </div>
214                 <div class="modal-body">
215                     {% csrf_token %}
216                     <input type="hidden" name="save-template" value="1">
217                     {% bootstrap_field template_form.name layout="horizontal" %}
218                 </div>
219                 <div class="modal-footer">
220                     <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
221                     <button type="submit" class="btn btn-primary" data-loading-text="Zapisywanie...">Zapisz</button>
222                 </div>
223             </div>
224         </div>
225     </form>
226
227     {% if template %}
228         <form id="delete-modal" action="{% url 'template_delete' template.id %}" method="post" class="modal fade" tabindex="-1"
229               role="dialog" aria-labelledby="delete-modal-label" aria-hidden="true">
230             <div class="modal-dialog">
231                 <div class="modal-content">
232                     <div class="modal-header">
233                         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
234                         <h4 class="modal-title" id="delete-modal-label">Usuwanie szablonu</h4>
235                     </div>
236                     <div class="modal-body">
237                         {% csrf_token %}
238                         <p>Czy na pewno usunąć szablon <em>{{ template.name }}</em>?</p>
239                     </div>
240                     <div class="modal-footer">
241                         <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
242                         <button type="submit" class="btn btn-danger">Usuń</button>
243                     </div>
244                 </div>
245             </div>
246         </form>
247     {% endif %}
248 {% endblock %}