Proposal, Debate, Budget Investment and Comment will be translatable models soon. This commit prepares suggestions script to work well with translatable forms elements too.
30 lines
763 B
CoffeeScript
30 lines
763 B
CoffeeScript
App.Suggest =
|
|
|
|
initialize: ->
|
|
|
|
$("[data-js-suggest-result]").each ->
|
|
|
|
$this = $(this)
|
|
|
|
callback = ->
|
|
$.ajax
|
|
url: $this.data("js-url")
|
|
data:
|
|
search: $this.val()
|
|
type: "GET"
|
|
dataType: "html"
|
|
success: (stHtml) ->
|
|
js_suggest_selector = $this.data("js-suggest")
|
|
if js_suggest_selector.startsWith(".")
|
|
locale = $this.closest(".translatable-fields").data("locale")
|
|
js_suggest_selector += "[data-locale=#{locale}]"
|
|
$(js_suggest_selector).html(stHtml)
|
|
|
|
timer = null
|
|
|
|
$this.on "keyup", ->
|
|
window.clearTimeout(timer)
|
|
timer = window.setTimeout(callback, 1000)
|
|
|
|
$this.on "change", callback
|