1 /**
  2  * A helper class to construct and manage RedQueryBuilder instances.
  3  * 
  4  * Use RedQueryBuilderFactory.create rather than the constructor.
  5  * 
  6  * @constructor
  7  */
  8 function RedQueryBuilderFactory(config, sql, args) {
  9     /**
 10      * The description of the database.
 11      * @type Configuration
 12      */
 13 	this.config = config;
 14 	
 15     /**
 16      * Initial SQL.
 17      * @type string
 18      */
 19 	this.sql = sql;
 20 	
 21     /**
 22      * Initial arguments.
 23      * @type string[]
 24      */
 25 	this.args = args;
 26 }
 27 
 28 RedQueryBuilderFactory.create = function(config, sql, args) {
 29   var x = new RedQueryBuilderFactory(config, sql, args);
 30   x.waitForLoad();
 31 }
 32 
 33 RedQueryBuilderFactory.prototype.waitForLoad = function() {
 34   var rqb = this;
 35   var fn = function() {
 36     if (!window.redQueryBuilder) {
 37       setTimeout(fn, 50);
 38     } else {
 39       rqb.ready();
 40     }
 41   }
 42   fn();
 43 }
 44 
 45 RedQueryBuilderFactory.prototype.ready = function() {
 46   var instance = window.redQueryBuilder(this.config, this.sql, this.args);
 47   if (this.config.onLoad) {
 48 	  this.config.onLoad(instance);
 49   }
 50 }