Skip to content

Commit 1bbb401

Browse files
Merge pull request #1615 from creative-commoners/pulls/1.13/toast-msg-gridfield
FIX ModelAdmin toast elements
2 parents 3ca706b + 53afb90 commit 1bbb401

File tree

8 files changed

+120
-24
lines changed

8 files changed

+120
-24
lines changed

client/dist/js/bundle.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/lang/src/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"Admin.REMOVE_LINK": "Remove link",
2424
"Admin.SELECTONEPAGE": "Please select at least one page",
2525
"Admin.VALIDATIONERROR": "Validation Error",
26+
"Admin.DELETE_CONFIRM_MESSAGE": "Deleted",
27+
"Admin.ARCHIVE_CONFIRM_MESSAGE": "Archived",
2628
"Admin.VALIDATION_ERRORS_IN_TAB": "This tab contains validation errors.",
2729
"Admin.VALIDATION_ERRORS_IN_TAB_SCREEN_READER": "(Has validation errors)",
2830
"Admin.VALIDATION_ERRORS_ON_PAGE": "There are validation errors on this page, please fix them before saving or publishing.",

client/src/legacy/GridField.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ $.entwine('ss', function($) {
557557
});
558558

559559
// Covers both tabular delete button, and the button on the detail form
560-
$('.grid-field .grid-field__col-compact .action--delete, .grid-field .grid-field__col-compact .action--archive, .cms-edit-form .btn-toolbar .action--delete, .cms-edit-form .btn-toolbar .action--archive').entwine({
560+
$('.grid-field .grid-field__col-compact .action--delete, .grid-field .grid-field__col-compact .action--archive, .cms-edit-form .btn-toolbar .action--delete, .cms-edit-form .btn-toolbar .action--archive, .grid-field__col-compact .gridfield-button-unlink').entwine({
561561
onclick: function(e){
562562
const confirmMessage = $(this).hasClass('action--archive')
563563
? i18n._t('Admin.ARCHIVECONFIRMMESSAGE', 'Are you sure you want to archive this record?')
@@ -569,6 +569,14 @@ $.entwine('ss', function($) {
569569
} else {
570570
this._super(e);
571571
}
572+
573+
const toastNotificationMessage = $(this).hasClass('action--archive')
574+
? ss.i18n._t('Admin.ARCHIVE_CONFIRM_MESSAGE', 'Archived')
575+
: ss.i18n._t('Admin.DELETE_CONFIRM_MESSAGE', 'Deleted');
576+
577+
if ($(this).hasClass('dropdown-item')) {
578+
jQuery.noticeAdd({text: toastNotificationMessage, type: 'success', stayTime: 5000, inEffect: {left: '0', opacity: 'show'}});
579+
}
572580
}
573581
});
574582

client/src/legacy/LeftAndMain.EditForm.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ $.entwine('ss', function($){
107107

108108
this._super();
109109
},
110+
110111
'from .cms-tabset': {
111112
onafterredrawtabs: function () {
112113

@@ -126,10 +127,7 @@ $.entwine('ss', function($){
126127
'Admin.VALIDATION_ERRORS_ON_PAGE',
127128
'There are validation errors on this page, please fix them before saving or publishing.'
128129
);
129-
const toastNotificationMessage = ss.i18n._t(
130-
'Admin.VALIDATIONERROR',
131-
'Validation Error'
132-
);
130+
133131
const $editFormErrorBanner = $("#Form_EditForm_error");
134132

135133
// Remove any existing invalid tab icons and screen-reader text
@@ -159,13 +157,6 @@ $.entwine('ss', function($){
159157
return;
160158
}
161159

162-
// Show a toast notification for DataObject::getCMSValidator() validation errors
163-
if (!this.getValidationErrorShown() && this.hasClass('validationerror')) {
164-
errorMessage(toastNotificationMessage);
165-
// Ensure that this error message popup won't be added more than once
166-
this.setValidationErrorShown(true);
167-
}
168-
169160
// Find tab-pane's with decedent validation .alert's
170161
const $invalidTabPanes = this.find('.tab-pane .alert-danger, .tab-pane .alert.error').closest('.tab-pane');
171162
if (!$invalidTabPanes.length) {
@@ -213,6 +204,17 @@ $.entwine('ss', function($){
213204
redraw: function() {
214205
if(window.debug) console.log('redraw', this.attr('class'), this.get(0));
215206

207+
if (!this.getValidationErrorShown() && this.hasClass('validationerror')) {
208+
const toastNotificationMessage = ss.i18n._t(
209+
'Admin.VALIDATIONERROR',
210+
'Validation Error'
211+
);
212+
213+
errorMessage(toastNotificationMessage);
214+
// Ensure that this error message popup won't be added more than once
215+
this.setValidationErrorShown(true);
216+
}
217+
216218
// Force initialization of tabsets to avoid layout glitches
217219
this.add(this.find('.cms-tabset')).redrawTabs();
218220
this.find('.cms-content-header').redraw();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Feature: Show toast messages
2+
As an author
3+
I want to see toast message in the CMS when I create, edit, delete, publish, unpublish, archive a record
4+
5+
Background:
6+
Given the "Company" "Company A" with "Category"="Other"
7+
And the "Company" "Company B" with "Category"="Other"
8+
And the "Company" "Company C" with "Category"="Other"
9+
And the "Employee" "Employee A" with "Company"="1"
10+
And the "Employee" "Employee B" with "Company"="1"
11+
And the "Employee" "Employee C" with "Company"="1"
12+
And the "group" "EDITOR" has permissions "Access to 'Pages' section" and "Access to 'Test ModelAdmin' section" and "TEST_DATAOBJECT_EDIT"
13+
And I am logged in as a member of "EDITOR" group
14+
And I go to "/admin/test"
15+
16+
Scenario: I can see toast message when I successfully create or publish a record
17+
When I press the "Add Company" button
18+
And I fill in "Name" with "My Company"
19+
And I press the "Create" button
20+
Then I should see a "Saved Company "My Company" successfully" success toast
21+
And I fill in "Name" with "My New Company"
22+
And I wait for 5 seconds
23+
And I press the "Publish" button
24+
Then I should see a "Published Company "My New Company"" success toast
25+
26+
Scenario: I can see toast message when I successfully unpublish and archive a record
27+
When I click "Company B" in the "#Form_EditForm" element
28+
And I press the "Publish" button
29+
Then I should see a "Published Company "Company B"" success toast
30+
And I wait for 5 seconds
31+
And I click "More options" in the "#ActionMenus" element
32+
And I press the "Unpublish" button, confirming the dialog
33+
Then I should see a "Unpublished Company "Company B"" success toast
34+
And I wait for 5 seconds
35+
And I click "More options" in the "#ActionMenus" element
36+
And I press the "Archive" button, confirming the dialog
37+
And I should not see "Validation Error"
38+
And I should see a "Archived Company "Company B"" success toast
39+
40+
Scenario: I can see toast message when I successfully delete a record
41+
When I click "Company A" in the "#Form_EditForm" element
42+
And I click "Employees" in the ".ui-tabs-nav" element
43+
Then I should see "Employee A" in the "#Form_ItemEditForm_Employees" element
44+
And I click "Employee A" in the "#Form_ItemEditForm_Employees" element
45+
And I press the "Delete" button, confirming the dialog
46+
Then I should see a "Deleted Employee "Employee A"" success toast
47+
Then I should not see "Employee A" in the "#Form_ItemEditForm_Employees" element
48+
49+
Scenario: I can see toast message when I successfully delete a record by clicking the Unlink button in action menu
50+
When I click "Company A" in the "#Form_EditForm" element
51+
And I click "Employees" in the ".ui-tabs-nav" element
52+
Then I should see "Employee A" in the "#Form_ItemEditForm_Employees" element
53+
And I press the "View actions" button
54+
And I press the "Unlink" button, confirming the dialog
55+
And I wait for 1 seconds
56+
Then I should see a "Deleted" success toast
57+
Then I should not see "Employee A" in the "#Form_ItemEditForm_Employees" element
58+
59+
Scenario: I can see toast message when I successfully delete a record by clicking the Archive button in action menu
60+
And I should see "Company A" in the "#Form_EditForm" element
61+
And I press the "View actions" button
62+
And I press the "Archive" button, confirming the dialog
63+
And I wait for 2 seconds
64+
Then I should see a "Archived" success toast
65+
Then I should not see "Company A" in the "#Form_EditForm" element
66+
67+
Scenario: I can see toast message when I have validation errors
68+
When I click "Company C" in the "#Form_EditForm" element
69+
And I fill in "Name" with ""
70+
And I press the "Save" button
71+
Then I should see "Validation Error"
72+
And I fill in "Name" with "New Company C"
73+
And I press the "Save" button
74+
Then I should see a "Saved Company "New Company C" successfully" success toast
75+
76+
Scenario: I can see toast message when I have validation errors when I edit a nested record
77+
When I click "Company A" in the "#Form_EditForm" element
78+
And I click "Employees" in the ".ui-tabs-nav" element
79+
Then I should see "Employee B" in the "#Form_ItemEditForm_Employees" element
80+
And I click "Employee B" in the "#Form_ItemEditForm_Employees" element
81+
And I fill in "Name" with ""
82+
And I press the "Save" button
83+
Then I should see "Validation Error"

tests/behat/features/lostpassword.feature

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Feature: Lost Password
1616
And there should be an email to "[email protected]" titled "Your password reset link"
1717
When I click on the "password reset link" link in the email to "[email protected]"
1818
Then I should see "Please enter a new password"
19-
When I fill in "newpassword" for "New Password"
20-
And I fill in "newpassword" for "Confirm New Password"
19+
When I fill in "NEWsecret!@#*&^" for "New Password"
20+
And I fill in "NEWsecret!@#*&^" for "Confirm New Password"
2121
And I press the "Change Password" button
22-
Then the password for "[email protected]" should be "newpassword"
22+
Then the password for "[email protected]" should be "NEWsecret!@#*&^"

tests/behat/features/manage-users.feature

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ Feature: Manage users
2222
Then I click "Groups" in the ".breadcrumbs-wrapper" element
2323
And I click the "Groups" CMS tab
2424
And I click "ADMIN group2" in the "#Root_Groups" element
25-
And I should see the "Unlink" button in the "Members" gridfield for the "ADMIN" row
26-
Then I click the "Unlink" button in the "Members" gridfield for the "ADMIN" row
27-
And I should not see the "Unlink" button in the "Members" gridfield for the "ADMIN" row
25+
And I press the "View actions" button
26+
And I press the "Unlink" button, confirming the dialog
27+
And I wait for 1 seconds
28+
Then I should see a "Deleted" success toast
2829
Then I click "Groups" in the ".breadcrumbs-wrapper" element
2930
And I click the "Groups" CMS tab
3031
And I click "ADMIN group" in the "#Root_Groups" element

tests/behat/features/profile.feature

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Feature: Manage my own settings
3737
Scenario: I can't reset the password without the original
3838
Given I follow "Change Password"
3939
And I fill in "Current Password" with "idontknow"
40-
And I fill in "New Password" with "newsecret"
41-
And I fill in "Confirm Password" with "newsecret"
40+
And I fill in "New Password" with "NEWsecret!@#*&^"
41+
And I fill in "Confirm Password" with "NEWsecret!@#*&^"
4242
And I press the "Save" button
4343
Then I should see "The current password you have entered is not correct."
4444

@@ -53,11 +53,11 @@ Feature: Manage my own settings
5353
Scenario: I can change my password
5454
Given I follow "Change Password"
5555
And I fill in "Current Password" with "secret"
56-
And I fill in "New Password" with "newsecret"
57-
And I fill in "Confirm Password" with "newsecret"
56+
And I fill in "New Password" with "NEWsecret!@#*&^"
57+
And I fill in "Confirm Password" with "NEWsecret!@#*&^"
5858
And I press the "Save" button
5959
And I am not logged in
60-
When I log in with "[email protected]" and "newsecret"
60+
When I log in with "[email protected]" and "NEWsecret!@#*&^"
6161
And I go to "admin/myprofile"
6262
Then I should see the CMS
6363

0 commit comments

Comments
 (0)