[icinga-checkins] icinga.org: icinga-web/jmosshammer/default: * Added agavi javascript actions to javascript config handler (ref #1548)

git at icinga.org git at icinga.org
Tue Aug 9 14:38:26 CEST 2011


Module: icinga-web
Branch: jmosshammer/default
Commit: 5ed55109433a6bff2098c6ab78d204438bbaf503
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=5ed55109433a6bff2098c6ab78d204438bbaf503

Author: Marius Hein <marius.hein at netways.de>
Date:   Fri Aug  5 11:26:28 2011 +0200

* Added agavi javascript actions to javascript config handler (ref #1548)

---

 app/config/config_handlers.xml                     |    5 ++-
 .../actions/Widgets/SquishLoaderAction.class.php   |   10 ++----
 app/modules/AppKit/config/javascript.xml           |   12 ++++++-
 .../config/AppKitResourceConfigHandler.class.php   |   21 +++++++++---
 app/modules/AppKit/models/ResourcesModel.class.php |    9 +++++
 .../Widgets/SquishLoaderSuccessView.class.php      |   35 ++++++++------------
 6 files changed, 56 insertions(+), 36 deletions(-)

diff --git a/app/config/config_handlers.xml b/app/config/config_handlers.xml
index 54ff0d9..9e4c387 100755
--- a/app/config/config_handlers.xml
+++ b/app/config/config_handlers.xml
@@ -46,7 +46,10 @@
             <handler pattern="%core.config_dir%/javascript.xml" class="AppKitXIncludeConfigHandler">
                 <ae:parameters>
                     <ae:parameter name="query"><![CDATA[//ae:configurations/ae:configuration]]></ae:parameter>
-                    <ae:parameter name="pointer"><![CDATA[xmlns(ae=http://agavi.org/agavi/config/global/envelope/1.0) xmlns(r=http://icinga.org/icinga/config/global/resource/1.0) xpointer(//ae:configurations/ae:configuration/r:javascript)]]></ae:parameter>
+                    <ae:parameter name="pointer">
+                    	<ae:parameter><![CDATA[xmlns(ae=http://agavi.org/agavi/config/global/envelope/1.0) xmlns(r=http://icinga.org/icinga/config/global/resource/1.0) xpointer(//ae:configurations/ae:configuration/r:javascript)]]></ae:parameter>
+                    	<ae:parameter><![CDATA[xmlns(ae=http://agavi.org/agavi/config/global/envelope/1.0) xmlns(r=http://icinga.org/icinga/config/global/resource/1.0) xpointer(//ae:configurations/ae:configuration/r:jactions)]]></ae:parameter>
+                    </ae:parameter>
                     <ae:parameter name="handler">AppKitResourceConfigHandler</ae:parameter>
                 </ae:parameters>
 
diff --git a/app/modules/AppKit/actions/Widgets/SquishLoaderAction.class.php b/app/modules/AppKit/actions/Widgets/SquishLoaderAction.class.php
index 1b7ff9c..581fb9e 100644
--- a/app/modules/AppKit/actions/Widgets/SquishLoaderAction.class.php
+++ b/app/modules/AppKit/actions/Widgets/SquishLoaderAction.class.php
@@ -29,13 +29,9 @@ class AppKit_Widgets_SquishLoaderAction extends AppKitBaseAction {
 					$loader->addFiles(
 						$resources->getJavascriptFiles()
 					);
-					/**
-					 * @todo URGENT: IMPLEMENT THIS ANYWAY
-					 **/	
-					// $actions = $this->getContext()->getRequest()->getAttribute('app.javascript_actions', AppKitModuleUtil::DEFAULT_NAMESPACE, array());
-					$actions = array ();
-				
-					$this->setAttribute('javascript_actions', $actions);
+					
+					$this->setAttribute('javascript_actions', $resources->getJavascriptActions());
+					
 				} catch(AppKitModelException $e) {
 					$this->setAttribute('errors', $e->getMessage());
 				}
diff --git a/app/modules/AppKit/config/javascript.xml b/app/modules/AppKit/config/javascript.xml
index 2049a0f..cdfe4d8 100644
--- a/app/modules/AppKit/config/javascript.xml
+++ b/app/modules/AppKit/config/javascript.xml
@@ -2,9 +2,7 @@
 <ae:configurations xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0" xmlns="http://icinga.org/icinga/config/global/resource/1.0">
 
     <ae:configuration>
-
         <javascript>
-
             <!-- ExtJS base files -->
             <ae:parameter>%core.root_dir%/lib/ext3/adapter/ext/ext-base.js</ae:parameter>
             <ae:parameter>%core.root_dir%/lib/ext3/ext-all.js</ae:parameter>
@@ -22,5 +20,15 @@
             <!-- jsgettext -->
             <ae:parameter>%core.root_dir%/lib/jsgettext/lib/Gettext.js</ae:parameter>
         </javascript>
+        
+        <!-- testtest -->
+        <jactions>
+        	<jaction>
+        		<ae:parameter name="module">AppKit</ae:parameter>
+				<ae:parameter name="action">Ext.initI18n</ae:parameter>
+				<ae:parameter name="output_type">javascript</ae:parameter>
+        	</jaction>
+        </jactions>
+        
     </ae:configuration>
 </ae:configurations>
diff --git a/app/modules/AppKit/lib/config/AppKitResourceConfigHandler.class.php b/app/modules/AppKit/lib/config/AppKitResourceConfigHandler.class.php
index 1a3754c..4519f30 100644
--- a/app/modules/AppKit/lib/config/AppKitResourceConfigHandler.class.php
+++ b/app/modules/AppKit/lib/config/AppKitResourceConfigHandler.class.php
@@ -52,7 +52,7 @@ class AppKitResourceConfigHandler extends AgaviXmlConfigHandler {
                     $_resources[] = $r;
                 }
             }
-
+            
             $resources = array_merge($resources, $_resources);
         }
 
@@ -68,19 +68,30 @@ class AppKitResourceConfigHandler extends AgaviXmlConfigHandler {
             array_keys($this->_resources),
             array_fill(0, count($this->_resources), array())
         );
-
+        
+        $jactions = array ();
+        
         foreach($doc->getConfigurationElements() as $cfg) {
+            
+            // Collecting resources
             foreach($this->_resources as $resource => $sfx) {
                 $resources[$resource] = array_merge(
                     $resources[$resource],
                     $this->collectResource($resource, $sfx, $cfg)
                 );
             }
+            // Collecting javascript actions
+            foreach ($cfg->getChildren('jactions', null, true) as $jaction) {
+                $jactions[] = $jaction->getAgaviParameters();
+            }
+            
         }
-
+        
         return $this->generate(sprintf(
-            '$this->resources = array_merge_recursive($this->resources, %s);',
-            var_export($resources, true)
+            '$this->resources = array_merge_recursive($this->resources, %s);%s$this->jactions=array_merge_recursive($this->jactions, %s);',
+            var_export($resources, true),
+            chr(10),
+            var_export($jactions, true)
         ), $doc->documentURI);
     }
 
diff --git a/app/modules/AppKit/models/ResourcesModel.class.php b/app/modules/AppKit/models/ResourcesModel.class.php
index 7e202f9..0a6c53f 100644
--- a/app/modules/AppKit/models/ResourcesModel.class.php
+++ b/app/modules/AppKit/models/ResourcesModel.class.php
@@ -12,6 +12,11 @@ class AppKit_ResourcesModel extends AppKitBaseModel implements AgaviISingletonMo
      * @var array string type => array files
      */
     protected $resources = array();
+    
+    /**
+	 * Collected agavi actions which produces javascript
+     */
+    protected $jactions = array ();
 
     /**
      * (non-PHPdoc)
@@ -63,5 +68,9 @@ class AppKit_ResourcesModel extends AppKitBaseModel implements AgaviISingletonMo
     public function getCssImports() {
     	return $this->resources['css_import'];
     }
+    
+    public function getJavascriptActions() {
+        return $this->jactions;
+    }
 
 }
diff --git a/app/modules/AppKit/views/Widgets/SquishLoaderSuccessView.class.php b/app/modules/AppKit/views/Widgets/SquishLoaderSuccessView.class.php
index 3d9ca66..e718103 100644
--- a/app/modules/AppKit/views/Widgets/SquishLoaderSuccessView.class.php
+++ b/app/modules/AppKit/views/Widgets/SquishLoaderSuccessView.class.php
@@ -31,30 +31,23 @@ class AppKit_Widgets_SquishLoaderSuccessView extends AppKitBaseView {
 		}		
 	}
 	
-	private function executeActions(array $actions = array()) {
+	private function executeActions(array $jactions = array()) {
 		$out = null;
 
-		if (count($actions)==1 && isset($actions[0])) {
-
-			foreach ($actions[0] as $modules) {
-
-				foreach ($modules as $a) {
-					$p = array ();
-					if(!isset($a['arguments']))
-						$a['arguments'] = false;
-					if (is_array($a['arguments'])) $p = $a['arguments'];
-					$a['arguments']['is_slot'] = true;
-					$r = $this->createForwardContainer($a['module'], $a['action'], $p, $a['output_type'])
-					->execute();
-
-					if ($r->hasContent()) {
-						$out .= $r->getContent(). "\n\n";
-					}
-				}
-
-			}
-
+		foreach ($jactions as $jaction) {
+
+		    if (!isset($jaction['arguments'])) {
+		        $jaction['arguments'] = array ();
+		    }
+		    
+		    $r = $this->createForwardContainer($jaction['module'], $jaction['action'], $jaction['arguments'], $jaction['output_type'])
+		        ->execute();
+		    
+		    if ($r->hasContent()) {
+		        $out .= $r->getContent(). str_repeat(chr(10), 2);
+		    }
 		}
+
 		return $out;
 	}
 	





More information about the icinga-checkins mailing list