CRM add missing comment blocks
[civicrm-core.git] / CRM / Core / Page / Angular.php
CommitLineData
e7ff7042
TO
1<?php
2
3/**
4 * This page is simply a container; any Angular modules defined by CiviCRM (or by CiviCRM extensions)
5 * will be activated on this page.
6 *
7 * @link https://issues.civicrm.org/jira/browse/CRM-14479
8 */
9class CRM_Core_Page_Angular extends CRM_Core_Page {
10 /**
11 * The weight to assign to any Angular JS module files
12 */
13 const DEFAULT_MODULE_WEIGHT = 200;
14
15 function run() {
4b07d5bd
TO
16 $this->registerResources(CRM_Core_Resources::singleton());
17 return parent::run();
18 }
19
20 public function registerResources(CRM_Core_Resources $res) {
e7ff7042
TO
21 $modules = self::getAngularModules();
22
23 $res->addSettingsFactory(function () use (&$modules) {
24 // TODO optimization; client-side caching
25 return array(
26 'resourceUrls' => CRM_Extension_System::singleton()->getMapper()->getActiveModuleUrls(),
27 'angular' => array(
28 'modules' => array_merge(array('ngRoute'), array_keys($modules)),
29 ),
30 );
31 });
32
2cc628e3
TO
33 $res->addScriptFile('civicrm', 'packages/bower_components/angular/angular.min.js', 100, 'html-header', FALSE);
34 $res->addScriptFile('civicrm', 'packages/bower_components/angular-route/angular-route.min.js', 110, 'html-header', FALSE);
e7ff7042 35 foreach ($modules as $module) {
d08319ae
TO
36 if (!empty($module['css'])) {
37 foreach ($module['css'] as $file) {
38 $res->addStyleFile($module['ext'], $file, self::DEFAULT_MODULE_WEIGHT, 'html-header', TRUE);
39 }
e7ff7042 40 }
d08319ae
TO
41 if (!empty($module['js'])) {
42 foreach ($module['js'] as $file) {
4b07d5bd
TO
43 $res->addScriptFile($module['ext'], $file, self::DEFAULT_MODULE_WEIGHT, 'html-header', TRUE);
44 }
45 }
e7ff7042 46 }
e7ff7042
TO
47 }
48
49 /**
50 * Get a list of AngularJS modules which should be autoloaded
51 *
d08319ae 52 * @return array (string $name => array('ext' => string $key, 'js' => array $paths, 'css' => array $paths))
e7ff7042
TO
53 */
54 public static function getAngularModules() {
55 $angularModules = array();
2cc628e3 56 $angularModules['ui.utils'] = array('ext' => 'civicrm', 'js' => array('packages/bower_components/angular-ui-utils/ui-utils.min.js'));
c45daff0
TO
57 $angularModules['ui.sortable'] = array('ext' => 'civicrm', 'js' => array('packages/bower_components/angular-ui-sortable/sortable.min.js'));
58
e7ff7042
TO
59 foreach (CRM_Core_Component::getEnabledComponents() as $component) {
60 $angularModules = array_merge($angularModules, $component->getAngularModules());
61 }
62 CRM_Utils_Hook::angularModules($angularModules);
63 return $angularModules;
64 }
65
66}