1 |
<?php |
---|
2 |
/** |
---|
3 |
* Legend Widget class |
---|
4 |
* |
---|
5 |
* @project CWC2 |
---|
6 |
* @revision $Id: |
---|
7 |
* @purpose LegendPopup Widget class |
---|
8 |
* @author DM Solutions Group (sfournier@dmsolutions.ca) |
---|
9 |
* @copyright |
---|
10 |
* <b>Copyright (c) 2002, DM Solutions Group Inc.</b> |
---|
11 |
* Permission is hereby granted, free of charge, to any person obtaining a |
---|
12 |
* copy of this software and associated documentation files (the "Software"), |
---|
13 |
* to deal in the Software without restriction, including without limitation |
---|
14 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
15 |
* and/or sell copies of the Software, and to permit persons to whom the |
---|
16 |
* Software is furnished to do so, subject to the following conditions: |
---|
17 |
* |
---|
18 |
* The above copyright notice and this permission notice shall be included |
---|
19 |
* in all copies or substantial portions of the Software. |
---|
20 |
* |
---|
21 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
22 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
23 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
---|
24 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
25 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
26 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
27 |
* DEALINGS IN THE SOFTWARE. |
---|
28 |
*/ |
---|
29 |
|
---|
30 |
|
---|
31 |
include_once(dirname(__FILE__)."/../Widget.php"); |
---|
32 |
include_once(dirname(__FILE__)."/../Button.php"); |
---|
33 |
include_once(dirname(__FILE__)."/../Popup.php"); |
---|
34 |
|
---|
35 |
/** |
---|
36 |
* Legend |
---|
37 |
* |
---|
38 |
* @desc Legend widget class |
---|
39 |
*/ |
---|
40 |
class Legend extends CWCWidget |
---|
41 |
{ |
---|
42 |
var $mszTemplate; /// [string] |
---|
43 |
|
---|
44 |
var $moButton; /// Button object |
---|
45 |
var $moPopup; /// Popup object |
---|
46 |
var $mnPopVal; //remember if a window is popped up |
---|
47 |
|
---|
48 |
|
---|
49 |
/** |
---|
50 |
* Legend |
---|
51 |
* |
---|
52 |
* Constctor method for the Legend widget. |
---|
53 |
*/ |
---|
54 |
function Legend() |
---|
55 |
{ |
---|
56 |
$this->mszLanguageResource = str_replace("\\","/",dirname(__FILE__))."/LegendPopup.dbf"; |
---|
57 |
|
---|
58 |
// invoke constructor of parent |
---|
59 |
parent::CWCWidget(); |
---|
60 |
|
---|
61 |
// set the description for this widget |
---|
62 |
$this->szWidgetDescription = <<<EOT |
---|
63 |
The LegendPopup widget allows the user to popup a legend for the current |
---|
64 |
context in a separate window. |
---|
65 |
EOT; |
---|
66 |
|
---|
67 |
$this->moButton = new CWCButton($this); |
---|
68 |
$this->moPopup = new CWCPopup($this); |
---|
69 |
$this->moPopup->mszLink = "widgets/Legend/LegendPopup.phtml"; |
---|
70 |
|
---|
71 |
$this->mnMaturityLevel = MATURITY_BETA; |
---|
72 |
} |
---|
73 |
|
---|
74 |
function InitDefaults() |
---|
75 |
{ |
---|
76 |
parent::InitDefaults(); |
---|
77 |
$this->moButton->InitDefaults(); |
---|
78 |
$this->moPopup->InitDefaults(); |
---|
79 |
$this->mnPopVal = 0; |
---|
80 |
|
---|
81 |
$szTemplate = ""; |
---|
82 |
if (isset($this->maParams["TEMPLATE"])) |
---|
83 |
$szTemplate = $this->maParams["TEMPLATE"]; |
---|
84 |
|
---|
85 |
if ($szTemplate != "") |
---|
86 |
{ |
---|
87 |
$this->moButton->SetOnClick("clickLegendPopup"); |
---|
88 |
} |
---|
89 |
else |
---|
90 |
{ |
---|
91 |
$this->moButton->SetOnClick('alert', trim($this->oMLT->get('1', 'ERROR: No legend template specified.')) ); |
---|
92 |
} |
---|
93 |
} |
---|
94 |
|
---|
95 |
function ParseURL() |
---|
96 |
{ |
---|
97 |
// add the hidden form variable |
---|
98 |
if ( $this->isVarSet('leg_wid_popup_open') && |
---|
99 |
$this->getVar('leg_wid_popup_open') == 1 ) |
---|
100 |
$this->mnPopVal = 1; |
---|
101 |
else |
---|
102 |
$this->mnPopup = 0; |
---|
103 |
|
---|
104 |
return true; |
---|
105 |
} |
---|
106 |
|
---|
107 |
/** |
---|
108 |
* GetHTMLHiddenVariables |
---|
109 |
* |
---|
110 |
* Returnrs an empty string. Should be redefined for Widgets |
---|
111 |
* returning hidden variables |
---|
112 |
*/ |
---|
113 |
function GetHTMLHiddenVariables() |
---|
114 |
{ |
---|
115 |
$aReturn = $this->moButton->GetHTMLHiddenVariables(); |
---|
116 |
|
---|
117 |
$aReturn["LEG_WID_POPUP_OPEN"] = "<input type=\"hidden\" name=\"leg_wid_popup_open\" value=\"".$this->mnPopVal."\">"; |
---|
118 |
|
---|
119 |
return $aReturn; |
---|
120 |
} |
---|
121 |
|
---|
122 |
/** |
---|
123 |
* GetJavascriptFunctions |
---|
124 |
* |
---|
125 |
* Build and return the array of functions needed in the |
---|
126 |
* widget. |
---|
127 |
*/ |
---|
128 |
function GetJavascriptFunctions() |
---|
129 |
{ |
---|
130 |
$aReturn = array(); |
---|
131 |
|
---|
132 |
$szTemplate = ""; |
---|
133 |
if (isset($this->maParams["TEMPLATE"])) |
---|
134 |
$szTemplate = $this->maParams["TEMPLATE"]; |
---|
135 |
if ($szTemplate != "") |
---|
136 |
{ |
---|
137 |
$this->moPopup->mszParam = "&szTemplate=".urlencode($szTemplate); |
---|
138 |
} |
---|
139 |
|
---|
140 |
$szJsFunctionName = "clickLegendPopup"; |
---|
141 |
$szFunction = "function $szJsFunctionName()\n" . |
---|
142 |
"{\n". |
---|
143 |
$this->moPopup->DrawPublish()."\n". |
---|
144 |
"return;\n" . |
---|
145 |
"}\n"; |
---|
146 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
147 |
|
---|
148 |
// add javascript API functions |
---|
149 |
if (isset($this->maSharedResourceWidgets["CWCJSAPI"])) |
---|
150 |
$bCWCJSAPI = 1; |
---|
151 |
else |
---|
152 |
$bCWCJSAPI = 0; |
---|
153 |
|
---|
154 |
if ($bCWCJSAPI) |
---|
155 |
{ |
---|
156 |
$szJsFunctionName = "LegendWRegisterForEvent"; |
---|
157 |
$szFunction = <<<EOT |
---|
158 |
/** |
---|
159 |
* {$szJsFunctionName} |
---|
160 |
* called to register events when the layers change (JSAPI) |
---|
161 |
*/ |
---|
162 |
function {$szJsFunctionName}() |
---|
163 |
{ |
---|
164 |
goCWCJSAPI.RegisterEvent(LAYER_STATUS_CHANGED, "LegendWLayersChanged"); |
---|
165 |
goCWCJSAPI.RegisterEvent(LAYER_ORDER_CHANGED, "LegendWLayersChanged"); |
---|
166 |
goCWCJSAPI.RegisterEvent(MAP_NEW_LAYER_ADDED, "LegendWLayersChanged"); |
---|
167 |
|
---|
168 |
|
---|
169 |
} |
---|
170 |
EOT; |
---|
171 |
|
---|
172 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
173 |
$szJsFunctionName = "LegendWLayersChanged"; |
---|
174 |
$szFunction = <<<EOT |
---|
175 |
/** |
---|
176 |
* {$szJsFunctionName} |
---|
177 |
* called when the layers are changed(JSAPI) |
---|
178 |
*/ |
---|
179 |
function {$szJsFunctionName}() |
---|
180 |
{ |
---|
181 |
UpdatePopup(); |
---|
182 |
} |
---|
183 |
EOT; |
---|
184 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
185 |
$szJsFunctionName = "UpdatePopup"; |
---|
186 |
$szFunction = <<<EOT |
---|
187 |
/** |
---|
188 |
* {$szJsFunctionName} |
---|
189 |
* update popup if open(JSAPI) |
---|
190 |
*/ |
---|
191 |
function {$szJsFunctionName}() |
---|
192 |
{ |
---|
193 |
// only update if the window is open |
---|
194 |
if ( {$this->mszHTMLForm}.leg_wid_popup_open != null && |
---|
195 |
{$this->mszHTMLForm}.leg_wid_popup_open.value == 1 ) |
---|
196 |
{ |
---|
197 |
clickLegendPopup(); |
---|
198 |
} |
---|
199 |
} |
---|
200 |
EOT; |
---|
201 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
202 |
|
---|
203 |
} |
---|
204 |
|
---|
205 |
// return the array of functions |
---|
206 |
return $aReturn; |
---|
207 |
} |
---|
208 |
|
---|
209 |
/** |
---|
210 |
* return an array of javascript functions needed by Legend widget |
---|
211 |
* and called when the page is loaded. |
---|
212 |
* @return array of name = function values |
---|
213 |
*/ |
---|
214 |
function GetJavascriptOnLoadFunctions() |
---|
215 |
{ |
---|
216 |
$aReturn = array(); |
---|
217 |
|
---|
218 |
if ($this->mbVisible) |
---|
219 |
$aReturn = $this->moButton->GetJavascriptOnLoadFunctions(); |
---|
220 |
else |
---|
221 |
$aReturn = array(); |
---|
222 |
|
---|
223 |
if (isset($this->maSharedResourceWidgets["CWCJSAPI"])) |
---|
224 |
{ |
---|
225 |
$szJsFunctionName = "LegendWRegisterForEvent"; |
---|
226 |
$szFunction = "$szJsFunctionName();\n"; |
---|
227 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
228 |
$szJsFunctionName = "UpdatePopup"; |
---|
229 |
$szFunction = "$szJsFunctionName();\n"; |
---|
230 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
231 |
} |
---|
232 |
|
---|
233 |
|
---|
234 |
return $aReturn; |
---|
235 |
} |
---|
236 |
function GetJavascriptVariables() |
---|
237 |
{ |
---|
238 |
if ($this->mbVisible) |
---|
239 |
return $this->moButton->GetJavascriptVariables(); |
---|
240 |
else return array(); |
---|
241 |
} |
---|
242 |
|
---|
243 |
function GetJavascriptInitFunctions() |
---|
244 |
{ |
---|
245 |
if ($this->mbVisible) |
---|
246 |
return $this->moButton->GetJavascriptInitFunctions(); |
---|
247 |
else return array(); |
---|
248 |
} |
---|
249 |
|
---|
250 |
function GetJavascriptIncludeFunctions() |
---|
251 |
{ |
---|
252 |
if ($this->mbVisible) |
---|
253 |
$aReturn = $this->moButton->GetJavascriptIncludeFunctions(); |
---|
254 |
else |
---|
255 |
$aReturn = array(); |
---|
256 |
return $aReturn; |
---|
257 |
} |
---|
258 |
/** |
---|
259 |
* DrawPublish |
---|
260 |
* |
---|
261 |
* Return the HTML code to display the link to the legend popup |
---|
262 |
*/ |
---|
263 |
function DrawPublish() |
---|
264 |
{ |
---|
265 |
if (!$this->mbVisible) |
---|
266 |
return "<!-- LegendWidget is hidden -->"; |
---|
267 |
|
---|
268 |
$szReturn = parent::DrawPublish(); |
---|
269 |
|
---|
270 |
$szReturn = $this->moButton->DrawPublish(); |
---|
271 |
|
---|
272 |
|
---|
273 |
return $szReturn; |
---|
274 |
} |
---|
275 |
} |
---|
276 |
?> |
---|