From ddae34c0096114d4cd47b330b31837e53e74e001 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 12 Jun 2018 22:21:21 -0700 Subject: [PATCH] afformCore - Move default directive logic from *.tpl to *.js --- ext/afform/ang/afformCore.js | 18 ++++++++++++++++++ .../templates/afform/FormAsDirective.tpl | 18 ++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) 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 -- 2.25.1