Skip to content

Commit

Permalink
Prevent unsaved changes notification
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Nov 16, 2023
1 parent 4401611 commit 0df879d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Changed

- Updated the SendGrid webhook event names.
- Adding or removing test contacts no longer shows an unsaved changes notification ([#437](https://github.com/putyourlightson/craft-campaign/issues/437)).

## 2.9.4 - 2023-11-07

Expand Down
1 change: 1 addition & 0 deletions src/controllers/SendoutsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public function actionPreview(int $sendoutId): Response
'schedule' => $sendout->getSchedule(),
'settings' => Campaign::$plugin->settings,
'contactElementType' => ContactElement::class,
'testContactCriteria' => ['status' => ContactElement::STATUS_ACTIVE],
'testContacts' => $campaignType ? $campaignType->getTestContactsWithDefault() : [],
'actions' => [],
'system' => [
Expand Down
11 changes: 10 additions & 1 deletion src/resources/js/SendTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
* SendTest class
*/
Campaign.SendTest = Garnish.Base.extend({
$elementSelect: null,

init: function() {
this.$elementSelect = $('.test-email .elementselect');
this.preventUnsavedChanges();
this.addListener(this.$elementSelect, 'change', 'preventUnsavedChanges');
this.addListener($('.send-test'), 'click', 'sendTest');
},

preventUnsavedChanges: function() {
this.$elementSelect.find('input').attr('name', '');
},

sendTest: function(event) {
event.preventDefault();

Expand All @@ -19,7 +28,7 @@ Campaign.SendTest = Garnish.Base.extend({
$('.send-test').addClass('disabled');

const contactIds = [];
$('.test-email .elementselect input').each(function() {
this.$elementSelect.find('input').each(function() {
contactIds.push($(this).val());
});

Expand Down
1 change: 1 addition & 0 deletions src/templates/sendouts/_preview.twig
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
name: 'testContacts',
elementType: contactElementType,
selectionLabel: "Add a contact"|t('campaign'),
criteria: testContactCriteria,
elements: testContacts,
}) }}
{% set button %}
Expand Down

0 comments on commit 0df879d

Please sign in to comment.