Extended autocompletion with customized templates
This commit is contained in:
@@ -1,9 +1,22 @@
|
||||
cache = {}
|
||||
template = tmpl = (str, data) ->
|
||||
# Simple JavaScript Templating
|
||||
# John Resig - http://ejohn.org/ - MIT Licensed
|
||||
fn = (if not /\W/.test(str) then cache[str] = cache[str] or tmpl(str) else new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + "with(obj){p.push('" + str.replace(/[\r\t\n]/g, " ").split("{{").join("\t").replace(/((^|}})[^\t]*)'/g, "$1\r").replace(/\t=(.*?)}}/g, "',$1,'").split("\t").join("');").split("}}").join("p.push('").split("\r").join("\\'") + "');}return p.join('');"))
|
||||
(if data then fn(data) else fn)
|
||||
|
||||
Mini =
|
||||
compile:(t)->
|
||||
{
|
||||
render:template(t)
|
||||
}
|
||||
|
||||
trigger_callback = (control_name,event)->
|
||||
$.ajax
|
||||
data:
|
||||
control_name: control_name
|
||||
event: event
|
||||
states: JSON.stringify(states)
|
||||
states: JSON.stringify(window.states)
|
||||
cache: no
|
||||
.done (new_states)->
|
||||
#Update all classes
|
||||
@@ -118,11 +131,21 @@ class WSF_TEXTAREA_CONTROL extends WSF_INPUT_CONTROL
|
||||
class WSF_AUTOCOMPLETE_CONTROL extends WSF_INPUT_CONTROL
|
||||
attach_events: () ->
|
||||
super
|
||||
self = @
|
||||
@$el.typeahead({
|
||||
name: @control_name
|
||||
local: ["one",
|
||||
"two",
|
||||
"three"]
|
||||
template: window.states[@control_name]['template']
|
||||
engine: Mini
|
||||
remote:
|
||||
url:""
|
||||
replace: (url, uriEncodedQuery) ->
|
||||
window.states[self.control_name]['text'] = self.$el.val()
|
||||
'?' + $.param
|
||||
control_name: self.control_name
|
||||
event: 'autocomplete'
|
||||
states: JSON.stringify(window.states)
|
||||
filter: (parsedResponse) ->
|
||||
parsedResponse[self.control_name]['suggestions']
|
||||
})
|
||||
|
||||
class WSF_CHECKBOX_CONTROL extends WSF_CONTROL
|
||||
|
||||
Reference in New Issue
Block a user