Labels autocomplete
This commit is contained in:
parent
2b921a6c72
commit
85d5f606f6
3 changed files with 45 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue