}
}
});
+ $routeProvider.when('/abtest/new', {
+ template: '<p>' + ts('Initializing...') + '</p>',
+ controller: 'CrmMailingABNewCtrl',
+ resolve: {
+ abtest: function ($route, CrmMailingAB) {
+ var abtest = new CrmMailingAB(null);
+ return abtest.load().then(function(){
+ return abtest.save();
+ });
+ }
+ }
+ });
$routeProvider.when('/abtest/:id', {
templateUrl: '~/crmMailingAB/edit.html',
controller: 'CrmMailingABEditCtrl',
$scope.crmMailingABStatus = crmMailingABStatus;
});
- angular.module('crmMailingAB').controller('CrmMailingABEditCtrl', function ($scope, abtest, crmMailingABCriteria, crmMailingMgr, crmMailingPreviewMgr, crmStatus, $q, $location) {
+ angular.module('crmMailingAB').controller('CrmMailingABNewCtrl', function ($scope, abtest, $location) {
+ // Transition URL "/abtest/new/foo" => "/abtest/123/foo"
+ var parts = $location.path().split('/'); // e.g. "/mailing/new" or "/mailing/123/wizard"
+ parts[2] = abtest.id;
+ $location.path(parts.join('/'));
+ $location.replace();
+ });
+
+ angular.module('crmMailingAB').controller('CrmMailingABEditCtrl', function ($scope, abtest, crmMailingABCriteria, crmMailingMgr, crmMailingPreviewMgr, crmStatus, $q, $location, crmBlocker) {
$scope.abtest = abtest;
var ts = $scope.ts = CRM.ts(null);
+ var block = $scope.block = crmBlocker();
$scope.crmMailingABCriteria = crmMailingABCriteria;
$scope.crmMailingConst = CRM.crmMailing;
// @return Promise
$scope.save = function save() {
$scope.sync();
- return crmStatus({start: ts('Saving...'), success: ts('Saved')}, abtest.save().then(updateUrl));
+ return block(crmStatus({start: ts('Saving...'), success: ts('Saved')}, abtest.save().then(updateUrl)));
};
// @return Promise
// @return Promise
$scope.sendTest = function sendTest(mailingName, recipient) {
$scope.sync();
- return crmStatus({start: ts('Saving...'), success: ''}, abtest.save().then(updateUrl))
+ return block(crmStatus({start: ts('Saving...'), success: ''}, abtest.save().then(updateUrl))
.then(function () {
crmMailingPreviewMgr.sendTest(abtest.mailings[mailingName], recipient);
- });
+ }));
};
// @return Promise
$scope.delete = function () {
- return crmStatus({start: ts('Deleting...'), success: ts('Deleted')}, abtest.delete().then(leave));
+ return block(crmStatus({start: ts('Deleting...'), success: ts('Deleted')}, abtest.delete().then($scope.leave)));
};
// @return Promise
$scope.submit = function submit() {
$scope.sync();
- return crmStatus({start: ts('Saving...'), success: ''}, abtest.save())
- .then(function () {
- return crmStatus({start: ts('Submitting...'), success: ts('Submitted')}, abtest.submitTest());
- // Note: We're going to leave, so we don't care that submit() modifies several server-side records.
- // If we stayed on this page, then we'd care about updating and call: abtest.submitTest().then(...abtest.load()...)
- })
- .then(leave);
+ if (block.check() || $scope.crmMailing.$invalid) {
+ return;
+ }
+ return block(crmStatus({start: ts('Saving...'), success: ''}, abtest.save())
+ .then(function() {
+ return crmStatus({start: ts('Submitting...'), success: ts('Submitted')}, abtest.submitTest());
+ // Note: We're going to leave, so we don't care that submit() modifies several server-side records.
+ // If we stayed on this page, then we'd care about updating and call: abtest.submitTest().then(...abtest.load()...)
+ })
+ .then($scope.leave));
};
- function leave() {
+ $scope.leave = function leave() {
$location.path('abtest');
$location.replace();
- }
+ };
function updateCriteriaName() {
var criteria = crmMailingABCriteria.get($scope.abtest.ab.testing_criteria_id);
{{ts('This mailing has been submitted.')}}
</div>
-<form name="crmMailingAB" novalidate ng-hide="isSubmitted()">
+<form name="crmMailingAB" novalidate ng-hide="isSubmitted()" crm-autosave="save()" crm-autosave-model="abtest.getAutosaveSignature()" crm-autosave-if="true">
<div class="crm-block crm-form-block crmMailing">
<div crm-ui-wizard>
<div crm-ui-wizard-step="10" crm-title="ts('Setup')" ng-form="setupForm">
}"
crm-abtest="abtest"></div>
<center>
- <a class="crmMailing-submit-button" ng-click="submit()" ng-class="{disabled: crmMailing.$invalid}">
+ <a class="crmMailing-submit-button" ng-click="submit()" ng-class="{blocking: block.check(), disabled: crmMailing.$invalid}">
<div>{{ts('Submit Mailing')}}</div>
</a>
</center>
</div>
<span crm-ui-wizard-buttons style="float:right;">
<button
+ ng-disabled="block.check()"
crm-confirm="{title:ts('Delete Draft?'), message:ts('Are you sure you want to delete the draft mailing?')}"
on-yes="delete()">{{ts('Delete Draft')}}
</button>
- <button ng-click="save()">{{ts('Save Draft')}}</button>
+ <button ng-disabled="block.check()" ng-click="save().then(leave) ">{{ts('Save Draft')}}</button>
</span>
</div>
</form>