CRM-15706 - Add Angular help directive
authorColeman Watts <coleman@civicrm.org>
Sat, 14 Mar 2015 00:23:47 +0000 (20:23 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 19 Mar 2015 15:39:47 +0000 (11:39 -0400)
js/angular-crm-ui.js
js/angular-crmMailing/directives.js
partials/crmMailing/mailing.html
partials/crmUi/field.html

index 0876e149a329f5a6e7407d5a587327550adbd435..70f7519fe172ce9330d19ce108e379a01bd3b35e 100644 (file)
         restrict: 'EA',
         scope: {
           crmUiField: '@',
-          crmTitle: '@'
+          crmTitle: '@',
+          crmHelp: '@'
         },
         templateUrl: function(tElement, tAttrs){
           var layout = tAttrs.crmLayout ? tAttrs.crmLayout : 'default';
           $(element).addClass('crm-section');
           scope.crmUiField = attrs.crmUiField;
           scope.crmTitle = attrs.crmTitle;
+          scope.crmHelp = attrs.crmHelp;
         }
       };
     })
       };
     })
 
+    // standalone: <a crm-ui-help="field_name">
+    // within crmUiField: <div crm-ui-field crm-title="My Field" crm-help="field_name">
+    .directive('crmUiHelp', function() {
+      return {
+        restrict: 'EA',
+        scope: {
+          crmUiHelp: '='
+        },
+        link: function (scope, element, attrs) {
+          element
+            .addClass('helpicon')
+            .attr('title', ts('%1 Help', {1: scope.crmUiHelp.title}))
+            .attr('href', '#')
+            .on('click', function(e) {
+              e.preventDefault();
+              CRM.help(scope.crmUiHelp.title, {id: scope.crmUiHelp.id, file: scope.$parent.$parent.$parent.helpFile});
+            });
+        }
+      };
+    })
+
     // example: <div ng-form="subform" crm-ui-id-scope><label crm-ui-for="subform.foo">Foo:</label><input crm-ui-id="subform.foo" name="foo"/></div>
     .directive('crmUiFor', function ($parse, $timeout) {
       return {
index 307df6369ee4e3aeb55ad4ce6aaca0f5d81f8bc6..7db48d4c0e313c9fc47cac29b022dc5a6ae1a7d4 100644 (file)
@@ -28,6 +28,7 @@
           });
           scope.crmMailingConst = CRM.crmMailing;
           scope.ts = CRM.ts(null);
+          scope.helpFile = 'CRM/Mailing/Form/Upload';
           scope[directiveName] = attr[directiveName] ? scope.$parent.$eval(attr[directiveName]) : {};
           $q.when(crmMetadata.getFields('Mailing'), function(fields) {
             scope.mailingFields = fields;
index 3ade3ee9f4ae4750962d090ac4e6b50adf976735..815bdf7b9cdd182fa042588eedf03011c3e9c777 100644 (file)
@@ -21,7 +21,7 @@ It could perhaps be thinned by 30-60% by making more directives.
         <a crm-icon="disk" ng-click="saveTemplate(mailing)" class="crm-hover-button" title="{{ts('Save As')}}"></a>
       </div>
     </div>
-    <div crm-ui-field="subform.fromAddress" crm-title="ts('From')">
+    <div crm-ui-field="subform.fromAddress" crm-title="ts('From')" crm-help="id-from_email">
       <div ng-controller="EmailAddrCtrl" crm-mailing-from-address="fromPlaceholder" crm-mailing="mailing">
         <select
           crm-ui-id="subform.fromAddress"
index e29c931b878368b762bb4b3f9c54b7764e8441ea..8aaa50a8242e039e7c054c6ea74ff105e50706af 100644 (file)
@@ -1,3 +1,6 @@
-<div class="label"><label crm-ui-for="{{crmUiField}}" crm-depth="1">{{$parent.$parent.$eval(crmTitle)}}</label></div>
+<div class="label">
+  <label crm-ui-for="{{crmUiField}}" crm-depth="1">{{$parent.$parent.$eval(crmTitle)}}</label>
+  <a crm-ui-help="{title: $parent.$parent.$eval(crmTitle), id: crmHelp}" ng-if="crmHelp"></a>
+</div>
 <div class="content" ng-transclude></div>
 <div class="clear"></div>