Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-ora2
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-ora2
Commits
ae5a369c
Commit
ae5a369c
authored
Jul 31, 2014
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify JavaScript file upload interface and clean up analytics events
parent
c56853ae
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
24 deletions
+24
-24
openassessment/xblock/static/js/openassessment.min.js
+0
-0
openassessment/xblock/static/js/spec/oa_file_upload.js
+15
-7
openassessment/xblock/static/js/spec/oa_response.js
+1
-3
openassessment/xblock/static/js/src/oa_file_upload.js
+7
-13
openassessment/xblock/static/js/src/oa_response.js
+1
-1
No files found.
openassessment/xblock/static/js/openassessment.min.js
View file @
ae5a369c
This diff is collapsed.
Click to expand it.
openassessment/xblock/static/js/spec/oa_file_upload.js
View file @
ae5a369c
...
...
@@ -2,13 +2,12 @@ describe("OpenAssessment.FileUploader", function() {
var
fileUploader
=
null
;
var
TEST_URL
=
"http://www.example.com/upload"
;
var
TEST_
IMAG
E
=
{
var
TEST_
FIL
E
=
{
data
:
"abcdefghijklmnopqrstuvwxyz"
,
name
:
"test.jpg"
,
size
:
10471
,
type
:
"image/jpeg"
};
var
TEST_CONTENT_TYPE
=
"image/jpeg"
;
beforeEach
(
function
()
{
fileUploader
=
new
OpenAssessment
.
FileUploader
();
...
...
@@ -25,15 +24,24 @@ describe("OpenAssessment.FileUploader", function() {
spyOn
(
Logger
,
'log'
);
// Upload a file
fileUploader
.
upload
(
TEST_URL
,
TEST_IMAGE
,
TEST_CONTENT_TYPE
);
fileUploader
.
upload
(
TEST_URL
,
TEST_FILE
);
// Verify that a PUT request was sent with the right parameters
expect
(
$
.
ajax
).
toHaveBeenCalledWith
({
url
:
TEST_URL
,
type
:
'PUT'
,
data
:
TEST_FILE
,
async
:
false
,
processData
:
false
,
contentType
:
'image/jpeg'
});
// Verify that the event was logged
expect
(
Logger
.
log
).
toHaveBeenCalledWith
(
"openassessment.upload_file"
,
{
contentType
:
TEST_CONTENT_TYPE
,
imageName
:
TEST_IMAGE
.
name
,
imageSize
:
TEST_IMAGE
.
size
,
imageType
:
TEST_IMAGE
.
type
fileName
:
TEST_FILE
.
name
,
fileSize
:
TEST_FILE
.
size
,
fileType
:
TEST_FILE
.
type
}
);
});
...
...
openassessment/xblock/static/js/spec/oa_response.js
View file @
ae5a369c
...
...
@@ -50,12 +50,11 @@ describe("OpenAssessment.ResponseView", function() {
this
.
uploadError
=
false
;
this
.
uploadArgs
=
null
;
this
.
upload
=
function
(
url
,
data
,
contentType
)
{
this
.
upload
=
function
(
url
,
data
)
{
// Store the args we were passed so we can verify them
this
.
uploadArgs
=
{
url
:
url
,
data
:
data
,
contentType
:
contentType
};
// Return a promise indicating success or error
...
...
@@ -421,7 +420,6 @@ describe("OpenAssessment.ResponseView", function() {
view
.
fileUpload
();
expect
(
fileUploader
.
uploadArgs
.
url
).
toEqual
(
FAKE_URL
);
expect
(
fileUploader
.
uploadArgs
.
data
).
toEqual
(
files
[
0
]);
expect
(
fileUploader
.
uploadArgs
.
contentType
).
toEqual
(
'image/jpg'
);
});
it
(
"displays an error if a one-time file upload URL cannot be retrieved"
,
function
()
{
...
...
openassessment/xblock/static/js/src/oa_file_upload.js
View file @
ae5a369c
...
...
@@ -8,38 +8,32 @@ PUT requests on the server.
Args:
url (string): The one-time URL we're uploading to.
imageData (object): The object to upload, which should have properties:
data (string)
name (string)
size (int)
type (string)
contentType (string): The MIME type of the data to upload.
file (File): The HTML5 file reference.
Returns:
JQuery promise
*/
OpenAssessment
.
FileUploader
=
function
()
{
this
.
upload
=
function
(
url
,
imageData
,
contentTyp
e
)
{
this
.
upload
=
function
(
url
,
fil
e
)
{
return
$
.
Deferred
(
function
(
defer
)
{
$
.
ajax
({
url
:
url
,
type
:
'PUT'
,
data
:
imageData
,
data
:
file
,
async
:
false
,
processData
:
false
,
contentType
:
contentT
ype
,
contentType
:
file
.
t
ype
,
}).
done
(
function
(
data
,
textStatus
,
jqXHR
)
{
// Log an analytics event
Logger
.
log
(
"openassessment.upload_file"
,
{
contentType
:
contentType
,
imageName
:
imageData
.
name
,
imageSize
:
imageData
.
size
,
imageType
:
imageData
.
type
fileName
:
file
.
name
,
fileSize
:
file
.
size
,
fileType
:
file
.
type
}
);
...
...
openassessment/xblock/static/js/src/oa_response.js
View file @
ae5a369c
...
...
@@ -466,7 +466,7 @@ OpenAssessment.ResponseView.prototype = {
this
.
server
.
getUploadUrl
(
view
.
imageType
).
done
(
function
(
url
)
{
var
image
=
view
.
files
[
0
];
view
.
fileUploader
.
upload
(
url
,
image
,
view
.
imageType
)
view
.
fileUploader
.
upload
(
url
,
image
)
.
done
(
function
()
{
view
.
imageUrl
();
view
.
baseView
.
toggleActionError
(
'upload'
,
null
);
...
...
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