Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Allow manual input of labels in bulk renamer.
Browse files Browse the repository at this point in the history
Closes #199
  • Loading branch information
Trey Terrell committed Dec 2, 2015
1 parent 74dd26c commit 8d727c2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
45 changes: 32 additions & 13 deletions app/assets/javascripts/bulk_label.es6
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@
this.actions_element = new window.LabelerActionsManager(this.element.children(".actions"))
$("#foliate-settings").hide()
this.element.children("ul").selectable({stop: this.stopped_label_select})
this.element.find("li input[type=text]").change(this.input_value_changed)
this.element.find("li input[type=text]").on("focus", function() {
$(this).data("current-value", $(this).val())
})
this.setup_buttons()
}

setup_buttons() {
this.actions_element.on_apply(this.apply_labels)
this.actions_element.on_save(this.save_labels)
let master = this
this.element.find("form").on("ajax:success", function() {
let form_input = $(this)
form_input.find("input[data-old-title]").attr("data-old-title",null)
master.actions_element.save_button.prop("disabled", master.changed_members.length == 0)
})
}

Expand All @@ -30,24 +36,27 @@
for(let i of this.selected_elements.toArray()) {
i = $(i)
value = generator.next().value
i.children(".text").text(value)
title_field = i.find("input[name='file_set[title][]']")
if(title_field.val() != value) {
if(!title_field.attr("data-old-title")) {
title_field.attr("data-old-title", title_field.val())
}
if(title_field.attr("data-old-title") == value) {
title_field.attr("data-old-title", null)
}
} else {
title_field.attr("data-old-title", null)
}
title_field.val(value)
this.title_field_changing(title_field, value)
}
this.actions_element.save_button.prop("disabled", this.changed_members.length == 0)
}
}

title_field_changing(title_field, value) {
if(title_field.val() != value) {
if(!title_field.attr("data-old-title")) {
title_field.attr("data-old-title", title_field.val())
}
if(title_field.attr("data-old-title") == value) {
title_field.attr("data-old-title", null)
}
} else {
title_field.attr("data-old-title", null)
}
title_field.val(value)
this.actions_element.save_button.prop("disabled", this.changed_members.length == 0)
}

get generator() {
return this.actions_element.generator
}
Expand All @@ -65,6 +74,16 @@
}
}

get input_value_changed() {
let master = this
return function() {
let title_field = $(this)
let new_value = title_field.val()
title_field.val(title_field.data("current-value"))
master.title_field_changing(title_field, new_value)
}
}

get changed_members() {
return this.element.find("*[data-old-title]").parents("li")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
<ul class="col-xs-8">
<% @members.each do |member| %>
<li>
<span class="text">
<%= member.to_s %>
</span>
<%= simple_form_for [main_app, :curation_concerns, member], remote: true do |f| %>
<%= f.input :title, as: :hidden, input_html: { name: "file_set[title][]" } %>
<%= f.input :title, as: :string, input_html: { name: "file_set[title][]" }, value: member.to_s %>
<% end %>
</li>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
let(:solr_doc) do
SolrDocument.new(
resource.to_solr.merge(
id: "test"
id: "test",
title_tesim: "Test"
)
)
end
Expand All @@ -31,8 +32,7 @@
end

it "displays each file set's label" do
expect(rendered).to have_text file_set.to_s
expect(rendered).to have_selector "input[name='file_set[title][]'][type='hidden']"
expect(rendered).to have_selector "input[name='file_set[title][]'][type='text'][value='#{file_set}']"
end

it "has a link back to parent" do
Expand Down

0 comments on commit 8d727c2

Please sign in to comment.