Merge pull request #9128 from colemanw/CRM-19065
[civicrm-core.git] / ang / crmUi.js
index fdd0cd62193a3606622446ea42ffe4920df4f22e..879b2a8c43f690622a069671d8743afc0adb6646 100644 (file)
@@ -2,7 +2,8 @@
 (function (angular, $, _) {
 
   var uidCount = 0,
-    pageTitle = 'CiviCRM';
+    pageTitle = 'CiviCRM',
+    documentTitle = 'CiviCRM';
 
   angular.module('crmUi', [])
 
 
           ngModel.$render = function(value) {
             editor.done(function() {
-              CRM.wysiwyg.setVal(elm, ngModel.$viewValue);
+              CRM.wysiwyg.setVal(elm, ngModel.$viewValue || '');
             });
           };
         }
               $timeout(function () {
                 // ex: msg_template_id adds new item then selects it; use $timeout to ensure that
                 // new item is added before selection is made
-                element.select2('val', ngModel.$viewValue);
+                element.select2('val', ngModel.$modelValue);
               });
             };
           }
             $timeout(function () {
               // ex: msg_template_id adds new item then selects it; use $timeout to ensure that
               // new item is added before selection is made
-              element.select2('val', ngModel.$viewValue);
+              element.select2('val', ngModel.$modelValue);
             });
           };
           function refreshModel() {
     })
 
     // example: <div crm-ui-wizard="myWizardCtrl"><div crm-ui-wizard-step crm-title="ts('Step 1')">...</div><div crm-ui-wizard-step crm-title="ts('Step 2')">...</div></div>
+    // example with custom nav classes: <div crm-ui-wizard crm-ui-wizard-nav-class="ng-animate-out ...">...</div>
     // Note: "myWizardCtrl" has various actions/properties like next() and $first().
     // WISHLIST: Allow each step to determine if it is "complete" / "valid" / "selectable"
     // WISHLIST: Allow each step to enable/disable (show/hide) itself
       return {
         restrict: 'EA',
         scope: {
-          crmUiWizard: '@'
+          crmUiWizard: '@',
+          crmUiWizardNavClass: '@' // string, A list of classes that will be added to the nav items
         },
         templateUrl: '~/crmUi/wizard.html',
         transclude: true,
     // example: <div crm-ui-wizard-step crm-title="ts('My Title')" ng-form="mySubForm">...content...</div>
     // If there are any conditional steps, then be sure to set a weight explicitly on *all* steps to maintain ordering.
     // example: <div crm-ui-wizard-step="100" crm-title="..." ng-if="...">...content...</div>
+    // example with custom classes: <div crm-ui-wizard-step="100" crm-ui-wizard-step-class="ng-animate-out ...">...content...</div>
     .directive('crmUiWizardStep', function() {
       var nextWeight = 1;
       return {
         restrict: 'EA',
         scope: {
           crmTitle: '@', // expression, evaluates to a printable string
-          crmUiWizardStep: '@' // int, a weight which determines the ordering of the steps
+          crmUiWizardStep: '@', // int, a weight which determines the ordering of the steps
+          crmUiWizardStepClass: '@' // string, A list of classes that will be added to the template
         },
-        template: '<div class="crm-wizard-step" ng-show="selected" ng-transclude/></div>',
+        template: '<div class="crm-wizard-step {{crmUiWizardStepClass}}" ng-show="selected" ng-transclude/></div>',
         transclude: true,
         link: function (scope, element, attrs, ctrls) {
           var crmUiWizardCtrl = ctrls[0], form = ctrls[1];
             return form.$valid;
           };
           crmUiWizardCtrl.add(scope);
-          element.on('$destroy', function(){
+          scope.$on('$destroy', function(){
             crmUiWizardCtrl.remove(scope);
           });
         }
       };
     })
 
-    // Sets the one and only page title - uses CMS title if available
+    // Sets document title & page title; attempts to override CMS title markup for the latter
     // WARNING: Use only once per route!
-    // Note: Title should be plain-text only
-    // Example: <h1 crm-ui-title>{{ts('Hello')}}</h1>
-    .directive('crmUiTitle', function($timeout) {
+    // Example (same title for both): <h1 crm-page-title>{{ts('Hello')}}</h1>
+    // Example (separate document title): <h1 crm-document-title="ts('Hello')" crm-page-title><i class="crm-i fa-flag"></i>{{ts('Hello')}}</h1>
+    .directive('crmPageTitle', function($timeout) {
       return {
+        scope: {
+          crmDocumentTitle: '='
+        },
         link: function(scope, $el, attrs) {
           function update() {
             $timeout(function() {
-              var newTitle = $el.text();
-              document.title = $('title').text().replace(pageTitle, newTitle);
+              var newPageTitle = _.trim($el.html()),
+                newDocumentTitle = scope.crmDocumentTitle || $el.text();
+              document.title = $('title').text().replace(documentTitle, newDocumentTitle);
               // If the CMS has already added title markup to the page, use it
               $('h1').not('.crm-container h1').each(function() {
-                if (_.trim($(this).text()) === _.trim(pageTitle)) {
-                  $(this).text(newTitle);
+                if (_.trim($(this).html()) === pageTitle) {
+                  $(this).html(newPageTitle);
                   $el.hide();
                 }
               });
-              pageTitle = newTitle;
+              pageTitle = newPageTitle;
+              documentTitle = newDocumentTitle;
             });
           }
 
-          scope.$watch(function() {return $el.html();}, update);
+          scope.$watch(function() {return scope.crmDocumentTitle + $el.html();}, update);
         }
       };
     })