From: Tobias Lounsbury Date: Wed, 22 Jul 2015 18:33:55 +0000 (-0700) Subject: Migrated from manual includes to using civi helpers, Cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6aeeacaf67f1d2b46cb10ea91d9a4829680ef210;p=civicrm-core.git Migrated from manual includes to using civi helpers, Cleanup --- diff --git a/Civi/Angular/Page/Main.php b/Civi/Angular/Page/Main.php index 0a0c070e9d..664ebbd605 100644 --- a/Civi/Angular/Page/Main.php +++ b/Civi/Angular/Page/Main.php @@ -44,6 +44,7 @@ class Main extends \CRM_Core_Page { parent::__construct($title, $mode); $this->res = \CRM_Core_Resources::singleton(); $this->angular = \Civi\Core\Container::singleton()->get('angular'); + $this->region = \CRM_Utils_Request::retrieve('snippet', 'String') ? 'ajax-snippet' : 'html-header'; } /** @@ -55,17 +56,14 @@ class Main extends \CRM_Core_Page { * The content generated by running this page */ public function run() { - $snippet = (array_key_exists('snippet', $_GET) && str_replace("/", "", $_GET['snippet']) != "0"); - $this->registerResources($snippet); + $this->registerResources(); return parent::run(); } /** * Register resources required by Angular. */ - public function registerResources($snippet = false) { - $scripts = array(); - $styles = array(); + public function registerResources() { $modules = $this->angular->getModules(); $page = $this; // PHP 5.3 does not propagate $this to inner functions. @@ -80,22 +78,17 @@ class Main extends \CRM_Core_Page { )); }); - $config = \CRM_Core_Config::singleton(); - - $this->res->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', 100, 'html-header', FALSE); - $scripts[] = $config->userFrameworkResourceURL .'bower_components/angular/angular.min.js'; - + $this->res->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', 100, $this->region, FALSE); $headOffset = 0; + $config = \CRM_Core_Config::singleton(); if ($config->debug) { foreach ($modules as $moduleName => $module) { foreach ($this->angular->getResources($moduleName, 'css', 'cacheUrl') as $url) { - $this->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), 'html-header'); - $styles[] = $url; + $this->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), $this->region); } foreach ($this->angular->getResources($moduleName, 'js', 'cacheUrl') as $url) { - $this->res->addScriptUrl($url, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), 'html-header'); - $scripts[] = $url; + $this->res->addScriptUrl($url, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), $this->region); // addScriptUrl() bypasses the normal string-localization of addScriptFile(), // but that's OK because all Angular strings (JS+HTML) will load via crmResource. } @@ -105,27 +98,22 @@ class Main extends \CRM_Core_Page { // Note: addScriptUrl() bypasses the normal string-localization of addScriptFile(), // but that's OK because all Angular strings (JS+HTML) will load via crmResource. $aggScriptUrl = \CRM_Utils_System::url('civicrm/ajax/angular-modules', 'format=js&r=' . $page->res->getCacheCode(), FALSE, NULL, FALSE); - $this->res->addScriptUrl($aggScriptUrl, 120, 'html-header'); - $scripts[] = $aggScriptUrl; + $this->res->addScriptUrl($aggScriptUrl, 120, $this->region); // FIXME: The following CSS aggregator doesn't currently handle path-adjustments - which can break icons. //$aggStyleUrl = \CRM_Utils_System::url('civicrm/ajax/angular-modules', 'format=css&r=' . $page->res->getCacheCode(), FALSE, NULL, FALSE); - //$this->res->addStyleUrl($aggStyleUrl, 120, 'html-header'); + //$this->res->addStyleUrl($aggStyleUrl, 120, $this->region); foreach ($this->angular->getResources(array_keys($modules), 'css', 'cacheUrl') as $url) { - $this->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), 'html-header'); - $styles[] = $url; + $this->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), $this->region); } } - //This allows angular apps to be loaded as snippets in tabs - $this->assign("snippet", $snippet); - if($snippet) { + //This will enable setting of the lacation hash so that Angular knows + //Which page it is trying to load. + $this->assign("setRoute", ($this->region == "ajax-snippet")); + if($this->region == "ajax-snippet") { $this->assign("route", $_REQUEST['route']); - $this->assign("scripts", $scripts); - $this->assign("styles", $styles); } - } - } diff --git a/templates/Civi/Angular/Page/Main.tpl b/templates/Civi/Angular/Page/Main.tpl index 6d28bcca5a..271124e4fc 100644 --- a/templates/Civi/Angular/Page/Main.tpl +++ b/templates/Civi/Angular/Page/Main.tpl @@ -1,13 +1,7 @@ -{if $snippet} +{if $setRoute} - {foreach from=$styles item=styleURL} - - {/foreach} - {foreach from=$scripts item=scriptURL} - - {/foreach} {/if} {literal}