1 | /** |
---|
2 | * Copyright (c) 2008-2010 The Open Source Geospatial Foundation |
---|
3 | * |
---|
4 | * Published under the BSD license. |
---|
5 | * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text |
---|
6 | * of the license. |
---|
7 | */ |
---|
8 | |
---|
9 | /** api: (define) |
---|
10 | * module = GeoExt.data |
---|
11 | * class = LayerRecord |
---|
12 | * base_link = `Ext.data.Record <http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Record>`_ |
---|
13 | */ |
---|
14 | Ext.namespace("GeoExt.data"); |
---|
15 | |
---|
16 | /** api: constructor |
---|
17 | * .. class:: LayerRecord |
---|
18 | * |
---|
19 | * A record that represents an ``OpenLayers.Layer``. This record |
---|
20 | * will always have at least the following fields: |
---|
21 | * |
---|
22 | * * title ``String`` |
---|
23 | */ |
---|
24 | GeoExt.data.LayerRecord = Ext.data.Record.create([ |
---|
25 | {name: "layer"}, |
---|
26 | {name: "title", type: "string", mapping: "name"} |
---|
27 | ]); |
---|
28 | |
---|
29 | /** api: method[getLayer] |
---|
30 | * :return: ``OpenLayers.Layer`` |
---|
31 | * |
---|
32 | * Gets the layer for this record. |
---|
33 | */ |
---|
34 | GeoExt.data.LayerRecord.prototype.getLayer = function() { |
---|
35 | return this.get("layer"); |
---|
36 | }; |
---|
37 | |
---|
38 | /** api: method[setLayer] |
---|
39 | * :param layer: ``OpenLayers.Layer`` |
---|
40 | * |
---|
41 | * Sets the layer for this record. |
---|
42 | */ |
---|
43 | GeoExt.data.LayerRecord.prototype.setLayer = function(layer) { |
---|
44 | if (layer !== this.data.layer) { |
---|
45 | this.dirty = true; |
---|
46 | if(!this.modified) { |
---|
47 | this.modified = {}; |
---|
48 | } |
---|
49 | if(this.modified.layer === undefined) { |
---|
50 | this.modified.layer = this.data.layer; |
---|
51 | } |
---|
52 | this.data.layer = layer; |
---|
53 | if(!this.editing) { |
---|
54 | this.afterEdit(); |
---|
55 | } |
---|
56 | } |
---|
57 | }; |
---|
58 | |
---|
59 | /** api: method[clone] |
---|
60 | * :param id: ``String`` (optional) A new Record id. |
---|
61 | * :return: class:`GeoExt.data.LayerRecord` A new layer record. |
---|
62 | * |
---|
63 | * Creates a clone of this LayerRecord. |
---|
64 | */ |
---|
65 | GeoExt.data.LayerRecord.prototype.clone = function(id) { |
---|
66 | var layer = this.getLayer() && this.getLayer().clone(); |
---|
67 | return new this.constructor( |
---|
68 | Ext.applyIf({layer: layer}, this.data), |
---|
69 | id || layer.id |
---|
70 | ); |
---|
71 | }; |
---|
72 | |
---|
73 | /** api: classmethod[create] |
---|
74 | * :param o: ``Array`` Field definition as in ``Ext.data.Record.create``. Can |
---|
75 | * be omitted if no additional fields are required. |
---|
76 | * :return: ``Function`` A specialized :class:`GeoExt.data.LayerRecord` |
---|
77 | * constructor. |
---|
78 | * |
---|
79 | * Creates a constructor for a :class:`GeoExt.data.LayerRecord`, optionally |
---|
80 | * with additional fields. |
---|
81 | */ |
---|
82 | GeoExt.data.LayerRecord.create = function(o) { |
---|
83 | var f = Ext.extend(GeoExt.data.LayerRecord, {}); |
---|
84 | var p = f.prototype; |
---|
85 | |
---|
86 | p.fields = new Ext.util.MixedCollection(false, function(field) { |
---|
87 | return field.name; |
---|
88 | }); |
---|
89 | |
---|
90 | GeoExt.data.LayerRecord.prototype.fields.each(function(f) { |
---|
91 | p.fields.add(f); |
---|
92 | }); |
---|
93 | |
---|
94 | if(o) { |
---|
95 | for(var i = 0, len = o.length; i < len; i++){ |
---|
96 | p.fields.add(new Ext.data.Field(o[i])); |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | f.getField = function(name) { |
---|
101 | return p.fields.get(name); |
---|
102 | }; |
---|
103 | |
---|
104 | return f; |
---|
105 | }; |
---|