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 | * | |
20 | * @return string The content generated by running this page | |
21 | */ | |
00be9182 | 22 | public function run() { |
4b07d5bd TO |
23 | $this->registerResources(CRM_Core_Resources::singleton()); |
24 | return parent::run(); | |
25 | } | |
26 | ||
a0ee3941 EM |
27 | /** |
28 | * @param CRM_Core_Resources $res | |
29 | */ | |
4b07d5bd | 30 | public function registerResources(CRM_Core_Resources $res) { |
e7ff7042 TO |
31 | $modules = self::getAngularModules(); |
32 | ||
33 | $res->addSettingsFactory(function () use (&$modules) { | |
34 | // TODO optimization; client-side caching | |
35 | return array( | |
36 | 'resourceUrls' => CRM_Extension_System::singleton()->getMapper()->getActiveModuleUrls(), | |
37 | 'angular' => array( | |
38 | 'modules' => array_merge(array('ngRoute'), array_keys($modules)), | |
39 | ), | |
2b7de044 TO |
40 | 'crmAttachment' => array( |
41 | 'token' => CRM_Core_Page_AJAX_Attachment::createToken(), | |
42 | ), | |
e7ff7042 TO |
43 | ); |
44 | }); | |
45 | ||
416abe87 PH |
46 | $res->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', 100, 'html-header', FALSE); |
47 | $res->addScriptFile('civicrm', 'bower_components/angular-route/angular-route.min.js', 110, 'html-header', FALSE); | |
1996b8b2 | 48 | $headOffset = 0; |
e7ff7042 | 49 | foreach ($modules as $module) { |
d08319ae TO |
50 | if (!empty($module['css'])) { |
51 | foreach ($module['css'] as $file) { | |
1996b8b2 | 52 | $res->addStyleFile($module['ext'], $file, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), 'html-header', TRUE); |
d08319ae | 53 | } |
e7ff7042 | 54 | } |
d08319ae TO |
55 | if (!empty($module['js'])) { |
56 | foreach ($module['js'] as $file) { | |
2aa397bc | 57 | $res->addScriptFile($module['ext'], $file, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), 'html-header', TRUE); |
4b07d5bd TO |
58 | } |
59 | } | |
e7ff7042 | 60 | } |
e7ff7042 TO |
61 | } |
62 | ||
63 | /** | |
64 | * Get a list of AngularJS modules which should be autoloaded | |
65 | * | |
d08319ae | 66 | * @return array (string $name => array('ext' => string $key, 'js' => array $paths, 'css' => array $paths)) |
e7ff7042 TO |
67 | */ |
68 | public static function getAngularModules() { | |
69 | $angularModules = array(); | |
416abe87 | 70 | $angularModules['angularFileUpload'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-file-upload/angular-file-upload.min.js')); |
416abe87 | 71 | $angularModules['crmApp'] = array('ext' => 'civicrm', 'js' => array('js/angular-crmApp.js')); |
f44610a1 | 72 | $angularModules['crmAttachment'] = array('ext' => 'civicrm', 'js' => array('js/angular-crmAttachment.js'), 'css' => array('css/angular-crmAttachment.css')); |
efd95528 | 73 | $angularModules['crmUi'] = array('ext' => 'civicrm', 'js' => array('js/angular-crm-ui.js', 'packages/ckeditor/ckeditor.js')); |
60ebf0a5 | 74 | $angularModules['crmUtil'] = array('ext' => 'civicrm', 'js' => array('js/angular-crm-util.js')); |
d89d6ff7 TO |
75 | // https://github.com/jwstadler/angular-jquery-dialog-service |
76 | $angularModules['dialogService'] = array('ext' => 'civicrm' , 'js' => array('bower_components/angular-jquery-dialog-service/dialog-service.js')); | |
efd95528 | 77 | $angularModules['ngSanitize'] = array('ext' => 'civicrm', 'js' => array('js/angular-sanitize.js')); |
d89d6ff7 TO |
78 | $angularModules['ui.utils'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-ui-utils/ui-utils.min.js')); |
79 | $angularModules['ui.sortable'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-ui-sortable/sortable.min.js')); | |
416abe87 | 80 | $angularModules['unsavedChanges'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-unsavedChanges/dist/unsavedChanges.min.js')); |
c45daff0 | 81 | |
e7ff7042 TO |
82 | foreach (CRM_Core_Component::getEnabledComponents() as $component) { |
83 | $angularModules = array_merge($angularModules, $component->getAngularModules()); | |
84 | } | |
85 | CRM_Utils_Hook::angularModules($angularModules); | |
86 | return $angularModules; | |
87 | } | |
88 | ||
b5c2afd0 | 89 | } |