{% extends 'dashboard/dashboard_base.html' %}
{% block stage %}
<div class="content">
	<div class="new">
	 <div class="new-header">
	    <label>Edit User</label>
	  </div>
	  <div class="new-user">
	    <form class="form-horizontal" name="categoryform" id="categoryform" method='post'>
	      <div class="form-group">
	        <label class="control-label col-sm-2" for="email">Badges:</label>
	        <div class="col-sm-10">
	           <select class="form-control select2" multiple name="badges" id="badges">
	              <option value="">Select A Badge</option>
	              {% for badge in badges %}
	                <option value='{{ badge.id }}' {% if badge in user_profile.badges.all %}selected{% endif %}>{{ badge.title }}</option>
	              {% endfor %}
	            </select>
	        </div>
	      </div>
	      <div class="form-group">
	        <div class="col-sm-offset-2 col-sm-10 save_buttons">
	          <button type="submit" class="btn btn-default submit">Submit</button>
	          <button type="button" class="btn btn-default cancel">Cancel</button>
	        </div>
	      </div>
	    </form>
	  </div>
	</div>
</div>
{% endblock %}
{% block extra_js %}
<script type="text/javascript">
$('form#categoryform').submit(function(e){
	e.preventDefault();
	$.post('.', $('form#categoryform').serialize(), function(data){
        if (data.error == false) {
          alert(data.response);
          window.location = "{% url 'django_simple_forum:users' %}";
        } else {
          $('div.error').remove();
          for (var key in data.response) {
            $('#' + key).after('<div class="error">' + data.response[key] + '</div>');
          }
        }
	}, 'json');
});
$('.cancel').click(function(e){
	window.location = "{% url 'django_simple_forum:users' %}";
});
</script>
{% endblock %}