Extended autocompletion with customized templates

This commit is contained in:
Severin Münger
2013-09-12 17:15:05 +02:00
parent 27023283e7
commit 162735b328
12 changed files with 260 additions and 66 deletions

View File

@@ -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