fix saving template from job submission form
authorMaciej Tronowski <mtro@man.poznan.pl>
Tue, 5 May 2015 12:51:07 +0000 (14:51 +0200)
committerMaciej Tronowski <mtro@man.poznan.pl>
Tue, 5 May 2015 12:51:07 +0000 (14:51 +0200)
qcg/templates/qcg/job_submit.html
qcg/views.py

index 560bd99..87b8a2c 100644 (file)
             });
 
             $('#template').on('show.bs.modal', function() {
-                $(this).find('.alert').remove();
                 this.reset();
             }).on('shown.bs.modal', function() {
                 $(this).find('input[type="text"]')[0].focus();
             }).on('submit', function(e) {
                 e.preventDefault();
 
-                var $this = $(this),
-                    $btn = $this.find('[type="submit"]');
-
-                $this.find('.alert-danger').remove();
-                $btn.button('loading');
-
-                $.post(this.action, $('#description,#template').serializeArray(), function(response) {
-                    // FIXME url after redirection
-                    document.open();
-                    document.write(response);
-                    document.close();
-                }).fail(function(xhr) {
-                    var error = (xhr.responseJSON || {}).error || 'Błąd serwera';
-
-                    $('<div>', {
-                        'class': 'alert alert-danger',
-                        html: '<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> ' + error
-                    }).prependTo($this.find('.modal-body'));
-
-                    $btn.button('reset');
-                });
+                // copy this form's fields to description form and send it
+                $('#description').append($(this).find('input').clone().attr('type', 'hidden')).submit();
             });
         });
     </script>
index 6462613..8a14c2f 100644 (file)
@@ -188,7 +188,7 @@ def job_submit(request, template_id=None):
         env_formset = EnvFormSet(request.POST, initial=env_formset_data)
         template_form = JobTemplateForm(request.POST, prefix='template', instance=template)
 
-        if form.is_valid() and env_formset.is_valid() and (not save_template or template_form.is_valid):
+        if form.is_valid() and env_formset.is_valid() and (not save_template or template_form.is_valid()):
             params = form.cleaned_data
             params['env_variables'] = [(env['name'], env['value'])
                                        for env in env_formset.cleaned_data if env and not env['DELETE']]