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
21 * The content generated by running this page
23 public function run() {
24 $this->registerResources(CRM_Core_Resources
::singleton());
29 * @param CRM_Core_Resources $res
31 public function registerResources(CRM_Core_Resources
$res) {
32 $modules = self
::getAngularModules();
34 $res->addSettingsFactory(function () use (&$modules) {
35 // TODO optimization; client-side caching
37 'resourceUrls' => CRM_Extension_System
::singleton()->getMapper()->getActiveModuleUrls(),
39 'modules' => array_merge(array('ngRoute'), array_keys($modules)),
41 'crmAttachment' => array(
42 'token' => CRM_Core_Page_AJAX_Attachment
::createToken(),
47 $res->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', 100, 'html-header', FALSE);
48 $res->addScriptFile('civicrm', 'bower_components/angular-route/angular-route.min.js', 110, 'html-header', FALSE);
50 foreach ($modules as $module) {
51 if (!empty($module['css'])) {
52 foreach ($module['css'] as $file) {
53 $res->addStyleFile($module['ext'], $file, self
::DEFAULT_MODULE_WEIGHT +
(++
$headOffset), 'html-header', TRUE);
56 if (!empty($module['js'])) {
57 foreach ($module['js'] as $file) {
58 $res->addScriptFile($module['ext'], $file, self
::DEFAULT_MODULE_WEIGHT +
(++
$headOffset), 'html-header', TRUE);
65 * Get a list of AngularJS modules which should be autoloaded
68 * (string $name => array('ext' => string $key, 'js' => array $paths, 'css' => array $paths))
70 public static function getAngularModules() {
71 $angularModules = array();
72 $angularModules['angularFileUpload'] = array(
74 'js' => array('bower_components/angular-file-upload/angular-file-upload.min.js'),
76 $angularModules['crmApp'] = array('ext' => 'civicrm', 'js' => array('js/angular-crmApp.js'));
77 $angularModules['crmAttachment'] = array(
79 'js' => array('js/angular-crmAttachment.js'),
80 'css' => array('css/angular-crmAttachment.css'),
82 $angularModules['crmUi'] = array(
84 'js' => array('js/angular-crm-ui.js', 'packages/ckeditor/ckeditor.js'),
86 $angularModules['crmUtil'] = array('ext' => 'civicrm', 'js' => array('js/angular-crm-util.js'));
87 // https://github.com/jwstadler/angular-jquery-dialog-service
88 $angularModules['dialogService'] = array(
90 'js' => array('bower_components/angular-jquery-dialog-service/dialog-service.js'),
92 $angularModules['ngSanitize'] = array('ext' => 'civicrm', 'js' => array('js/angular-sanitize.js'));
93 $angularModules['ui.utils'] = array(
95 'js' => array('bower_components/angular-ui-utils/ui-utils.min.js'),
97 $angularModules['ui.sortable'] = array(
99 'js' => array('bower_components/angular-ui-sortable/sortable.min.js'),
101 $angularModules['unsavedChanges'] = array(
103 'js' => array('bower_components/angular-unsavedChanges/dist/unsavedChanges.min.js'),
106 foreach (CRM_Core_Component
::getEnabledComponents() as $component) {
107 $angularModules = array_merge($angularModules, $component->getAngularModules());
109 CRM_Utils_Hook
::angularModules($angularModules);
110 return $angularModules;