From: Tim Otten Date: Wed, 8 Apr 2015 00:26:40 +0000 (-0700) Subject: CRM-16145 - crmMailingAB - Split directives into separate files X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=02dd48b0c27275b09ba5bb697d2c3926bae1856b;p=civicrm-core.git CRM-16145 - crmMailingAB - Split directives into separate files --- diff --git a/ang/crmMailingAB/BlockMailing.js b/ang/crmMailingAB/BlockMailing.js new file mode 100644 index 0000000000..d738ab6e6f --- /dev/null +++ b/ang/crmMailingAB/BlockMailing.js @@ -0,0 +1,32 @@ +(function(angular, $, _) { + + // example: + // scope.myAbtest = new CrmMailingAB(); + // + 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 index 0000000000..5809cdd0f2 --- /dev/null +++ b/ang/crmMailingAB/BlockSetup.js @@ -0,0 +1,32 @@ +(function(angular, $, _) { + + // example: + // scope.myAbtest = new CrmMailingAB(); + // + 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 index 0000000000..d26e35b17e --- /dev/null +++ b/ang/crmMailingAB/Slider.js @@ -0,0 +1,60 @@ +(function(angular, $, _) { + + // example:
+ 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._); diff --git a/js/angular-crmMailingAB/directives.js b/ang/crmMailingAB/Stats.js similarity index 76% rename from js/angular-crmMailingAB/directives.js rename to ang/crmMailingAB/Stats.js index 4c3f5fb605..3363ea625b 100644 --- a/js/angular-crmMailingAB/directives.js +++ b/ang/crmMailingAB/Stats.js @@ -1,91 +1,5 @@ (function (angular, $, _) { - // example: - // scope.myAbtest = new CrmMailingAB(); - // - 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:
- 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.