<div id="bootstrap-theme" crm-dialog="crmSearchTask">
  <form name="civiCaseTaskOpenCaseForm" ng-controller="civiCaseTaskOpenCase as $ctrl">
    <div ng-if="$ctrl.ids.length &gt; 1 && $ctrl.task.allowMultipleClients" class="alert alert-info">
      <div>
        <i class="crm-i fa-folder-open" role="img" aria-hidden="true"></i>
        {{:: ts('Multiple contacts selected...') }}
        <div class="form-inline">
          <label><input type="radio" ng-model="$ctrl.multipleClients" ng-value="false"> {{:: ts('Open new cases for each contact') }}</label>
          <label><input type="radio" ng-model="$ctrl.multipleClients" ng-value="true"> {{:: ts('Open a single case with all contacts jointly') }}</label>
        </div>
      </div>
    </div>
    <div class="form-inline" ng-repeat="clause in $ctrl.values" >
      <input class="form-control crm-auto-width" ng-change="$ctrl.updateField($index)" ng-disabled="$ctrl.run" ng-model="clause[0]" crm-ui-select="{data: $ctrl.availableFields, allowClear: true, placeholder: 'Field'}" />
      <crm-search-input class="form-group" ng-model="clause[1]" field="$ctrl.getField(clause[0])" ></crm-search-input>
    </div>
    <div class="form-inline" ng-hide="$ctrl.run">
      <input class="form-control" on-crm-ui-select="$ctrl.addField(selection)" ng-disabled="!$ctrl.fields.length" ng-class="{loading: !$ctrl.fields.length}" crm-ui-select="{data: $ctrl.availableFields, placeholder: ts('Add Value')}"/>
    </div>
    <div ng-if="!$ctrl.run && $ctrl.existingCaseContacts.length" class="alert alert-warning">
      <div>
        <i class="crm-i fa-exclamation-triangle" role="img" aria-hidden="true"></i>
        {{:: ts('1 contact already has an open case.', {plural: '%count contacts already have an open case.', count: $ctrl.existingCaseContacts.length}) }}
        <div class="form-inline">
          <label><input type="radio" ng-model="$ctrl.skipDuplicates" ng-value="true"> {{:: ts('Skip contact with open case', {plural: 'Skip contacts with open cases', count: $ctrl.existingCaseContacts.length}) }}</label>
          <label><input type="radio" ng-model="$ctrl.skipDuplicates" ng-value="false"> {{:: ts('Create new case anyway', {plural: 'Create new cases anyway', count: $ctrl.existingCaseContacts.length}) }}</label>
        </div>
      </div>
    </div>
    <div ng-if="$ctrl.run && $ctrl.multipleClients" class="crm-search-task-progress">
      <h5>{{:: ts('Opening case...') }}</h5>
      <crm-search-batch-runner entity="'Case'" action="create" params="$ctrl.run" success="$ctrl.onSuccess(result)" error="$ctrl.onError(error)" ></crm-search-batch-runner>
    </div>
    <div ng-if="$ctrl.run && !$ctrl.multipleClients" class="crm-search-task-progress">
      <h5>{{:: ts('Opening case...', {plural: 'Opening %count cases...', count: $ctrl.ids.length}) }}</h5>
      <crm-search-batch-runner entity="'Case'" action="save" params="$ctrl.run" ids="$ctrl.ids" id-field="contact_id" success="$ctrl.onSuccess(result)" error="$ctrl.onError(error)" ></crm-search-batch-runner>
    </div>
    <crm-dialog-button text="ts('Cancel')" icons="{primary: 'fa-times'}" on-click="$ctrl.cancel()" disabled="$ctrl.run" />
    <crm-dialog-button text="ts('Save')" icons="{primary: 'fa-user-plus'}" on-click="$ctrl.submit()" disabled="$ctrl.run || $ctrl.existingCount === null || !civiCaseTaskOpenCaseForm.$valid" />
  </form>
</div>
