From dfc2a8685b2ea16edc077b1b61fa95df2bdd1567 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 17 Mar 2015 17:18:08 -0700 Subject: [PATCH] CRM-15706 - Use scope.help() instead of scope.crmUiHelpFile The old code relied explicitly passing ```help-id``` string and implicitly passing a ```crmUiHelpFile``` string through various layers. This broke down when trying to implicitly pass crmUiHelpFile through isolate-scopes. By contrast, this patch relies on explicitly passing a help object. The help object is complete (i.e. it has both id and file), so it's easier to pass through various layers. --- js/angular-crm-ui.js | 68 +++++++++++++++++++----- js/angular-crmMailing/directives.js | 4 +- js/angular-crmMailingAB/directives.js | 4 +- partials/crmMailing/headerFooter.html | 4 +- partials/crmMailing/mailing.html | 2 +- partials/crmMailing/summary.html | 4 +- partials/crmMailingAB/joint-mailing.html | 6 +-- partials/crmMailingAB/setup.html | 4 +- partials/crmUi/field.html | 2 +- 9 files changed, 71 insertions(+), 27 deletions(-) diff --git a/js/angular-crm-ui.js b/js/angular-crm-ui.js index e59e7427c3..2b6b1abaae 100644 --- a/js/angular-crm-ui.js +++ b/js/angular-crm-ui.js @@ -114,7 +114,7 @@ // example:
{{mydata}}
// example:
// example:
- // example:
{{mydata}}
+ // example:
{{mydata}}
.directive('crmUiField', function() { // Note: When writing new templates, the "label" position is particular. See/patch "var label" below. var templateUrls = { @@ -136,8 +136,13 @@ 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 + }); + } + }); } }; }) @@ -156,26 +161,65 @@ }; }) - // 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: + // scope.help = crmUiHelp({file: 'Path/To/Help/File'}); + // HTML: // Example: Use an explicit *.hlp file - // HTML: + // HTML: .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(); }); } }; diff --git a/js/angular-crmMailing/directives.js b/js/angular-crmMailing/directives.js index 80a022a327..16ddb84ee6 100644 --- a/js/angular-crmMailing/directives.js +++ b/js/angular-crmMailing/directives.js @@ -16,7 +16,7 @@ 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: '@' @@ -28,7 +28,7 @@ }); 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; diff --git a/js/angular-crmMailingAB/directives.js b/js/angular-crmMailingAB/directives.js index 7cf79d7313..d46c3885aa 100644 --- a/js/angular-crmMailingAB/directives.js +++ b/js/angular-crmMailingAB/directives.js @@ -8,7 +8,7 @@ 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] = '@'; @@ -21,7 +21,7 @@ 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); diff --git a/partials/crmMailing/headerFooter.html b/partials/crmMailing/headerFooter.html index 2e611c5a6c..c6df982a64 100644 --- a/partials/crmMailing/headerFooter.html +++ b/partials/crmMailing/headerFooter.html @@ -4,7 +4,7 @@ Required vars: mailing, crmMailingConst -->
-
+
-
+
-
+
-
+
-
+
-
+
-