From 2d06b3b60b0c1b4304c941847008ee6b831ec770 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 1 Dec 2014 11:19:23 -0800 Subject: [PATCH] CRM-15578 - crmMailing2 - Implement "schedule.html" --- js/angular-crmMailing2.js | 52 ++++++++++++++++++++++++++++++ partials/crmMailing2/schedule.html | 14 +++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/js/angular-crmMailing2.js b/js/angular-crmMailing2.js index 48d3c24006..c8453cbd02 100644 --- a/js/angular-crmMailing2.js +++ b/js/angular-crmMailing2.js @@ -410,4 +410,56 @@ } setTimeout(scopeApply(init), 0); }); + + // Controller for schedule-editing widget. + // Scope members: + // - [input] mailing: object + // - scheduled_date: null|string(YYYY-MM-DD hh:mm) + crmMailing2.controller('EditScheduleCtrl', function EditScheduleCtrl($scope, $parse) { + var schedModelExpr = 'mailing.scheduled_date'; + var schedModel = $parse(schedModelExpr); + + $scope.schedule = { + mode: 'now', + datetime: '' + }; + var updateChildren = (function () { + var sched = schedModel($scope); + if (sched) { + $scope.schedule.mode = 'at'; + $scope.schedule.datetime = sched; + } + else { + $scope.schedule.mode = 'now'; + } + }); + var updateParent = (function () { + switch ($scope.schedule.mode) { + case 'now': + schedModel.assign($scope, null); + break; + case 'at': + schedModel.assign($scope, $scope.schedule.datetime); + break; + default: + throw 'Unrecognized schedule mode: ' + $scope.schedule.mode; + } + }); + + $scope.$watch(schedModelExpr, updateChildren); + $scope.$watch('schedule.mode', updateParent); + $scope.$watch('schedule.datetime', function (newValue, oldValue) { + // automatically switch mode based on datetime entry + if (oldValue != newValue) { + if (!newValue || newValue == " ") { + $scope.schedule.mode = 'now'; + } + else { + $scope.schedule.mode = 'at'; + } + } + updateParent(); + }); + }); + })(angular, CRM.$, CRM._); diff --git a/partials/crmMailing2/schedule.html b/partials/crmMailing2/schedule.html index 1f9d4e7b7a..445e8bd473 100644 --- a/partials/crmMailing2/schedule.html +++ b/partials/crmMailing2/schedule.html @@ -1 +1,13 @@ -schedule.html +
+
+
+ + +
+
+ + + +
+
+
-- 2.25.1