X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi%2FAngular%2FManager.php;h=a9036908ad22a115c61666b230db257af1ba37ca;hb=3a3c02959ef5d544627fee776e0eba866b82b305;hp=a93c8790baefceee4e4556be5b08ee7fbb162d4f;hpb=d9327fe8f46640cde1c08fbac61c46aef9024f8a;p=civicrm-core.git diff --git a/Civi/Angular/Manager.php b/Civi/Angular/Manager.php index a93c8790ba..a9036908ad 100644 --- a/Civi/Angular/Manager.php +++ b/Civi/Angular/Manager.php @@ -17,9 +17,14 @@ class Manager { * @var array|NULL * Each item has some combination of these keys: * - ext: string + * The Civi extension which defines the Angular module. * - js: array(string $relativeFilePath) + * List of JS files (relative to the extension). * - css: array(string $relativeFilePath) + * List of CSS files (relative to the extension). * - partials: array(string $relativeFilePath) + * A list of partial-HTML folders (relative to the extension). + * This will be mapped to "~/moduleName" by crmResource. */ protected $modules = NULL; @@ -32,10 +37,19 @@ class Manager { } /** - * Get a list of AngularJS modules which should be autoloaded + * Get a list of AngularJS modules which should be autoloaded. * * @return array - * (string $name => array('ext' => string $key, 'js' => array $paths, 'css' => array $paths)) + * Each item has some combination of these keys: + * - ext: string + * The Civi extension which defines the Angular module. + * - js: array(string $relativeFilePath) + * List of JS files (relative to the extension). + * - css: array(string $relativeFilePath) + * List of CSS files (relative to the extension). + * - partials: array(string $relativeFilePath) + * A list of partial-HTML folders (relative to the extension). + * This will be mapped to "~/moduleName" by crmResource. */ public function getModules() { if ($this->modules === NULL) { @@ -47,14 +61,23 @@ class Manager { ); $angularModules['crmApp'] = array( 'ext' => 'civicrm', - 'js' => array('js/angular-crmApp.js'), + 'js' => array('ang/crmApp.js'), ); $angularModules['crmAttachment'] = array( 'ext' => 'civicrm', - 'js' => array('js/angular-crmAttachment.js'), - 'css' => array('css/angular-crmAttachment.css'), - 'partials' => array('partials/crmAttachment'), + 'js' => array('ang/crmAttachment.js'), + 'css' => array('ang/crmAttachment.css'), + 'partials' => array('ang/crmAttachment'), + ); + $angularModules['crmAutosave'] = array( + 'ext' => 'civicrm', + 'js' => array('ang/crmAutosave.js'), ); + //$angularModules['crmExample'] = array( + // 'ext' => 'civicrm', + // 'js' => array('ang/crmExample.js'), + // 'partials' => array('ang/crmExample'), + //); $angularModules['crmResource'] = array( 'ext' => 'civicrm', // 'js' => array('js/angular-crmResource/byModule.js'), // One HTTP request per module. @@ -62,22 +85,18 @@ class Manager { ); $angularModules['crmUi'] = array( 'ext' => 'civicrm', - 'js' => array('js/angular-crm-ui.js', 'packages/ckeditor/ckeditor.js'), - 'partials' => array('partials/crmUi'), + 'js' => array('ang/crmUi.js'), + 'partials' => array('ang/crmUi'), ); $angularModules['crmUtil'] = array( 'ext' => 'civicrm', - 'js' => array('js/angular-crm-util.js'), + 'js' => array('ang/crmUtil.js'), ); // https://github.com/jwstadler/angular-jquery-dialog-service $angularModules['dialogService'] = array( 'ext' => 'civicrm', 'js' => array('bower_components/angular-jquery-dialog-service/dialog-service.js'), ); - $angularModules['ngSanitize'] = array( - 'ext' => 'civicrm', - 'js' => array('js/angular-sanitize.js'), - ); $angularModules['ui.utils'] = array( 'ext' => 'civicrm', 'js' => array('bower_components/angular-ui-utils/ui-utils.min.js'), @@ -236,38 +255,45 @@ class Manager { } /** - * @param string $name - * Module name. + * Get resources for one or more modules. + * + * @param string|array $moduleNames + * List of module names. + * @param string $resType + * Type of resource ('js', 'css'). + * @param string $refType + * Type of reference to the resource ('cacheUrl', 'rawUrl', 'path'). * @return array - * List of URLs. - * @throws \Exception + * List of URLs or paths. + * @throws \CRM_Core_Exception */ - public function getScriptUrls($name) { - $module = $this->getModule($name); + public function getResources($moduleNames, $resType, $refType) { $result = array(); - if (isset($module['js'])) { - foreach ($module['js'] as $file) { - $result[] = $this->res->getUrl($module['ext'], $file, TRUE); - } - } - return $result; - } + $moduleNames = (array) $moduleNames; + foreach ($moduleNames as $moduleName) { + $module = $this->getModule($moduleName); + if (isset($module[$resType])) { + foreach ($module[$resType] as $file) { + switch ($refType) { + case 'path': + $result[] = $this->res->getPath($module['ext'], $file); + break; - /** - * @param string $name - * Module name. - * @return array - * List of URLs. - * @throws \Exception - */ - public function getStyleUrls($name) { - $module = $this->getModule($name); - $result = array(); - if (isset($module['css'])) { - foreach ($module['css'] as $file) { - $result[] = $this->res->getUrl($module['ext'], $file, TRUE); + case 'rawUrl': + $result[] = $this->res->getUrl($module['ext'], $file); + break; + + case 'cacheUrl': + $result[] = $this->res->getUrl($module['ext'], $file, TRUE); + break; + + default: + throw new \CRM_Core_Exception("Unrecognized resource format"); + } + } } } return $result; } + }