4 * This page is simply a container; any Angular modules defined by CiviCRM (or by CiviCRM extensions)
5 * will be activated on this page.
7 * @link https://issues.civicrm.org/jira/browse/CRM-14479
9 class CRM_Core_Page_Angular
extends CRM_Core_Page
{
11 * The weight to assign to any Angular JS module files
13 const DEFAULT_MODULE_WEIGHT
= 200;
16 * This function takes care of all the things common to all
17 * pages. This typically involves assigning the appropriate
20 * @return string The content generated by running this page
23 $this->registerResources(CRM_Core_Resources
::singleton());
28 * @param CRM_Core_Resources $res
30 public function registerResources(CRM_Core_Resources
$res) {
31 $modules = self
::getAngularModules();
33 $res->addSettingsFactory(function () use (&$modules) {
34 // TODO optimization; client-side caching
36 'resourceUrls' => CRM_Extension_System
::singleton()->getMapper()->getActiveModuleUrls(),
38 'modules' => array_merge(array('ngRoute'), array_keys($modules)),
43 $res->addScriptFile('civicrm', 'packages/bower_components/angular/angular.min.js', 100, 'html-header', FALSE);
44 $res->addScriptFile('civicrm', 'packages/bower_components/angular-route/angular-route.min.js', 110, 'html-header', FALSE);
45 foreach ($modules as $module) {
46 if (!empty($module['css'])) {
47 foreach ($module['css'] as $file) {
48 $res->addStyleFile($module['ext'], $file, self
::DEFAULT_MODULE_WEIGHT
, 'html-header', TRUE);
51 if (!empty($module['js'])) {
52 foreach ($module['js'] as $file) {
53 $res->addScriptFile($module['ext'], $file, self
::DEFAULT_MODULE_WEIGHT
, 'html-header', TRUE);
60 * Get a list of AngularJS modules which should be autoloaded
62 * @return array (string $name => array('ext' => string $key, 'js' => array $paths, 'css' => array $paths))
64 public static function getAngularModules() {
65 $angularModules = array();
66 $angularModules['ui.utils'] = array('ext' => 'civicrm', 'js' => array('packages/bower_components/angular-ui-utils/ui-utils.min.js'));
67 $angularModules['ui.sortable'] = array('ext' => 'civicrm', 'js' => array('packages/bower_components/angular-ui-sortable/sortable.min.js'));
68 $angularModules['unsavedChanges'] = array('ext' => 'civicrm', 'js' => array('packages/bower_components/angular-unsavedChanges/dist/unsavedChanges.min.js'));
69 $angularModules['crmUi'] = array('ext' => 'civicrm', 'js' => array('js/angular-crm-ui.js'));
71 foreach (CRM_Core_Component
::getEnabledComponents() as $component) {
72 $angularModules = array_merge($angularModules, $component->getAngularModules());
74 CRM_Utils_Hook
::angularModules($angularModules);
75 return $angularModules;