Move jQuery.validate to bower
[civicrm-core.git] / CRM / Core / Resources.php
index f160634176e937e937b04448cdce72503a988212..89bcdd9632f0b207b649047a0ea2a833ee0c1bd7 100644 (file)
@@ -99,7 +99,7 @@ class CRM_Core_Resources {
   public $ajaxPopupsEnabled;
 
   /**
-   * Get or set the single instance of CRM_Core_Resources
+   * Get or set the single instance of CRM_Core_Resources.
    *
    * @param CRM_Core_Resources $instance
    *   New copy of the manager.
@@ -125,7 +125,7 @@ class CRM_Core_Resources {
   }
 
   /**
-   * Construct a resource manager
+   * Construct a resource manager.
    *
    * @param CRM_Extension_Mapper $extMapper
    *   Map extension names to their base path or URLs.
@@ -148,6 +148,29 @@ class CRM_Core_Resources {
     );
   }
 
+  /**
+   * Export permission data to the client to enable smarter GUIs.
+   *
+   * Note: Application security stems from the server's enforcement
+   * of the security logic (e.g. in the API permissions). There's no way
+   * the client can use this info to make the app more secure; however,
+   * it can produce a better-tuned (non-broken) UI.
+   *
+   * @param array $permNames
+   *   List of permission names to check/export.
+   * @return CRM_Core_Resources
+   */
+  public function addPermissions($permNames) {
+    $permNames = (array) $permNames;
+    $perms = array();
+    foreach ($permNames as $permName) {
+      $perms[$permName] = CRM_Core_Permission::check($permName);
+    }
+    return $this->addSetting(array(
+      'permissions' => $perms,
+    ));
+  }
+
   /**
    * Add a JavaScript file to the current page using <SCRIPT SRC>.
    *
@@ -286,7 +309,7 @@ class CRM_Core_Resources {
   }
 
   /**
-   * Helper fn for addSettingsFactory
+   * Helper fn for addSettingsFactory.
    */
   public function getSettings() {
     $result = $this->settings;
@@ -313,7 +336,7 @@ class CRM_Core_Resources {
   }
 
   /**
-   * Helper fn for addSetting
+   * Helper fn for addSetting.
    * Render JavaScript variables for the global CRM object.
    *
    * @return string
@@ -364,6 +387,7 @@ class CRM_Core_Resources {
     foreach ((array) $text as $str) {
       $translated = ts($str, array(
         'domain' => ($domain == 'civicrm') ? NULL : array($domain, NULL),
+        'raw' => TRUE,
       ));
 
       // We only need to push this string to client if the translation
@@ -439,7 +463,7 @@ class CRM_Core_Resources {
   }
 
   /**
-   * Determine file path of a resource provided by an extension
+   * Determine file path of a resource provided by an extension.
    *
    * @param string $ext
    *   extension name; use 'civicrm' for core.
@@ -462,7 +486,7 @@ class CRM_Core_Resources {
   }
 
   /**
-   * Determine public URL of a resource provided by an extension
+   * Determine public URL of a resource provided by an extension.
    *
    * @param string $ext
    *   extension name; use 'civicrm' for core.
@@ -566,7 +590,7 @@ class CRM_Core_Resources {
       foreach ($this->coreResourceList() as $file) {
         if (substr($file, -2) == 'js') {
           // Don't bother  looking for ts() calls in packages, there aren't any
-          $translate = (substr($file, 0, 9) != 'packages/');
+          $translate = (substr($file, 0, 3) == 'js/');
           $this->addScriptFile('civicrm', $file, $jsWeight++, $region, $translate);
         }
         else {
@@ -580,7 +604,6 @@ class CRM_Core_Resources {
       // Add global settings
       $settings = array(
         'config' => array(
-          'ajaxPopupsEnabled' => $this->ajaxPopupsEnabled,
           'isFrontend' => $config->userFrameworkFrontend,
         ),
       );
@@ -624,7 +647,7 @@ class CRM_Core_Resources {
   }
 
   /**
-   * Flushes cached translated strings
+   * Flushes cached translated strings.
    * @return CRM_Core_Resources
    */
   public function flushStrings() {
@@ -653,13 +676,14 @@ class CRM_Core_Resources {
         'contactCreate' => CRM_Core_BAO_UFGroup::getCreateLinks(),
         'filters' => self::getEntityRefFilters(),
       ),
+      'ajaxPopupsEnabled' => self::singleton()->ajaxPopupsEnabled,
     );
     print CRM_Core_Smarty::singleton()->fetchWith('CRM/common/l10n.js.tpl', $vars);
     CRM_Utils_System::civiExit();
   }
 
   /**
-   * List of core resources we add to every CiviCRM page
+   * List of core resources we add to every CiviCRM page.
    *
    * @return array
    */
@@ -672,13 +696,13 @@ class CRM_Core_Resources {
     // Scripts needed by everyone, everywhere
     // FIXME: This is too long; list needs finer-grained segmentation
     $items = array(
-      "packages/jquery/jquery-1.11.1$min.js",
-      "packages/jquery/jquery-ui/jquery-ui$min.js",
-      "packages/jquery/jquery-ui/jquery-ui$min.css",
-      "packages/backbone/lodash.compat$min.js",
+      "bower_components/jquery/dist/jquery.min.js",
+      "bower_components/jquery-ui/jquery-ui.min.js",
+      "bower_components/jquery-ui/themes/smoothness/jquery-ui$min.css",
+      "bower_components/lodash-compat/lodash.min.js",
       "packages/jquery/plugins/jquery.mousewheel$min.js",
-      "packages/jquery/plugins/select2/select2$min.js",
-      "packages/jquery/plugins/select2/select2.css",
+      "bower_components/select2/select2$min.js",
+      "bower_components/select2/select2.css",
       "packages/jquery/plugins/jquery.tableHeader.js",
       "packages/jquery/plugins/jquery.textarearesizer.js",
       "packages/jquery/plugins/jquery.form$min.js",
@@ -686,7 +710,7 @@ class CRM_Core_Resources {
       "packages/jquery/plugins/jquery.blockUI$min.js",
       "packages/jquery/plugins/DataTables/media/js/jquery.dataTables$min.js",
       "packages/jquery/plugins/DataTables/media/css/jquery.dataTables$min.css",
-      "packages/jquery/plugins/jquery.validate$min.js",
+      "bower_components/jquery-validation/dist/jquery.validate$min.js",
       "packages/jquery/plugins/jquery.ui.datepicker.validation.pack.js",
       "js/Common.js",
       "js/crm.ajax.js",
@@ -695,7 +719,7 @@ class CRM_Core_Resources {
     // These scripts are only needed by back-office users
     if (CRM_Core_Permission::check('access CiviCRM')) {
       $items[] = "packages/jquery/plugins/jquery.menu$min.js";
-      $items[] = "packages/jquery/css/menu.css";
+      $items[] = "css/navigation.css";
       $items[] = "packages/jquery/plugins/jquery.jeditable$min.js";
       $items[] = "packages/jquery/plugins/jquery.notify$min.js";
       $items[] = "js/jquery/jquery.crmeditable.js";
@@ -715,7 +739,7 @@ class CRM_Core_Resources {
     if ($config->lcMessages && $config->lcMessages != 'en_US') {
       // Search for i18n file in order of specificity (try fr-CA, then fr)
       list($lang) = explode('_', $config->lcMessages);
-      $path = "packages/jquery/jquery-ui/i18n";
+      $path = "bower_components/jquery-ui/ui/i18n";
       foreach (array(str_replace('_', '-', $config->lcMessages), $lang) as $language) {
         $localizationFile = "$path/datepicker-{$language}.js";
         if ($this->getPath('civicrm', $localizationFile)) {
@@ -744,7 +768,7 @@ class CRM_Core_Resources {
   }
 
   /**
-   * Provide a list of available entityRef filters
+   * Provide a list of available entityRef filters.
    * FIXME: This function doesn't really belong in this class
    * @TODO: Provide a sane way to extend this list for other entities - a hook or??
    * @return array