{{!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
}}

<table class="table">
  <thead>
    <tr>
      <th>{{t "columns.fileResource"}}</th>
      {{#each column in columns}}
        <th>
          {{#if column.caption}}
            {{column-filter-widget class="pull-left"
                                   column=column
                                   filterValue=column.filterValue
                                   sortAscending=controller.sortAscending
                                   sortProperties=controller.sortProperties
                                   columnSorted="sort"
                                   columnFiltered="filter"}}
          {{else}}
            {{column.caption}}
          {{/if}}
        </th>
      {{/each}}
      <th>
        <div class="pull-right">
          <button type="button" class="btn btn-sm btn-warning clear-filters" {{action "clearFilters"}}>{{t "buttons.clearFilters"}}</button>
          <button type="button" class="btn btn-sm btn-success add-udf" {{action "add"}}>{{t "buttons.newUdf"}}</button>
        </div>
      </th>
    </tr>
  </thead>
  <tbody>
    {{#each udf in this}}
      <tr>
        <td>
          {{#if udf.isEditing}}
            {{#if udf.isEditingResource}}
              {{extended-input type="text"
                               class="pull-left form-control halfed input-sm"
                               placeholderTranslation="placeholders.fileResource.name"
                               value=udf.fileResource.name}}
              {{extended-input type="text"
                               class="pull-left form-control halfed input-sm"
                               placeholderTranslation="placeholders.fileResource.path"
                               value=udf.fileResource.path}}
            {{else}}
              {{select-widget items=controller.fileResources
                              selectedValue=udf.fileResource
                              labelPath="name"
                              defaultLabelTranslation="placeholders.select.file"
                              itemAdded="addFileResource"
                              itemEdited="editFileResource"
                              itemRemoved="removeFileResource"
                              canAdd=true
                              canEdit=true}}
            {{/if}}
          {{else}}
            {{#if udf.fileResource}}
              {{udf.fileResource.name}}  ({{udf.fileResource.path}})
            {{/if}}
          {{/if}}
        </td>
        {{#each column in controller.columns}}
          <td>
            {{#if udf.isEditing}}
              {{extended-input type="text"
                               class="pull-left form-control input-sm"
                               placeholderTranslation=column.caption
                               dynamicContextBinding="udf"
                               dynamicValueBinding="column.property"}}
            {{else}}
              {{path-binding udf column.property}}
            {{/if}}
          </td>
        {{/each}}
        <td>
          {{#if udf.isEditing}}
            <div class="pull-right">
              <button type="button" class="btn btn-sm btn-warning" {{action "cancel"}}>{{t "buttons.cancel"}}</button>
              <button type="button" class="btn btn-sm btn-success" {{action "save"}}>{{t "buttons.save"}}</button>
            </div>
          {{else}}
            <div class="btn-group pull-right">
              <span data-toggle="dropdown">
                <a class="fa fa-gear"></a>
              </span>
              <ul class="dropdown-menu" role="menu">
                {{#each link in controller.links}}
                  <li {{action 'executeAction' link}}><a>{{tb-helper link}}</a></li>
                {{/each}}
              </ul>
            </div>
          {{/if}}
        </td>
      </tr>
    {{/each}}
  </tbody>
</table>