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
8e47219a
Commit
8e47219a
authored
Jun 11, 2014
by
zubair-arbi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trigger change event for file field while uploading pdf
STUD-1775
parent
f1bc7a16
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletions
+33
-1
cms/static/coffee/spec/views/upload_spec.coffee
+26
-0
cms/static/js/views/uploads.js
+7
-1
No files found.
cms/static/coffee/spec/views/upload_spec.coffee
View file @
8e47219a
...
@@ -64,6 +64,32 @@ define ["js/models/uploads", "js/views/uploads", "js/models/chapter", "js/spec_h
...
@@ -64,6 +64,32 @@ define ["js/models/uploads", "js/views/uploads", "js/models/chapter", "js/spec_h
expect
(
@
view
.
$el
).
toContain
(
"#upload_error"
)
expect
(
@
view
.
$el
).
toContain
(
"#upload_error"
)
expect
(
@
view
.
$
(
".action-upload"
)).
toHaveClass
(
"disabled"
)
expect
(
@
view
.
$
(
".action-upload"
)).
toHaveClass
(
"disabled"
)
it
"should render an error with an invalid file type after a correct file type selected"
,
->
correctFile
=
{
name
:
"fake.pdf"
,
"type"
:
"application/pdf"
}
inCorrectFile
=
{
name
:
"fake.png"
,
"type"
:
"image/png"
}
event
=
{}
@
view
.
render
()
event
.
target
=
{
"files"
:
[
correctFile
]}
@
view
.
selectFile
(
event
)
expect
(
@
view
.
$el
).
toContain
(
"input[type=file]"
)
expect
(
@
view
.
$el
).
not
.
toContain
(
"#upload_error"
)
expect
(
@
view
.
$
(
".action-upload"
)).
not
.
toHaveClass
(
"disabled"
)
realMethod
=
@
model
.
set
spyOn
(
@
model
,
"set"
).
andCallFake
(
data
)
->
if
data
.
selectedFile
!=
undefined
this
.
attributes
.
selectedFile
=
data
.
selectedFile
this
.
changed
=
{}
else
realMethod
.
apply
(
this
,
arguments
)
event
.
target
=
{
"files"
:
[
inCorrectFile
]}
@
view
.
selectFile
(
event
)
expect
(
@
view
.
$el
).
toContain
(
"input[type=file]"
)
expect
(
@
view
.
$el
).
toContain
(
"#upload_error"
)
expect
(
@
view
.
$
(
".action-upload"
)).
toHaveClass
(
"disabled"
)
describe
"Uploads"
,
->
describe
"Uploads"
,
->
beforeEach
->
beforeEach
->
@
clock
=
sinon
.
useFakeTimers
()
@
clock
=
sinon
.
useFakeTimers
()
...
...
cms/static/js/views/uploads.js
View file @
8e47219a
...
@@ -61,9 +61,15 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", "jquery
...
@@ -61,9 +61,15 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", "jquery
},
},
selectFile
:
function
(
e
)
{
selectFile
:
function
(
e
)
{
var
selectedFile
=
e
.
target
.
files
[
0
]
||
null
;
this
.
model
.
set
({
this
.
model
.
set
({
selectedFile
:
e
.
target
.
files
[
0
]
||
null
selectedFile
:
selectedFile
});
});
// This change event triggering necessary for FireFox, because the browser don't
// consider change of File object (file input field) as a change in model.
if
(
selectedFile
&&
$
.
isEmptyObject
(
this
.
model
.
changed
)){
this
.
model
.
trigger
(
'change'
);
}
},
},
upload
:
function
(
e
)
{
upload
:
function
(
e
)
{
...
...
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