From c506864205f205111004c73517231b695e5e422c Mon Sep 17 00:00:00 2001 From: Rodolfo Zitellini Date: Wed, 14 Jul 2021 15:09:17 +0200 Subject: [PATCH] #516 Initial "-" implementation --- app/assets/javascripts/marc_editor.js | 46 ++++++++++++++++++++++---- app/views/editor/_subfield_li.html.erb | 12 +++++++ app/views/editor/_tag.html.erb | 6 +--- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/marc_editor.js b/app/assets/javascripts/marc_editor.js index 1c199bd34..abff043ee 100644 --- a/app/assets/javascripts/marc_editor.js +++ b/app/assets/javascripts/marc_editor.js @@ -532,25 +532,29 @@ function marc_editor_incipit(clef, keysig, timesig, incipit, target, width) { render_music(pae, 'pae', target, width); } -// This is the last non-ujs function remaining -// it is called when ckicking the "+" button +// These two are the last non-ujs function remaining +// This one is called when ckicking the "+" button // near a repeatable field. It makes a copy // of it function marc_editor_add_subfield(id) { - grid = id.parents("tr"); + var grid = id.parents("tr"); //ul = grid.siblings(".repeating_subfield"); - ul = $(".repeating_subfield", grid); + var ul = $(".repeating_subfield", grid); - li_all = $("li", ul); + var li_all = $("li", ul); - li_original = $(li_all[li_all.length - 1]); + var li_original = $(li_all[li_all.length - 1]); - new_li = li_original.clone(); + var new_li = li_original.clone(); $(".serialize_marc", new_li).each(function() { $(this).val(""); }); + $(".add-button", new_li).each(function() { + $(this).hide(); + }); + // This is a special case for the light-weight "t" tag // in 031, as it is a select_subfield which normally is // never repeatable, but in this case, since it does not @@ -569,6 +573,34 @@ function marc_editor_add_subfield(id) { } +// This one removes the item +function marc_editor_remove_subfield(id) { + + var element = id.parents("li"); + + var button = $(".add-button", element); + if (button.is(":visible")) { + var grid = id.parents("tr"); + var ul = $(".repeating_subfield", grid); + + if ($(ul).children().length == 1) { + $(".serialize_marc", element).each(function() { + $(this).val(""); + }); + } else { + element.remove(); + + var next = $(ul).children()[0] + + var add_button = $(".add-button", next); + add_button.show(); + + } + } else { + element.remove(); + } +} + // Hardcoded for marc_editor_panel function marc_editor_get_model() { return $("#marc_editor_panel").data("editor-model"); diff --git a/app/views/editor/_subfield_li.html.erb b/app/views/editor/_subfield_li.html.erb index d4a328faa..0836e3aef 100644 --- a/app/views/editor/_subfield_li.html.erb +++ b/app/views/editor/_subfield_li.html.erb @@ -1,8 +1,20 @@
  • + + + + + +
    + <%if @item.marc.config.multiples_allowed?(tag_name, subfield) %> + <%= safe_link_to_function_stub "
    _
    ".html_safe, "marc_editor_remove_subfield($(this))", :title => "Add another instance of this subfield" %> + <%= safe_link_to_function_stub "
    _
    ".html_safe, "marc_editor_add_subfield($(this))", :title => "Add another instance of this subfield" %> + <%end%> +
    <%= render :partial => (field_settings.has_key?('editor_partial') ? "options/#{field_settings['editor_partial']}" : "editor/subfield"), :locals => { :marc_tag => marc_tag, :tag_name => tag_name, :marc_subfield => marc_subfield, :subfield => subfield, :params => field_settings } %> +
  • diff --git a/app/views/editor/_tag.html.erb b/app/views/editor/_tag.html.erb index 13eb03f14..357cb1124 100644 --- a/app/views/editor/_tag.html.erb +++ b/app/views/editor/_tag.html.erb @@ -1,13 +1,10 @@ - + <%- @editor_profile.each_subfield_for(tag_name) do |subfield, field_settings| field_label = "" field_leader = "" field_settings = Hash.new if !field_settings - if @item.marc.config.multiples_allowed?(tag_name, subfield) - extra_leader = safe_link_to_function_stub "
    _
    ".html_safe, "marc_editor_add_subfield($(this))", :title => "Add another instance of this subfield" - end if @editor_profile.has_sub_label?(tag_name, subfield) sub_label = @editor_profile.get_sub_label(tag_name, subfield, true) @@ -20,7 +17,6 @@
    <%= field_label.html_safe %> - <%= extra_leader -%>