CRM-15706 - Loosen coupling between crmUiHelp and crmUiField. Document input "crmUiHe...
authorTim Otten <totten@civicrm.org>
Mon, 16 Mar 2015 01:06:12 +0000 (18:06 -0700)
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 70f7519fe172ce9330d19ce108e379a01bd3b35e..e68b3a10f71da3fbea2a08999201959f17238c34 100644 (file)
     // example: <div crm-ui-field crm-title="My Field"> {{mydata}} </div>
     // example: <div crm-ui-field="subform.myfield" crm-title="'My Field'"> <input crm-ui-id="subform.myfield" name="myfield" /> </div>
     // example: <div crm-ui-field="subform.myfield" crm-title="'My Field'"> <input crm-ui-id="subform.myfield" name="myfield" required /> </div>
+    // example: <div crm-ui-field crm-title="My Field" crm-ui-help="'help_field_name'"> {{mydata}} </div>
     .directive('crmUiField', function() {
       // Note: When writing new templates, the "label" position is particular. See/patch "var label" below.
       var templateUrls = {
         require: '^crmUiIdScope',
         restrict: 'EA',
         scope: {
+          // string, e.g. "myform.myfield"
           crmUiField: '@',
+          // string, an expression producing a printable title
           crmTitle: '@',
+          // string, an expression producing a help id
           crmHelp: '@'
         },
         templateUrl: function(tElement, tAttrs){
           scope.crmUiField = attrs.crmUiField;
           scope.crmTitle = attrs.crmTitle;
           scope.crmHelp = attrs.crmHelp;
+          scope.crmUiHelpFile = scope.$parent.crmUiHelpFile;
         }
       };
     })
       };
     })
 
-    // standalone: <a crm-ui-help="field_name">
-    // within crmUiField: <div crm-ui-field crm-title="My Field" crm-help="field_name">
+    // Display a help icon which loads help from a *.hlp file.
+    // Example: Use a default *.hlp file
+    //   JS: scope.crmUiHelpFile='CRM/Foo/Bar';
+    //   HTML: <a crm-ui-help="{title:ts('My Field'), id:'my_field'}">
+    // Example: Use an explicit *.hlp file
+    //   HTML: <a crm-ui-help="{title:ts('My Field'), id:'my_field', file:'CRM/Foo/Bar'}">
     .directive('crmUiHelp', function() {
       return {
         restrict: 'EA',
             .attr('href', '#')
             .on('click', function(e) {
               e.preventDefault();
-              CRM.help(scope.crmUiHelp.title, {id: scope.crmUiHelp.id, file: scope.$parent.$parent.$parent.helpFile});
+              CRM.help(scope.crmUiHelp.title, {id: scope.crmUiHelp.id, file: scope.crmUiHelp.file || scope.$parent.crmUiHelpFile});
             });
         }
       };
index 7db48d4c0e313c9fc47cac29b022dc5a6ae1a7d4..646d285848c6a9975cd11ff176dff946357b5617 100644 (file)
@@ -28,7 +28,7 @@
           });
           scope.crmMailingConst = CRM.crmMailing;
           scope.ts = CRM.ts(null);
-          scope.helpFile = 'CRM/Mailing/Form/Upload';
+          scope.crmUiHelpFile = 'CRM/Mailing/Form/Upload';
           scope[directiveName] = attr[directiveName] ? scope.$parent.$eval(attr[directiveName]) : {};
           $q.when(crmMetadata.getFields('Mailing'), function(fields) {
             scope.mailingFields = fields;
index 815bdf7b9cdd182fa042588eedf03011c3e9c777..79603b1b6e4326891e879932129088e955b6bc40 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')" crm-help="id-from_email">
+    <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 8aaa50a8242e039e7c054c6ea74ff105e50706af..7f27ae342d561c6bff286d80f0a3f13558c062bf 100644 (file)
@@ -1,6 +1,6 @@
 <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>
+  <a crm-ui-help="{title: $parent.$parent.$eval(crmTitle), id: $parent.$parent.$eval(crmHelp), file: $parent.crmUiHelpFile}" ng-if="crmHelp"></a>
 </div>
 <div class="content" ng-transclude></div>
 <div class="clear"></div>