UNC-Libraries/hy-c

View on GitHub
app/views/hyrax/base/_form_child_work_relationships.html.erb

Summary

Maintainability
Test Coverage
<%# [hyc-override] https://github.com/samvera/hyrax/tree/hyrax-v4.0.0/app/views/hyrax/base/_form_child_work_relationships.html.erb %>
<%# Form UI behavior code and details;
Code:
  app/assets/javascripts/hyrax/relationships
CSS:
  [data-behavior="remove-relationship"] : Button to remove its parent TR from the table
  [data-behavior="add-relationship"] : Button to clone its parent TR and inject a new row into the table
  .message.has-warning : Used to display UI errors related to input values and server errors
HTML Properties:
  table:
    [data-behavior="child-relationships"] : allows the javascript to be initialized
    data-param-key : the parameter key value for this model type %>
<div class="form-group" data-behavior="child-relationships" data-param-key="<%= f.object.model_name.param_key %>" data-members="<%= work_members_json(f.object) %>">
  <div class="form-inline">
    <%= f.label :find_child_work %>
    <%= f.input_field :find_child_work,
                      prompt: :translate,
                      autocomplete: 'off',
                      data: {
                          autocomplete: 'work',
                          'autocomplete-url' => Rails.application.routes.url_helpers.qa_path + '/search/find_works',
                          'exclude-work': f.object.model.id.to_s # exclude this item from the result set.
                      } %>
    <%# [hyc-override] Change to button and add tabindex to button to make it keyboard accessible %>
    <button type="button" class="btn btn-secondary ml-2" tabindex="0" data-behavior="add-relationship"><%= t('.add') %></button>
  </div>
  <div class="message has-warning"></div>
  <div class="my-4">
    <%= link_to t('.attach_new_work'), polymorphic_path([main_app, :new, :hyrax, :parent, curation_concern.model_name.singular.to_sym], parent_id: curation_concern.id), target: "_blank", class: 'btn btn-primary' %>
  </div>
  <table class="table table-striped">
    <caption><%= t('.caption') %></caption>
    <thead>
    <tr>
      <th><%= t('.header.title') %></th>
      <th><%= t('.header.actions') %></th>
    </tr>
    </thead>
    <tbody>
    </tbody>
  </table>
</div>

<script type="text/x-tmpl" id="tmpl-child-work">
<tr>
  <td>{%= o.title %}</td>
  <%# [hyc-override] Add tab index to make button keyboard accessible %>
  <td><button type="button" class="btn btn-danger" tab-index="0" data-behavior="remove-relationship" data-confirm-text="<%= t('.confirm.text') %>" data-confirm-cancel="<%= t('.confirm.cancel') %>" data-confirm-remove="<%= t('.confirm.remove') %>"><%= t('.actions.remove') %></button></td>
</tr>
</script>