Skip to content

Instantly share code, notes, and snippets.

@jstotz
Created June 26, 2009 17:25
Show Gist options
  • Save jstotz/136610 to your computer and use it in GitHub Desktop.
Save jstotz/136610 to your computer and use it in GitHub Desktop.
/////////////////////////////////////
// In the promotion rule application:
rule = new Rule();
rule.callbacks.get_condition_options = function(type, property, operator, value) {
// Make AJAX call to services:
// GET /promos/rules/options?type=type&property=property&operator=operator&value=value
// Parse the server response into whatever return format is expected of this type of
// callback function (as defined by the general purpose rule system)
return {
types: [...]
properties: [...]
operators: [...]
value_options: [...]
}
});
/////////////////////////////////////
// In the general purpose rule system:
Rule = function() {
this.callbacks = {};
}
Condition = function(rule) {
this.rule = rule;
this.to_html= function() {
options = rule.callbacks.get_condition_options();
// Do whatever you processing we need with those options to render html
return html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment