<h3 ng-if="editModalIsNew">
  <translate>model.association.create</translate>
</h3>
<h3 ng-if="!editModalIsNew">
  <translate>model.association.edit</translate>
</h3>
<form
  ng-submit="editAssociation();closeThisDialog()"
  class="form"
  role="form"
  name="AssociationForm"
>
  <div class="form-group clearfix">
    <div class="col-xs-6" ng-class="{'has-error': !validFormName}">
      <label for="inputname">
        <translate>model.association.name</translate>
      </label>
      <input
        type="text"
        class="form-control"
        id="inputname"
        ng-model="edit_resource.name"
        ng-init="validateName();nameInit()"
        ng-blur="fillAliasWithNameIfEmpty()"
        required
      />
      <div class="alert inlinealert alert-danger" ng-if="!validFormName">
        <translate>model.association.already_exist</translate>
      </div>
    </div>
    <div class="col-xs-6">
      <label for="inputalias">
        <translate>model.association.alias</translate>
      </label>
      <input
        type="text"
        class="form-control"
        id="inputalias"
        ng-model="edit_resource.alias"
        required
      />
    </div>
  </div>
  <div class="form-group clearfix" ng-show="edit_resource.name || duplicate">
    <div class="col-xs-6">
      <label for="inputcategory">
        <translate>model.association.category</translate>
      </label>
      <input
          type="text"
          id="inputcategory"
          class="form-control"
          ng-model="edit_resource.category"
          bs-options="category for category in categorys"
          data-min-length="0"
          data-html="1"
          data-auto-select="true"
          data-animation="am-flip-x"
          bs-typeahead
          
      />
    </div>
    <div class="col-xs-6 mt-25">
        <input
          type="checkbox"
          ng-model="edit_resource.type_patrimoine"
          id="type_patrimoine"
          ng-change = "clickPatrimoine()"
        />
        <label for="type_patrimoine" translate>model.association.type_patrimoine</label>
    </div>
  </div>
  <div class="form-group clearfix" ng-show="edit_resource.name || duplicate">
    <div class="col-xs-6">
      <label for="inputsourceassociationtable">
        <translate>model.association.source_association_table</translate>
      </label>
      <select
        id="inputsourceassociationtable"
        ng-options="datastore.name as datastore.name for datastore in dataStores"
        class="form-control"
        ng-model="edit_resource.source_association"
        ng-change="checkObjIncluded()"
        required
      >
      </select>
    </div>
    <div class="col-xs-6" ng-if="edit_resource.source_association">
      <label for="inputassociationtablename">
        <translate>model.association.name_association_table_name</translate>
      </label>
      <select
        id="inputassociationtablename"
        ng-options="table.name as table.name for table in tableList | filter:{storeName:edit_resource.source_association}"
        class="form-control"
        ng-model="edit_resource.name_association_table"
        required
        ng-change="nameAssociationChanged()"
      ></select>
    </div>
  </div>
  <div class="form-group clearfix" ng-show="edit_resource.name || duplicate">
    <div class="col-xs-7" class="form-control">
      <label>
        <input
          type="radio"
          ng-value=1
          ng-model="edit_resource.type"
          ng-disabled= "isEvtIncluded(edit_resource.name_association_table)"
        />
        Structure de type: atable, afield, aid, btable, bfield, bid
      </label>
    </div>
    <div class="col-xs-5" class="form-control">
      <label>
        <input
          type="radio"
          ng-value=2
          ng-model="edit_resource.type"
          ng-disabled= "isObjIncluded(edit_resource.name_association_table) || isEvtIncluded(edit_resource.name_association_table)"
        />
        Structure de type: aid, bid
      </label>
    </div>
    <div class="col-xs-12" class="form-control">
      <label>
        <input
          type="radio"
          ng-value=3
          ng-model="edit_resource.type"
          ng-disabled= "isObjIncluded(edit_resource.name_association_table)"
        />
        Structure de type: lefttable, leftfield, leftid, righttable, rightfield, rightid
      </label>
    </div>
  </div>
  <br/>
  <div class="form-group clearfix" ng-show="edit_resource.name_association_table && edit_resource.type && (edit_resource.name || duplicate)">
    <div class="col-xs-6">
      <label for="inputasource">
        <translate>model.association.asource</translate>
      </label>
      <select
        id="inputasource"
        ng-options="datastore.name as datastore.name for datastore in dataStores"
        class="form-control"
        ng-model="edit_resource.asource"
        required
      >
      </select>
    </div>
    <div class="col-xs-6">
      <label for="inputbsource">
        <translate>model.association.bsource</translate>
      </label>
      <select
        id="inputbsource"
        ng-options="datastore.name as datastore.name for datastore in dataStores"
        class="form-control"
        ng-model="edit_resource.bsource"
        required
      >
      </select>
    </div>
  </div>
  <div class="form-group clearfix" ng-show="edit_resource.name_association_table && edit_resource.type && (edit_resource.name || duplicate)">
    <div class="col-xs-6" ng-if="edit_resource.asource">
      <label for="inputatable">
        <translate>model.association.atable</translate>
      </label>
      <select
        id="inputatable"
        ng-options="table.name as table.name for table in tableList | filter:{storeName:edit_resource.asource}"
        class="form-control"
        ng-model="edit_resource.atable"
        ng-change="getFields('atable')"
        ng-init="getFields('atable')"
        required
      ></select>
    </div>
    <div class="col-xs-6" ng-if="edit_resource.bsource">
      <label for="inputbtable">
        <translate>model.association.btable</translate>
      </label>
      <select
        id="inputbtable"
        ng-options="table.name as table.name for table in tableList | filter:{storeName:edit_resource.bsource}"
        class="form-control"
        ng-model="edit_resource.btable"
        ng-change="getFields('btable')"
        ng-init="getFields('btable')"
        required
      ></select>
    </div>
  </div>
  <div class="form-group clearfix" ng-show="edit_resource.name_association_table && edit_resource.type && (edit_resource.name || duplicate)">
    <div class="col-xs-6" ng-if="edit_resource.atable">
      <label for="inputafield">
        <translate>model.association.afield</translate>
      </label>
      <select
        id="inputafield"
        ng-options="attribute.name as attribute.name for attribute in aFieldList.attributes | filter:filterAField"
        class="form-control"
        ng-model="edit_resource.afield"
        required
        
      ></select>
    </div>
    <div class="col-xs-6" ng-if="edit_resource.btable">
      <label for="inputbfield">
        <translate>model.association.bfield</translate>
      </label>
      <select
        id="inputbfield"
        ng-options="attribute.name as attribute.name for attribute in bFieldList.attributes | filter:filterBField"
        class="form-control"
        ng-model="edit_resource.bfield"
        required
      ></select>
    </div>
  </div>
  <div class="form-group clearfix" ng-if="edit_resource.type == 2" ng-show="edit_resource.name_association_table && edit_resource.type && (edit_resource.name || duplicate)">
    <div class="col-xs-6">
      <label for="inputaid">
        <translate>model.association.aid</translate>
      </label>
      <input
        type="text"
        class="form-control"
        id="inputaid"
        ng-model="edit_resource.aid"
        required
      />
    </div>
    <div class="col-xs-6">
      <label for="inputbid">
        <translate>model.association.bid</translate>
      </label>
      <input
        type="text"
        class="form-control"
        id="inputbid"
        ng-model="edit_resource.bid"
        required
      />
    </div>
  </div>
  <div class="form-group text-right clearfix">
    <div class="col col-xs-12">
      <close-modale-button></close-modale-button>
      <button class="btn btn-primary" ng-disabled="disableAddButton()">
        <translate>common.save</translate>
      </button>
    </div>
  </div>
</form>
