~ubuntu-branches/ubuntu/quantal/maas/quantal-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/docs/recordset/index.html

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html>
2
 
<html lang="en">
3
 
<head>
4
 
    <meta charset="utf-8">
5
 
    <title>Recordset</title>
6
 
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
 
    <link rel="stylesheet" href="../assets/css/main.css">
8
 
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
 
    <script src="../../build/yui/yui-min.js"></script>
10
 
</head>
11
 
<body>
12
 
 
13
 
<div id="doc">
14
 
    <h1>Recordset</h1>
15
 
 
16
 
    
17
 
        <a href="#toc" class="jump">Jump to Table of Contents</a>
18
 
    
19
 
 
20
 
    <div class="yui3-g">
21
 
        <div id="main" class="yui3-u">
22
 
            <div class="content"><div class="intro component">
23
 
    <p>
24
 
        The Recordset utility allows the storage and retrieval of objects with
25
 
        similar properties.
26
 
    </p>
27
 
</div>
28
 
 
29
 
<h2 id="getting-started">Getting Started</h2>
30
 
 
31
 
<p>
32
 
To include the source files for Recordset and its dependencies, first load
33
 
the YUI seed file if you haven't already loaded it.
34
 
</p>
35
 
 
36
 
<pre class="code prettyprint">&lt;script src=&quot;http:&#x2F;&#x2F;yui.yahooapis.com&#x2F;3.4.1&#x2F;build&#x2F;yui&#x2F;yui-min.js&quot;&gt;&lt;&#x2F;script&gt;</pre>
37
 
 
38
 
 
39
 
<p>
40
 
Next, create a new YUI instance for your application and populate it with the
41
 
modules you need by specifying them as arguments to the <code>YUI().use()</code> method.
42
 
YUI will automatically load any dependencies required by the modules you
43
 
specify.
44
 
</p>
45
 
 
46
 
<pre class="code prettyprint">&#x2F;&#x2F; Create a new YUI instance and populate it with the required modules.
47
 
YUI().use(&#x27;recordset&#x27;, function (Y) {
48
 
    &#x2F;&#x2F; Recordset is available and ready for use. Add implementation
49
 
    &#x2F;&#x2F; code here.
50
 
});</pre>
51
 
 
52
 
 
53
 
<p>
54
 
For more information on creating YUI instances and on the
55
 
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the
56
 
documentation for the <a href="../yui/index.html">YUI Global object</a>.
57
 
</p>
58
 
 
59
 
 
60
 
<h2 id="using">Using Recordsets</h2>
61
 
 
62
 
<h3 id="basics">Recordset basics</h3>
63
 
 
64
 
<p>
65
 
    A Recordset in its simplest form is a collection of records, where records
66
 
    can be considered to be object literals. Recordset allows the user to
67
 
    handle this collection of records with a consistent API.
68
 
</p>
69
 
 
70
 
<p>
71
 
    Recordset augments the functionality of <code>Y.Arraylist</code> but goes a
72
 
    step further, by allowing the developer to quickly store and retrieve
73
 
    objects with similar properties. Additional submodules can be plugged into
74
 
    a <code>Y.Recordset</code> instance to enable sorting, filtering and
75
 
    indexing by specific keys.
76
 
</p>
77
 
 
78
 
<p>
79
 
    Initializing a Recordset is straight-forward:
80
 
</p>
81
 
 
82
 
<pre class="code prettyprint">YUI().use(&quot;recordset-base&quot;, function(Y) {
83
 
    var data = [
84
 
                {a:3, b:2, c:1},
85
 
                {a:9, b:8, c:7},
86
 
                {a:1, b:2, c:3}
87
 
        ],
88
 
 
89
 
        &#x2F;&#x2F;Recordset is created with the objects from the data array
90
 
        myRecordset = new Y.Recordset({records: data}),
91
 
 
92
 
        &#x2F;&#x2F;Empty Recordsets can also be created
93
 
        anEmptyRecordset = new Y.Recordset();
94
 
 
95
 
});</pre>
96
 
 
97
 
 
98
 
 
99
 
<h3 id="crud">Adding, Removing, Updating and Emptying</h3>
100
 
 
101
 
<p>
102
 
    A <code>Y.Recordset</code> can be filled with a single, or an array of
103
 
    object literals. Under the hood, Recordset will convert these objects into
104
 
    <code>record</code> instances - essentially creating a light wrapper around
105
 
    them.
106
 
</p>
107
 
 
108
 
<p>
109
 
    More information on performing operations on Recordset can be seen the the
110
 
    documentation for the <a href="recordset-basic.html">
111
 
    <code>recordset-base</code> sub-module</a>.
112
 
</p>
113
 
 
114
 
