Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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