Commit | Line | Data |
---|---|---|
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 | */ | |
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 | ||
b5c2afd0 EM |
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 | * | |
a6c01b45 CW |
20 | * @return string |
21 | * The content generated by running this page | |
b5c2afd0 | 22 | */ |
00be9182 | 23 | public function run() { |
4b07d5bd TO |
24 | $this->registerResources(CRM_Core_Resources::singleton()); |
25 | return parent::run(); | |
26 | } | |
27 | ||
a0ee3941 EM |
28 | /** |
29 | * @param CRM_Core_Resources $res | |
30 | */ | |
4b07d5bd | 31 | public function registerResources(CRM_Core_Resources $res) { |
e7ff7042 TO |
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 | ), | |
2b7de044 TO |
41 | 'crmAttachment' => array( |
42 | 'token' => CRM_Core_Page_AJAX_Attachment::createToken(), | |
43 | ), | |
e7ff7042 TO |
44 | ); |
45 | }); | |
46 | ||
416abe87 PH |
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); | |
1996b8b2 | 49 | $headOffset = 0; |
e7ff7042 | 50 | foreach ($modules as $module) { |
d08319ae TO |
51 | if (!empty($module['css'])) { |
52 | foreach ($module['css'] as $file) { | |
1996b8b2 | 53 | $res->addStyleFile($module['ext'], $file, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), 'html-header', TRUE); |
d08319ae | 54 | } |
e7ff7042 | 55 | } |
d08319ae TO |
56 | if (!empty($module['js'])) { |
57 | foreach ($module['js'] as $file) { | |
2aa397bc | 58 | $res->addScriptFile($module['ext'], $file, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), 'html-header', TRUE); |
4b07d5bd TO |
59 | } |
60 | } | |
e7ff7042 | 61 | } |
e7ff7042 TO |
62 | } |
63 | ||
64 | /** | |
65 | * Get a list of AngularJS modules which should be autoloaded | |
66 | * | |
a6c01b45 CW |
67 | * @return array |
68 | * (string $name => array('ext' => string $key, 'js' => array $paths, 'css' => array $paths)) | |
e7ff7042 TO |
69 | */ |
70 | public static function getAngularModules() { | |
71 | $angularModules = array(); | |
353ffa53 TO |
72 | $angularModules['angularFileUpload'] = array( |
73 | 'ext' => 'civicrm', | |
d5cc0fc2 | 74 | 'js' => array('bower_components/angular-file-upload/angular-file-upload.min.js'), |
353ffa53 | 75 | ); |
416abe87 | 76 | $angularModules['crmApp'] = array('ext' => 'civicrm', 'js' => array('js/angular-crmApp.js')); |
353ffa53 TO |
77 | $angularModules['crmAttachment'] = array( |
78 | 'ext' => 'civicrm', | |
79 | 'js' => array('js/angular-crmAttachment.js'), | |
d5cc0fc2 | 80 | 'css' => array('css/angular-crmAttachment.css'), |
353ffa53 TO |
81 | ); |
82 | $angularModules['crmUi'] = array( | |
83 | 'ext' => 'civicrm', | |
d5cc0fc2 | 84 | 'js' => array('js/angular-crm-ui.js', 'packages/ckeditor/ckeditor.js'), |
353ffa53 | 85 | ); |
60ebf0a5 | 86 | $angularModules['crmUtil'] = array('ext' => 'civicrm', 'js' => array('js/angular-crm-util.js')); |
d89d6ff7 | 87 | // https://github.com/jwstadler/angular-jquery-dialog-service |
353ffa53 TO |
88 | $angularModules['dialogService'] = array( |
89 | 'ext' => 'civicrm', | |
d5cc0fc2 | 90 | 'js' => array('bower_components/angular-jquery-dialog-service/dialog-service.js'), |
353ffa53 | 91 | ); |
efd95528 | 92 | $angularModules['ngSanitize'] = array('ext' => 'civicrm', 'js' => array('js/angular-sanitize.js')); |
353ffa53 TO |
93 | $angularModules['ui.utils'] = array( |
94 | 'ext' => 'civicrm', | |
d5cc0fc2 | 95 | 'js' => array('bower_components/angular-ui-utils/ui-utils.min.js'), |
353ffa53 TO |
96 | ); |
97 | $angularModules['ui.sortable'] = array( | |
98 | 'ext' => 'civicrm', | |
d5cc0fc2 | 99 | 'js' => array('bower_components/angular-ui-sortable/sortable.min.js'), |
353ffa53 TO |
100 | ); |
101 | $angularModules['unsavedChanges'] = array( | |
102 | 'ext' => 'civicrm', | |
d5cc0fc2 | 103 | 'js' => array('bower_components/angular-unsavedChanges/dist/unsavedChanges.min.js'), |
353ffa53 | 104 | ); |
c45daff0 | 105 | |
e7ff7042 TO |
106 | foreach (CRM_Core_Component::getEnabledComponents() as $component) { |
107 | $angularModules = array_merge($angularModules, $component->getAngularModules()); | |
108 | } | |
109 | CRM_Utils_Hook::angularModules($angularModules); | |
110 | return $angularModules; | |
111 | } | |
112 | ||
b5c2afd0 | 113 | } |