BigW Consortium Gitlab

Commit 85d5f606 by Dmitriy Zaporozhets

Labels autocomplete

parent 2b921a6c
......@@ -13,6 +13,12 @@ window.errorMessage = (message) ->
ehtml.html(message)
ehtml
window.split = (val) ->
return val.split( /,\s*/ )
window.extractLast = (term) ->
return split( term ).pop()
# Disable button if text field is empty
window.disableButtonIfEmptyField = (field_selector, button_selector) ->
field = $(field_selector)
......
......@@ -30,4 +30,10 @@ module IssuesHelper
open: "open"
}
end
def labels_autocomplete_source
labels = @project.issues_labels.order('count DESC')
labels = labels.map{ |l| { label: l.name, value: l.name } }
labels.to_json
end
end
......@@ -55,3 +55,36 @@
= link_to "Cancel", project_issues_path(@project), class: cancel_class
- else
= link_to "Cancel", project_issue_path(@project, @issue), class: cancel_class
:javascript
$(function(){
$("#issue_label_list")
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source: function( request, response ) {
response( $.ui.autocomplete.filter(
#{raw labels_autocomplete_source}, extractLast( request.term ) ) );
},
focus: function() {
return false;
},
select: function(event, ui) {
var terms = split( this.value );
terms.pop();
terms.push( ui.item.value );
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment