{% extends "formwizard/profesor/wizard_base.html" %} 

{% block formwizard%}
<legend> <h1 style="padding-left:3%;">Nueva Pregunta</h1> </legend> 
               <form method="post" action="" class="form-horizontal ">
                  {% csrf_token %}
				{% for field in form%}
					<div class="control-group">
						<label class="control-label" for="input01" style="margin-right:10%;"><p><strong>{{ field.label}}</strong></p></label>
						{% if  field.errors %}
	                        <div class="alert alert-error" style="margin-top:0.4em;width:10em;">
	                            <a class="close" data-dismiss="alert">×</a>
	                            <strong>ERROR</strong>{{ field.errors }}
	                        </div>
                        {%endif%}
						<div class="controls">						
							<p>{{field}}</p>
						</div>
					</div>

				{% endfor %}
				<br/>
                  <div id="form-edit">
				  <div class="form-actions">
				  	<div class="pull-left">
                     <a href="{% url editar_actividad_wizard informacion.asignatura step0 %}" class="btn btn-primary btn-large btn-info">Anterior</a>
				  	</div>
				  	<div class="pull-right">
                     <button type="submit" class="btn btn-primary btn-large btn-success" id="salvar">Siguiente</button>
                     <a href="{% url crear_cuestionario_wizard informacion.asignatura step0 %}" class="btn btn-primary btn-large btn-danger">Cancelar</a>
				  	</div>
                  </div>
              	</div>
			  	</form>

{% endblock %}

{% block extra_js%}

	{{super}}

	<script>
$(document).ready(function($) {
  $("#title-0").removeClass("current-step");
  $("#title-2").addClass("current-step")

  $('#title-0 a').attr('href', '{% url editar_actividad_wizard informacion.asignatura step0 %}');
  $('#title-1 a').attr('href', '{% url crear_cuestionario_wizard informacion.asignatura step0 %}');

  $('button[type=submit]').bind('click', function(e) {
		    e.preventDefault() // previene que sea enviado varias veces
		    $('#salvar').attr('disabled','true');	// desactiva el boton
		    // Envia la peticion
		    var args = { type:"POST", url:'{%url crear_pregunta_cuestionario_wizard informacion.asignatura.slug step0 step1%}', data:$('form').serialize()};
		   	$.ajax(args);

		});
	  $('body').ajaxComplete(function(e, xhr, settings) {
	        if (xhr.status == 278) {
	            window.location.href = xhr.getResponseHeader("Location").replace(/\?.*$/, "?next="+window.location.pathname);
	        }
	    });

});
</script>
{% endblock %}