Move functionality to label[]

This commit is contained in:
Jacob Schatz 2016-04-08 14:23:51 -04:00 committed by Jacob Schatz
parent e684480eeb
commit 1617d1e026
2 changed files with 16 additions and 45 deletions

View File

@ -50,45 +50,8 @@
, 500)
filterResults: (form) =>
# Assume for now there is only 1 multi select field
# Find the hidden inputs with square brackets
$multiInputs = form.find('input[name$="[]"]')
if $multiInputs.length
# get the name of one of them
multiInputName = $multiInputs
.first()
.attr('name')
# get the singular name by
# removing the square brackets from the name
singularName = multiInputName.replace('[]','')
# clone the form so we can mess around with it.
$clonedForm = form.clone()
# get those inputs from the cloned form
$inputs = $clonedForm
.find("input[name='#{multiInputName}']")
# make a comma seperated list of labels
commaSeperated = $inputs
.map( -> $(this).val())
.get()
.join(',')
# append on a hidden input with the comma
# seperated values in it
$clonedForm.append(
$('<input />')
.attr('type','hidden')
.attr('name', singularName)
.val(commaSeperated)
)
# remove the multi inputs from the
# cloned form so they don't get serialized
$inputs.remove()
# serialize the cloned form
formData = $clonedForm.serialize()
else
formData = form.serialize()
formData = form.serialize()
$('.issues-holder, .merge-requests-holder').css("opacity", '0.5')
formAction = form.attr('action')

View File

@ -17,15 +17,23 @@ module IssuablesHelper
end
def multi_label_name(current_labels, default_label)
if current_labels.presence
if current_labels.include? ','
labels = current_labels.split(',')
"#{labels[0]} +#{labels.count - 1} more"
# current_labels may be a string from before
if current_labels.respond_to?('any?')
if current_labels.any?
if current_labels.count > 1
"#{current_labels[0]} +#{current_labels.count - 1} more"
else
current_labels[0]
end
else
default_label
end
else
if current_labels.nil?
default_label
else
current_labels
end
else
default_label
end
end