1 /**
  2  * This is the root Configuration object to configure RedQueryBuilder.
  3  * 
  4  * @constructor
  5  */
  6 function Configuration(meta) {
  7     /**
  8      * The description of the database.
  9      * @type Meta
 10      */
 11 	this.meta = meta;
 12 
 13 	/** 
 14 	 * Notification of the SQL or argument values changing.
 15 	 * @function 
 16 	 * @param {string} sql the new SQL.
 17 	 * @param {object[]} args the new argument values.*/
 18 	this.onSqlChange = function(sql, args) {}
 19 	
 20 	/** 
 21 	 * Notification of the set of tables changing.
 22 	 * @function 
 23 	 * @param {TableFilter[]} filters the latest TableFilters.*/
 24 	this.onTableChange = function(filters) {}
 25 	
 26 	/** 
 27 	 * Notification that widget is fully loaded.
 28 	 * @function 
 29 	 */
 30 	this.onLoad = function() {}
 31 	
 32 	/** 
 33 	 * Initial request from the Suggestion Oracle.
 34 	 * @function
 35 	 * @param {SuggestRequest} request details.
 36 	 * @param {function} callback to return any suggestions.*/
 37 	this.defaultSuggest = function(request, callback) {}
 38 	
 39 	/** 
 40 	 * Request from the Suggestion Oracle.
 41 	 * @function
 42 	 * @param {SuggestRequest} request details.
 43 	 * @param {function} callback to return any suggestions.*/
 44 	this.suggest = function(request, callback) {}
 45 	
 46 	/**
 47 	 * Request from the Select editor etc.
 48 	 * @function
 49 	 * @param {EnumerateRequest} request request details.
 50 	 * @param {function} callback to return any suggestions. Can be an array of strings or
 51 	 * array of {Suggestion}s.
 52 	 */
 53 	this.enumerate = function(request, callback) {}
 54 	
 55 	/**
 56 	 * Configuration of Editors.
 57 	 * @type Editor[]
 58 	 */
 59 	this.editors = [];
 60 	
 61 	/**
 62 	 * Configuration of the From control.
 63 	 * @type From
 64 	 */
 65 	this.from = null;
 66 }
 67 
 68 /**
 69  * Database meta data.
 70  * 
 71  * @constructor
 72  */
 73 function Meta() {
 74 	/**
 75 	 * @type Table[] 
 76 	 */
 77 	this.tables = [];
 78 	/**
 79 	 * @type Type[]
 80 	 */
 81 	this.types = [];
 82 }
 83 
 84 /**
 85  * Database table.
 86  * 
 87  * @constructor
 88  */
 89 function Table(name, label, columns) {
 90     /**
 91      * Name to be used in the SQL.
 92      * @type string
 93      */
 94 	this.name = name;
 95 	
 96     /**
 97      * The text to display to the user.
 98      * @type string
 99      */
100 	this.label = label;
101 
102     /**
103      * Table columns.
104      * @type Column[]
105      */
106 	this.columns = columns;
107 	
108     /**
109      * Optional set of foreign keys.
110      * @type ForeignKey[]
111      */
112 	this.fks = [];
113 }
114 
115 
116 /**
117  * Database column.
118  * 
119  * @constructor
120  */
121 function Column(name, label, type) {
122     /**
123      * The name to be used in the SQL.
124      * @type string
125      */
126 	this.name = name;
127 	
128     /**
129      * The text to display to the user.
130      * @type string
131      */
132 	this.label = label;
133 	
134     /**
135      * The type name that references a type defined in meta.types[].
136      * @type string
137      */
138 	this.type = type;
139 	
140 	/**
141 	 * Optional override of the Editor.
142      * @type string
143      */
144     this.editor = null;
145     
146     /**
147      * CSS style name(s).
148      * @type string
149      */
150 	this.class = null;
151 }
152 
153 /**
154  * Request to enumerate the applicable values.
155  * 
156  * @constructor
157  */
158 function EnumerateRequest() {
159     /**
160      * SQL table name.
161      * @type string
162      */
163 	this.tableName = null;
164 	
165 	/**
166      * Column name.
167      * @type string
168      */
169 	this.columnName = null;
170 	
171 	/**
172      * Column Type name.
173      * @type string
174      */
175 	this.columnTypeName = null;
176 }
177 
178 /**
179  * A value in a Suggestion Request Reponse.
180  * 
181  * @constructor
182  */
183 function Suggestion(value, label) {
184     /**
185      * Value to be used in the SQL query.
186      * @type object
187      */
188 	this.value = value;
189 	
190 	/**
191      * Label to show to the user.
192      * @type string
193      */
194 	this.label = label;
195 }
196 
197 /**
198  * Database column type.
199  * 
200  * @constructor
201  */
202 function Type(name, editor, operators){
203     /**
204      * Type identifier.
205      * @type string
206      */
207 	this.name = name;
208 	
209     /**
210      * An {@link Editor} name.
211      * @type string
212      */
213 	this.editor = editor;
214 	
215     /**
216      * Operators for this type.
217      * @type Operator[]
218      */
219 	this.operators = operators;
220 	
221     /**
222      * CSS style name(s).
223      * @type string
224      */
225 	this.class = null;
226 }
227 
228 /**
229  * A SQL operator.
230  * 
231  * @constructor
232  */
233 function Operator(name, label, cardinality) {
234     /**
235      * The string to be used in the SQL.
236      * @type string
237      */
238 	this.name = name;
239 	
240     /**
241      * The text to display to the user rather than the actual SQL.
242      * @type string
243      */
244 	this.label = label;
245 	
246     /**
247      * The number of values. 'ZERO' such as "a IS NULL", 'ONE' such as "a = b" or 'MULTI' such as "a IN (1,2,3)"
248      * @type string
249      */
250 	this.cardinality = cardinality;
251 	
252 }
253 
254 
255 
256 /**
257  * A database foreign key. Used to generate joins.
258  * 
259  * @constructor
260  */
261 function ForeignKey(name, foreignKeyNames, referencedTableName, referencedKeyNames) {
262     /**
263      * Name for debugging purposes.
264      * @type string
265      */
266 	this.name = name;
267 	
268     /**
269      * The referencing/child column names that reference the key in a foreign table.
270      * @type string[]
271      */
272 	this.foreignKeyNames = foreignKeyNames;
273 	
274     /**
275      * The referenced/parent table name.
276      * @type string
277      */
278 	this.referencedTableName = referencedTableName;
279 
280 	/**
281      * The referenced/parent table column names.
282      * @type string[]
283      */
284 	this.referencedKeyNames = referencedKeyNames;
285 	
286     /**
287      * Text to display to the user when going from owning table to referenced table.
288      * @type string
289      */
290 	this.label = label;
291 
292     /**
293      * Text to display to the user when going from the referenced table to the owning table.
294      * @type string
295      */
296 	this.reverseLabel = reverseLabel;
297 }
298 
299 
300 /**
301  * Request to make suggestions for a search oracle.
302  * 
303  * @constructor
304  */
305 function SuggestRequest() {
306     /**
307      * SQL table name.
308      * @type string
309      */
310 	this.tableName = null;
311 	
312 	/**
313      * Column name.
314      * @type string
315      */
316 	this.columnName = null;
317 	
318 	/**
319      * Column Type name.
320      * @type string
321      */
322 	this.columnTypeName = null;
323 	
324 	/**
325      * Partial text entered by the user.
326      * @type string
327      */
328 	this.query = null;
329 	
330 	/**
331      * Maximum results to return.
332      * @type number
333      */
334 	this.limit = null;
335 }
336 
337 
338 /**
339  * SQL combination of alias and tableName. 
340  * The same table could be used more than once but the alias must be unique.
341  * 
342  * @constructor
343  */
344 function TableFilter(tableName, alias) {
345     /**
346      * SQL table alias.
347      * @type string
348      */
349 	this.alias = alias;
350 	
351 	/**
352      * Table name.
353      * @type string
354      */
355 	this.tableName = tableName;
356 }
357 
358 /**
359  * Configure the From selector.
360  * 
361  * @constructor
362  */
363 function From() {
364     /**
365      * Control if the widget is visible.
366      * @type boolean
367      */
368 	this.visible = true;
369 }
370 
371 
372 /**
373  * Editors inspired by HTML5 elements/attributes.
374  * 
375  * @constructor
376  */
377 function Editor(name) {
378     /**
379      * Editor name.
380      * @type string
381      */
382 	this.name = name;
383 	
384     /**
385      * CSS style name(s).
386      * @type string
387      */
388 	this.class = null;
389 }
390 
391 /** String editor 
392  * @deprecated Since 0.2.0 please use TEXT.
393  * */
394 Editor.STRING = 'STRING';
395 
396 /** Text editor */
397 Editor.TEXT = 'TEXT';
398 
399 /** Date editor 
400  * Configuration attribute 'format' - see http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/i18n/client/DateTimeFormat.html */
401 Editor.DATE = 'DATE';
402 
403 /** Select editor */
404 Editor.SELECT = 'SELECT';
405