<h4 id="add">Adding Records</h4>
115
 
 
116
 
<pre class="code prettyprint">var data = [
117
 
    {key:&quot;a&quot;, label:&quot;Column A&quot;},
118
 
    {key:&quot;b&quot;, label:&quot;Column B&quot;},
119
 
    {key:&quot;c&quot;, label:&quot;Column C&quot;}
120
 
],
121
 
myRecordset = new Y.Recordset({records:data});
122
 
 
123
 
&#x2F;&#x2F;Adding a single record to the end of a Recordset
124
 
myRecordset.add({key:&quot;d&quot;, label:&quot;Column D&quot;});
125
 
 
126
 
&#x2F;&#x2F;Adding multiple records at the 2nd index of the Recordset
127
 
myRecordset.add([
128
 
    {key:&quot;e&quot;, label:&quot;Column E&quot;},
129
 
    {key:&quot;f&quot;, label:&quot;Column F&quot;}
130
 
], 2);</pre>
131
 
 
132
 
 
133
 
<h4 id="remove">Removing Records</h4>
134
 
 
135
 
<pre class="code prettyprint">var data = [
136
 
    {key:&quot;a&quot;, label:&quot;Column A&quot;},
137
 
    {key:&quot;b&quot;, label:&quot;Column B&quot;},
138
 
    {key:&quot;c&quot;, label:&quot;Column C&quot;}
139
 
],
140
 
myRecordset = new Y.Recordset({records:data});
141
 
 
142
 
&#x2F;&#x2F;removes the record stored at index 2 (in this case {key:&quot;c&quot;, label:&quot;Column C&quot;} is removed)
143
 
myRecordset.remove(2);
144
 
 
145
 
&#x2F;&#x2F;Removes 2 records starting at index zero
146
 
myRecordset.remove(0,2);</pre>
147
 
 
148
 
 
149
 
<h4 id="updating-records">Updating Records</h4>
150
 
 
151
 
<pre class="code prettyprint">var data = [
152
 
    {key:&quot;a&quot;, label:&quot;Column A&quot;},
153
 
    {key:&quot;b&quot;, label:&quot;Column B&quot;},
154
 
    {key:&quot;c&quot;, label:&quot;Column C&quot;}
155
 
],
156
 
 
157
 
myRecordset = new Y.Recordset({records:data});
158
 
 
159
 
&#x2F;&#x2F;overwite the record at index 2 with the following record
160
 
myRecordset.update({key:&quot;d&quot;, label:&quot;Column D&quot;}, 2);
161
 
 
162
 
&#x2F;&#x2F;You can also update multiple records at a time.
163
 
&#x2F;&#x2F;Here we are updating indices 0 and 1 of the Recordset with the corresponding two objects.
164
 
myRecordset.update([
165
 
    {key:&quot;e&quot;, label:&quot;Column E&quot;},
166
 
    {key: &quot;f&quot;, label: &quot;Column F&quot;}
167
 
], 0);</pre>
168
 
 
169
 
 
170
 
<h4 id="emptying-a-recordset">Emptying a Recordset</h4>
171
 
 
172
 
<pre class="code prettyprint">var data = [
173
 
    {key:&quot;a&quot;, label:&quot;Column A&quot;},
174
 
    {key:&quot;b&quot;, label:&quot;Column B&quot;},
175
 
    {key:&quot;c&quot;, label:&quot;Column C&quot;}
176
 
],
177
 
 
178
 
myRecordset = new Y.Recordset({records:data});
179
 
myRecordset.empty();</pre>
180
 
 
181
 
 
182
 
<h3 id="events">Events</h3>
183
 
 
184
 
<p>
185
 
    The Recordset Utility fires custom events in addition attribute change
186
 
    events. Details on these events are shown below. The sub-module responsible
187
 
    for firing each event is represented in square braces.
188
 
</p>
189
 
 
190
 
<table>
191
 
        <thead>
192
 
                <tr>
193
 
                        <th>Event [sub-module]</th>
194
 
                        <th>Payload</th>
195
 
                </tr>
196
 
        </thead>
197
 
        <tbody>
198
 
                <tr>
199
 
                        <td><code>add</code> [base]</td>
200
 
                        <td><strong>added:</strong> an array of new records that were added (can contain a single record)<br/>
201
 
                        <strong>index:</strong> index that the addition started at
202
 
                        </td>
203
 
                </tr>
204
 
                <tr>
205
 
                        <td><code>remove</code> [base]</td>
206
 
                        <td><strong>removed:</strong> an array of records that were removed (can contain a single record)<br/>
207
 
                        <strong>index:</strong> index that the removals started at<br/>
208
 
                                <strong>range:</strong> range of records that were removed
209
 
                        </td>
210
 
                </tr>
