]> git.wh0rd.org - tt-rss.git/blob - lib/dojo/data/api/Read.js
upgrade Dojo to 1.6.1
[tt-rss.git] / lib / dojo / data / api / Read.js
1 /*
2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
5 */
6
7
8 if(!dojo._hasResource["dojo.data.api.Read"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo._hasResource["dojo.data.api.Read"] = true;
10 dojo.provide("dojo.data.api.Read");
11 dojo.require("dojo.data.api.Request");
12
13
14 dojo.declare("dojo.data.api.Read", null, {
15 // summary:
16 // This is an abstract API that data provider implementations conform to.
17 // This file defines methods signatures and intentionally leaves all the
18 // methods unimplemented. For more information on the dojo.data APIs,
19 // please visit: http://www.dojotoolkit.org/node/98
20
21 getValue: function( /* item */ item,
22 /* attribute-name-string */ attribute,
23 /* value? */ defaultValue){
24 // summary:
25 // Returns a single attribute value.
26 // Returns defaultValue if and only if *item* does not have a value for *attribute*.
27 // Returns null if and only if null was explicitly set as the attribute value.
28 // Returns undefined if and only if the item does not have a value for the
29 // given attribute (which is the same as saying the item does not have the attribute).
30 // description:
31 // Saying that an "item x does not have a value for an attribute y"
32 // is identical to saying that an "item x does not have attribute y".
33 // It is an oxymoron to say "that attribute is present but has no values"
34 // or "the item has that attribute but does not have any attribute values".
35 // If store.hasAttribute(item, attribute) returns false, then
36 // store.getValue(item, attribute) will return undefined.
37 //
38 // item:
39 // The item to access values on.
40 // attribute:
41 // The attribute to access represented as a string.
42 // defaultValue:
43 // Optional. A default value to use for the getValue return in the attribute does not exist or has no value.
44 //
45 // exceptions:
46 // Throws an exception if *item* is not an item, or *attribute* is not a string
47 // example:
48 // | var darthVader = store.getValue(lukeSkywalker, "father");
49 var attributeValue = null;
50 throw new Error('Unimplemented API: dojo.data.api.Read.getValue');
51 return attributeValue; // a literal, an item, null, or undefined (never an array)
52 },
53
54 getValues: function(/* item */ item,
55 /* attribute-name-string */ attribute){
56 // summary:
57 // This getValues() method works just like the getValue() method, but getValues()
58 // always returns an array rather than a single attribute value. The array
59 // may be empty, may contain a single attribute value, or may contain
60 // many attribute values.
61 // If the item does not have a value for the given attribute, then getValues()
62 // will return an empty array: []. (So, if store.hasAttribute(item, attribute)
63 // has a return of false, then store.getValues(item, attribute) will return [].)
64 //
65 // item:
66 // The item to access values on.
67 // attribute:
68 // The attribute to access represented as a string.
69 //
70 // exceptions:
71 // Throws an exception if *item* is not an item, or *attribute* is not a string
72 // example:
73 // | var friendsOfLuke = store.getValues(lukeSkywalker, "friends");
74 var array = [];
75 throw new Error('Unimplemented API: dojo.data.api.Read.getValues');
76 return array; // an array that may contain literals and items
77 },
78
79 getAttributes: function(/* item */ item){
80 // summary:
81 // Returns an array with all the attributes that this item has. This
82 // method will always return an array; if the item has no attributes
83 // at all, getAttributes() will return an empty array: [].
84 //
85 // item:
86 // The item to access attributes on.
87 //
88 // exceptions:
89 // Throws an exception if *item* is not an item, or *attribute* is not a string
90 // example:
91 // | var array = store.getAttributes(kermit);
92 var array = [];
93 throw new Error('Unimplemented API: dojo.data.api.Read.getAttributes');
94 return array; // array
95 },
96
97 hasAttribute: function( /* item */ item,
98 /* attribute-name-string */ attribute){
99 // summary:
100 // Returns true if the given *item* has a value for the given *attribute*.
101 //
102 // item:
103 // The item to access attributes on.
104 // attribute:
105 // The attribute to access represented as a string.
106 //
107 // exceptions:
108 // Throws an exception if *item* is not an item, or *attribute* is not a string
109 // example:
110 // | var trueOrFalse = store.hasAttribute(kermit, "color");
111 throw new Error('Unimplemented API: dojo.data.api.Read.hasAttribute');
112 return false; // boolean
113 },
114
115 containsValue: function(/* item */ item,
116 /* attribute-name-string */ attribute,
117 /* anything */ value){
118 // summary:
119 // Returns true if the given *value* is one of the values that getValues()
120 // would return.
121 //
122 // item:
123 // The item to access values on.
124 // attribute:
125 // The attribute to access represented as a string.
126 // value:
127 // The value to match as a value for the attribute.
128 //
129 // exceptions:
130 // Throws an exception if *item* is not an item, or *attribute* is not a string
131 // example:
132 // | var trueOrFalse = store.containsValue(kermit, "color", "green");
133 throw new Error('Unimplemented API: dojo.data.api.Read.containsValue');
134 return false; // boolean
135 },
136
137 isItem: function(/* anything */ something){
138 // summary:
139 // Returns true if *something* is an item and came from the store instance.
140 // Returns false if *something* is a literal, an item from another store instance,
141 // or is any object other than an item.
142 //
143 // something:
144 // Can be anything.
145 //
146 // example:
147 // | var yes = store.isItem(store.newItem());
148 // | var no = store.isItem("green");
149 throw new Error('Unimplemented API: dojo.data.api.Read.isItem');
150 return false; // boolean
151 },
152
153 isItemLoaded: function(/* anything */ something){
154 // summary:
155 // Returns false if isItem(something) is false. Returns false if
156 // if isItem(something) is true but the the item is not yet loaded
157 // in local memory (for example, if the item has not yet been read
158 // from the server).
159 //
160 // something:
161 // Can be anything.
162 //
163 // example:
164 // | var yes = store.isItemLoaded(store.newItem());
165 // | var no = store.isItemLoaded("green");
166 throw new Error('Unimplemented API: dojo.data.api.Read.isItemLoaded');
167 return false; // boolean
168 },
169
170 loadItem: function(/* object */ keywordArgs){
171 // summary:
172 // Given an item, this method loads the item so that a subsequent call
173 // to store.isItemLoaded(item) will return true. If a call to
174 // isItemLoaded() returns true before loadItem() is even called,
175 // then loadItem() need not do any work at all and will not even invoke
176 // the callback handlers. So, before invoking this method, check that
177 // the item has not already been loaded.
178 // keywordArgs:
179 // An anonymous object that defines the item to load and callbacks to invoke when the
180 // load has completed. The format of the object is as follows:
181 // {
182 // item: object,
183 // onItem: Function,
184 // onError: Function,
185 // scope: object
186 // }
187 // The *item* parameter.
188 // The item parameter is an object that represents the item in question that should be
189 // contained by the store. This attribute is required.
190
191 // The *onItem* parameter.
192 // Function(item)
193 // The onItem parameter is the callback to invoke when the item has been loaded. It takes only one
194 // parameter, the fully loaded item.
195 //
196 // The *onError* parameter.
197 // Function(error)
198 // The onError parameter is the callback to invoke when the item load encountered an error. It takes only one
199 // parameter, the error object
200 //
201 // The *scope* parameter.
202 // If a scope object is provided, all of the callback functions (onItem,
203 // onError, etc) will be invoked in the context of the scope object.
204 // In the body of the callback function, the value of the "this"
205 // keyword will be the scope object. If no scope object is provided,
206 // the callback functions will be called in the context of dojo.global().
207 // For example, onItem.call(scope, item, request) vs.
208 // onItem.call(dojo.global(), item, request)
209 if(!this.isItemLoaded(keywordArgs.item)){
210 throw new Error('Unimplemented API: dojo.data.api.Read.loadItem');
211 }
212 },
213
214 fetch: function(/* Object */ keywordArgs){
215 // summary:
216 // Given a query and set of defined options, such as a start and count of items to return,
217 // this method executes the query and makes the results available as data items.
218 // The format and expectations of stores is that they operate in a generally asynchronous
219 // manner, therefore callbacks are always used to return items located by the fetch parameters.
220 //
221 // description:
222 // A Request object will always be returned and is returned immediately.
223 // The basic request is nothing more than the keyword args passed to fetch and
224 // an additional function attached, abort(). The returned request object may then be used
225 // to cancel a fetch. All data items returns are passed through the callbacks defined in the
226 // fetch parameters and are not present on the 'request' object.
227 //
228 // This does not mean that custom stores can not add methods and properties to the request object
229 // returned, only that the API does not require it. For more info about the Request API,
230 // see dojo.data.api.Request
231 //
232 // keywordArgs:
233 // The keywordArgs parameter may either be an instance of
234 // conforming to dojo.data.api.Request or may be a simple anonymous object
235 // that may contain any of the following:
236 // {
237 // query: query-object or query-string,
238 // queryOptions: object,
239 // onBegin: Function,
240 // onItem: Function,
241 // onComplete: Function,
242 // onError: Function,
243 // scope: object,
244 // start: int
245 // count: int
246 // sort: array
247 // }
248 // All implementations should accept keywordArgs objects with any of
249 // the 9 standard properties: query, onBegin, onItem, onComplete, onError
250 // scope, sort, start, and count. Some implementations may accept additional
251 // properties in the keywordArgs object as valid parameters, such as
252 // {includeOutliers:true}.
253 //
254 // The *query* parameter.
255 // The query may be optional in some data store implementations.
256 // The dojo.data.api.Read API does not specify the syntax or semantics
257 // of the query itself -- each different data store implementation
258 // may have its own notion of what a query should look like.
259 // However, as of dojo 0.9, 1.0, and 1.1, all the provided datastores in dojo.data
260 // and dojox.data support an object structure query, where the object is a set of
261 // name/value parameters such as { attrFoo: valueBar, attrFoo1: valueBar1}. Most of the
262 // dijit widgets, such as ComboBox assume this to be the case when working with a datastore
263 // when they dynamically update the query. Therefore, for maximum compatibility with dijit
264 // widgets the recommended query parameter is a key/value object. That does not mean that the
265 // the datastore may not take alternative query forms, such as a simple string, a Date, a number,
266 // or a mix of such. Ultimately, The dojo.data.api.Read API is agnostic about what the query
267 // format.
268 // Further note: In general for query objects that accept strings as attribute
269 // value matches, the store should also support basic filtering capability, such as *
270 // (match any character) and ? (match single character). An example query that is a query object
271 // would be like: { attrFoo: "value*"}. Which generally means match all items where they have
272 // an attribute named attrFoo, with a value that starts with 'value'.
273 //
274 // The *queryOptions* parameter
275 // The queryOptions parameter is an optional parameter used to specify optiosn that may modify
276 // the query in some fashion, such as doing a case insensitive search, or doing a deep search
277 // where all items in a hierarchical representation of data are scanned instead of just the root
278 // items. It currently defines two options that all datastores should attempt to honor if possible:
279 // {
280 // ignoreCase: boolean, //Whether or not the query should match case sensitively or not. Default behaviour is false.
281 // deep: boolean //Whether or not a fetch should do a deep search of items and all child
282 // //items instead of just root-level items in a datastore. Default is false.
283 // }
284 //
285 // The *onBegin* parameter.
286 // function(size, request);
287 // If an onBegin callback function is provided, the callback function
288 // will be called just once, before the first onItem callback is called.
289 // The onBegin callback function will be passed two arguments, the
290 // the total number of items identified and the Request object. If the total number is
291 // unknown, then size will be -1. Note that size is not necessarily the size of the
292 // collection of items returned from the query, as the request may have specified to return only a
293 // subset of the total set of items through the use of the start and count parameters.
294 //
295 // The *onItem* parameter.
296 // function(item, request);
297 // If an onItem callback function is provided, the callback function
298 // will be called as each item in the result is received. The callback
299 // function will be passed two arguments: the item itself, and the
300 // Request object.
301 //
302 // The *onComplete* parameter.
303 // function(items, request);
304 //
305 // If an onComplete callback function is provided, the callback function
306 // will be called just once, after the last onItem callback is called.
307 // Note that if the onItem callback is not present, then onComplete will be passed
308 // an array containing all items which matched the query and the request object.
309 // If the onItem callback is present, then onComplete is called as:
310 // onComplete(null, request).
311 //
312 // The *onError* parameter.
313 // function(errorData, request);
314 // If an onError callback function is provided, the callback function
315 // will be called if there is any sort of error while attempting to
316 // execute the query.
317 // The onError callback function will be passed two arguments:
318 // an Error object and the Request object.
319 //
320 // The *scope* parameter.
321 // If a scope object is provided, all of the callback functions (onItem,
322 // onComplete, onError, etc) will be invoked in the context of the scope
323 // object. In the body of the callback function, the value of the "this"
324 // keyword will be the scope object. If no scope object is provided,
325 // the callback functions will be called in the context of dojo.global().
326 // For example, onItem.call(scope, item, request) vs.
327 // onItem.call(dojo.global(), item, request)
328 //
329 // The *start* parameter.
330 // If a start parameter is specified, this is a indication to the datastore to
331 // only start returning items once the start number of items have been located and
332 // skipped. When this parameter is paired withh 'count', the store should be able
333 // to page across queries with millions of hits by only returning subsets of the
334 // hits for each query
335 //
336 // The *count* parameter.
337 // If a count parameter is specified, this is a indication to the datastore to
338 // only return up to that many items. This allows a fetch call that may have
339 // millions of item matches to be paired down to something reasonable.
340 //
341 // The *sort* parameter.
342 // If a sort parameter is specified, this is a indication to the datastore to
343 // sort the items in some manner before returning the items. The array is an array of
344 // javascript objects that must conform to the following format to be applied to the
345 // fetching of items:
346 // {
347 // attribute: attribute || attribute-name-string,
348 // descending: true|false; // Optional. Default is false.
349 // }
350 // Note that when comparing attributes, if an item contains no value for the attribute
351 // (undefined), then it the default ascending sort logic should push it to the bottom
352 // of the list. In the descending order case, it such items should appear at the top of the list.
353 //
354 // returns:
355 // The fetch() method will return a javascript object conforming to the API
356 // defined in dojo.data.api.Request. In general, it will be the keywordArgs
357 // object returned with the required functions in Request.js attached.
358 // Its general purpose is to provide a convenient way for a caller to abort an
359 // ongoing fetch.
360 //
361 // The Request object may also have additional properties when it is returned
362 // such as request.store property, which is a pointer to the datastore object that
363 // fetch() is a method of.
364 //
365 // exceptions:
366 // Throws an exception if the query is not valid, or if the query
367 // is required but was not supplied.
368 //
369 // example:
370 // Fetch all books identified by the query and call 'showBooks' when complete
371 // | var request = store.fetch({query:"all books", onComplete: showBooks});
372 // example:
373 // Fetch all items in the story and call 'showEverything' when complete.
374 // | var request = store.fetch(onComplete: showEverything);
375 // example:
376 // Fetch only 10 books that match the query 'all books', starting at the fifth book found during the search.
377 // This demonstrates how paging can be done for specific queries.
378 // | var request = store.fetch({query:"all books", start: 4, count: 10, onComplete: showBooks});
379 // example:
380 // Fetch all items that match the query, calling 'callback' each time an item is located.
381 // | var request = store.fetch({query:"foo/bar", onItem:callback});
382 // example:
383 // Fetch the first 100 books by author King, call showKing when up to 100 items have been located.
384 // | var request = store.fetch({query:{author:"King"}, start: 0, count:100, onComplete: showKing});
385 // example:
386 // Locate the books written by Author King, sort it on title and publisher, then return the first 100 items from the sorted items.
387 // | var request = store.fetch({query:{author:"King"}, sort: [{ attribute: "title", descending: true}, {attribute: "publisher"}], ,start: 0, count:100, onComplete: 'showKing'});
388 // example:
389 // Fetch the first 100 books by authors starting with the name King, then call showKing when up to 100 items have been located.
390 // | var request = store.fetch({query:{author:"King*"}, start: 0, count:100, onComplete: showKing});
391 // example:
392 // Fetch the first 100 books by authors ending with 'ing', but only have one character before it (King, Bing, Ling, Sing, etc.), then call showBooks when up to 100 items have been located.
393 // | var request = store.fetch({query:{author:"?ing"}, start: 0, count:100, onComplete: showBooks});
394 // example:
395 // Fetch the first 100 books by author King, where the name may appear as King, king, KING, kInG, and so on, then call showKing when up to 100 items have been located.
396 // | var request = store.fetch({query:{author:"King"}, queryOptions:(ignoreCase: true}, start: 0, count:100, onComplete: showKing});
397 // example:
398 // Paging
399 // | var store = new dojo.data.LargeRdbmsStore({url:"jdbc:odbc:foobar"});
400 // | var fetchArgs = {
401 // | query: {type:"employees", name:"Hillary *"}, // string matching
402 // | sort: [{attribute:"department", descending:true}],
403 // | start: 0,
404 // | count: 20,
405 // | scope: displayer,
406 // | onBegin: showThrobber,
407 // | onItem: displayItem,
408 // | onComplete: stopThrobber,
409 // | onError: handleFetchError,
410 // | };
411 // | store.fetch(fetchArgs);
412 // | ...
413 // and then when the user presses the "Next Page" button...
414 // | fetchArgs.start += 20;
415 // | store.fetch(fetchArgs); // get the next 20 items
416 var request = null;
417 throw new Error('Unimplemented API: dojo.data.api.Read.fetch');
418 return request; // an object conforming to the dojo.data.api.Request API
419 },
420
421 getFeatures: function(){
422 // summary:
423 // The getFeatures() method returns an simple keyword values object
424 // that specifies what interface features the datastore implements.
425 // A simple CsvStore may be read-only, and the only feature it
426 // implements will be the 'dojo.data.api.Read' interface, so the
427 // getFeatures() method will return an object like this one:
428 // {'dojo.data.api.Read': true}.
429 // A more sophisticated datastore might implement a variety of
430 // interface features, like 'dojo.data.api.Read', 'dojo.data.api.Write',
431 // 'dojo.data.api.Identity', and 'dojo.data.api.Attribution'.
432 return {
433 'dojo.data.api.Read': true
434 };
435 },
436
437 close: function(/*dojo.data.api.Request || keywordArgs || null */ request){
438 // summary:
439 // The close() method is intended for instructing the store to 'close' out
440 // any information associated with a particular request.
441 //
442 // description:
443 // The close() method is intended for instructing the store to 'close' out
444 // any information associated with a particular request. In general, this API
445 // expects to recieve as a parameter a request object returned from a fetch.
446 // It will then close out anything associated with that request, such as
447 // clearing any internal datastore caches and closing any 'open' connections.
448 // For some store implementations, this call may be a no-op.
449 //
450 // request:
451 // An instance of a request for the store to use to identify what to close out.
452 // If no request is passed, then the store should clear all internal caches (if any)
453 // and close out all 'open' connections. It does not render the store unusable from
454 // there on, it merely cleans out any current data and resets the store to initial
455 // state.
456 //
457 // example:
458 // | var request = store.fetch({onComplete: doSomething});
459 // | ...
460 // | store.close(request);
461 throw new Error('Unimplemented API: dojo.data.api.Read.close');
462 },
463
464 getLabel: function(/* item */ item){
465 // summary:
466 // Method to inspect the item and return a user-readable 'label' for the item
467 // that provides a general/adequate description of what the item is.
468 //
469 // description:
470 // Method to inspect the item and return a user-readable 'label' for the item
471 // that provides a general/adequate description of what the item is. In general
472 // most labels will be a specific attribute value or collection of the attribute
473 // values that combine to label the item in some manner. For example for an item
474 // that represents a person it may return the label as: "firstname lastlame" where
475 // the firstname and lastname are attributes on the item. If the store is unable
476 // to determine an adequate human readable label, it should return undefined. Users that wish
477 // to customize how a store instance labels items should replace the getLabel() function on
478 // their instance of the store, or extend the store and replace the function in
479 // the extension class.
480 //
481 // item:
482 // The item to return the label for.
483 //
484 // returns:
485 // A user-readable string representing the item or undefined if no user-readable label can
486 // be generated.
487 throw new Error('Unimplemented API: dojo.data.api.Read.getLabel');
488 return undefined;
489 },
490
491 getLabelAttributes: function(/* item */ item){
492 // summary:
493 // Method to inspect the item and return an array of what attributes of the item were used
494 // to generate its label, if any.
495 //
496 // description:
497 // Method to inspect the item and return an array of what attributes of the item were used
498 // to generate its label, if any. This function is to assist UI developers in knowing what
499 // attributes can be ignored out of the attributes an item has when displaying it, in cases
500 // where the UI is using the label as an overall identifer should they wish to hide
501 // redundant information.
502 //
503 // item:
504 // The item to return the list of label attributes for.
505 //
506 // returns:
507 // An array of attribute names that were used to generate the label, or null if public attributes
508 // were not used to generate the label.
509 throw new Error('Unimplemented API: dojo.data.api.Read.getLabelAttributes');
510 return null;
511 }
512 });
513
514 }