{% extends 'kfet/base_form.html' %}
{% load staticfiles %}
{% load widget_tweaks %}

{% block extra_head %}
<link rel="stylesheet" text="text/css" href="{% static 'kfet/css/multiple-select.css' %}">
<script src="{% static 'kfet/js/multiple-select.js' %}"></script>
{% endblock %}

{% block title %}Permissions - Édition{% endblock %}
{% block header-title %}Modification des permissions{% endblock %}

{% block main %}

<form action="" method="post" class="form-horizontal">
  {% csrf_token %}
  <div class="form-group">
    <label for="{{ form.name.id_for_label }}" class="col-sm-2 control-label">{{ form.name.label }}</label>
    <div class="col-sm-10">
      <div class="input-group">
        <span class="input-group-addon">K-Fêt</span>
        {{ form.name|add_class:"form-control" }}
      </div>
      {% if form.name.errors %}
        <span class="help-block">{{ form.name.errors }}</span>
      {% endif %}
      {% if form.name.help_text %}
        <span class="help-block">{{ form.name.help_text }}</span>
      {% endif %}
    </div>
  </div>
  {% include "kfet/form_field_snippet.html" with field=form.permissions %}
  {% if not perms.kfet.manage_perms %}
    {% include "kfet/form_authentication_snippet.html" %}
  {% endif %}
  {% include "kfet/form_submit_snippet.html" with value="Enregistrer" %}
</form>

<script type="text/javascript">
$(document).ready(function() {
    let $name_input = $("#id_name");
    let raw_name = $name_input.val();
    let prefix = "K-Fêt ";
    if (raw_name.startsWith(prefix))
        $name_input.val(raw_name.substring(prefix.length));
});
</script>

{% endblock %}
