forked from extnet/Ext.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractReader.cs
More file actions
308 lines (298 loc) · 11.9 KB
/
AbstractReader.cs
File metadata and controls
308 lines (298 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/********
* @version : 2.1.1 - Ext.NET Pro License
* @author : Ext.NET, Inc. http://www.ext.net/
* @date : 2012-12-10
* @copyright : Copyright (c) 2007-2012, Ext.NET, Inc. (http://www.ext.net/). All rights reserved.
* @license : See license.txt and http://www.ext.net/license/.
********/
using System.ComponentModel;
using System.Web.UI;
namespace Ext.Net
{
/// <summary>
/// Readers are used to interpret data to be loaded into a Model instance or a Store - usually in response to an AJAX request. This is normally handled transparently by passing some configuration to either the Model or the Store in question - see their documentation for further details.
///
/// Loading Nested Data
///
/// Readers have the ability to automatically load deeply-nested data objects based on the associations configured on each Model. Below is an example demonstrating the flexibility of these associations in a fictional CRM system which manages a User, their Orders, OrderItems and Products. First we'll define the models:
///
/// Ext.regModel("User", {
/// fields: [
/// 'id', 'name'
/// ],
///
/// hasMany: {model: 'Order', name: 'orders'},
///
/// proxy: {
/// type: 'rest',
/// url : 'users.json',
/// reader: {
/// type: 'json',
/// root: 'users'
/// }
/// }
/// });
///
/// Ext.regModel("Order", {
/// fields: [
/// 'id', 'total'
/// ],
///
/// hasMany : {model: 'OrderItem', name: 'orderItems', associationKey: 'order_items'},
/// belongsTo: 'User'
/// });
///
/// Ext.regModel("OrderItem", {
/// fields: [
/// 'id', 'price', 'quantity', 'order_id', 'product_id'
/// ],
///
/// belongsTo: ['Order', {model: 'Product', associationKey: 'product'}]
/// });
///
/// Ext.regModel("Product", {
/// fields: [
/// 'id', 'name'
/// ],
///
/// hasMany: 'OrderItem'
/// });
/// This may be a lot to take in - basically a User has many Orders, each of which is composed of several OrderItems. Finally, each OrderItem has a single Product. This allows us to consume data like this:
///
/// {
/// "users": [
/// {
/// "id": 123,
/// "name": "Ed",
/// "orders": [
/// {
/// "id": 50,
/// "total": 100,
/// "order_items": [
/// {
/// "id" : 20,
/// "price" : 40,
/// "quantity": 2,
/// "product" : {
/// "id": 1000,
/// "name": "MacBook Pro"
/// }
/// },
/// {
/// "id" : 21,
/// "price" : 20,
/// "quantity": 3,
/// "product" : {
/// "id": 1001,
/// "name": "iPhone"
/// }
/// }
/// ]
/// }
/// ]
/// }
/// ]
/// }
/// The JSON response is deeply nested - it returns all Users (in this case just 1 for simplicity's sake), all of the Orders for each User (again just 1 in this case), all of the OrderItems for each Order (2 order items in this case), and finally the Product associated with each OrderItem. Now we can read the data and use it as follows:
///
/// var store = new Ext.data.Store({
/// model: "User"
/// });
///
/// store.load({
/// callback: function() {
/// //the user that was loaded
/// var user = store.first();
///
/// console.log("Orders for " + user.get('name') + ":")
///
/// //iterate over the Orders for each User
/// user.orders().each(function(order) {
/// console.log("Order ID: " + order.getId() + ", which contains items:");
///
/// //iterate over the OrderItems for each Order
/// order.orderItems().each(function(orderItem) {
/// //we know that the Product data is already loaded, so we can use the synchronous getProduct
/// //usually, we would use the asynchronous version (see Ext.data.BelongsToAssociation)
/// var product = orderItem.getProduct();
///
/// console.log(orderItem.get('quantity') + ' orders of ' + product.get('name'));
/// });
/// });
/// }
/// });
/// Running the code above results in the following:
///
/// Orders for Ed:
/// Order ID: 50, which contains items:
/// 2 orders of MacBook Pro
/// 3 orders of iPhone
/// </summary>
[Meta]
public abstract partial class AbstractReader : BaseItem
{
/// <summary>
/// Alias
/// </summary>
[ConfigOption]
[DefaultValue(null)]
protected abstract string Type
{
get;
}
/// <summary>
/// Name of the property within a row object that contains a record identifier value. Defaults to The id of the model. If an idProperty is explicitly specified it will override that of the one specified on the model
/// </summary>
[Meta]
[ConfigOption("idProperty")]
[DefaultValue("")]
[NotifyParentProperty(true)]
[Description("Name of the property within a row object that contains a record identifier value. Defaults to The id of the model. If an idProperty is explicitly specified it will override that of the one specified on the model")]
public virtual string IDProperty
{
get
{
return this.State.Get<string>("IDProperty", "");
}
set
{
this.State.Set("IDProperty", value);
}
}
/// <summary>
/// True to automatically parse models nested within other models in a response object. See the Ext.data.reader.Reader intro docs for full explanation. Defaults to true.
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(true)]
[NotifyParentProperty(true)]
[Description("True to automatically parse models nested within other models in a response object. See the Ext.data.reader.Reader intro docs for full explanation. Defaults to true.")]
public virtual bool ImplicitIncludes
{
get
{
return this.State.Get<bool>("ImplicitIncludes", true);
}
set
{
this.State.Set("ImplicitIncludes", value);
}
}
/// <summary>
/// True to read extract the records from a data packet even if the success property returns false. Defaults to: true
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(true)]
[NotifyParentProperty(true)]
[Description("True to read extract the records from a data packet even if the success property returns false. Defaults to: true")]
public virtual bool ReadRecordsOnFailure
{
get
{
return this.State.Get<bool>("ReadRecordsOnFailure", true);
}
set
{
this.State.Set("ReadRecordsOnFailure", value);
}
}
/// <summary>
/// The name of the property which contains the Array of row objects. For JSON reader it's dot-separated list of property names. For XML reader it's a CSS selector. For array reader it's not applicable.
/// By default the natural root of the data will be used. The root Json array, the root XML element, or the array.
/// The data packet value for this property should be an empty array to clear the data or show no data.
/// Defaults to: ""
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue("")]
[NotifyParentProperty(true)]
[Description("The name of the property which contains the Array of row objects. For JSON reader it's dot-separated list of property names. For XML reader it's a CSS selector. For array reader it's not applicable.")]
public virtual string Root
{
get
{
return this.State.Get<string>("Root", "");
}
set
{
this.State.Set("Root", value);
}
}
/// <summary>
/// Name of the property from which to retrieve the success attribute. Defaults to success. See Ext.data.proxy.Proxy.exception for additional information.
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue("")]
[NotifyParentProperty(true)]
[Description("Name of the property from which to retrieve the success attribute. Defaults to success. See Ext.data.proxy.Proxy.exception for additional information.")]
public virtual string SuccessProperty
{
get
{
return this.State.Get<string>("SuccessProperty", "");
}
set
{
this.State.Set("SuccessProperty", value);
}
}
/// <summary>
/// Name of the property from which to retrieve the total number of records in the dataset. This is only needed if the whole dataset is not passed in one go, but is being paged from the remote server. Defaults to total.
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue("")]
[NotifyParentProperty(true)]
[Description("Name of the property from which to retrieve the total number of records in the dataset. This is only needed if the whole dataset is not passed in one go, but is being paged from the remote server. Defaults to total.")]
public virtual string TotalProperty
{
get
{
return this.State.Get<string>("TotalProperty", "");
}
set
{
this.State.Set("TotalProperty", value);
}
}
/// <summary>
/// The name of the property which contains a response message. This property is optional.
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue("")]
[NotifyParentProperty(true)]
[Description("The name of the property which contains a response message. This property is optional.")]
public virtual string MessageProperty
{
get
{
return this.State.Get<string>("MessageProperty", "");
}
set
{
this.State.Set("MessageProperty", value);
}
}
/// <summary>
/// The Ext.data.Model associated with this reader
/// </summary>
[Meta]
[ConfigOption("model")]
[DefaultValue(null)]
[Description("The Ext.data.Model associated with this reader")]
public virtual string ModelName
{
get
{
return this.State.Get<string>("ModelName", null);
}
set
{
this.State.Set("ModelName", value);
}
}
}
}