afformCore - Move default directive logic from *.tpl to *.js
authorTim Otten <totten@civicrm.org>
Wed, 13 Jun 2018 05:21:21 +0000 (22:21 -0700)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:16 +0000 (19:13 -0700)
ext/afform/ang/afformCore.js
ext/afform/templates/afform/FormAsDirective.tpl

index d29921bc1ef845d4b1cfbcb67720c6fa20345c5a..c8de4b61580effca223de16908066e472adc2bfa 100644 (file)
@@ -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._);
index 75eb2a15baad221184dc6cb551f98cf155bae276..f448ad4406aed925a5becc64960426a315ccaa17 100644 (file)
@@ -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