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 | Ext.namespace("GeoExt.plugins"); |
---|
9 | |
---|
10 | /** api: (define) |
---|
11 | * module = GeoExt.plugins |
---|
12 | * class = PrintProviderField |
---|
13 | * base_link = `Ext.util.Observable <http://dev.sencha.com/deploy/dev/docs/?class=Ext.util.Observable>`_ |
---|
14 | */ |
---|
15 | |
---|
16 | /** api: example |
---|
17 | * A form with combo boxes for layout and resolution, and a text field for a |
---|
18 | * map title. The latter is a custom parameter to the print module, which is |
---|
19 | * a default for all print pages. For setting custom parameters on the page |
---|
20 | * level, use :class:`GeoExt.plugins.PrintPageField`): |
---|
21 | * |
---|
22 | * .. code-block:: javascript |
---|
23 | * |
---|
24 | * var printProvider = new GeoExt.data.PrintProvider({ |
---|
25 | * capabilities: printCapabilities |
---|
26 | * }); |
---|
27 | * new Ext.form.FormPanel({ |
---|
28 | * renderTo: "form", |
---|
29 | * width: 200, |
---|
30 | * height: 300, |
---|
31 | * items: [{ |
---|
32 | * xtype: "combo", |
---|
33 | * displayField: "name", |
---|
34 | * store: printProvider.layouts, // printProvider.layout |
---|
35 | * fieldLabel: "Layout", |
---|
36 | * typeAhead: true, |
---|
37 | * mode: "local", |
---|
38 | * forceSelection: true, |
---|
39 | * triggerAction: "all", |
---|
40 | * selectOnFocus: true, |
---|
41 | * plugins: new GeoExt.plugins.PrintProviderField({ |
---|
42 | * printProvider: printProvider |
---|
43 | * }) |
---|
44 | * }, { |
---|
45 | * xtype: "combo", |
---|
46 | * displayField: "name", |
---|
47 | * store: printProvider.dpis, // printProvider.dpi |
---|
48 | * fieldLabel: "Resolution", |
---|
49 | * typeAhead: true, |
---|
50 | * mode: "local", |
---|
51 | * forceSelection: true, |
---|
52 | * triggerAction: "all", |
---|
53 | * selectOnFocus: true, |
---|
54 | * plugins: new GeoExt.plugins.PrintProviderField({ |
---|
55 | * printProvider: printProvider |
---|
56 | * }) |
---|
57 | * }, { |
---|
58 | * xtype: "textfield", |
---|
59 | * name: "mapTitle", // printProvider.customParams.mapTitle |
---|
60 | * fieldLabel: "Map Title", |
---|
61 | * plugins: new GeoExt.plugins.PrintProviderField({ |
---|
62 | * printProvider: printProvider |
---|
63 | * }) |
---|
64 | * }] |
---|
65 | * }): |
---|
66 | */ |
---|
67 | |
---|
68 | /** api: constructor |
---|
69 | * .. class:: PrintProviderField |
---|
70 | * |
---|
71 | * A plugin for ``Ext.form.Field`` components which provides synchronization |
---|
72 | * with a :class:`GeoExt.data.PrintProvider`. |
---|
73 | */ |
---|
74 | GeoExt.plugins.PrintProviderField = Ext.extend(Ext.util.Observable, { |
---|
75 | |
---|
76 | /** api: config[printProvider] |
---|
77 | * ``GeoExt.data.PrintProvider`` The print provider to use with this |
---|
78 | * plugin's field. Not required if set on the owner container of the |
---|
79 | * field. |
---|
80 | */ |
---|
81 | |
---|
82 | /** private: property[target] |
---|
83 | * ``Ext.form.Field`` This plugin's target field. |
---|
84 | */ |
---|
85 | target: null, |
---|
86 | |
---|
87 | /** private: method[constructor] |
---|
88 | */ |
---|
89 | constructor: function(config) { |
---|
90 | this.initialConfig = config; |
---|
91 | Ext.apply(this, config); |
---|
92 | |
---|
93 | GeoExt.plugins.PrintProviderField.superclass.constructor.apply(this, arguments); |
---|
94 | }, |
---|
95 | |
---|
96 | /** private: method[init] |
---|
97 | * :param target: ``Ext.form.Field`` The component that this plugin |
---|
98 | * extends. |
---|
99 | */ |
---|
100 | init: function(target) { |
---|
101 | this.target = target; |
---|
102 | var onCfg = { |
---|
103 | scope: this, |
---|
104 | "render": this.onRender, |
---|
105 | "beforedestroy": this.onBeforeDestroy |
---|
106 | }; |
---|
107 | onCfg[target instanceof Ext.form.ComboBox ? "select" : "valid"] = |
---|
108 | this.onFieldChange; |
---|
109 | target.on(onCfg); |
---|
110 | }, |
---|
111 | |
---|
112 | /** private: method[onRender] |
---|
113 | * :param field: ``Ext.Form.Field`` |
---|
114 | * |
---|
115 | * Handler for the target field's "render" event. |
---|
116 | */ |
---|
117 | onRender: function(field) { |
---|
118 | var printProvider = this.printProvider || field.ownerCt.printProvider; |
---|
119 | if(field.store === printProvider.layouts) { |
---|
120 | field.setValue(printProvider.layout.get(field.displayField)); |
---|
121 | printProvider.on({ |
---|
122 | "layoutchange": this.onProviderChange, |
---|
123 | scope: this |
---|
124 | }); |
---|
125 | } else if(field.store === printProvider.dpis) { |
---|
126 | field.setValue(printProvider.dpi.get(field.displayField)); |
---|
127 | printProvider.on({ |
---|
128 | "dpichange": this.onProviderChange, |
---|
129 | scope: this |
---|
130 | }); |
---|
131 | } else if(field.initialConfig.value === undefined) { |
---|
132 | field.setValue(printProvider.customParams[field.name]); |
---|
133 | } |
---|
134 | }, |
---|
135 | |
---|
136 | /** private: method[onFieldChange] |
---|
137 | * :param field: ``Ext.form.Field`` |
---|
138 | * :param record: ``Ext.data.Record`` Optional. |
---|
139 | * |
---|
140 | * Handler for the target field's "valid" or "select" event. |
---|
141 | */ |
---|
142 | onFieldChange: function(field, record) { |
---|
143 | var printProvider = this.printProvider || field.ownerCt.printProvider; |
---|
144 | var value = field.getValue(); |
---|
145 | this._updating = true; |
---|
146 | if(record) { |
---|
147 | switch(field.store) { |
---|
148 | case printProvider.layouts: |
---|
149 | printProvider.setLayout(record); |
---|
150 | break; |
---|
151 | case printProvider.dpis: |
---|
152 | printProvider.setDpi(record); |
---|
153 | } |
---|
154 | } else { |
---|
155 | printProvider.customParams[field.name] = value; |
---|
156 | } |
---|
157 | delete this._updating; |
---|
158 | }, |
---|
159 | |
---|
160 | /** private: method[onProviderChange] |
---|
161 | * :param printProvider: :class:`GeoExt.data.PrintProvider` |
---|
162 | * :param rec: ``Ext.data.Record`` |
---|
163 | * |
---|
164 | * Handler for the printProvider's dpichange and layoutchange event |
---|
165 | */ |
---|
166 | onProviderChange: function(printProvider, rec) { |
---|
167 | if(!this._updating) { |
---|
168 | this.target.setValue(rec.get(this.target.displayField)); |
---|
169 | } |
---|
170 | }, |
---|
171 | |
---|
172 | /** private: method[onBeforeDestroy] |
---|
173 | */ |
---|
174 | onBeforeDestroy: function() { |
---|
175 | this.target.un("beforedestroy", this.onBeforeDestroy, this); |
---|
176 | this.target.un("render", this.onRender, this); |
---|
177 | this.target.un("select", this.onFieldChange, this); |
---|
178 | this.target.un("valid", this.onFieldChange, this); |
---|
179 | this.printProvider.un("layoutchange", this.onProviderChange, this); |
---|
180 | this.printProvider.un("dpichange", this.onProviderChange, |
---|
181 | this); |
---|
182 | } |
---|
183 | |
---|
184 | }); |
---|
185 | |
---|
186 | /** api: ptype = gx_printproviderfield */ |
---|
187 | Ext.preg("gx_printproviderfield", GeoExt.plugins.PrintProviderField); |
---|