Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
ddc986f7
Commit
ddc986f7
authored
Jun 25, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call event.preventDefault() on notification action buttons
But allow you to specify that the event should not be prevented
parent
4c269c10
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
2 deletions
+51
-2
cms/static/coffee/spec/views/feedback_spec.coffee
+39
-0
cms/static/js/views/feedback.js
+12
-2
No files found.
cms/static/coffee/spec/views/feedback_spec.coffee
View file @
ddc986f7
...
...
@@ -17,6 +17,16 @@ beforeEach ->
return
text
.
test
(
trimmedText
)
else
return
trimmedText
.
indexOf
(
text
)
!=
-
1
;
toHaveBeenPrevented
:
->
# remove this when we upgrade jasmine-jquery
eventName
=
@
actual
.
eventName
selector
=
@
actual
.
selector
@
message
=
->
[
"Expected event
#{
eventName
}
to have been prevented on
#{
selector
}
"
,
"Expected event
#{
eventName
}
not to have been prevented on
#{
selector
}
"
]
return
jasmine
.
JQuery
.
events
.
wasPrevented
(
selector
,
eventName
)
describe
"CMS.Views.SystemFeedback"
,
->
beforeEach
->
...
...
@@ -123,6 +133,35 @@ describe "CMS.Views.SystemFeedback click events", ->
it
"should apply class to secondary action"
,
->
expect
(
@
view
.
$
(
".action-secondary"
)).
toHaveClass
(
"cancel-button"
)
it
"should preventDefault on primary action"
,
->
spyOnEvent
(
".action-primary"
,
"click"
)
@
view
.
$
(
".action-primary"
).
click
()
expect
(
"click"
).
toHaveBeenPreventedOn
(
".action-primary"
)
it
"should preventDefault on secondary action"
,
->
spyOnEvent
(
".action-secondary"
,
"click"
)
@
view
.
$
(
".action-secondary"
).
click
()
expect
(
"click"
).
toHaveBeenPreventedOn
(
".action-secondary"
)
describe
"CMS.Views.SystemFeedback not preventing events"
,
->
beforeEach
->
@
clickSpy
=
jasmine
.
createSpy
(
'clickSpy'
)
@
view
=
new
CMS
.
Views
.
Alert
.
Confirmation
(
title
:
"It's all good"
message
:
"No reason for this alert"
actions
:
primary
:
text
:
"Whatever"
click
:
@
clickSpy
preventDefault
:
false
)
@
view
.
show
()
it
"should not preventDefault"
,
->
spyOnEvent
(
".action-primary"
,
"click"
)
@
view
.
$
(
".action-primary"
).
click
()
expect
(
"click"
).
not
.
toHaveBeenPreventedOn
(
".action-primary"
)
expect
(
@
clickSpy
).
toHaveBeenCalled
()
describe
"CMS.Views.SystemFeedback multiple secondary actions"
,
->
beforeEach
->
...
...
cms/static/js/views/feedback.js
View file @
ddc986f7
...
...
@@ -10,8 +10,12 @@ CMS.Views.SystemFeedback = Backbone.View.extend({
minShown
:
0
,
// length of time after this view has been shown before it can be hidden (milliseconds)
maxShown
:
Infinity
// length of time after this view has been shown before it will be automatically hidden (milliseconds)
/* could also have an "actions" hash: here is an example demonstrating
the expected structure
/* Could also have an "actions" hash: here is an example demonstrating
the expected structure. For each action, by default the framework
will call preventDefault on the click event before the function is
run; to make it not do that, just pass `preventDefault: false` in
the action object.
actions: {
primary: {
"text": "Save",
...
...
@@ -106,6 +110,9 @@ CMS.Views.SystemFeedback = Backbone.View.extend({
if
(
!
actions
)
{
return
;
}
var
primary
=
actions
.
primary
;
if
(
!
primary
)
{
return
;
}
if
(
primary
.
preventDefault
!==
false
)
{
event
.
preventDefault
();
}
if
(
primary
.
click
)
{
primary
.
click
.
call
(
event
.
target
,
this
,
event
);
}
...
...
@@ -121,6 +128,9 @@ CMS.Views.SystemFeedback = Backbone.View.extend({
i
=
_
.
indexOf
(
this
.
$
(
".action-secondary"
),
event
.
target
);
}
var
secondary
=
secondaryList
[
i
];
if
(
secondary
.
preventDefault
!==
false
)
{
event
.
preventDefault
();
}
if
(
secondary
.
click
)
{
secondary
.
click
.
call
(
event
.
target
,
this
,
event
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment