{% import 'macros/form.html' as form %}

<form id='organization-edit-form' class="dataset-form" method="post" data-module="basic-form" enctype="multipart/form-data">
  {% block error_summary %}
    {{ form.errors(error_summary) }}
  {% endblock %}

  {% block basic_fields %}
    {% set attrs = {'data-module': 'slug-preview-target', 'class': 'form-control'} %}
    {{ form.input('title', label=_('Name'), id='field-name', placeholder=_('My Organization'), value=data.title, error=errors.title, classes=['control-full'], attrs=attrs) }}

    {%- set prefix = h.url_for(group_type + '_read', id='') -%}
    {%- set domain = h.url_for(group_type + '_read', id='', qualified=true) -%}
    {% set domain = domain|replace("http://", "")|replace("https://", "") %}
    {% set attrs = {'data-module': 'slug-preview-slug', 'class': 'form-control input-sm', 'data-module-prefix': domain, 'data-module-placeholder': '<' + group_type + '>'} %}

    {{ form.prepend('name', label=_('URL'), prepend=prefix, id='field-url', placeholder=_('my-' + group_type), value=data.name, error=errors.name, attrs=attrs, is_required=true) }}

    {{ form.markdown('description', label=_('Description'), id='field-description', placeholder=_('A little information about my organization...'), value=data.description, error=errors.description) }}

    {% set is_upload = data.image_url and not data.image_url.startswith('http') %}
    {% set is_url = data.image_url and data.image_url.startswith('http') %}

    {{ form.image_upload(data, errors, is_upload_enabled=h.uploads_enabled(), is_url=is_url, is_upload=is_upload) }}

  {% endblock %}

  {% block custom_fields %}
    {% snippet 'snippets/custom_form_fields.html', extras=data.extras, errors=errors, limit=3 %}
  {% endblock %}

  {{ form.required_message() }}

  <div class="form-actions">
    {% block delete_button %}
      {% if h.check_access('organization_delete', {'id': data.id})  %}
        <a class="btn btn-danger pull-left" href="{% url_for controller='organization', action='delete', id=data.id %}" data-module="confirm-action" data-module-content="{{ _('Are you sure you want to delete this Organization? Note*: Deleting cannot be performed while public or private datasets belong to this organization.') }}">{% block delete_button_text %}{{ _('Delete') }}{% endblock %}</a>
      {% endif %}
    {% endblock %}
    <button class="btn btn-primary" name="save" type="submit">{% block save_text %}{{ _('Save Organization') }}{% endblock %}</button>
  </div>
</form>
