// example: <div crm-ui-field="{title: ts('My Field')}"> {{mydata}} </div>
// example: <div crm-ui-field="{name: 'subform.myfield', title: ts('My Field')}"> <input crm-ui-id="subform.myfield" name="myfield" /> </div>
// example: <div crm-ui-field="{name: 'subform.myfield', title: ts('My Field')}"> <input crm-ui-id="subform.myfield" name="myfield" required /> </div>
- // example: <div crm-ui-field="{name: 'subform.myfield', title: ts('My Field'), help: 'help_field_name'}"> {{mydata}} </div>
+ // example: <div crm-ui-field="{name: 'subform.myfield', title: ts('My Field'), help: 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 = {
transclude: true,
link: function (scope, element, attrs, crmUiIdCtrl) {
$(element).addClass('crm-section');
- // Inherit helpFile from parent scope if not specified
- scope.crmUiHelpFile = scope.crmUiField.helpFile || scope.$parent.crmUiHelpFile;
+ scope.$watch('crmUiField', function(crmUiField) {
+ if (crmUiField && crmUiField.help) {
+ scope.help = crmUiField.help.clone({}, {
+ title: crmUiField.title
+ });
+ }
+ });
}
};
})
};
})
- // Display a help icon which loads help from a *.hlp file.
+ // for example, see crmUiHelp
+ .service('crmUiHelp', function(){
+ // example: var h = new FieldHelp({id: 'foo'}); h.open();
+ function FieldHelp(options) {
+ this.options = options;
+ }
+ angular.extend(FieldHelp.prototype, {
+ get: function(n) {
+ return this.options[n];
+ },
+ open: function open() {
+ console.log('open', this.options.title, this.options.id, this.options.file);
+ CRM.help(this.options.title, {id: this.options.id, file: this.options.file});
+ },
+ clone: function clone(options, defaults) {
+ options = options || {};
+ defaults = defaults || {};
+ console.log('clone', defaults, this.options, options);
+ return new FieldHelp(angular.extend({}, defaults, this.options, options));
+ }
+ });
+
+ // example: var help = crmUiHelp({file: 'CRM/Foo/Bar'});
+ return function(defaults){
+ // example: help('myfield')
+ // example: help({id: 'myfield', title: 'Foo Bar', file: 'Whiz/Bang'})
+ return function(options) {
+ if (_.isString(options)) {
+ options = {id: options};
+ }
+ return new FieldHelp(angular.extend({}, defaults, options));
+ }
+ }
+ })
+
+ // Display a help icon
// Example: Use a default *.hlp file
- // JS: scope.crmUiHelpFile='CRM/Foo/Bar';
- // HTML: <a crm-ui-help="{title:ts('My Field'), id:'my_field'}">
+ // scope.help = crmUiHelp({file: 'Path/To/Help/File'});
+ // HTML: <a crm-ui-help="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'}">
+ // HTML: <a crm-ui-help="help({title:ts('My Field'), id:'my_field', file:'CRM/Foo/Bar'})">
.directive('crmUiHelp', function() {
return {
restrict: 'EA',
- scope: {
- crmUiHelp: '='
- },
link: function (scope, element, attrs) {
+ var crmUiHelp = null;
+
+ scope.$watch(attrs.crmUiHelp, function(newCrmUiHelp){
+ crmUiHelp = newCrmUiHelp;
+ var title = crmUiHelp && crmUiHelp.get('title') ? ts('%1 Help', {1: crmUiHelp.get('title')}) : ts('Help');
+ element.attr('title', title);
+ });
+
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.crmUiHelp.file || scope.$parent.crmUiHelpFile});
+ crmUiHelp.open();
});
}
};
crmMailingBodyText: '~/crmMailing/body_text.html'
};
_.each(simpleBlocks, function(templateUrl, directiveName){
- angular.module('crmMailing').directive(directiveName, function ($q, crmMetadata) {
+ angular.module('crmMailing').directive(directiveName, function ($q, crmMetadata, crmUiHelp) {
return {
scope: {
crmMailing: '@'
});
scope.crmMailingConst = CRM.crmMailing;
scope.ts = CRM.ts(null);
- scope.crmUiHelpFile = 'CRM/Mailing/MailingUI';
+ scope.help = crmUiHelp({file: 'CRM/Mailing/MailingUI'});
scope[directiveName] = attr[directiveName] ? scope.$parent.$eval(attr[directiveName]) : {};
$q.when(crmMetadata.getFields('Mailing'), function(fields) {
scope.mailingFields = fields;
crmMailingAbBlockSetup: '~/crmMailingAB/setup.html'
};
_.each(simpleDirectives, function (templateUrl, directiveName) {
- angular.module('crmMailingAB').directive(directiveName, function ($parse, crmMailingABCriteria) {
+ angular.module('crmMailingAB').directive(directiveName, function ($parse, crmMailingABCriteria, crmUiHelp) {
var scopeDesc = {crmAbtest: '@'};
scopeDesc[directiveName] = '@';
scope.crmMailingConst = CRM.crmMailing;
scope.crmMailingABCriteria = crmMailingABCriteria;
scope.ts = CRM.ts(null);
- scope.crmUiHelpFile = 'CRM/Mailing/MailingUI';
+ scope.help = crmUiHelp({file: 'CRM/Mailing/MailingUI'});
var fieldsModel = $parse(attr[directiveName]);
scope.fields = fieldsModel(scope.$parent);
-->
<div class="crm-block" ng-form="subform" crm-ui-id-scope>
<div class="crm-group" ng-controller="EmailBodyCtrl">
- <div crm-ui-field="{name: 'subform.header_id', title: ts('Mailing Header'), help: 'header'}">
+ <div crm-ui-field="{name: 'subform.header_id', title: ts('Mailing Header'), help: help('header')}">
<select
crm-ui-id="subform.header_id"
name="header_id"
<option value=""></option>
</select>
</div>
- <div crm-ui-field="{name: 'subform.footer_id', title: ts('Mailing Footer'), help: 'footer'}">
+ <div crm-ui-field="{name: 'subform.footer_id', title: ts('Mailing Footer'), help: help('footer')}">
<select
crm-ui-id="subform.footer_id"
name="footer_id"
<a crm-icon="disk" ng-click="saveTemplate(mailing)" class="crm-hover-button" title="{{ts('Save As')}}"></a>
</div>
</div>
- <div crm-ui-field="{name: 'subform.fromAddress', title: ts('From'), help: 'from_email'}">
+ <div crm-ui-field="{name: 'subform.fromAddress', title: ts('From'), help: help('from_email')}">
<div ng-controller="EmailAddrCtrl" crm-mailing-from-address="fromPlaceholder" crm-mailing="mailing">
<select
crm-ui-id="subform.fromAddress"
-->
<div class="crm-block" ng-form="subform" crm-ui-id-scope>
<div class="crm-group">
- <div crm-ui-field="{name: 'subform.mailingName', title: ts('Mailing Name'), help: 'name'}">
+ <div crm-ui-field="{name: 'subform.mailingName', title: ts('Mailing Name'), help: help('name')}">
<div>
<input
crm-ui-id="subform.mailingName"
name="mailingName" />
</div>
</div>
- <div crm-ui-field="{name: 'subform.campaign', title: ts('Campaign'), help: 'id-campaign_id', helpFile: 'CRM/Campaign/Form/addCampaignToComponent'}" ng-show="crmMailingConst.campNames.length > 0">
+ <div crm-ui-field="{name: 'subform.campaign', title: ts('Campaign'), help: help({id: 'id-campaign_id', file: 'CRM/Campaign/Form/addCampaignToComponent'})}" ng-show="crmMailingConst.campNames.length > 0">
<select
crm-ui-id="subform.campaign"
name="campaign"
</div>
- <div crm-ui-field="{name: 'subform.fromAddress', title: ts('From'), help: 'from_email'}" ng-if="fields.fromAddress">
+ <div crm-ui-field="{name: 'subform.fromAddress', title: ts('From'), help: help('from_email')}" ng-if="fields.fromAddress">
<span ng-controller="EmailAddrCtrl" crm-mailing-from-address="fromPlaceholder" crm-mailing="abtest.mailings.a">
<select
crm-ui-id="subform.fromAddress"
</select>
</span>
</div>
- <div crm-ui-field="{name: 'subform.fromAddressA', title: ts('From (A)'), help: 'from_email'}" ng-if="fields.fromAddressA">
+ <div crm-ui-field="{name: 'subform.fromAddressA', title: ts('From (A)'), help: help('from_email')}" ng-if="fields.fromAddressA">
<span ng-controller="EmailAddrCtrl" crm-mailing-from-address="fromPlaceholder" crm-mailing="abtest.mailings.a">
<select
crm-ui-id="subform.fromAddressA"
</select>
</span>
</div>
- <div crm-ui-field="{name: 'subform.fromAddressB', title: ts('From (B)'), help: 'from_email'}" ng-if="fields.fromAddressB">
+ <div crm-ui-field="{name: 'subform.fromAddressB', title: ts('From (B)'), help: help('from_email')}" ng-if="fields.fromAddressB">
<span ng-controller="EmailAddrCtrl" crm-mailing-from-address="fromPlaceholder" crm-mailing="abtest.mailings.b">
<select
crm-ui-id="subform.fromAddressB"
{{ts('A/B testing allows you to send two test mailings to a random subset of your recipients. After collecting and
comparing metrics, the more successful mailing will be sent to the remaining recipients.')}}
</div>
- <div crm-ui-field="{name: 'setupForm.abName', title: ts('Name'), help: 'name'}" ng-if="fields.abName">
+ <div crm-ui-field="{name: 'setupForm.abName', title: ts('Name'), help: help('name')}" ng-if="fields.abName">
<input
crm-ui-id="setupForm.abName"
name="abName"
placeholder="A/B Test Name"
required/>
</div>
- <div crm-ui-field="{name: 'setupForm.campaign', title: ts('Campaign'), help: 'id-campaign_id', helpFile: 'CRM/Campaign/Form/addCampaignToComponent'}" ng-show="crmMailingConst.campNames.length > 0"
+ <div crm-ui-field="{name: 'setupForm.campaign', title: ts('Campaign'), help: help({id: 'id-campaign_id', file: 'CRM/Campaign/Form/addCampaignToComponent'})}" ng-show="crmMailingConst.campNames.length > 0"
ng-if="fields.campaign">
<select
crm-ui-id="setupForm.campaign"
<div class="label">
<label crm-ui-for="{{crmUiField.name}}" crm-depth="1">{{crmUiField.title}}</label>
- <a crm-ui-help="{title: crmUiField.title, id: crmUiField.help}" ng-if="crmUiField.help"></a>
+ <a crm-ui-help="help" ng-if="crmUiField.help"></a>
</div>
<div class="content" ng-transclude></div>
<div class="clear"></div>