Commit 86f7e3ba by Brian Jacobel

Implement Pattern Library alerts in Discussions

TNL-5164
parent 6d8c0759
...@@ -252,33 +252,36 @@ ...@@ -252,33 +252,36 @@
}; };
DiscussionUtil.formErrorHandler = function(errorsField) { DiscussionUtil.formErrorHandler = function(errorsField) {
return function(xhr, textStatus, error) { return function(xhr) {
var makeErrorElem, response, _i, _len, _ref, _results, $errorItem; var makeErrorElem, response, i, $errorItem;
makeErrorElem = function(message) { makeErrorElem = function(message, alertId) {
return edx.HtmlUtils.setHtml( return edx.HtmlUtils.joinHtml(
$('<li>').addClass('post-error'), edx.HtmlUtils.HTML('<li>'),
message edx.HtmlUtils.template(
$('#new-post-alert-template').html()
)({
message: message,
alertId: alertId
}),
edx.HtmlUtils.HTML('</li>')
); );
}; };
errorsField.empty().show(); errorsField.empty().show();
if (xhr.status === 400) { if (xhr.status === 400) {
response = JSON.parse(xhr.responseText); response = JSON.parse(xhr.responseText);
if (response.errors) { if (response.errors) {
_ref = response.errors; for (i = 0; i < response.errors.length; i++) {
_results = []; $errorItem = makeErrorElem(response.errors[i], i);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { edx.HtmlUtils.append(errorsField, $errorItem);
error = _ref[_i];
$errorItem = makeErrorElem(error);
_results.push(errorsField.append($errorItem));
} }
return _results;
} }
} else { } else {
$errorItem = makeErrorElem( $errorItem = makeErrorElem('We had some trouble processing your request. Please try again.', 0);
gettext('We had some trouble processing your request. Please try again.') edx.HtmlUtils.append(errorsField, $errorItem);
);
return errorsField.append($errorItem);
} }
// Set focus on the first error displayed
$('div[role="alert"]', errorsField).first().focus();
}; };
}; };
......
...@@ -195,7 +195,7 @@ ...@@ -195,7 +195,7 @@
expect($.ajax.calls.mostRecent().args[0].data.body).toEqual(this.updatedBody); expect($.ajax.calls.mostRecent().args[0].data.body).toEqual(this.updatedBody);
expect(this.view.model.get('body')).toEqual(originalBody); expect(this.view.model.get('body')).toEqual(originalBody);
expect(this.view.cancelEdit).not.toHaveBeenCalled(); expect(this.view.cancelEdit).not.toHaveBeenCalled();
return expect(this.view.$('.edit-comment-form-errors *').length).toEqual(1); return expect(this.view.$('.edit-comment-form-errors > *').length).toEqual(1);
}); });
}); });
}); });
......
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
templateNames = [ templateNames = [
'thread', 'thread-show', 'thread-edit', 'thread-response', 'thread-response-show', 'thread', 'thread-show', 'thread-edit', 'thread-response', 'thread-response-show',
'thread-response-edit', 'response-comment-show', 'response-comment-edit', 'thread-list-item', 'thread-response-edit', 'response-comment-show', 'response-comment-edit', 'thread-list-item',
'discussion-home', 'search-alert', 'new-post', 'thread-type', 'new-post-menu-entry', 'discussion-home', 'search-alert', 'new-post', 'thread-type', 'new-post-menu-entry', 'new-post-alert',
'new-post-menu-category', 'topic', 'post-user-display', 'inline-discussion', 'pagination', 'new-post-menu-category', 'topic', 'post-user-display', 'inline-discussion', 'pagination',
'profile-thread', 'customwmd-prompt', 'nav-loading' 'profile-thread', 'customwmd-prompt', 'nav-loading'
]; ];
......
<div class="alert alert-error pattern-library-shim" role="alert" aria-labelledby="alert-title-error-<%- alertId %>" tabindex="-1">
<span class="icon alert-icon fa fa-warning" aria-hidden="true"></span>
<div class="alert-message">
<h3 class="sr-only alert-title" id="alert-title-error-<%- alertId %>">
<%- gettext("Error posting your message.") %>
</h3>
<p class="alert-copy">
<%- gettext(message) %>
</p>
</div>
</div>
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
padding: $baseline; padding: $baseline;
max-width: 1180px; max-width: 1180px;
.post-errors {
padding: 0 !important;
list-style: none !important;
}
.post-field { .post-field {
margin-bottom: $baseline; margin-bottom: $baseline;
...@@ -183,23 +188,9 @@ ...@@ -183,23 +188,9 @@
.forum-new-post-form, .forum-new-post-form,
.edit-post-form { .edit-post-form {
.post-errors { .post-errors {
margin-bottom: $baseline;
border-radius: $forum-border-radius;
padding: 0; padding: 0;
background: $error-color; margin: 0 0 $baseline 0;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3) inset, 0 1px 0 rgba(255, 255, 255, .2);
color: $white;
list-style: none; list-style: none;
.post-error {
padding: ($baseline/2) $baseline 12px 45px;
border-bottom: 1px solid $forum-color-error;
background: url('#{$static-path}/images/white-error-icon.png') no-repeat 15px 14px;
&:last-child {
border-bottom: none;
}
}
} }
} }
......
...@@ -19,38 +19,49 @@ ...@@ -19,38 +19,49 @@
// #CONFIG // #CONFIG
// ---------------------------- // ----------------------------
// alert colors // Overrides for other things available in the UXPL but not here
$alert-information-color: #6fa0ba; // This is super gross. Don't do this in other places if you can avoid it.
$alert-warning-color: #fdbc56; $palette-brand-accent: #2991c3;
$alert-error-color: #b20610; $palette-brand-back: #cce3f0;
$alert-success-color: #25b85a; $palette-warning-accent: #ffc01f;
$alert-background-color: #fcfcfc; $palette-warning-back: #fff9eb;
$alert-icon-color: #fcfcfc; $palette-error-accent: #cb0712;
$alert-border-grey: #cdd7db; $palette-error-back: #feeced;
$alert-shadow-grey: #eef1f2; $palette-success-accent: #009b00;
$palette-success-back: #ecfaec;
// alert borders $palette-grey-accent: #a0a0a0;
$alert-border-radius: 0.3125rem; $palette-grey-back: #d9d9d9;
$alert-border: 0.0625rem solid $alert-border-grey; $spacing-vertical-xx-small: ($baseline / 4);
$spacing-vertical-x-small: ($baseline / 2);
$spacing-vertical-small: $baseline;
$spacing-horizontal-small: ($baseline / 2);
$spacing-horizontal-base: $baseline;
$font-size-small: 14px;
$bp-screen-md: 768px !default;
// ---------------------------- // ----------------------------
// #UTILITIES // #UTILITIES
// ---------------------------- // ----------------------------
@mixin alert($alert-color) { @mixin alert($shim-alert-color, $shim-alert-color-glow) {
border-top: rem(2) solid $alert-color; border: 1px solid $shim-alert-color;
box-shadow: inset 0 0 0 4px $shim-alert-color-glow;
.alert-icon { .alert-icon {
color: $alert-icon-color; color: $white;
background-color: $alert-color; background-color: $shim-alert-color;
} }
} }
@mixin alert-message($width) { @mixin alert-message($width) {
box-sizing: border-box;
@media (min-width: $bp-screen-md) {
@include float(left); @include float(left);
width: $width; width: $width;
padding: 1.25rem; padding: $spacing-vertical-small;
padding-top: 0; padding-top: 0;
padding-bottom: 0; padding-bottom: 0;
}
:last-child { :last-child {
// keeps the message compact // keeps the message compact
...@@ -60,23 +71,53 @@ $alert-border: 0.0625rem solid $alert-border-grey; ...@@ -60,23 +71,53 @@ $alert-border: 0.0625rem solid $alert-border-grey;
// everything below here gets added specificity pattern-library-shim // everything below here gets added specificity pattern-library-shim
.pattern-library-shim { .pattern-library-shim {
// ---------------------------- // ----------------------------
// #GENERAL // #GENERAL
// ---------------------------- // ----------------------------
&.alert { &.alert {
background-color: $alert-background-color; background-color: $white;
border: $alert-border; border: 1px solid $palette-grey-accent;
border-radius: $alert-border-radius; padding: $spacing-vertical-small $spacing-horizontal-base;
border-top-left-radius: 0; box-shadow: inset 0 0 0 4px $palette-grey-back;
border-top-right-radius: 0;
padding: 1.25rem;
overflow: auto; overflow: auto;
box-shadow: 0 rem(2) rem(2) 0 $alert-shadow-grey;
&.alert-slim {
padding: $spacing-vertical-x-small;
.alert-message {
padding: $spacing-vertical-small $spacing-horizontal-base;
font-size: $font-size-small;
.copy {
margin-bottom: 0;
} }
}
}
&.alert-tiny {
padding: $spacing-vertical-x-small;
.alert-message {
padding: $spacing-vertical-x-small $spacing-horizontal-small;
font-size: $font-size-small;
&.alert-icon { .copy {
margin-bottom: 0;
.icon {
display: inline-block;
margin-right: $baseline;
}
}
}
}
}
.alert-icon {
// hide icons on small screens
display: none;
@media (min-width: $bp-screen-md) {
@include float(left); @include float(left);
display: block; display: block;
...@@ -84,42 +125,51 @@ $alert-border: 0.0625rem solid $alert-border-grey; ...@@ -84,42 +125,51 @@ $alert-border: 0.0625rem solid $alert-border-grey;
border-radius: 50%; border-radius: 50%;
// create room around the icon for the circle // create room around the icon for the circle
padding: 0.625rem; padding: $spacing-vertical-x-small;
}
} }
&.alert-message-with-action { .alert-message-with-action {
// provide room for the action to be displayed next to the alert message // provide room for the action to be displayed next to the alert message
@include alert-message(70%); @include alert-message(70%);
} }
&.alert-message { .alert-message {
@include alert-message(90%); @include alert-message(90%);
} }
&.alert-title { .alert-title {
@extend %hd-5; @extend %hd-5;
@extend %headings-emphasized; @extend %headings-emphasized;
@media (min-width: $bp-screen-md) {
// shift the section up to make the alert more compact // shift the section up to make the alert more compact
margin-top: -0.625rem; margin-top: - $spacing-vertical-x-small;
}
} }
&.alert-copy { .alert-copy {
@extend %copy-base; @extend %copy-base;
@media (min-width: $bp-screen-md) {
// shift the message down to be in line with the icon // shift the message down to be in line with the icon
margin-top: 0.3125rem; margin-top: $spacing-vertical-xx-small;
}
} }
&.alert-copy-with-title { .alert-copy-with-title {
@extend %copy-base; @extend %copy-base;
} }
&.alert-action { .alert-action {
width: 100%;
@media (min-width: $bp-screen-md) {
@include float(right); @include float(right);
width: inherit; width: inherit;
} }
}
// ---------------------------- // ----------------------------
// #INDIVIDUAL CASES // #INDIVIDUAL CASES
...@@ -127,46 +177,21 @@ $alert-border: 0.0625rem solid $alert-border-grey; ...@@ -127,46 +177,21 @@ $alert-border: 0.0625rem solid $alert-border-grey;
// information-based alert // information-based alert
&.alert-information { &.alert-information {
@include alert($alert-information-color); @include alert($palette-brand-accent, $palette-brand-back);
} }
// warning-based alert // warning-based alert
&.alert-warning { &.alert-warning {
@include alert($alert-warning-color); @include alert($palette-warning-accent, $palette-warning-back);
} }
// error-based alert // error-based alert
&.alert-error { &.alert-error {
@include alert($alert-error-color); @include alert($palette-error-accent, $palette-error-back);
} }
// success-based alert // success-based alert
&.alert-success { &.alert-success {
@include alert($alert-success-color); @include alert($palette-success-accent, $palette-success-back);
}
// added from _icons.scss
&.icon {
display: inline-block;
height: auto;
width: auto;
font-family: FontAwesome;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
&.icon-bullhorn:before {
content: "\f0a1";
}
// handles negative margin on navigation bar
&.subsection-header {
margin-top: -4px;
margin-bottom: 14px;
} }
} }
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
template_names = [ template_names = [
'thread', 'thread-show', 'thread-edit', 'thread-response', 'thread-response-show', 'thread-response-edit', 'thread', 'thread-show', 'thread-edit', 'thread-response', 'thread-response-show', 'thread-response-edit',
'response-comment-show', 'response-comment-edit', 'thread-list-item', 'discussion-home', 'search-alert', 'response-comment-show', 'response-comment-edit', 'thread-list-item', 'discussion-home', 'search-alert',
'new-post', 'thread-type', 'new-post-menu-entry', 'new-post-menu-category', 'topic', 'post-user-display', 'new-post', 'new-post-menu-entry', 'new-post-menu-category', 'new-post-alert', 'topic', 'post-user-display',
'inline-discussion', 'pagination', 'profile-thread', 'customwmd-prompt', 'nav-loading' 'inline-discussion', 'pagination', 'profile-thread', 'customwmd-prompt', 'nav-loading', 'thread-type'
] ]
## same, but without trailing "-template" in script ID - these templates does not contain any free variables ## same, but without trailing "-template" in script ID - these templates does not contain any free variables
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment