NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/Chameleon/trunk/Chameleon/SharedResource/SharedResource.widget.php

Revision 13 (checked in by jcleary, 17 years ago)

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Base SharedResource class
4  *
5  * @project     CWC2
6  * @revision    $Id: SharedResource.widget.php,v 1.10 2005/01/11 12:32:21 pspencer Exp $
7  * @purpose     Base SharedResourceWidget 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 include_once(dirname(__FILE__)."/../Widget.php");
30
31 /**
32  *  class  SharedResource
33  *
34  * @description Base Shared memory widget class
35  */
36 class SharedResource extends CWCWidget
37 {
38     var $mszName = "";
39     var $mbEnableJS = false;
40
41     /**
42      * ShareResourceWidget
43      *
44      * Base CWC Share memory Widget.
45      */
46     function SharedResource()
47     {
48         // invoke constructor of parent
49         parent::CWCWidget();
50
51         // set the description for this widget
52         $this->szWidgetDescription = <<<EOT
53 SharedResource is an invisible widget that defines some set of values that
54 are to be shared among one or more widgets.  This was implemented to share
55 projection information between the ProjectionSelector and ProjectionLabel
56 widgets, but could be used for any widgets that might need it.  The format
57 of subtags is arbitrary and depends on the widgets that are using the
58 information.
59 EOT;
60
61         $this->maAttributes["NAME"] = new StringAttribute( "NAME", true );
62         $this->maAttributes["ENABLEJS"] = new BooleanAttribute( "ENABLEJS", false);
63         $this->mnMaturityLevel = MATURITY_TECHNICALRELEASE;
64     }
65    
66     /**
67      * MakeJSObject
68      * utility function to parse object trees
69      * and create a javascript object hierarchy to attach to the root object.
70      */
71     function MakeJSObject($szJSResourceType, $aChildren, $szJSParent)
72     {
73          $szJSResult = "";
74
75          if (!is_array( $aChildren ))
76          {
77              return "";
78          }
79          foreach ($aChildren as $szChild => $aProperties)
80          {
81             if (!is_array($aProperties))
82                 continue;
83            
84             $szJSObjectName = $szJSResourceType; // . $szChild;
85             $szJSResult .= "var " . $szJSObjectName . " = new CWC_JS_SharedResource();\n";
86            
87             foreach ($aProperties as $key => $val)
88             {
89                 $szJSElement = $key;
90                
91                 if (is_array ($val))
92                 {
93                     foreach ($val as $szChildResource => $aSubChildren)
94                     {
95                         $szJSResult .= $this->MakeJSObject ($szJSObjectName . "_" /*. $szChildResource*/, $aSubChildren, $szJSObjectName);
96                     }
97                 }
98                 else
99                 {
100                     $szJSResult .= $szJSObjectName . ".SetProperty(\"" . addslashes(trim($key)) . "\",\"" . addslashes(trim($val)) . "\");\n";
101                 }
102             }
103             $szJSResult .= $szJSParent . ".AddChild($szJSObjectName);\n";
104            
105         }
106         return $szJSResult;
107     }
108
109
110     /**
111      * InitDefaults
112      *
113      */
114     function InitDefaults()
115     {
116         parent::InitDefaults();
117         $this->mbEnableJS = 0;
118         if (isset($this->maParams["ENABLEJS"]))
119         {
120             $this->mbEnableJS = (strcasecmp($this->maParams["ENABLEJS"], "true") == 0) ? true : false;
121         }
122
123         if (isset($this->maParams["NAME"]))
124             $this->mszName = $this->maParams["NAME"];
125
126     }
127
128     /**
129      * GetJavascriptFunctions
130      *
131      */
132     function GetJavascriptFunctions()
133     {
134         $aReturn = array();
135        
136         parent::GetJavascriptFunctions();
137        
138         //check if there is a resource to build as javascript
139         if (!($this->maszContents != "" && $this->mbEnableJS))
140         {
141             return $aReturn;
142         }
143
144         //print_r($this->maszContents);
145         $szJSTree = "var ".$this->mszName." = new CWC_JS_SharedResource();\n";
146         foreach ($this->maszContents as $szJSResourceType => $aProperties)
147         {
148             $szJSTree .= $this->MakeJSObject($szJSResourceType, $aProperties, $this->mszName);
149         }
150         $szJSTree .= "goJSSR.SetProperty( \"".$this->mszName."\", $this->mszName );\n";
151        
152         $szJsFunctionName = "JSSharedResourceInit_".$this->mnId;
153         $szFunction = <<<EOT
154 /**
155  * {$szJsFunctionName}
156  * called to create a client side copy of the shared resource.
157  */
158 function {$szJsFunctionName}()
159 {   
160     //dump javascript that creates js tree for each JSSharedResource.
161     {$szJSTree}       
162 }
163
164 {$szJsFunctionName}();
165 EOT;
166
167         $aReturn[$szJsFunctionName] = $szFunction;       
168    
169         return $aReturn;
170     }
171
172     /**
173      * javascript include files
174      */
175     function GetJavascriptIncludeFunctions()
176     {
177         $aReturn = array();
178        
179         $aReturn = parent::GetJavascriptIncludeFunctions();
180         if ($this->mbEnableJS)
181         {
182             $szJsIncludeName = $_SESSION["gszCoreWebPath"]."/widgets/js/cwc_sr.js";
183             $szInclude = "<script language=\"JavaScript\" src=\"".$_SESSION["gszCoreWebPath"]."/widgets/js/cwc_sr.js\" type=\"text/javascript\"></script>";
184             $aReturn[$szJsIncludeName] = $szInclude;
185
186         }
187         return $aReturn;
188     }
189
190     /**
191      * GetJavascriptVariables
192      *
193      * Global var code
194      */
195     function GetJavascriptVariables()
196     {
197         $aReturn = array();
198         if ($this->mbEnableJS)
199         {
200             $szVariable = "goJSSR";
201             $szValue = " var $szVariable = new CWC_JS_SharedResource();\n";
202             $aReturn[$szVariable] = $szValue;
203
204         }
205         return $aReturn;
206     }
207
208 }
209 ?>
Note: See TracBrowser for help on using the browser.