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