211
 
                <tr>
212
 
                        <td><code>update</code> [base]</td>
213
 
                        <td><strong>updated:</strong> an array of records that updated (added to the Recordset)<br/>
214
 
                        <strong>index:</strong> index that the updates started at<br/>
215
 
                                <strong>range:</strong> range of records that were updated
216
 
                        </td>
217
 
                </tr>
218
 
                <tr>
219
 
                        <td><code>empty</code> [base]</td>
220
 
                        <td>Empty object bag</td>
221
 
                </tr>
222
 
                <tr>
223
 
                        <td><code>change</code> [base]</td>
224
 
                        <td>Empty object bag, fired whenever records in the Recordset change (ie: they are added, removed, updated, or emptied)</td>
225
 
                </tr>
226
 
                <tr>
227
 
                        <td><code>sort</code> [sort]</td>
228
 
                        <td><strong>field:</strong> A string representing the key to sort by<br/>
229
 
                        <strong>desc:</strong> Boolean representing whether sorting order is descending<br/>
230
 
                                <strong>sorter:</strong> The comparison function being used to sort
231
 
                        </td>
232
 
                </tr>
233
 
        </tbody>
234
 
</table>
235
 
 
236
 
<h3 id="sorting">Sorting</h3>
237
 
 
238
 
<p>
239
 
    The <code>RecordsetSort</code> plugin allows a Recordset to have default
240
 
    and custom sorting functionality. Various helper methods and attributes are
241
 
    provided. A brief listing is shown below. Refer to the documentation for
242
 
    the <a href="recordset-sort.html">
243
 
    <code>RecordsetSort</code> plugin</a> to see code snippets.
244
 
</p>
245
 
 
246
 
<dl>
247
 
        <dt><code>sort(key,desc,function [optional])</code></dt>
248
 
                <dd>
249
 
            Sorts a Recordset by the value in the provided key. Recordset is
250
 
            sorted in descending order if <code>desc</code> is truthy. Optional
251
 
            custom comparison function can be supplied to sort by.
252
 
        </dd>
253
 
    <dt><code>resort()</code></dt>
254
 
        <dd>Resorts a Recordset using last-used sorting arguments</dd>
255
 
    <dt><code>reverse()</code></dt>
256
 
        <dd>Reverses the Recordset without performing any sort operations</dd>
257
 
    <dt><code>flip()</code></dt>
258
 
        <dd>
259
 
            Resorts the Recordset in ascending order if the last sort arguments
260
 
            specified descending, and vice versa.
261
 
        </dd>
262
 
    <dt><code>lastSortProperties Attribute</code></dt>
263
 
        <dd>
264
 
            An object bag with <code>field</code>, <code>desc</code> and
265
 
            <code>sorter</code> keys listing the last-used arguments to sort
266
 
            by.
267
 
        </dd>
268
 
    <dt><code>isSorted Attribute</code></dt>
269
 
        <dd>A boolean representing if the Recordset is in a sorted state.</dd>
270
 
</dl>
271
 
 
272
 
<h3 id="filtering">Filtering</h3>
273
 
 
274
 
<p>
275
 
    The <code>RecordsetFilter</code> plugin allows a Recordset to be filtered,
276
 
    and returns subsets of that Recordset (as a separate Recordset instance).
277
 
    Refer to the documentation for the <a
278
 
    href="recordset-filter.html">
279
 
    <code>RecordsetFilter</code> plugin to see code snippets.</a>
280
 
</p>
281
 
 
282
 
<dl>
283
 
        <dt><code>filter(key or function, value)</code></dt>
284
 
                <dd>
285
 
            If a key/value pair is passed in, returns a Recordset with records
286
 
            that match the key/value pair. Supports a custom function for more
287
 
            advanced filtering. The custom function must return a boolean.
288
 
        </dd>
289
 
    <dt><code>reject(function)</code></dt>
290
 
        <dd>
291
 
            The inverse of filter. Executes the supplied function on each item.
292
 
            Returns a new Recordset containing the items that the supplied
293
 
            function returned <code>false</code> for.
294
 
        </dd>
295
 
    <dt><code>grep(pattern)</code></dt>
296
 
        <dd>
297
 
            Iterates over the Recordset, returning a new Recordset of all the
298
 
            elements that match the supplied regular expression
299
 
        </dd>
300
 
</dl>
301
 
 
302
 
 
303
 
<h3 id="indexing">Indexing</h3>
304
 
 
305
 
<p>
306
 
    In the <code>recordset-base</code> submodule, the <code>table</code>
307
 
    attribute stores an associative array that hashes all records within the
308
 
    Recordset by their unique YUIDs. This table is kept in sync with the
309
 
    Recordset through custom events.
310
 
