{% extends "app_home/base.html" %}
{% load static %}
{% load i18n %}

{% block navbar_app %}
{% include 'app_home/_sidebar.html' %}
{% endblock %}

{% block title %}
<h2>
  <i class="fa {{ schema.icon }}"></i>
  &nbsp; {{ schema.displayname }} : {{ formular.displayname|default:formular.keyname }}
</h2>
<small class="text-muted">{{ formular.keyname|default:formular.id }} </small>
<hr>
{% endblock %}


{% block content %}
<form action="" method="post"  enctype="multipart/form-data"> {% csrf_token %}

<a class="btn btn-outline-dark"
 
 href="{% url 'app_data:instance_detail' formular.id %}"
 role="button">
 <i class="fa fa-backward" aria-hidden="true"></i>&nbsp; {% translate 'Cancel' %}
</a>


{% if ui_save %}
<input class="btn btn-outline-danger" type="submit" name="save" value="{% translate 'Save' %}">
{% endif %}


{% if ui_save_as %}
<input class="btn btn-outline-danger" type="submit" name="save-as" value="{% translate 'Save as' %}">
{% endif %}

<hr>


<!-- KEYNAME -->
{% if schema.keyname_mode == "edit" %}
<div class="mb-3 row">
  <label class="col-sm-2 col-form-label">{{ schema.keyname_label }}</label>
  <div class="form-check col-sm-10">
   <input type="text" disabled class="form-control" name="keyname" value="{{ formular.keyname|default_if_none:''}}">
    <div class="form-text">Unique for this class - any chars</div>
  </div>
</div>
{% endif %}

<!-- DISPLAYNAME -->
<div class="mb-3 row">
<label class="col-form-label col-sm-2">{{ schema.displayname_label }}</label>
<div class="form-check col-sm-10">
<input type="text" class="form-control col-sm-10" name="displayname" value="{{ formular.displayname|default_if_none:''}}">
</div>
</div>

<!-- IS ENABLED -->
<div class="mb-3 row">
<label class="col-form-label col-sm-2">{% translate 'Is Enabled' %}</label>
<div class="col-sm-10 form-check">
<input class="form-check mt-2" type="checkbox" name="is_enabled"
  {% if formular.is_enabled %}checked{% endif %}> 
</div>
</div>


{% for page,pageitems in formular.PAGES.items %} 
<hr>
<div class="d-flex bg-success-subtle p-2">
  <strong>
    {{ page|default:schema.displayname }}
  </strong>
</div>
<hr>

{%  for order,orderitems in pageitems.items %}{% for item in orderitems %}
  {% include 'app_data/fields/_'|add:item.dataformat|add:'.html' %}
{%  endfor %} <!-- internal item loop -->{%  endfor %} <!-- order loop -->{%  endfor %} <!-- page loop -->


<!-- Permissions -->
{% if ui_security_edit %}
<hr>
<div class="d-flex bg-danger-subtle p-2"><strong>{% trans 'Permissions' %}</strong></div>
<hr>

<div class="mb-3 row">
  <label class="col-form-label col-sm-2"><b>{% translate 'Read Permission' %}</b></label>
  <div class="form-check col-sm-10">
  <input type="text" class="form-control col-sm-10" name="p_read" value="{{ formular.p_read|default_if_none:''}}">
  </div>
  </div>
<div class="mb-3 row">
  <label class="col-form-label col-sm-2"><b>{% translate 'Update Permission' %}</b></label>
  <div class="form-check col-sm-10">
  <input type="text" class="form-control col-sm-10" name="p_update" value="{{ formular.p_update|default_if_none:''}}">
  </div>
</div>
<div class="mb-3 row">
  <label class="col-form-label col-sm-2"><b>{% translate 'Delete Permission' %}</b></label>
  <div class="form-check col-sm-10">
  <input type="text" class="form-control col-sm-10" name="p_delete" value="{{ formular.p_delete|default_if_none:''}}">
  </div>
</div>

{% elif ui_security_view %}
<hr>
<div class="d-flex bg-danger-subtle p-2"><strong>{% trans 'Permissions' %}</strong></div>
<hr>
<div class="mb-3 row">
  <label class="col-form-label col-sm-2"><b>{% translate 'Read Permission' %}</b></label>
  <div class="form-check col-sm-10">
  <input disabled type="text" class="form-control col-sm-10" name="p_read" value="{{ formular.p_read|default_if_none:''}}">
  </div>
  </div>
<div class="mb-3 row">
  <label class="col-form-label col-sm-2"><b>{% translate 'Update Permission' %}</b></label>
  <div class="form-check col-sm-10">
  <input disabled type="text" class="form-control col-sm-10" name="p_update" value="{{ formular.p_update|default_if_none:''}}">
  </div>
</div>
<div class="mb-3 row">
  <label class="col-form-label col-sm-2"><b>{% translate 'Delete Permission' %}</b></label>
  <div class="form-check col-sm-10">
  <input disabled type="text" class="form-control col-sm-10" name="p_delete" value="{{ formular.p_delete|default_if_none:''}}">
  </div>
</div>
{% endif %}


</form>

{% endblock %}


{% block script %}
<script src="{% static 'cavaliba_select2.js' %}"></script>
{% endblock %}
