Merge branch 'master' of http://git.roojs.com/roojs1
[roojs1] / Roo / data / DataReader.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11  
12 // Base class for reading structured data from a data source.  This class is intended to be
13 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
14
15 /**
16  * @class Roo.data.DataReader
17  * @abstract
18  * Base class for reading structured data from a data source.  This class is intended to be
19  * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
20  */
21
22 Roo.data.DataReader = function(meta, recordType){
23     
24     this.meta = meta;
25     
26     this.recordType = recordType instanceof Array ? 
27         Roo.data.Record.create(recordType) : recordType;
28 };
29
30 Roo.data.DataReader.prototype = {
31     
32     
33     readerType : 'Data',
34      /**
35      * Create an empty record
36      * @param {Object} data (optional) - overlay some values
37      * @return {Roo.data.Record} record created.
38      */
39     newRow :  function(d) {
40         var da =  {};
41         this.recordType.prototype.fields.each(function(c) {
42             switch( c.type) {
43                 case 'int' : da[c.name] = 0; break;
44                 case 'date' : da[c.name] = new Date(); break;
45                 case 'float' : da[c.name] = 0.0; break;
46                 case 'boolean' : da[c.name] = false; break;
47                 default : da[c.name] = ""; break;
48             }
49             
50         });
51         return new this.recordType(Roo.apply(da, d));
52     }
53     
54     
55 };