INFRA-132 - Fix spacing of @return tag in comments
[civicrm-core.git] / CRM / Core / Page / Angular.php
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 */
9 class 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 /**
16 * This function takes care of all the things common to all
17 * pages. This typically involves assigning the appropriate
18 * smarty variable :)
19 *
20 * @return string
21 * The content generated by running this page
22 */
23 public function run() {
24 $this->registerResources(CRM_Core_Resources::singleton());
25 return parent::run();
26 }
27
28 /**
29 * @param CRM_Core_Resources $res
30 */
31 public function registerResources(CRM_Core_Resources $res) {
32 $modules = self::getAngularModules();
33
34 $res->addSettingsFactory(function () use (&$modules) {
35 // TODO optimization; client-side caching
36 return array(
37 'resourceUrls' => CRM_Extension_System::singleton()->getMapper()->getActiveModuleUrls(),
38 'angular' => array(
39 'modules' => array_merge(array('ngRoute'), array_keys($modules)),
40 ),
41 'crmAttachment' => array(
42 'token' => CRM_Core_Page_AJAX_Attachment::createToken(),
43 ),
44 );
45 });
46
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);
49 $headOffset = 0;
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);
54 }
55 }
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);
59 }
60 }
61 }
62 }
63
64 /**
65 * Get a list of AngularJS modules which should be autoloaded
66 *
67 * @return array
68 * (string $name => array('ext' => string $key, 'js' => array $paths, 'css' => array $paths))
69 */
70 public static function getAngularModules() {
71 $angularModules = array();
72 $angularModules['angularFileUpload'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-file-upload/angular-file-upload.min.js'));
73 $angularModules['crmApp'] = array('ext' => 'civicrm', 'js' => array('js/angular-crmApp.js'));
74 $angularModules['crmAttachment'] = array('ext' => 'civicrm', 'js' => array('js/angular-crmAttachment.js'), 'css' => array('css/angular-crmAttachment.css'));
75 $angularModules['crmUi'] = array('ext' => 'civicrm', 'js' => array('js/angular-crm-ui.js', 'packages/ckeditor/ckeditor.js'));
76 $angularModules['crmUtil'] = array('ext' => 'civicrm', 'js' => array('js/angular-crm-util.js'));
77 // https://github.com/jwstadler/angular-jquery-dialog-service
78 $angularModules['dialogService'] = array('ext' => 'civicrm' , 'js' => array('bower_components/angular-jquery-dialog-service/dialog-service.js'));
79 $angularModules['ngSanitize'] = array('ext' => 'civicrm', 'js' => array('js/angular-sanitize.js'));
80 $angularModules['ui.utils'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-ui-utils/ui-utils.min.js'));
81 $angularModules['ui.sortable'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-ui-sortable/sortable.min.js'));
82 $angularModules['unsavedChanges'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-unsavedChanges/dist/unsavedChanges.min.js'));
83
84 foreach (CRM_Core_Component::getEnabledComponents() as $component) {
85 $angularModules = array_merge($angularModules, $component->getAngularModules());
86 }
87 CRM_Utils_Hook::angularModules($angularModules);
88 return $angularModules;
89 }
90
91 }