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
f9aecb27
Commit
f9aecb27
authored
Aug 20, 2013
by
Peter Fogg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for PNGs as course images.
Also change the file uploader to accept multiple file types.
parent
c626c773
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
13 deletions
+43
-13
cms/static/coffee/spec/models/upload_spec.coffee
+1
-1
cms/static/js/models/uploads.js
+41
-10
cms/static/js/views/settings/main_settings_view.js
+1
-2
No files found.
cms/static/coffee/spec/models/upload_spec.coffee
View file @
f9aecb27
...
...
@@ -28,6 +28,6 @@ describe "CMS.Models.FileUpload", ->
it
"can accept non-PDF files when explicitly set"
,
->
file
=
{
"type"
:
"image/png"
}
@
model
.
set
(
"mimeType
"
:
"image/png"
)
@
model
.
set
(
"mimeType
s"
:
[
"image/png"
]
)
@
model
.
set
(
"selectedFile"
,
file
)
expect
(
@
model
.
isValid
()).
toBeTruthy
()
cms/static/js/models/uploads.js
View file @
f9aecb27
...
...
@@ -7,22 +7,53 @@ CMS.Models.FileUpload = Backbone.Model.extend({
"uploadedBytes"
:
0
,
"totalBytes"
:
0
,
"finished"
:
false
,
"mimeType"
:
"application/pdf"
,
"fileType"
:
"PDF"
"mimeTypes"
:
[
"application/pdf"
]
},
// NOTE: validation functions should return non-internationalized error
// messages. The messages will be passed through gettext in the template.
validate
:
function
(
attrs
,
options
)
{
if
(
attrs
.
selectedFile
&&
attrs
.
selectedFile
.
type
!==
this
.
attributes
.
mimeType
)
{
if
(
attrs
.
selectedFile
&&
!
_
.
contains
(
this
.
attributes
.
mimeTypes
,
attrs
.
selectedFile
.
type
)
)
{
return
{
message
:
_
.
template
(
gettext
(
"Only {fileType} files can be uploaded. Please select a file ending in .{fileExtension} to upload."
),
{
fileType
:
this
.
attributes
.
fileType
,
fileExtension
:
this
.
attributes
.
fileType
.
toLowerCase
()
}),
gettext
(
"Only <%= fileTypes %> files can be uploaded. Please select a file ending in <%= fileExtensions %> to upload."
),
this
.
formatValidTypes
()
),
attributes
:
{
selectedFile
:
true
}
};
}
},
// Return a list of this uploader's valid file types
fileTypes
:
function
()
{
return
_
.
map
(
this
.
attributes
.
mimeTypes
,
function
(
type
)
{
return
type
.
split
(
'/'
)[
1
].
toUpperCase
();
}
);
},
// Return strings for the valid file types and extensions this
// uploader accepts, formatted as natural language
formatValidTypes
:
function
()
{
if
(
this
.
attributes
.
mimeTypes
.
length
===
1
)
{
return
{
fileTypes
:
this
.
fileTypes
()[
0
],
fileExtensions
:
this
.
fileTypes
()[
0
].
toLowerCase
()
};
}
var
or
=
gettext
(
'or'
);
var
formatTypes
=
function
(
types
)
{
return
_
.
template
(
'<%= initial %> <%= or %> <%= last %>'
,
{
initial
:
_
.
initial
(
types
).
join
(
', '
),
or
:
or
,
last
:
_
.
last
(
types
)
});
};
return
{
fileTypes
:
formatTypes
(
this
.
fileTypes
()),
fileExtensions
:
formatTypes
(
_
.
map
(
this
.
fileTypes
(),
function
(
type
)
{
return
'.'
+
type
.
toLowerCase
();
})
)
};
}
});
cms/static/js/views/settings/main_settings_view.js
View file @
f9aecb27
...
...
@@ -239,8 +239,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
var
upload
=
new
CMS
.
Models
.
FileUpload
({
title
:
gettext
(
"Upload your course image."
),
message
:
gettext
(
"Files must be in JPG format."
),
mimeType
:
"image/jpeg"
,
fileType
:
"JPG"
mimeTypes
:
[
'image/jpeg'
,
'image/png'
]
});
var
self
=
this
;
var
modal
=
new
CMS
.
Views
.
UploadDialog
({
...
...
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