<div
    class="attributes-restriction-modal"
    ng-class="{'attributes-restriction-modal-expanded': featureTypeAttrRestriction.roles && featureTypeAttrRestriction.roles.length > 0}">
  <h3 ng-if="editModalIsNew">
    <translate>model.featuretypes.attributes.restrictions.create</translate>
  </h3>
  <h3 ng-if="!editModalIsNew">
    <translate>model.featuretypes.attributes.restrictions.edit</translate>
  </h3>

  <form
      class="form"
      ng-submit="addRestrictionToFeatureTypeAttribute(); closeThisDialog()"
      role="form"
  >
    <!-- Type of Restriction -->
    <div class="form-group clearfix">
      <div class="col-sm-12">
        <select
            class="form-control"
            id="inputrestrictiontype"
            ng-disabled="!isNewResource && featureTypeAttrRestriction.type"
            ng-model="featureTypeAttrRestriction.type"
            ng-options="k as v for (k,v) in restrictionsTypes"
            required
        >
        </select>
      </div>
    </div>

    <div
        class="alert inlinealert alert-danger"
        ng-if="isNewFeatureTypeAttributeRestriction && (currentFeatureTypeAttribute.restrictions|arrayMap:'type').indexOf(featureTypeAttrRestriction.type)!=-1"
    >
      <translate
      >model.featuretypes.attributes.restrictions.already_used
      </translate
      >
    </div>

    <!-- Interval restriction-->
    <div
        class="form-group clearfix"
        ng-if="featureTypeAttrRestriction.type=='Interval'"
    >
      <div class="col-sm-6">
        <div style="float: right">
          <input
              id="inputintervalminincl"
              ng-model="featureTypeAttrRestriction.interval.mininclus"
              type="checkbox"
          />
          <label for="inputintervalminincl"
          >
            <translate>common.included</translate>
            ?</label
          >
        </div>
        <label for="inputintervalmin"
        >
          <translate
          >model.featuretypes.attributes.restrictions.interval.min
          </translate
          >
        </label
        >
        <input
            class="form-control"
            id="inputintervalmin"
            ng-model="featureTypeAttrRestriction.interval.min"
            required
            step="any"
            type="number"
        />
      </div>
      <div class="col-sm-6">
        <div style="float: right">
          <input
              id="inputintervalmaxincl"
              ng-model="featureTypeAttrRestriction.interval.maxinclus"
              type="checkbox"
          />
          <label for="inputintervalmaxincl"
          >
            <translate>common.included</translate>
            ?</label
          >
        </div>
        <label for="inputintervalmax"
        >
          <translate
          >model.featuretypes.attributes.restrictions.interval.max
          </translate
          >
        </label
        >
        <input
            class="form-control"
            id="inputintervalmax"
            ng-model="featureTypeAttrRestriction.interval.max"
            required
            step="any"
            type="number"
        />
      </div>
    </div>

    <!-- inputSize restriction-->
    <div
        class="form-group clearfix"
        ng-if="featureTypeAttrRestriction.type=='inputSize'"
    >
      <div class="col col-xs-12">
        <label
        >
          <translate
          >model.featuretypes.attributes.restrictions.inputsize.label
          </translate
          >
        </label
        >
      </div>
      <div class="col col-xs-6">
        <input
            class="form-control"
            id="inputsizemin"
            ng-model="featureTypeAttrRestriction.minocc"
            required
            step="any"
            type="number"
        />
      </div>
      <div class="col col-xs-6">
        <input
            class="form-control"
            id="inputsizemax"
            ng-model="featureTypeAttrRestriction.maxocc"
            required
            step="any"
            type="number"
        />
      </div>
    </div>

    <!-- Table restriction -->
    <div ng-if="featureTypeAttrRestriction.type=='Tables'">
      <div class="form-group clearfix">
        <div class="col-xs-12">
          <label for="inputtabletable"
          >
            <translate
            >model.featuretypes.attributes.restrictions.table.table
            </translate
            >
          </label
          >
          <select
              class="form-control"
              id="inputtabletable"
              ng-change="setfeatureTypeAttrRestriction(afeatureTypeAttrRestriction.table)"
              ng-model="afeatureTypeAttrRestriction.table"
              ng-options="featureType.name for featureType in featureTypesList track by featureType.name"
              required
          >
          </select>
        </div>
      </div>
      <div class="form-group clearfix">
        <div class="col-xs-6">
          <label for="inputtablekeyfield"
          >
            <translate
            >model.featuretypes.attributes.restrictions.table.key
            </translate
            >
          </label
          >
          <select
              class="form-control"
              id="inputtablekeyfield"
              ng-change="setfeatureTypeAttrRestrictionKey(afeatureTypeAttrRestriction.keyField)"
              ng-model="afeatureTypeAttrRestriction.keyField"
              ng-options="attribute.name for attribute in afeatureTypeAttrRestriction.table.attributes track by attribute.name"
              required
          >
          </select>
        </div>
        <div class="col-xs-6">
          <label for="inputtablevaluefield"
          >
            <translate
            >model.featuretypes.attributes.restrictions.table.value
            </translate
            >
          </label
          >
          <select
              class="form-control"
              id="inputtablevaluefield"
              ng-change="setfeatureTypeAttrRestrictionValue(afeatureTypeAttrRestriction.valueField)"
              ng-model="afeatureTypeAttrRestriction.valueField"
              ng-options="attribute as filterAttribute(attribute) for attribute in afeatureTypeAttrRestriction.table.attributes track by attribute.name"
              required
          >
          </select>
        </div>
      </div>
      <div class="form-group clearfix">
        <div class="col-xs-12">
          <label class="checkbox-inline">
            <input
                ng-change="setfeatureTypeAttrRestrictionMultiple(afeatureTypeAttrRestriction.allowMultipleSelection)"
                ng-model="afeatureTypeAttrRestriction.allowMultipleSelection"
                type="checkbox"
            />
            <translate>model.featuretypes.attributes.restrictions.table.allowMultipleSelection
            </translate>
          </label>
        </div>
      </div>
      <div class="form-group clearfix">
        <div class="col-xs-12 alert alert-info centeredAlert">
          <i class="fa fa-info-circle"></i>
          <translate class="multiLineAlert">model.featuretypes.attributes.restrictions.table.filterTip</translate>
        </div>
      </div>
      <div class="form-group clearfix">
        <div class="col-xs-12">
          <label>
            <translate>model.featuretypes.attributes.restrictions.table.filterDefinition
            </translate>
          </label>
          <input
              class="form-control"
              ng-change="setfeatureTypeAttrFilterDefinition(afeatureTypeAttrRestriction.filterDefinition)"
              ng-disabled="!afeatureTypeAttrRestriction.applyFilter"
              ng-model="afeatureTypeAttrRestriction.filterDefinition"
          >
          </input>
        </div>
      </div>
      <div class="form-group clearfix">
        <div class="col-xs-12">
          <label class="checkbox-inline">
            <input
                ng-change="setfeatureTypeAttrApplyFilter(afeatureTypeAttrRestriction.applyFilter)"
                ng-model="afeatureTypeAttrRestriction.applyFilter"
                type="checkbox"
            />
            <translate>model.featuretypes.attributes.restrictions.table.applyFilter</translate>
          </label>
        </div>
      </div>

      <!--        <div class="form-group clearfix">
                      <div class="col-sm-6">
                          <label for="inputtablename"><translate>model.featuretypes.attributes.restrictions.table.min</translate></label>
                          <input type="text" class="form-control" id="inputtablename"  required>
                      </div>
                      <div class="col-sm-6">
                          <label for="inputdatastorename"><translate>model.featuretypes.attributes.restrictions.interval.max</translate></label>
                          <input type="text" class="form-control" id="inputdatastorename"  required>
                      </div>
                  </div>
                  <div class="form-group clearfix">
                      <div class="col-sm-6">
                          <label for="inputtablekey"><translate>model.featuretypes.attributes.restrictions.interval.min</translate></label>
                          <input type="text" class="form-control" id="inputtablekey"  required>
                      </div>
                      <div class="col-sm-6">
                          <label for="inputtablevalue"><translate>model.featuretypes.attributes.restrictions.interval.max</translate></label>
                          <input type="text" class="form-control" id="inputtablevalue"  required>
                      </div>
                  </div>-->
    </div>

    <!-- Domain restriction -->
    <div
        class="form-group clearfix"
        ng-if="featureTypeAttrRestriction.type=='Domain'"
    >
      <!-- Headers -->
      <div
          class="form-group clearfix"
          ng-if="featureTypeAttrRestriction.listofValues"
      >
        <div class="col-xs-5 text-center">
          <label>
            <translate>common.key</translate>
          </label>
        </div>
        <div class="col-xs-5 text-center">
          <label>
            <translate>common.value</translate>
          </label>
        </div>
        <div class="col-xs-2"></div>
      </div>

      <!-- List of values -->

      <div
          ng-repeat="(key, prop) in featureTypeAttrRestriction.listofValues track by key"
      >
        <div class="form-group clearfix">
          <div class="col-xs-5">
            <input
                class="form-control"
                ng-disabled="!isEditable(key)"
                ng-init="newKey = key"
                ng-model="newKey"
                type="text"
            />
          </div>
          <div class="col-xs-5">
            <input
                class="form-control"
                ng-disabled="!isEditable(key)"
                ng-model="featureTypeAttrRestriction.listofValues[key]"
                type="text"
            />
          </div>
          <div align="center" class="col-xs-2">
            <button
                class="btn btn-xs btn-default"
                ng-click="EnableFeatureTypeAttrRestrictionDomainValue(key)"
                ng-show="!isEditable(key)"
                type="button"
            >
              <span class="glyphicon glyphicon-pencil"></span>
            </button>
            <button
                class="btn btn-xs btn-success"
                ng-click="EditFeatureTypeAttrRestrictionDomainValue(key,newKey)"
                ng-show="isEditable(key)"

                type="button"
            >
              <span class="glyphicon glyphicon-ok"></span>
            </button>
            <button
                class="btn btn-xs btn-danger"
                ng-click="DeleteFeatureTypeAttrRestrictionDomainValue(key)"
                type="button"
            >
              <span class="glyphicon glyphicon-remove"></span>
            </button>
          </div>
        </div>
      </div>
      <div class="form-group clearfix">
        <div class="col-xs-12">
          <label class="checkbox-inline">
            <input
                ng-model="featureTypeAttrRestriction.domainRestrictionAllowDifferentValues"
                type="checkbox"
            />
            Autoriser la saisie d'autres valeurs
          </label>
        </div>
      </div>

      <!-- Add value  -->
      <div class="form-group clearfix">
        <hr/>
        <div class="col-xs-5">
          <input
              class="form-control"
              ng-blur="fillDomainEntryValueIfEmpty(newValue)"
              ng-model="newValue.k"
              placeholder="{{'common.key' | translate}}"
              type="text"
          />
        </div>
        <div class="col-xs-5">
          <input
              class="form-control"
              ng-model="newValue.v"
              placeholder="{{'common.value' | translate}}"
              type="text"
          />
        </div>
        <div align="center" class="col-xs-2">
          <button
              class="btn btn-xs btn-info"
              ng-click="newValue = addFeatureTypeAttrRestrictionDomainValue(newValue)"
              type="button"
          >
            <span class="glyphicon glyphicon-plus"></span>
          </button>
        </div>
      </div>
    </div>

    <!-- User restriction -->
    <div
        class="user-restriction"
        ng-if="featureTypeAttrRestriction.type==='User'">

      <div class="form-group clearfix">
        <div class="row">
          <div class="col-xs-6">
            <get-roles
                curtool="featureTypeAttrRestriction">
            </get-roles>
          </div>
        
          <div class="col-xs-6">
            <label translate>model.featuretypes.attributes.restrictions.user.keyDefinition</label>
            <br/>
            <input
              type="radio"
              name="isLoginKey"
              ng-model="featureTypeAttrRestriction.isLoginKey"
              ng-value="{{true}}"
              >
            <translate>model.featuretypes.attributes.restrictions.user.saveLogin</translate>
            <br/>
            <input
              type="radio"
              name="isLoginKey"
              ng-model="featureTypeAttrRestriction.isLoginKey"
              ng-value="{{false}}"
              >
            <translate>model.featuretypes.attributes.restrictions.user.saveName</translate>
          </div>
        </div>
      </div>
    </div>

    <!-- Actions -->
    <div class="form-group clearfix button-container">
      <div class="col-sm-12 text-right">
        <close-modale-button></close-modale-button>
        <button
            class="btn btn-primary"
            ng-disabled="isNewFeatureTypeAttributeRestriction && (currentFeatureTypeAttribute.restrictions|arrayMap:'type').indexOf(featureTypeAttrRestriction.type)!=-1"
            type="submit"
        >
          <translate>common.save</translate>
        </button>
      </div>
    </div>
  </form>
</div>