2 namespace Civi\Angular\Page
;
5 * This page is simply a container; any Angular modules defined by CiviCRM (or by CiviCRM extensions)
6 * will be activated on this page.
8 * @link https://issues.civicrm.org/jira/browse/CRM-14479
10 class Main
extends \CRM_Core_Page
{
12 * The weight to assign to any Angular JS module files.
14 const DEFAULT_MODULE_WEIGHT
= 200;
17 * The resource manager.
19 * Do not use publicly. Inject your own copy!
21 * @var \CRM_Core_Resources
27 * The Angular module manager.
29 * Do not use publicly. Inject your own copy!
31 * @var \Civi\Angular\Manager
36 * @param string $title
40 * @param \CRM_Core_Resources|null $res
43 public function __construct($title = NULL, $mode = NULL, $res = NULL) {
44 parent
::__construct($title, $mode);
45 $this->res
= \CRM_Core_Resources
::singleton();
46 $this->angular
= \Civi\Core\Container
::singleton()->get('angular');
50 * This function takes care of all the things common to all
51 * pages. This typically involves assigning the appropriate
55 * The content generated by running this page
57 public function run() {
58 $this->registerResources();
63 * Register resources required by Angular.
65 public function registerResources() {
66 $modules = $this->angular
->getModules();
67 $page = $this; // PHP 5.3 does not propagate $this to inner functions.
69 $this->res
->addSettingsFactory(function () use (&$modules, $page) {
70 // TODO optimization; client-side caching
71 return array_merge($page->angular
->getResources(array_keys($modules), 'settings', 'settings'), array(
72 'resourceUrls' => \CRM_Extension_System
::singleton()->getMapper()->getActiveModuleUrls(),
74 'modules' => array_merge(array('ngRoute'), array_keys($modules)),
75 'cacheCode' => $page->res
->getCacheCode(),
80 $this->res
->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', 100, 'html-header', FALSE);
82 // FIXME: crmUi depends on loading ckeditor, but ckeditor doesn't work with this aggregation.
83 $this->res
->addScriptFile('civicrm', 'packages/ckeditor/ckeditor.js', 100, 'page-header', FALSE);
86 $config = \CRM_Core_Config
::singleton();
88 foreach ($modules as $moduleName => $module) {
89 foreach ($this->angular
->getResources($moduleName, 'css', 'cacheUrl') as $url) {
90 $this->res
->addStyleUrl($url, self
::DEFAULT_MODULE_WEIGHT +
(++
$headOffset), 'html-header');
92 foreach ($this->angular
->getResources($moduleName, 'js', 'cacheUrl') as $url) {
93 $this->res
->addScriptUrl($url, self
::DEFAULT_MODULE_WEIGHT +
(++
$headOffset), 'html-header');
94 // addScriptUrl() bypasses the normal string-localization of addScriptFile(),
95 // but that's OK because all Angular strings (JS+HTML) will load via crmResource.
100 // Note: addScriptUrl() bypasses the normal string-localization of addScriptFile(),
101 // but that's OK because all Angular strings (JS+HTML) will load via crmResource.
102 $aggScriptUrl = \CRM_Utils_System
::url('civicrm/ajax/angular-modules', 'format=js&r=' . $page->res
->getCacheCode(), FALSE, NULL, FALSE);
103 $this->res
->addScriptUrl($aggScriptUrl, 120, 'html-header');
105 // FIXME: The following CSS aggregator doesn't currently handle path-adjustments - which can break icons.
106 //$aggStyleUrl = \CRM_Utils_System::url('civicrm/ajax/angular-modules', 'format=css&r=' . $page->res->getCacheCode(), FALSE, NULL, FALSE);
107 //$this->res->addStyleUrl($aggStyleUrl, 120, 'html-header');
109 foreach ($this->angular
->getResources(array_keys($modules), 'css', 'cacheUrl') as $url) {
110 $this->res
->addStyleUrl($url, self
::DEFAULT_MODULE_WEIGHT +
(++
$headOffset), 'html-header');