Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / data / SequentialIdGenerator.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @author Don Griffin
17  *
18  * This class is a sequential id generator. A simple use of this class would be like so:
19  *
20  *     Ext.define('MyApp.data.MyModel', {
21  *         extend: 'Ext.data.Model',
22  *         idgen: 'sequential'
23  *     });
24  *     // assign id's of 1, 2, 3, etc.
25  *
26  * An example of a configured generator would be:
27  *
28  *     Ext.define('MyApp.data.MyModel', {
29  *         extend: 'Ext.data.Model',
30  *         idgen: {
31  *             type: 'sequential',
32  *             prefix: 'ID_',
33  *             seed: 1000
34  *         }
35  *     });
36  *     // assign id's of ID_1000, ID_1001, ID_1002, etc.
37  *
38  */
39 Ext.define('Ext.data.SequentialIdGenerator', {
40     extend: 'Ext.data.IdGenerator',
41     alias: 'idgen.sequential',
42
43     constructor: function() {
44         var me = this;
45
46         me.callParent(arguments);
47
48         me.parts = [ me.prefix, ''];
49     },
50
51     /**
52      * @cfg {String} prefix
53      * The string to place in front of the sequential number for each generated id. The
54      * default is blank.
55      */
56     prefix: '',
57
58     /**
59      * @cfg {Number} seed
60      * The number at which to start generating sequential id's. The default is 1.
61      */
62     seed: 1,
63
64     /**
65      * Generates and returns the next id.
66      * @return {String} The next id.
67      */
68     generate: function () {
69         var me = this,
70             parts = me.parts;
71
72         parts[1] = me.seed++;
73         return parts.join('');
74     }
75 });
76