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
8e45668a
Commit
8e45668a
authored
Oct 15, 2013
by
Christina Roberts
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1329 from edx/christina/import-cleanup
Remove dead code and move import code into import.js.
parents
54498e15
75071b6b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
168 additions
and
176 deletions
+168
-176
cms/static/js/base.js
+1
-32
cms/static/js/views/import.js
+167
-144
No files found.
cms/static/js/base.js
View file @
8e45668a
...
@@ -123,13 +123,6 @@ domReady(function() {
...
@@ -123,13 +123,6 @@ domReady(function() {
$
(
'.sync-date'
).
bind
(
'click'
,
syncReleaseDate
);
$
(
'.sync-date'
).
bind
(
'click'
,
syncReleaseDate
);
// import form setup
$
(
'.view-import .file-input'
).
bind
(
'change'
,
showImportSubmit
);
$
(
'.view-import .choose-file-button, .view-import .choose-file-button-inline'
).
bind
(
'click'
,
function
(
e
)
{
e
.
preventDefault
();
$
(
'.view-import .file-input'
).
click
();
});
$
(
'.new-course-button'
).
bind
(
'click'
,
addNewCourse
);
$
(
'.new-course-button'
).
bind
(
'click'
,
addNewCourse
);
// section date setting
// section date setting
...
@@ -218,20 +211,6 @@ function editSectionPublishDate(e) {
...
@@ -218,20 +211,6 @@ function editSectionPublishDate(e) {
$modalCover
.
show
();
$modalCover
.
show
();
}
}
function
showImportSubmit
(
e
)
{
var
filepath
=
$
(
this
).
val
();
if
(
filepath
.
substr
(
filepath
.
length
-
6
,
6
)
==
'tar.gz'
)
{
$
(
'.error-block'
).
hide
();
$
(
'.file-name'
).
html
(
$
(
this
).
val
().
replace
(
'C:
\\
fakepath
\
\'
, ''));
$('
.
file
-
name
-
block
').show();
$('
.
view
-
import
.
choose
-
file
-
button
').hide();
$('
.
submit
-
button
').show();
$('
.
progress
').show();
} else {
$('
.
error
-
block
').html(gettext('
File
format
not
supported
.
Please
upload
a
file
with
a
<
code
>
tar
.
gz
<
/code> extension.'
))
.show
()
;
}
}
function
syncReleaseDate
(
e
)
{
function
syncReleaseDate
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
this
).
closest
(
'.notice'
).
hide
();
$
(
this
).
closest
(
'.notice'
).
hide
();
...
@@ -428,16 +407,6 @@ function setVisibility(e) {
...
@@ -428,16 +407,6 @@ function setVisibility(e) {
$
(
e
.
target
).
closest
(
'.option'
).
addClass
(
'checked'
);
$
(
e
.
target
).
closest
(
'.option'
).
addClass
(
'checked'
);
}
}
function
editComponent
(
e
)
{
e
.
preventDefault
();
$
(
this
).
closest
(
'.xmodule_edit'
).
addClass
(
'editing'
).
find
(
'.component-editor'
).
slideDown
(
150
);
}
function
closeComponentEditor
(
e
)
{
e
.
preventDefault
();
$
(
this
).
closest
(
'.xmodule_edit'
).
removeClass
(
'editing'
).
find
(
'.component-editor'
).
slideUp
(
150
);
}
function
showDateSetter
(
e
)
{
function
showDateSetter
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
var
$block
=
$
(
this
).
closest
(
'.due-date-input'
);
var
$block
=
$
(
this
).
closest
(
'.due-date-input'
);
...
@@ -466,7 +435,7 @@ function hideAlert(e) {
...
@@ -466,7 +435,7 @@ function hideAlert(e) {
$
(
this
).
closest
(
'.wrapper-alert'
).
removeClass
(
'is-shown'
);
$
(
this
).
closest
(
'.wrapper-alert'
).
removeClass
(
'is-shown'
);
}
}
function
addNewSection
(
e
,
isTemplate
)
{
function
addNewSection
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
e
.
target
).
addClass
(
'disabled'
);
$
(
e
.
target
).
addClass
(
'disabled'
);
...
...
cms/static/js/views/import.js
View file @
8e45668a
...
@@ -2,149 +2,172 @@
...
@@ -2,149 +2,172 @@
* Course import-related js.
* Course import-related js.
*/
*/
define
(
define
(
[
"jquery"
,
"underscore"
,
"gettext"
],
[
"domReady"
,
"jquery"
,
"underscore"
,
"gettext"
],
function
(
$
,
_
,
gettext
)
{
function
(
domReady
,
$
,
_
,
gettext
)
{
"use strict"
;
"use strict"
;
/********** Private functions ************************************************/
/********** Private functions ************************************************/
/**
/**
* Toggle the spin on the progress cog.
* Toggle the spin on the progress cog.
* @param {boolean} isSpinning Turns cog spin on if true, off otherwise.
* @param {boolean} isSpinning Turns cog spin on if true, off otherwise.
*/
*/
var
updateCog
=
function
(
elem
,
isSpinning
)
{
var
updateCog
=
function
(
elem
,
isSpinning
)
{
var
cogI
=
elem
.
find
(
'i.icon-cog'
);
var
cogI
=
elem
.
find
(
'i.icon-cog'
);
if
(
isSpinning
)
{
cogI
.
addClass
(
"icon-spin"
);}
if
(
isSpinning
)
{
cogI
.
addClass
(
"icon-spin"
);}
else
{
cogI
.
removeClass
(
"icon-spin"
);}
else
{
cogI
.
removeClass
(
"icon-spin"
);}
};
};
/**
/**
* Manipulate the DOM to reflect current status of upload.
* Manipulate the DOM to reflect current status of upload.
* @param {int} stageNo Current stage.
* @param {int} stageNo Current stage.
*/
*/
var
updateStage
=
function
(
stageNo
){
var
updateStage
=
function
(
stageNo
){
var
all
=
$
(
'ol.status-progress'
).
children
();
var
all
=
$
(
'ol.status-progress'
).
children
();
var
prevList
=
all
.
slice
(
0
,
stageNo
);
var
prevList
=
all
.
slice
(
0
,
stageNo
);
_
.
map
(
prevList
,
function
(
elem
){
_
.
map
(
prevList
,
function
(
elem
){
$
(
elem
).
$
(
elem
).
removeClass
(
"is-not-started"
).
removeClass
(
"is-not-started"
).
removeClass
(
"is-started"
).
removeClass
(
"is-started"
).
addClass
(
"is-complete"
);
addClass
(
"is-complete"
);
updateCog
(
$
(
elem
),
false
);
updateCog
(
$
(
elem
),
false
);
});
});
var
curList
=
all
.
eq
(
stageNo
);
var
curList
=
all
.
eq
(
stageNo
);
curList
.
removeClass
(
"is-not-started"
).
addClass
(
"is-started"
);
curList
.
removeClass
(
"is-not-started"
).
addClass
(
"is-started"
);
updateCog
(
curList
,
true
);
updateCog
(
curList
,
true
);
};
};
/**
/**
* Check for import status updates every `timemout` milliseconds, and update
* Check for import status updates every `timeout` milliseconds, and update
* the page accordingly.
* the page accordingly.
* @param {string} url Url to call for status updates.
* @param {string} url Url to call for status updates.
* @param {int} timeout Number of milliseconds to wait in between ajax calls
* @param {int} timeout Number of milliseconds to wait in between ajax calls
* for new updates.
* for new updates.
* @param {int} stage Starting stage.
* @param {int} stage Starting stage.
*/
*/
var
getStatus
=
function
(
url
,
timeout
,
stage
)
{
var
getStatus
=
function
(
url
,
timeout
,
stage
)
{
var
currentStage
=
stage
||
0
;
var
currentStage
=
stage
||
0
;
if
(
CourseImport
.
stopGetStatus
)
{
return
;}
if
(
CourseImport
.
stopGetStatus
)
{
return
;}
updateStage
(
currentStage
);
updateStage
(
currentStage
);
if
(
currentStage
==
3
)
{
return
;}
if
(
currentStage
==
3
)
{
return
;}
var
time
=
timeout
||
1000
;
var
time
=
timeout
||
1000
;
$
.
getJSON
(
url
,
$
.
getJSON
(
url
,
function
(
data
)
{
function
(
data
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
getStatus
(
url
,
time
,
data
.
ImportStatus
);
getStatus
(
url
,
time
,
data
.
ImportStatus
);
},
time
);
},
time
);
}
}
);
);
};
};
/********** Public functions *************************************************/
/********** Public functions *************************************************/
var
CourseImport
=
{
var
CourseImport
=
{
/**
/**
* Whether to stop sending AJAX requests for updates on the import
* Whether to stop sending AJAX requests for updates on the import
* progress.
* progress.
*/
*/
stopGetStatus
:
false
,
stopGetStatus
:
false
,
/**
/**
* Update DOM to set all stages as not-started (for retrying an upload that
* Update DOM to set all stages as not-started (for retrying an upload that
* failed).
* failed).
*/
*/
clearImportDisplay
:
function
()
{
clearImportDisplay
:
function
()
{
var
all
=
$
(
'ol.status-progress'
).
children
();
var
all
=
$
(
'ol.status-progress'
).
children
();
_
.
map
(
all
,
function
(
elem
){
_
.
map
(
all
,
function
(
elem
){
$
(
elem
).
removeClass
(
"is-complete"
).
$
(
elem
).
removeClass
(
"is-complete"
).
removeClass
(
"is-started"
).
removeClass
(
"is-started"
).
removeClass
(
"has-error"
).
removeClass
(
"has-error"
).
addClass
(
"is-not-started"
);
addClass
(
"is-not-started"
);
$
(
elem
).
find
(
'p.error'
).
remove
();
// remove error messages
$
(
elem
).
find
(
'p.error'
).
remove
();
// remove error messages
$
(
elem
).
find
(
'p.copy'
).
show
();
$
(
elem
).
find
(
'p.copy'
).
show
();
updateCog
(
$
(
elem
),
false
);
updateCog
(
$
(
elem
),
false
);
});
this
.
stopGetStatus
=
false
;
},
/**
* Update DOM to set all stages as complete, and stop asking for status
* updates.
*/
displayFinishedImport
:
function
()
{
this
.
stopGetStatus
=
true
;
var
all
=
$
(
'ol.status-progress'
).
children
();
_
.
map
(
all
,
function
(
elem
){
$
(
elem
).
removeClass
(
"is-not-started"
).
removeClass
(
"is-started"
).
addClass
(
"is-complete"
);
updateCog
(
$
(
elem
),
false
);
});
},
/**
* Entry point for server feedback. Makes status list visible and starts
* sending requests to the server for status updates.
* @param {string} url The url to send Ajax GET requests for updates.
*/
startServerFeedback
:
function
(
url
){
this
.
stopGetStatus
=
false
;
$
(
'div.wrapper-status'
).
removeClass
(
'is-hidden'
);
$
(
'.status-info'
).
show
();
getStatus
(
url
,
500
,
0
);
},
/**
* Give error message at the list element that corresponds to the stage
* where the error occurred.
* @param {int} stageNo Stage of import process at which error occured.
* @param {string} msg Error message to display.
*/
stageError
:
function
(
stageNo
,
msg
)
{
var
all
=
$
(
'ol.status-progress'
).
children
();
// Make all stages up to, and including, the error stage 'complete'.
var
prevList
=
all
.
slice
(
0
,
stageNo
+
1
);
_
.
map
(
prevList
,
function
(
elem
){
$
(
elem
).
removeClass
(
"is-not-started"
).
removeClass
(
"is-started"
).
addClass
(
"is-complete"
);
updateCog
(
$
(
elem
),
false
);
});
var
message
=
msg
||
gettext
(
"There was an error with the upload"
);
var
elem
=
$
(
'ol.status-progress'
).
children
().
eq
(
stageNo
);
elem
.
removeClass
(
'is-started'
).
addClass
(
'has-error'
);
elem
.
find
(
'p.copy'
).
hide
().
after
(
"<p class='copy error'>"
+
message
+
"</p>"
);
}
};
var
showImportSubmit
=
function
(
e
)
{
var
filepath
=
$
(
this
).
val
();
if
(
filepath
.
substr
(
filepath
.
length
-
6
,
6
)
==
'tar.gz'
)
{
$
(
'.error-block'
).
hide
();
$
(
'.file-name'
).
html
(
$
(
this
).
val
().
replace
(
'C:
\\
fakepath
\
\'
, ''));
$('
.
file
-
name
-
block
').show();
$('
.
view
-
import
.
choose
-
file
-
button
').hide();
$('
.
submit
-
button
').show();
$('
.
progress
').show();
} else {
$('
.
error
-
block
').html(gettext('
File
format
not
supported
.
Please
upload
a
file
with
a
<
code
>
tar
.
gz
<
/code> extension.'
))
.show
()
;
}
};
domReady
(
function
()
{
// import form setup
$
(
'.view-import .file-input'
).
bind
(
'change'
,
showImportSubmit
);
$
(
'.view-import .choose-file-button, .view-import .choose-file-button-inline'
).
bind
(
'click'
,
function
(
e
)
{
e
.
preventDefault
();
$
(
'.view-import .file-input'
).
click
();
});
});
});
this
.
stopGetStatus
=
false
;
},
/**
* Update DOM to set all stages as complete, and stop asking for status
* updates.
*/
displayFinishedImport
:
function
()
{
this
.
stopGetStatus
=
true
;
var
all
=
$
(
'ol.status-progress'
).
children
();
_
.
map
(
all
,
function
(
elem
){
$
(
elem
).
removeClass
(
"is-not-started"
).
removeClass
(
"is-started"
).
addClass
(
"is-complete"
);
updateCog
(
$
(
elem
),
false
);
});
},
/**
* Entry point for server feedback. Makes status list visible and starts
* sending requests to the server for status updates.
* @param {string} url The url to send Ajax GET requests for updates.
*/
startServerFeedback
:
function
(
url
){
this
.
stopGetStatus
=
false
;
$
(
'div.wrapper-status'
).
removeClass
(
'is-hidden'
);
$
(
'.status-info'
).
show
();
getStatus
(
url
,
500
,
0
);
},
/**
* Give error message at the list element that corresponds to the stage
* where the error occurred.
* @param {int} stageNo Stage of import process at which error occured.
* @param {string} msg Error message to display.
*/
stageError
:
function
(
stageNo
,
msg
)
{
var
all
=
$
(
'ol.status-progress'
).
children
();
// Make all stages up to, and including, the error stage 'complete'.
var
prevList
=
all
.
slice
(
0
,
stageNo
+
1
);
_
.
map
(
prevList
,
function
(
elem
){
$
(
elem
).
removeClass
(
"is-not-started"
).
removeClass
(
"is-started"
).
addClass
(
"is-complete"
);
updateCog
(
$
(
elem
),
false
);
});
var
message
=
msg
||
gettext
(
"There was an error with the upload"
);
var
elem
=
$
(
'ol.status-progress'
).
children
().
eq
(
stageNo
);
elem
.
removeClass
(
'is-started'
).
addClass
(
'has-error'
);
elem
.
find
(
'p.copy'
).
hide
().
after
(
"<p class='copy error'>"
+
message
+
"</p>"
);
}
};
return
CourseImport
;
});
return
CourseImport
;
});
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