</p>
311
 
 
312
 
<p>
313
 
    To allow for customization when indexing, there is the
314
 
    <code>RecordsetIndexer</code> plugin. Refer to the <a
315
 
    href="recordset-indexer.html"><code>RecordsetIndexer</code>
316
 
    documentation</a> for full details.
317
 
</p>
318
 
 
319
 
 
320
 
<dl>
321
 
        <dt><code>createTable(key)</code></dt>
322
 
                <dd>
323
 
            Creates a hash table with the given key with all existing records
324
 
            in the Recordset.
325
 
        </dd>
326
 
    <dt><code>getTable(key)</code></dt>
327
 
        <dd>Get a hash table that hashes records by a given key.</dd>
328
 
    <dt><code>hashTables</code> attribute</dt>
329
 
        <dd>
330
 
            An object bag, with each property referring to a user-created hash
331
 
            table.
332
 
        </dd>
333
 
</dl>
334
 
</div>
335
 
        </div>
336
 
 
337
 
        <div id="sidebar" class="yui3-u">
338
 
            
339
 
                <div id="toc" class="sidebox">
340
 
                    <div class="hd">
341
 
                        <h2 class="no-toc">Table of Contents</h2>
342
 
                    </div>
343
 
 
344
 
                    <div class="bd">
345
 
                        <ul class="toc">
346
 
<li>
347
 
<a href="#getting-started">Getting Started</a>
348
 
</li>
349
 
<li>
350
 
<a href="#using">Using Recordsets</a>
351
 
<ul class="toc">
352
 
<li>
353
 
<a href="#basics">Recordset basics</a>
354
 
</li>
355
 
<li>
356
 
<a href="#crud">Adding, Removing, Updating and Emptying</a>
357
 
<ul class="toc">
358
 
<li>
359
 
<a href="#add">Adding Records</a>
360
 
</li>
361
 
<li>
362
 
<a href="#remove">Removing Records</a>
363
 
</li>
364
 
<li>
365
 
<a href="#updating-records">Updating Records</a>
366
 
</li>
367
 
<li>
368
 
<a href="#emptying-a-recordset">Emptying a Recordset</a>
369
 
</li>
370
 
</ul>
371
 
</li>
372
 
<li>
373
 
<a href="#events">Events</a>
374
 
</li>
375
 
<li>
376
 
<a href="#sorting">Sorting</a>
377
 
</li>
378
 
<li>
379
 
<a href="#filtering">Filtering</a>
380
 
</li>
381
 
<li>
382
 
<a href="#indexing">Indexing</a>
383
 
</li>
384
 
</ul>
385
 
</li>
386
 
</ul>
387
 
                    </div>
388
 
                </div>
389
 
            
390
 
 
391
 
            
392
 
                <div class="sidebox">
393
 
                    <div class="hd">
394
 
                        <h2 class="no-toc">Examples</h2>
395
 
                    </div>
396
 
 
397
 
                    <div class="bd">
398
 
                        <ul class="examples">
399
 
                            
400
 
                                
401
 
                                    <li data-description="Shows how to instantiate and interact with a standard Recordset by adding, removing and updating records/objects. Explains the events that are fired, and shows how to access the built-in hash table that stores records by their YUIDs.">
402
 
                                        <a href="recordset-basic.html">Basic Recordset</a>
403
 
                                    </li>
404
 
                                
405
 
                            
406
 
                                
407
 
                                    <li data-description="Shows how to sort a Recordset using the default sorter, or a custom sort function. Additionally, demonstrates how convenience attributes help in determining when Recordset is in a sorted state, and what the last sort parameters were.">
408
 
                                        <a href="recordset-sort.html">Recordset Sort Plugin</a>
409
 
                                    </li>
410
 
                                
411
 
                            
412
 
                                
413
 
                                    <li data-description="Shows how to use filtering methods to Recordset. Key-value filtering, and filtering by providing a custom function are covered.">
414
 
                                        <a href="recordset-filter.html">Recordset Filter Plugin</a>
415
 
                                    </li>
416
 
                                
417
 
                            
418
 
                                
419
 
                                    <li data-description="Shows how to create and access hash tables on Recordset. Tables are kept in sync through events fired by Recordset.">
420
 
                                        <a href="recordset-indexer.html">Recordset Indexer Plugin</a>
421
 
                                    </li>
422
 
                                
423
 
                            
424
 
                        </ul>
425
 
                    </div>
426
 
                </div>
427
 
            
428
 
 
429
 
            
430
 
        </div>
431
 
    </div>
432
 
</div>
433
 
 
434
 
<script src="../assets/vendor/prettify/prettify-min.js"></script>
435
 
<script>prettyPrint();</script>
436
 
 
437
 
</body>
438
 
</html>