Extended autocompletion with customized templates
This commit is contained in:
@@ -1,15 +1,35 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
(function() {
|
||||
var $el, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_REGEXP_VALIDATOR, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, controls, name, state, trigger_callback, type, typemap, validatormap, _ref, _ref1, _ref2,
|
||||
var $el, Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_REGEXP_VALIDATOR, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, cache, controls, name, state, template, tmpl, trigger_callback, type, typemap, validatormap, _ref, _ref1, _ref2,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
cache = {};
|
||||
|
||||
template = tmpl = function(str, data) {
|
||||
var fn;
|
||||
fn = (!/\W/.test(str) ? cache[str] = cache[str] || tmpl(str) : 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) {
|
||||
return fn(data);
|
||||
} else {
|
||||
return fn;
|
||||
}
|
||||
};
|
||||
|
||||
Mini = {
|
||||
compile: function(t) {
|
||||
return {
|
||||
render: template(t)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
trigger_callback = function(control_name, event) {
|
||||
return $.ajax({
|
||||
data: {
|
||||
control_name: control_name,
|
||||
event: event,
|
||||
states: JSON.stringify(states)
|
||||
states: JSON.stringify(window.states)
|
||||
},
|
||||
cache: false
|
||||
}).done(function(new_states) {
|
||||
@@ -228,75 +248,46 @@
|
||||
return WSF_TEXTAREA_CONTROL.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
WSF_TEXTAREA_CONTROL.prototype.attach_events = function() {
|
||||
var self;
|
||||
self = this;
|
||||
return this.$el.change(function() {
|
||||
return self.change();
|
||||
});
|
||||
};
|
||||
|
||||
WSF_TEXTAREA_CONTROL.prototype.change = function() {
|
||||
window.states[this.control_name]['text'] = this.$el.val();
|
||||
if (window.states[this.control_name]['callback_change']) {
|
||||
trigger_callback(this.control_name, 'change');
|
||||
}
|
||||
return this.trigger('change');
|
||||
};
|
||||
|
||||
WSF_TEXTAREA_CONTROL.prototype.value = function() {
|
||||
return this.$el.val();
|
||||
};
|
||||
|
||||
WSF_TEXTAREA_CONTROL.prototype.update = function(state) {
|
||||
if (state.text != null) {
|
||||
window.states[this.control_name]['text'] = state.text;
|
||||
return this.$el.val(state.text);
|
||||
}
|
||||
};
|
||||
|
||||
return WSF_TEXTAREA_CONTROL;
|
||||
|
||||
})(WSF_CONTROL);
|
||||
})(WSF_INPUT_CONTROL);
|
||||
|
||||
WSF_TEXTAREA_CONTROL = (function(_super) {
|
||||
WSF_AUTOCOMPLETE_CONTROL = (function(_super) {
|
||||
|
||||
__extends(WSF_TEXTAREA_CONTROL, _super);
|
||||
__extends(WSF_AUTOCOMPLETE_CONTROL, _super);
|
||||
|
||||
function WSF_TEXTAREA_CONTROL() {
|
||||
return WSF_TEXTAREA_CONTROL.__super__.constructor.apply(this, arguments);
|
||||
function WSF_AUTOCOMPLETE_CONTROL() {
|
||||
return WSF_AUTOCOMPLETE_CONTROL.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
WSF_TEXTAREA_CONTROL.prototype.attach_events = function() {
|
||||
WSF_AUTOCOMPLETE_CONTROL.prototype.attach_events = function() {
|
||||
var self;
|
||||
WSF_AUTOCOMPLETE_CONTROL.__super__.attach_events.apply(this, arguments);
|
||||
self = this;
|
||||
return this.$el.change(function() {
|
||||
return self.change();
|
||||
return this.$el.typeahead({
|
||||
name: this.control_name,
|
||||
template: window.states[this.control_name]['template'],
|
||||
engine: Mini,
|
||||
remote: {
|
||||
url: "",
|
||||
replace: function(url, uriEncodedQuery) {
|
||||
window.states[self.control_name]['text'] = self.$el.val();
|
||||
return '?' + $.param({
|
||||
control_name: self.control_name,
|
||||
event: 'autocomplete',
|
||||
states: JSON.stringify(window.states)
|
||||
});
|
||||
},
|
||||
filter: function(parsedResponse) {
|
||||
return parsedResponse[self.control_name]['suggestions'];
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
WSF_TEXTAREA_CONTROL.prototype.change = function() {
|
||||
window.states[this.control_name]['text'] = this.$el.val();
|
||||
if (window.states[this.control_name]['callback_change']) {
|
||||
trigger_callback(this.control_name, 'change');
|
||||
}
|
||||
return this.trigger('change');
|
||||
};
|
||||
return WSF_AUTOCOMPLETE_CONTROL;
|
||||
|
||||
WSF_TEXTAREA_CONTROL.prototype.value = function() {
|
||||
return this.$el.val();
|
||||
};
|
||||
|
||||
WSF_TEXTAREA_CONTROL.prototype.update = function(state) {
|
||||
if (state.text != null) {
|
||||
window.states[this.control_name]['text'] = state.text;
|
||||
return this.$el.val(state.text);
|
||||
}
|
||||
};
|
||||
|
||||
return WSF_TEXTAREA_CONTROL;
|
||||
|
||||
})(WSF_CONTROL);
|
||||
})(WSF_INPUT_CONTROL);
|
||||
|
||||
WSF_CHECKBOX_CONTROL = (function(_super) {
|
||||
|
||||
@@ -476,6 +467,7 @@
|
||||
"WSF_BUTTON_CONTROL": WSF_BUTTON_CONTROL,
|
||||
"WSF_INPUT_CONTROL": WSF_INPUT_CONTROL,
|
||||
"WSF_TEXTAREA_CONTROL": WSF_TEXTAREA_CONTROL,
|
||||
"WSF_AUTOCOMPLETE_CONTROL": WSF_AUTOCOMPLETE_CONTROL,
|
||||
"WSF_CHECKBOX_CONTROL": WSF_CHECKBOX_CONTROL,
|
||||
"WSF_FORM_ELEMENT_CONTROL": WSF_FORM_ELEMENT_CONTROL,
|
||||
"WSF_HTML_CONTROL": WSF_HTML_CONTROL,
|
||||
|
||||
Reference in New Issue
Block a user