CRM-16145 - crmMailingAB - Split directives into separate files
authorTim Otten <totten@civicrm.org>
Wed, 8 Apr 2015 00:26:40 +0000 (17:26 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 8 Apr 2015 04:22:14 +0000 (21:22 -0700)
ang/crmMailingAB/BlockMailing.js [new file with mode: 0644]
ang/crmMailingAB/BlockSetup.js [new file with mode: 0644]
ang/crmMailingAB/Slider.js [new file with mode: 0644]
ang/crmMailingAB/Stats.js [moved from js/angular-crmMailingAB/directives.js with 76% similarity]

diff --git a/ang/crmMailingAB/BlockMailing.js b/ang/crmMailingAB/BlockMailing.js
new file mode 100644 (file)
index 0000000..d738ab6
--- /dev/null
@@ -0,0 +1,32 @@
+(function(angular, $, _) {
+
+  // example:
+  //   scope.myAbtest = new CrmMailingAB();
+  //   <crm-mailing-ab-block-mailing="{fromAddressA: 1, fromAddressB: 1}" crm-abtest="myAbtest" />
+  var simpleDirectives = {
+    crmMailingAbBlockMailing: '~/crmMailingAB/BlockMailing.html'
+  };
+  _.each(simpleDirectives, function(templateUrl, directiveName) {
+    angular.module('crmMailingAB').directive(directiveName, function($parse, crmMailingABCriteria, crmUiHelp) {
+      var scopeDesc = {crmAbtest: '@'};
+      scopeDesc[directiveName] = '@';
+
+      return {
+        scope: scopeDesc,
+        templateUrl: templateUrl,
+        link: function(scope, elm, attr) {
+          var model = $parse(attr.crmAbtest);
+          scope.abtest = model(scope.$parent);
+          scope.crmMailingConst = CRM.crmMailing;
+          scope.crmMailingABCriteria = crmMailingABCriteria;
+          scope.ts = CRM.ts(null);
+          scope.hs = crmUiHelp({file: 'CRM/Mailing/MailingUI'});
+
+          var fieldsModel = $parse(attr[directiveName]);
+          scope.fields = fieldsModel(scope.$parent);
+        }
+      };
+    });
+  });
+
+})(angular, CRM.$, CRM._);
diff --git a/ang/crmMailingAB/BlockSetup.js b/ang/crmMailingAB/BlockSetup.js
new file mode 100644 (file)
index 0000000..5809cdd
--- /dev/null
@@ -0,0 +1,32 @@
+(function(angular, $, _) {
+
+  // example:
+  //   scope.myAbtest = new CrmMailingAB();
+  //   <crm-mailing-ab-block-setup="{abName: 1, group_percentage: 1}" crm-abtest="myAbtest" />
+  var simpleDirectives = {
+    crmMailingAbBlockSetup: '~/crmMailingAB/BlockSetup.html'
+  };
+  _.each(simpleDirectives, function(templateUrl, directiveName) {
+    angular.module('crmMailingAB').directive(directiveName, function($parse, crmMailingABCriteria, crmUiHelp) {
+      var scopeDesc = {crmAbtest: '@'};
+      scopeDesc[directiveName] = '@';
+
+      return {
+        scope: scopeDesc,
+        templateUrl: templateUrl,
+        link: function(scope, elm, attr) {
+          var model = $parse(attr.crmAbtest);
+          scope.abtest = model(scope.$parent);
+          scope.crmMailingConst = CRM.crmMailing;
+          scope.crmMailingABCriteria = crmMailingABCriteria;
+          scope.ts = CRM.ts(null);
+          scope.hs = crmUiHelp({file: 'CRM/Mailing/MailingUI'});
+
+          var fieldsModel = $parse(attr[directiveName]);
+          scope.fields = fieldsModel(scope.$parent);
+        }
+      };
+    });
+  });
+
+})(angular, CRM.$, CRM._);
diff --git a/ang/crmMailingAB/Slider.js b/ang/crmMailingAB/Slider.js
new file mode 100644 (file)
index 0000000..d26e35b
--- /dev/null
@@ -0,0 +1,60 @@
+(function(angular, $, _) {
+
+  // example: <div crm-mailing-ab-slider ng-model="abtest.ab.group_percentage"></div>
+  angular.module('crmMailingAB').directive('crmMailingAbSlider', function() {
+    return {
+      require: '?ngModel',
+      scope: {},
+      templateUrl: '~/crmMailingAB/Slider.html',
+      link: function(scope, element, attrs, ngModel) {
+        var TEST_MIN = 1, TEST_MAX = 50;
+        var sliders = $('.slider-test,.slider-win', element);
+        var sliderTests = $('.slider-test', element);
+        var sliderWin = $('.slider-win', element);
+
+        scope.ts = CRM.ts(null);
+        scope.testValue = 0;
+        scope.winValue = 100;
+
+        // set the base value (following a GUI event)
+        function setValue(value) {
+          value = Math.min(TEST_MAX, Math.max(TEST_MIN, value));
+          scope.$apply(function() {
+            ngModel.$setViewValue(value);
+            scope.testValue = value;
+            scope.winValue = 100 - (2 * scope.testValue);
+            sliderTests.slider('value', scope.testValue);
+            sliderWin.slider('value', scope.winValue);
+          });
+        }
+
+        sliders.slider({
+          min: 0,
+          max: 100,
+          range: 'min',
+          step: 1
+        });
+        sliderTests.slider({
+          slide: function slideTest(event, ui) {
+            event.preventDefault();
+            setValue(ui.value);
+          }
+        });
+        sliderWin.slider({
+          slide: function slideWinner(event, ui) {
+            event.preventDefault();
+            setValue(Math.round((100 - ui.value) / 2));
+          }
+        });
+
+        ngModel.$render = function() {
+          scope.testValue = ngModel.$viewValue;
+          scope.winValue = 100 - (2 * scope.testValue);
+          sliderTests.slider('value', scope.testValue);
+          sliderWin.slider('value', scope.winValue);
+        };
+      }
+    };
+  });
+
+})(angular, CRM.$, CRM._);
similarity index 76%
rename from js/angular-crmMailingAB/directives.js
rename to ang/crmMailingAB/Stats.js
index 4c3f5fb6050c3fa815b5fde6051c4533cdd6c10b..3363ea625b3b0920e122d9f8d4ec12401b74e50f 100644 (file)
@@ -1,91 +1,5 @@
 (function (angular, $, _) {
 
-  // example:
-  //   scope.myAbtest = new CrmMailingAB();
-  //   <crm-mailing-ab-block-mailing="{fromAddressA: 1, fromAddressB: 1}" crm-abtest="myAbtest" />
-  var simpleDirectives = {
-    crmMailingAbBlockMailing: '~/crmMailingAB/BlockMailing.html',
-    crmMailingAbBlockSetup: '~/crmMailingAB/BlockSetup.html'
-  };
-  _.each(simpleDirectives, function (templateUrl, directiveName) {
-    angular.module('crmMailingAB').directive(directiveName, function ($parse, crmMailingABCriteria, crmUiHelp) {
-      var scopeDesc = {crmAbtest: '@'};
-      scopeDesc[directiveName] = '@';
-
-      return {
-        scope: scopeDesc,
-        templateUrl: templateUrl,
-        link: function (scope, elm, attr) {
-          var model = $parse(attr.crmAbtest);
-          scope.abtest = model(scope.$parent);
-          scope.crmMailingConst = CRM.crmMailing;
-          scope.crmMailingABCriteria = crmMailingABCriteria;
-          scope.ts = CRM.ts(null);
-          scope.hs = crmUiHelp({file: 'CRM/Mailing/MailingUI'});
-
-          var fieldsModel = $parse(attr[directiveName]);
-          scope.fields = fieldsModel(scope.$parent);
-        }
-      };
-    });
-  });
-
-  // example: <div crm-mailing-ab-slider ng-model="abtest.ab.group_percentage"></div>
-  angular.module('crmMailingAB').directive('crmMailingAbSlider', function () {
-    return {
-      require: '?ngModel',
-      scope: {},
-      templateUrl: '~/crmMailingAB/Slider.html',
-      link: function (scope, element, attrs, ngModel) {
-        var TEST_MIN = 1, TEST_MAX = 50;
-        var sliders = $('.slider-test,.slider-win', element);
-        var sliderTests = $('.slider-test', element);
-        var sliderWin = $('.slider-win', element);
-
-        scope.ts = CRM.ts(null);
-        scope.testValue = 0;
-        scope.winValue = 100;
-
-        // set the base value (following a GUI event)
-        function setValue(value) {
-          value = Math.min(TEST_MAX, Math.max(TEST_MIN, value));
-          scope.$apply(function () {
-            ngModel.$setViewValue(value);
-            scope.testValue = value;
-            scope.winValue = 100 - (2 * scope.testValue);
-            sliderTests.slider('value', scope.testValue);
-            sliderWin.slider('value', scope.winValue);
-          });
-        }
-
-        sliders.slider({
-          min: 0,
-          max: 100,
-          range: 'min',
-          step: 1
-        });
-        sliderTests.slider({
-          slide: function slideTest(event, ui) {
-            event.preventDefault();
-            setValue(ui.value);
-          }
-        });
-        sliderWin.slider({
-          slide: function slideWinner(event, ui) {
-            event.preventDefault();
-            setValue(Math.round((100 - ui.value) / 2));
-          }
-        });
-
-        ngModel.$render = function () {
-          scope.testValue = ngModel.$viewValue;
-          scope.winValue = 100 - (2 * scope.testValue);
-          sliderTests.slider('value', scope.testValue);
-          sliderWin.slider('value', scope.winValue);
-        };
-      }
-    };
-  });
 
   // FIXME: This code is long and hasn't been fully working for me, but I've moved it into a spot
   // where it at least fits in a bit better.