From: Tim Otten Date: Wed, 13 Jun 2018 05:21:21 +0000 (-0700) Subject: afformCore - Move default directive logic from *.tpl to *.js X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ddae34c0096114d4cd47b330b31837e53e74e001;p=civicrm-core.git afformCore - Move default directive logic from *.tpl to *.js --- diff --git a/ext/afform/ang/afformCore.js b/ext/afform/ang/afformCore.js index d29921bc1e..c8de4b6158 100644 --- a/ext/afform/ang/afformCore.js +++ b/ext/afform/ang/afformCore.js @@ -3,4 +3,22 @@ angular.module('afformCore', [ 'crmUi', 'crmUtil', 'ngRoute' ]); + + // Use `afformCoreDirective(string name)` to generate an AngularJS directive. + angular.module('afformCore').service('afformCoreDirective', function($routeParams){ + return function(camelName, d){ + d.restrict = 'AE'; + d.scope = {}; + d.scope.options = '=' + camelName; + d.link = function($scope, $el, $attr) { + $scope.ts = CRM.ts(camelName); + $scope.routeParams = $routeParams; + console.log('$routeParams', $routeParams); + // $scope.$watch(camelName, function(newValue){ + // $scope.options = newValue; + // }); + }; + return d; + }; + }); })(angular, CRM.$, CRM._); diff --git a/ext/afform/templates/afform/FormAsDirective.tpl b/ext/afform/templates/afform/FormAsDirective.tpl index 75eb2a15ba..f448ad4406 100644 --- a/ext/afform/templates/afform/FormAsDirective.tpl +++ b/ext/afform/templates/afform/FormAsDirective.tpl @@ -7,20 +7,10 @@ {literal} (function(angular, $, _) { angular.module('{/literal}{$afform.camel}{literal}', CRM.angRequires('{/literal}{$afform.camel}{literal}')); - angular.module('{/literal}{$afform.camel}{literal}').directive('{/literal}{$afform.camel}{literal}', function() { - return { - restrict: 'AE', - template: {/literal}{$afform.layout|json}{literal}, - scope: { - {/literal}{$afform.camel}{literal}: '=' - }, - link: function($scope, $el, $attr) { - var ts = $scope.ts = CRM.ts('{/literal}{$afform.camel}{literal}'); - $scope.$watch('{/literal}{$afform.camel}{literal}', function(newValue){ - $scope.myOptions = newValue; - }); - } - }; + angular.module('{/literal}{$afform.camel}{literal}').directive('{/literal}{$afform.camel}{literal}', function(afformCoreDirective) { + return afformCoreDirective({/literal}{$afform.camel|json}{literal}, { + template: {/literal}{$afform.layout|json}{literal} + }); }); })(angular, CRM.$, CRM._); {/literal} \ No newline at end of file