Skip to content

Instantly share code, notes, and snippets.

@aravindgd
Last active August 29, 2015 14:11
Show Gist options
  • Save aravindgd/627f81d9810b3fe8fc69 to your computer and use it in GitHub Desktop.
Save aravindgd/627f81d9810b3fe8fc69 to your computer and use it in GitHub Desktop.
$("#ticket_id_select").select2
width: "150px"
multiple: true
placeholder: "Search for a ticket with id"
minimumInputLength: 1
ajax: # instead of writing the function to execute the ticket we use Select2's convenient helper
url: "/list_ticket_id"
dataType: "json"
data: (term, page) ->
page: page
q: term # search term
q1: get_ticket_if_from_already_selected
q2: $('input[name=ticket_ser_type]:checked').val()
max: 20
results: (data, page) -> # parse the results into the format expected by Select2.
more = (page * 10) < data.total;
results: data
return {results: data, more: more};
formatResult: format
formatSelection: format
dropdownCssClass: "bigdrop"
escapeMarkup: (m) ->
m
format = (ticket) ->
search_type = $('input[name=ticket_ser_type]:checked').val()
console.log search_type
console.log search_type is "ticket"
if search_type is "ticket"
ticket.id
else
ticket.text
json.array!(@ticket) do |ticket|
json.id ticket.display_number
json.text ticket.user_name+" "+" #"+ticket.display_number.to_s+" "+ticket.subject
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment