Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

304 - Refactor _author partial for clarity #306

Merged
merged 4 commits into from
Nov 21, 2023

Conversation

Janell-Huyck
Copy link
Contributor

@Janell-Huyck Janell-Huyck commented Nov 16, 2023

Fixes #304

This PR refactors the _authors partial at app/views/partials/_author.html.erb for clarity. It does not change the calls to the JavaScript functions to add or delete authors. There is one visible change from the original version. The original version had a blank space after the first author because it includes an invisible "remove" button. The refactored version does not include the blank button.

The layout issues will be addressed with issue #305.

Refactored code:
(Included to make it easier to read)


<div id="author_group">
    <% if publication.author_first_name.empty? && publication.author_last_name.empty? %>
    <% publication.author_first_name << '' %>
    <% publication.author_last_name << '' %>
    <% end %>

    <% publication.author_first_name.each_with_index do |_, index| %>
    <div class="form-row" id="author_<%= index %>">
        <div class="col-md-5">
            <%= label_tag(:author_first_name, author_or_artist_label + ' First Name', class: "required") %>
            <%= text_field_tag "#{name}[author_first_name][]", publication.author_first_name[index], required: true, class: "form-control form-group" %>
        </div>
        <div class="col-md-5">
        <%= label_tag "#{name}_author_last_name_#{index}", "Author Last Name", class: "required" %>
        <%= text_field_tag "#{name}[author_last_name][]", publication.author_last_name[index], required: true, class: "form-control form-group" %>
        </div>
        <% if index > 0 %>
        <div class="col-md-2">
            <%= button_tag "Remove Author", type: "button", onclick: "removeAuthor('author_#{index}')", class: "form-control form-group bg-danger text-white" %>
        </div>
        <% end %>
    </div>
    <% end %>
</div>
<%= button_tag "Add Author", type: "button", id: "add_author_btn", onclick: "addAuthor('#{name}')", class: "btn btn-primary" %>

@Janell-Huyck Janell-Huyck changed the title Refactor _author partial for clarity WIP Refactor _author partial for clarity Nov 16, 2023
@Janell-Huyck Janell-Huyck changed the title WIP Refactor _author partial for clarity 304 - Refactor _author partial for clarity Nov 20, 2023
@hortongn hortongn merged commit 640577d into qa Nov 21, 2023
@hortongn hortongn deleted the refactor-304-author-partial-refactor branch November 21, 2023 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modularization (_forms partials): Refactor _author partial for clarity
2 participants