{% extends 'dashboard/base.html' %}
{% block title %}
User Role
{% endblock %}
{% block content %}
<div class="row" id="head_style">
  <h3 id="page_title">Edit User Role</h3>
</div>
<!-- end class of row -->
<div class="row">
  <form action="" id="post-form" enctype="multipart/form-data" method="post" role="form">
    {% csrf_token %}
      <div class="form-group">
        <select class='input form-control' id="role" name="role">
          <option value="">Role</option>
          {% for role in roles %}
              <option value="{{ role.0 }}" {% ifequal user_role.0.role role.0 %}Selected{% endifequal %}>{{ role.1 }}</option>
          {% endfor %}
        </select>
      </div>
    <div class="form-group">
      <button class="btn btn-primary" type="submit">Submit</button>
    </div>
  </form>
</div>
<!-- end div row of form -->
{% endblock %}
{% block js_script %}
<script type="text/javascript">
  $('#post-form').submit(function(event){
      event.preventDefault();
      $.post("",$('#post-form').serialize(), function(data){
          if(data.error){
              $('p.error_required').remove();
              for (var key in data.response) {
                  $('#' + key).after('<p class="error_required">* ' + data.response[key] + '</p>');
              }
          }else{
              //alert(data['response']);
              window.location="{% url 'users' %}";
          }
      }, 'json');
  });
</script>
{% endblock %}