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
5acf9cb3
Commit
5acf9cb3
authored
Feb 15, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformat to 4 spaces.
parent
2486ebc2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
621 additions
and
621 deletions
+621
-621
cms/static/js/base.js
+621
-621
No files found.
cms/static/js/base.js
View file @
5acf9cb3
...
@@ -5,147 +5,149 @@ var $newComponentItem;
...
@@ -5,147 +5,149 @@ var $newComponentItem;
var
$changedInput
;
var
$changedInput
;
var
$spinner
;
var
$spinner
;
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
$body
=
$
(
'body'
);
$body
=
$
(
'body'
);
$modal
=
$
(
'.history-modal'
);
$modal
=
$
(
'.history-modal'
);
$modalCover
=
$
(
'<div class="modal-cover">'
);
$modalCover
=
$
(
'<div class="modal-cover">'
);
// cdodge: this looks funny, but on AWS instances, this base.js get's wrapped in a separate scope as part of Django static
// cdodge: this looks funny, but on AWS instances, this base.js get's wrapped in a separate scope as part of Django static
// pipelining (note, this doesn't happen on local runtimes). So if we set it on window, when we can access it from other
// pipelining (note, this doesn't happen on local runtimes). So if we set it on window, when we can access it from other
// scopes (namely the course-info tab)
// scopes (namely the course-info tab)
window
.
$modalCover
=
$modalCover
;
window
.
$modalCover
=
$modalCover
;
// Control whether template caching in local memory occurs (see template_loader.js). Caching screws up development but may
// Control whether template caching in local memory occurs (see template_loader.js). Caching screws up development but may
// be a good optimization in production (it works fairly well)
// be a good optimization in production (it works fairly well)
window
.
cachetemplates
=
false
;
window
.
cachetemplates
=
false
;
$body
.
append
(
$modalCover
);
$body
.
append
(
$modalCover
);
$newComponentItem
=
$
(
'.new-component-item'
);
$newComponentItem
=
$
(
'.new-component-item'
);
$newComponentTypePicker
=
$
(
'.new-component'
);
$newComponentTypePicker
=
$
(
'.new-component'
);
$newComponentTemplatePickers
=
$
(
'.new-component-templates'
);
$newComponentTemplatePickers
=
$
(
'.new-component-templates'
);
$newComponentButton
=
$
(
'.new-component-button'
);
$newComponentButton
=
$
(
'.new-component-button'
);
$spinner
=
$
(
'<span class="spinner-in-field-icon"></span>'
);
$spinner
=
$
(
'<span class="spinner-in-field-icon"></span>'
);
$body
.
bind
(
'keyup'
,
onKeyUp
);
$body
.
bind
(
'keyup'
,
onKeyUp
);
$
(
'.expand-collapse-icon'
).
bind
(
'click'
,
toggleSubmodules
);
$
(
'.expand-collapse-icon'
).
bind
(
'click'
,
toggleSubmodules
);
$
(
'.visibility-options'
).
bind
(
'change'
,
setVisibility
);
$
(
'.visibility-options'
).
bind
(
'change'
,
setVisibility
);
$modal
.
bind
(
'click'
,
hideModal
);
$modal
.
bind
(
'click'
,
hideModal
);
$modalCover
.
bind
(
'click'
,
hideModal
);
$modalCover
.
bind
(
'click'
,
hideModal
);
$
(
'.uploads .upload-button'
).
bind
(
'click'
,
showUploadModal
);
$
(
'.uploads .upload-button'
).
bind
(
'click'
,
showUploadModal
);
$
(
'.upload-modal .close-button'
).
bind
(
'click'
,
hideModal
);
$
(
'.upload-modal .close-button'
).
bind
(
'click'
,
hideModal
);
$body
.
on
(
'click'
,
'.embeddable-xml-input'
,
function
(){
$
(
this
).
select
();
});
$body
.
on
(
'click'
,
'.embeddable-xml-input'
,
function
()
{
$
(
this
).
select
();
$
(
'.unit .item-actions .delete-button'
).
bind
(
'click'
,
deleteUnit
);
});
$
(
'.new-unit-item'
).
bind
(
'click'
,
createNewUnit
);
$
(
'body'
).
addClass
(
'js'
);
// nav - dropdown related
$body
.
click
(
function
(
e
){
$
(
'.nav-dropdown .nav-item .wrapper-nav-sub'
).
removeClass
(
'is-shown'
);
$
(
'.nav-dropdown .nav-item .title'
).
removeClass
(
'is-selected'
);
});
$
(
'.nav-dropdown .nav-item .title'
).
click
(
function
(
e
){
$subnav
=
$
(
this
).
parent
().
find
(
'.wrapper-nav-sub'
);
$title
=
$
(
this
).
parent
().
find
(
'.title'
);
e
.
preventDefault
();
e
.
stopPropagation
();
if
(
$subnav
.
hasClass
(
'is-shown'
))
{
$
(
'.unit .item-actions .delete-button'
).
bind
(
'click'
,
deleteUnit
);
$subnav
.
removeClass
(
'is-shown'
);
$
(
'.new-unit-item'
).
bind
(
'click'
,
createNewUnit
);
$title
.
removeClass
(
'is-selected'
);
}
else
{
$
(
'body'
).
addClass
(
'js'
);
$
(
'.nav-dropdown .nav-item .title'
).
removeClass
(
'is-selected'
);
$
(
'.nav-dropdown .nav-item .wrapper-nav-sub'
).
removeClass
(
'is-shown'
);
$title
.
addClass
(
'is-selected'
);
$subnav
.
addClass
(
'is-shown'
);
}
});
// general link management - new window/tab
// nav - dropdown related
$
(
'a[rel="external"]'
).
attr
(
'title'
,
'This link will open in a new browser window/tab'
).
click
(
function
(
e
)
{
$body
.
click
(
function
(
e
)
{
window
.
open
(
$
(
this
).
attr
(
'href'
)
);
$
(
'.nav-dropdown .nav-item .wrapper-nav-sub'
).
removeClass
(
'is-shown'
);
e
.
preventDefault
(
);
$
(
'.nav-dropdown .nav-item .title'
).
removeClass
(
'is-selected'
);
});
});
// general link management - lean modal window
$
(
'.nav-dropdown .nav-item .title'
).
click
(
function
(
e
)
{
$
(
'a[rel="modal"]'
).
attr
(
'title'
,
'This link will open in a modal window'
).
leanModal
({
overlay
:
0.50
,
closeButton
:
'.action-modal-close'
});
$
(
'.action-modal-close'
).
click
(
function
(
e
){
(
e
).
preventDefault
();
});
// toggling overview section details
$subnav
=
$
(
this
).
parent
().
find
(
'.wrapper-nav-sub'
);
$
(
function
(){
$title
=
$
(
this
).
parent
().
find
(
'.title'
);
if
(
$
(
'.courseware-section'
).
length
>
0
)
{
e
.
preventDefault
();
$
(
'.toggle-button-sections'
).
addClass
(
'is-shown'
);
e
.
stopPropagation
();
}
});
$
(
'.toggle-button-sections'
).
bind
(
'click'
,
toggleSections
);
// autosave when a field is updated on the subsection page
if
(
$subnav
.
hasClass
(
'is-shown'
))
{
$body
.
on
(
'keyup'
,
'.subsection-display-name-input, .unit-subtitle, .policy-list-value'
,
checkForNewValue
);
$subnav
.
removeClass
(
'is-shown'
);
$
(
'.subsection-display-name-input, .unit-subtitle, .policy-list-name, .policy-list-value'
).
each
(
function
(
i
)
{
$title
.
removeClass
(
'is-selected'
);
this
.
val
=
$
(
this
).
val
();
}
});
$
(
"#start_date, #start_time, #due_date, #due_time"
).
bind
(
'change'
,
autosaveInput
);
else
{
$
(
'.sync-date, .remove-date'
).
bind
(
'click'
,
autosaveInput
);
$
(
'.nav-dropdown .nav-item .title'
).
removeClass
(
'is-selected'
);
$
(
'.nav-dropdown .nav-item .wrapper-nav-sub'
).
removeClass
(
'is-shown'
);
// expand/collapse methods for optional date setters
$title
.
addClass
(
'is-selected'
);
$
(
'.set-date'
).
bind
(
'click'
,
showDateSetter
);
$subnav
.
addClass
(
'is-shown'
);
$
(
'.remove-date'
).
bind
(
'click'
,
removeDateSetter
);
}
// add new/delete section
});
$
(
'.new-courseware-section-button'
).
bind
(
'click'
,
addNewSection
);
$
(
'.delete-section-button'
).
bind
(
'click'
,
deleteSection
);
// general link management - new window/tab
$
(
'a[rel="external"]'
).
attr
(
'title'
,
'This link will open in a new browser window/tab'
).
click
(
function
(
e
)
{
// add new/delete subsection
window
.
open
(
$
(
this
).
attr
(
'href'
));
$
(
'.new-subsection-item'
).
bind
(
'click'
,
addNewSubsection
);
e
.
preventDefault
();
$
(
'.delete-subsection-button'
).
bind
(
'click'
,
deleteSubsection
);
});
// add/remove policy metadata button click handlers
$
(
'.add-policy-data'
).
bind
(
'click'
,
addPolicyMetadata
);
// general link management - lean modal window
$
(
'.remove-policy-data'
).
bind
(
'click'
,
removePolicyMetadata
);
$
(
'a[rel="modal"]'
).
attr
(
'title'
,
'This link will open in a modal window'
).
leanModal
({
overlay
:
0.50
,
closeButton
:
'.action-modal-close'
});
$body
.
on
(
'click'
,
'.policy-list-element .save-button'
,
savePolicyMetadata
);
$
(
'.action-modal-close'
).
click
(
function
(
e
)
{
$body
.
on
(
'click'
,
'.policy-list-element .cancel-button'
,
cancelPolicyMetadata
);
(
e
).
preventDefault
();
});
$
(
'.sync-date'
).
bind
(
'click'
,
syncReleaseDate
);
// toggling overview section details
// import form setup
$
(
function
()
{
$
(
'.import .file-input'
).
bind
(
'change'
,
showImportSubmit
);
if
(
$
(
'.courseware-section'
).
length
>
0
)
{
$
(
'.import .choose-file-button, .import .choose-file-button-inline'
).
bind
(
'click'
,
function
(
e
)
{
$
(
'.toggle-button-sections'
).
addClass
(
'is-shown'
);
e
.
preventDefault
();
}
$
(
'.import .file-input'
).
click
();
});
});
$
(
'.toggle-button-sections'
).
bind
(
'click'
,
toggleSections
);
$
(
'.new-course-button'
).
bind
(
'click'
,
addNewCourse
);
// autosave when a field is updated on the subsection page
$body
.
on
(
'keyup'
,
'.subsection-display-name-input, .unit-subtitle, .policy-list-value'
,
checkForNewValue
);
// section name editing
$
(
'.subsection-display-name-input, .unit-subtitle, .policy-list-name, .policy-list-value'
).
each
(
function
(
i
)
{
$
(
'.section-name'
).
bind
(
'click'
,
editSectionName
);
this
.
val
=
$
(
this
).
val
();
$
(
'.edit-section-name-cancel'
).
bind
(
'click'
,
cancelEditSectionName
);
});
// $('.edit-section-name-save').bind('click', saveEditSectionName);
$
(
"#start_date, #start_time, #due_date, #due_time"
).
bind
(
'change'
,
autosaveInput
);
$
(
'.sync-date, .remove-date'
).
bind
(
'click'
,
autosaveInput
);
// section date setting
$
(
'.set-publish-date'
).
bind
(
'click'
,
setSectionScheduleDate
);
// expand/collapse methods for optional date setters
$
(
'.edit-section-start-cancel'
).
bind
(
'click'
,
cancelSetSectionScheduleDate
);
$
(
'.set-date'
).
bind
(
'click'
,
showDateSetter
);
$
(
'.edit-section-start-save'
).
bind
(
'click'
,
saveSetSectionScheduleDate
);
$
(
'.remove-date'
).
bind
(
'click'
,
removeDateSetter
);
// add new/delete section
$
(
'.upload-modal .choose-file-button'
).
bind
(
'click'
,
showFileSelectionMenu
);
$
(
'.new-courseware-section-button'
).
bind
(
'click'
,
addNewSection
);
$
(
'.delete-section-button'
).
bind
(
'click'
,
deleteSection
);
$body
.
on
(
'click'
,
'.section-published-date .edit-button'
,
editSectionPublishDate
);
$body
.
on
(
'click'
,
'.section-published-date .schedule-button'
,
editSectionPublishDate
);
// add new/delete subsection
$body
.
on
(
'click'
,
'.edit-subsection-publish-settings .save-button'
,
saveSetSectionScheduleDate
);
$
(
'.new-subsection-item'
).
bind
(
'click'
,
addNewSubsection
);
$body
.
on
(
'click'
,
'.edit-subsection-publish-settings .cancel-button'
,
hideModal
);
$
(
'.delete-subsection-button'
).
bind
(
'click'
,
deleteSubsection
);
$body
.
on
(
'change'
,
'.edit-subsection-publish-settings .start-date'
,
function
()
{
// add/remove policy metadata button click handlers
if
(
$
(
'.edit-subsection-publish-settings'
).
find
(
'.start-time'
).
val
()
==
''
)
{
$
(
'.add-policy-data'
).
bind
(
'click'
,
addPolicyMetadata
);
$
(
'.edit-subsection-publish-settings'
).
find
(
'.start-time'
).
val
(
'12:00am'
);
$
(
'.remove-policy-data'
).
bind
(
'click'
,
removePolicyMetadata
);
}
$body
.
on
(
'click'
,
'.policy-list-element .save-button'
,
savePolicyMetadata
);
});
$body
.
on
(
'click'
,
'.policy-list-element .cancel-button'
,
cancelPolicyMetadata
);
$
(
'.edit-subsection-publish-settings'
).
on
(
'change'
,
'.start-date, .start-time'
,
function
()
{
$
(
'.edit-subsection-publish-settings'
).
find
(
'.save-button'
).
show
();
$
(
'.sync-date'
).
bind
(
'click'
,
syncReleaseDate
);
});
// import form setup
$
(
'.import .file-input'
).
bind
(
'change'
,
showImportSubmit
);
$
(
'.import .choose-file-button, .import .choose-file-button-inline'
).
bind
(
'click'
,
function
(
e
)
{
e
.
preventDefault
();
$
(
'.import .file-input'
).
click
();
});
$
(
'.new-course-button'
).
bind
(
'click'
,
addNewCourse
);
// section name editing
$
(
'.section-name'
).
bind
(
'click'
,
editSectionName
);
$
(
'.edit-section-name-cancel'
).
bind
(
'click'
,
cancelEditSectionName
);
// $('.edit-section-name-save').bind('click', saveEditSectionName);
// section date setting
$
(
'.set-publish-date'
).
bind
(
'click'
,
setSectionScheduleDate
);
$
(
'.edit-section-start-cancel'
).
bind
(
'click'
,
cancelSetSectionScheduleDate
);
$
(
'.edit-section-start-save'
).
bind
(
'click'
,
saveSetSectionScheduleDate
);
$
(
'.upload-modal .choose-file-button'
).
bind
(
'click'
,
showFileSelectionMenu
);
$body
.
on
(
'click'
,
'.section-published-date .edit-button'
,
editSectionPublishDate
);
$body
.
on
(
'click'
,
'.section-published-date .schedule-button'
,
editSectionPublishDate
);
$body
.
on
(
'click'
,
'.edit-subsection-publish-settings .save-button'
,
saveSetSectionScheduleDate
);
$body
.
on
(
'click'
,
'.edit-subsection-publish-settings .cancel-button'
,
hideModal
);
$body
.
on
(
'change'
,
'.edit-subsection-publish-settings .start-date'
,
function
()
{
if
(
$
(
'.edit-subsection-publish-settings'
).
find
(
'.start-time'
).
val
()
==
''
)
{
$
(
'.edit-subsection-publish-settings'
).
find
(
'.start-time'
).
val
(
'12:00am'
);
}
});
$
(
'.edit-subsection-publish-settings'
).
on
(
'change'
,
'.start-date, .start-time'
,
function
()
{
$
(
'.edit-subsection-publish-settings'
).
find
(
'.save-button'
).
show
();
});
});
});
// function collapseAll(e) {
// function collapseAll(e) {
...
@@ -154,672 +156,670 @@ $(document).ready(function() {
...
@@ -154,672 +156,670 @@ $(document).ready(function() {
// }
// }
function
toggleSections
(
e
)
{
function
toggleSections
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$section
=
$
(
'.courseware-section'
);
sectionCount
=
$section
.
length
;
$button
=
$
(
this
);
$labelCollapsed
=
$
(
'<i class="ss-icon ss-symbolicons-block">up</i> <span class="label">Collapse All Sections</span>'
);
$labelExpanded
=
$
(
'<i class="ss-icon ss-symbolicons-block">down</i> <span class="label">Expand All Sections</span>'
);
var
buttonLabel
=
$button
.
hasClass
(
'is-activated'
)
?
$labelCollapsed
:
$labelExpanded
;
$button
.
toggleClass
(
'is-activated'
).
html
(
buttonLabel
);
if
(
$button
.
hasClass
(
'is-activated'
))
{
$section
=
$
(
'.courseware-section'
);
$section
.
addClass
(
'collapsed'
);
sectionCount
=
$section
.
length
;
// first child in order to avoid the icons on the subsection lists which are not in the first child
$button
=
$
(
this
);
$section
.
find
(
'header .expand-collapse-icon'
).
removeClass
(
'collapse'
).
addClass
(
'expand'
);
$labelCollapsed
=
$
(
'<i class="ss-icon ss-symbolicons-block">up</i> <span class="label">Collapse All Sections</span>'
);
}
else
{
$labelExpanded
=
$
(
'<i class="ss-icon ss-symbolicons-block">down</i> <span class="label">Expand All Sections</span>'
);
$section
.
removeClass
(
'collapsed'
);
// first child in order to avoid the icons on the subsection lists which are not in the first child
var
buttonLabel
=
$button
.
hasClass
(
'is-activated'
)
?
$labelCollapsed
:
$labelExpanded
;
$section
.
find
(
'header .expand-collapse-icon'
).
removeClass
(
'expand'
).
addClass
(
'collapse'
);
$button
.
toggleClass
(
'is-activated'
).
html
(
buttonLabel
);
}
if
(
$button
.
hasClass
(
'is-activated'
))
{
$section
.
addClass
(
'collapsed'
);
// first child in order to avoid the icons on the subsection lists which are not in the first child
$section
.
find
(
'header .expand-collapse-icon'
).
removeClass
(
'collapse'
).
addClass
(
'expand'
);
}
else
{
$section
.
removeClass
(
'collapsed'
);
// first child in order to avoid the icons on the subsection lists which are not in the first child
$section
.
find
(
'header .expand-collapse-icon'
).
removeClass
(
'expand'
).
addClass
(
'collapse'
);
}
}
}
function
editSectionPublishDate
(
e
)
{
function
editSectionPublishDate
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$modal
=
$
(
'.edit-subsection-publish-settings'
).
show
();
$modal
=
$
(
'.edit-subsection-publish-settings'
).
show
();
$modal
=
$
(
'.edit-subsection-publish-settings'
).
show
();
$modal
=
$
(
'.edit-subsection-publish-settings'
).
show
();
$modal
.
attr
(
'data-id'
,
$
(
this
).
attr
(
'data-id'
));
$modal
.
attr
(
'data-id'
,
$
(
this
).
attr
(
'data-id'
));
$modal
.
find
(
'.start-date'
).
val
(
$
(
this
).
attr
(
'data-date'
));
$modal
.
find
(
'.start-date'
).
val
(
$
(
this
).
attr
(
'data-date'
));
$modal
.
find
(
'.start-time'
).
val
(
$
(
this
).
attr
(
'data-time'
));
$modal
.
find
(
'.start-time'
).
val
(
$
(
this
).
attr
(
'data-time'
));
if
(
$modal
.
find
(
'.start-date'
).
val
()
==
''
&&
$modal
.
find
(
'.start-time'
).
val
()
==
''
)
{
if
(
$modal
.
find
(
'.start-date'
).
val
()
==
''
&&
$modal
.
find
(
'.start-time'
).
val
()
==
''
)
{
$modal
.
find
(
'.save-button'
).
hide
();
$modal
.
find
(
'.save-button'
).
hide
();
}
}
$modal
.
find
(
'.section-name'
).
html
(
'"'
+
$
(
this
).
closest
(
'.courseware-section'
).
find
(
'.section-name-span'
).
text
()
+
'"'
);
$modal
.
find
(
'.section-name'
).
html
(
'"'
+
$
(
this
).
closest
(
'.courseware-section'
).
find
(
'.section-name-span'
).
text
()
+
'"'
);
$modalCover
.
show
();
$modalCover
.
show
();
}
}
function
showImportSubmit
(
e
)
{
function
showImportSubmit
(
e
)
{
var
filepath
=
$
(
this
).
val
();
var
filepath
=
$
(
this
).
val
();
if
(
filepath
.
substr
(
filepath
.
length
-
6
,
6
)
==
'tar.gz'
)
{
if
(
filepath
.
substr
(
filepath
.
length
-
6
,
6
)
==
'tar.gz'
)
{
$
(
'.error-block'
).
hide
();
$
(
'.error-block'
).
hide
();
$
(
'.file-name'
).
html
(
$
(
this
).
val
().
replace
(
'C:
\\
fakepath
\
\'
, ''));
$
(
'.file-name'
).
html
(
$
(
this
).
val
().
replace
(
'C:
\\
fakepath
\
\'
, ''));
$('
.
file
-
name
-
block
').show();
$('
.
file
-
name
-
block
').show();
$('
.
import
.
choose
-
file
-
button
').hide();
$('
.
import
.
choose
-
file
-
button
').hide();
$('
.
submit
-
button
').show();
$('
.
submit
-
button
').show();
$('
.
progress
').show();
$('
.
progress
').show();
} else {
} else {
$('
.
error
-
block
').html('
File
format
not
supported
.
Please
upload
a
file
with
a
<
code
>
tar
.
gz
<
/code> extension.'
)
.show
()
;
$('
.
error
-
block
').html('
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
();
$
(
"#start_date"
).
val
(
""
);
$
(
"#start_date"
).
val
(
""
);
$
(
"#start_time"
).
val
(
""
);
$
(
"#start_time"
).
val
(
""
);
}
}
function
addPolicyMetadata
(
e
)
{
function
addPolicyMetadata
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
var
template
=
$
(
'#add-new-policy-element-template > li'
);
var
template
=
$
(
'#add-new-policy-element-template > li'
);
var
newNode
=
template
.
clone
();
var
newNode
=
template
.
clone
();
var
_parent_el
=
$
(
this
).
parent
(
'ol:.policy-list'
);
var
_parent_el
=
$
(
this
).
parent
(
'ol:.policy-list'
);
newNode
.
insertBefore
(
'.add-policy-data'
);
newNode
.
insertBefore
(
'.add-policy-data'
);
$
(
'.remove-policy-data'
).
bind
(
'click'
,
removePolicyMetadata
);
$
(
'.remove-policy-data'
).
bind
(
'click'
,
removePolicyMetadata
);
newNode
.
find
(
'.policy-list-name'
).
focus
();
newNode
.
find
(
'.policy-list-name'
).
focus
();
}
}
function
savePolicyMetadata
(
e
)
{
function
savePolicyMetadata
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
var
$policyElement
=
$
(
this
).
parents
(
'.policy-list-element'
);
var
$policyElement
=
$
(
this
).
parents
(
'.policy-list-element'
);
saveSubsection
()
saveSubsection
()
$policyElement
.
removeClass
(
'new-policy-list-element'
);
$policyElement
.
removeClass
(
'new-policy-list-element'
);
$policyElement
.
find
(
'.policy-list-name'
).
attr
(
'disabled'
,
'disabled'
);
$policyElement
.
find
(
'.policy-list-name'
).
attr
(
'disabled'
,
'disabled'
);
$policyElement
.
removeClass
(
'editing'
);
$policyElement
.
removeClass
(
'editing'
);
}
}
function
cancelPolicyMetadata
(
e
)
{
function
cancelPolicyMetadata
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
var
$policyElement
=
$
(
this
).
parents
(
'.policy-list-element'
);
var
$policyElement
=
$
(
this
).
parents
(
'.policy-list-element'
);
if
(
!
$policyElement
.
hasClass
(
'editing'
))
{
if
(
!
$policyElement
.
hasClass
(
'editing'
))
{
$policyElement
.
remove
();
$policyElement
.
remove
();
}
else
{
}
else
{
$policyElement
.
removeClass
(
'new-policy-list-element'
);
$policyElement
.
removeClass
(
'new-policy-list-element'
);
$policyElement
.
find
(
'.policy-list-name'
).
val
(
$policyElement
.
data
(
'currentValues'
)[
0
]);
$policyElement
.
find
(
'.policy-list-name'
).
val
(
$policyElement
.
data
(
'currentValues'
)[
0
]);
$policyElement
.
find
(
'.policy-list-value'
).
val
(
$policyElement
.
data
(
'currentValues'
)[
1
]);
$policyElement
.
find
(
'.policy-list-value'
).
val
(
$policyElement
.
data
(
'currentValues'
)[
1
]);
}
}
$policyElement
.
removeClass
(
'editing'
);
$policyElement
.
removeClass
(
'editing'
);
}
}
function
removePolicyMetadata
(
e
)
{
function
removePolicyMetadata
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
if
(
!
confirm
(
'Are you sure you wish to delete this item. It cannot be reversed!'
))
if
(
!
confirm
(
'Are you sure you wish to delete this item. It cannot be reversed!'
))
return
;
return
;
policy_name
=
$
(
this
).
data
(
'policy-name'
);
policy_name
=
$
(
this
).
data
(
'policy-name'
);
var
_parent_el
=
$
(
this
).
parent
(
'li:.policy-list-element'
);
var
_parent_el
=
$
(
this
).
parent
(
'li:.policy-list-element'
);
if
(
$
(
_parent_el
).
hasClass
(
"new-policy-list-element"
))
{
if
(
$
(
_parent_el
).
hasClass
(
"new-policy-list-element"
))
{
_parent_el
.
remove
();
_parent_el
.
remove
();
}
else
{
}
else
{
_parent_el
.
appendTo
(
"#policy-to-delete"
);
_parent_el
.
appendTo
(
"#policy-to-delete"
);
}
}
saveSubsection
()
saveSubsection
()
}
}
function
getEdxTimeFromDateTimeVals
(
date_val
,
time_val
,
format
)
{
function
getEdxTimeFromDateTimeVals
(
date_val
,
time_val
,
format
)
{
var
edxTimeStr
=
null
;
var
edxTimeStr
=
null
;
if
(
date_val
!=
''
)
{
if
(
date_val
!=
''
)
{
if
(
time_val
==
''
)
if
(
time_val
==
''
)
time_val
=
'00:00'
;
time_val
=
'00:00'
;
// Note, we are using date.js utility which has better parsing abilities than the built in JS date parsing
// Note, we are using date.js utility which has better parsing abilities than the built in JS date parsing
date
=
Date
.
parse
(
date_val
+
" "
+
time_val
);
date
=
Date
.
parse
(
date_val
+
" "
+
time_val
);
if
(
format
==
null
)
if
(
format
==
null
)
format
=
'yyyy-MM-ddTHH:mm'
;
format
=
'yyyy-MM-ddTHH:mm'
;
edxTimeStr
=
date
.
toString
(
format
);
edxTimeStr
=
date
.
toString
(
format
);
}
}
return
edxTimeStr
;
return
edxTimeStr
;
}
}
function
getEdxTimeFromDateTimeInputs
(
date_id
,
time_id
,
format
)
{
function
getEdxTimeFromDateTimeInputs
(
date_id
,
time_id
,
format
)
{
var
input_date
=
$
(
'#'
+
date_id
).
val
();
var
input_date
=
$
(
'#'
+
date_id
).
val
();
var
input_time
=
$
(
'#'
+
time_id
).
val
();
var
input_time
=
$
(
'#'
+
time_id
).
val
();
return
getEdxTimeFromDateTimeVals
(
input_date
,
input_time
,
format
);
return
getEdxTimeFromDateTimeVals
(
input_date
,
input_time
,
format
);
}
}
function
checkForNewValue
(
e
)
{
function
checkForNewValue
(
e
)
{
if
(
$
(
this
).
parents
(
'.new-policy-list-element'
)[
0
])
{
if
(
$
(
this
).
parents
(
'.new-policy-list-element'
)[
0
])
{
return
;
return
;
}
if
(
this
.
val
)
{
this
.
hasChanged
=
this
.
val
!=
$
(
this
).
val
();
}
else
{
this
.
hasChanged
=
false
;
}
this
.
val
=
$
(
this
).
val
();
if
(
this
.
hasChanged
)
{
if
(
this
.
saveTimer
)
{
clearTimeout
(
this
.
saveTimer
);
}
}
this
.
saveTimer
=
setTimeout
(
function
()
{
if
(
this
.
val
)
{
$changedInput
=
$
(
e
.
target
);
this
.
hasChanged
=
this
.
val
!=
$
(
this
).
val
();
saveSubsection
();
}
else
{
this
.
saveTimer
=
null
;
this
.
hasChanged
=
false
;
},
500
);
}
}
this
.
val
=
$
(
this
).
val
();
if
(
this
.
hasChanged
)
{
if
(
this
.
saveTimer
)
{
clearTimeout
(
this
.
saveTimer
);
}
this
.
saveTimer
=
setTimeout
(
function
()
{
$changedInput
=
$
(
e
.
target
);
saveSubsection
();
this
.
saveTimer
=
null
;
},
500
);
}
}
}
function
autosaveInput
(
e
)
{
function
autosaveInput
(
e
)
{
if
(
this
.
saveTimer
)
{
if
(
this
.
saveTimer
)
{
clearTimeout
(
this
.
saveTimer
);
clearTimeout
(
this
.
saveTimer
);
}
}
this
.
saveTimer
=
setTimeout
(
function
()
{
this
.
saveTimer
=
setTimeout
(
function
()
{
$changedInput
=
$
(
e
.
target
);
$changedInput
=
$
(
e
.
target
);
saveSubsection
();
saveSubsection
();
this
.
saveTimer
=
null
;
this
.
saveTimer
=
null
;
},
500
);
},
500
);
}
}
function
saveSubsection
()
{
function
saveSubsection
()
{
if
(
$changedInput
&&
!
$changedInput
.
hasClass
(
'no-spinner'
))
{
if
(
$changedInput
&&
!
$changedInput
.
hasClass
(
'no-spinner'
))
{
$spinner
.
css
({
$spinner
.
css
({
'position'
:
'absolute'
,
'position'
:
'absolute'
,
'top'
:
Math
.
floor
(
$changedInput
.
position
().
top
+
(
$changedInput
.
outerHeight
()
/
2
)
+
3
),
'top'
:
Math
.
floor
(
$changedInput
.
position
().
top
+
(
$changedInput
.
outerHeight
()
/
2
)
+
3
),
'left'
:
$changedInput
.
position
().
left
+
$changedInput
.
outerWidth
()
-
24
,
'left'
:
$changedInput
.
position
().
left
+
$changedInput
.
outerWidth
()
-
24
,
'margin-top'
:
'-10px'
'margin-top'
:
'-10px'
});
});
$changedInput
.
after
(
$spinner
);
$changedInput
.
after
(
$spinner
);
$spinner
.
show
();
$spinner
.
show
();
}
}
var
id
=
$
(
'.subsection-body'
).
data
(
'id'
);
var
id
=
$
(
'.subsection-body'
).
data
(
'id'
);
// pull all 'normalized' metadata editable fields on page
// pull all 'normalized' metadata editable fields on page
var
metadata_fields
=
$
(
'input[data-metadata-name]'
);
var
metadata_fields
=
$
(
'input[data-metadata-name]'
);
var
metadata
=
{};
var
metadata
=
{};
for
(
var
i
=
0
;
i
<
metadata_fields
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
metadata_fields
.
length
;
i
++
)
{
var
el
=
metadata_fields
[
i
];
var
el
=
metadata_fields
[
i
];
metadata
[
$
(
el
).
data
(
"metadata-name"
)]
=
el
.
value
;
metadata
[
$
(
el
).
data
(
"metadata-name"
)]
=
el
.
value
;
}
// now add 'free-formed' metadata which are presented to the user as dual input fields (name/value)
$
(
'ol.policy-list > li.policy-list-element'
).
each
(
function
(
i
,
element
)
{
var
name
=
$
(
element
).
children
(
'.policy-list-name'
).
val
();
metadata
[
name
]
=
$
(
element
).
children
(
'.policy-list-value'
).
val
();
});
// now add any 'removed' policy metadata which is stored in a separate hidden div
// 'null' presented to the server means 'remove'
$
(
"#policy-to-delete > li.policy-list-element"
).
each
(
function
(
i
,
element
)
{
var
name
=
$
(
element
).
children
(
'.policy-list-name'
).
val
();
if
(
name
!=
""
)
metadata
[
name
]
=
null
;
});
// Piece back together the date/time UI elements into one date/time string
// NOTE: our various "date/time" metadata elements don't always utilize the same formatting string
// so make sure we're passing back the correct format
metadata
[
'start'
]
=
getEdxTimeFromDateTimeInputs
(
'start_date'
,
'start_time'
);
metadata
[
'due'
]
=
getEdxTimeFromDateTimeInputs
(
'due_date'
,
'due_time'
,
'MMMM dd HH:mm'
);
$
.
ajax
({
url
:
"/save_item"
,
type
:
"POST"
,
dataType
:
"json"
,
contentType
:
"application/json"
,
data
:
JSON
.
stringify
({
'id'
:
id
,
'metadata'
:
metadata
}),
success
:
function
()
{
$spinner
.
delay
(
500
).
fadeOut
(
150
);
},
error
:
function
()
{
showToastMessage
(
'There has been an error while saving your changes.'
);
}
}
});
// now add 'free-formed' metadata which are presented to the user as dual input fields (name/value)
$
(
'ol.policy-list > li.policy-list-element'
).
each
(
function
(
i
,
element
)
{
var
name
=
$
(
element
).
children
(
'.policy-list-name'
).
val
();
metadata
[
name
]
=
$
(
element
).
children
(
'.policy-list-value'
).
val
();
});
// now add any 'removed' policy metadata which is stored in a separate hidden div
// 'null' presented to the server means 'remove'
$
(
"#policy-to-delete > li.policy-list-element"
).
each
(
function
(
i
,
element
)
{
var
name
=
$
(
element
).
children
(
'.policy-list-name'
).
val
();
if
(
name
!=
""
)
metadata
[
name
]
=
null
;
});
// Piece back together the date/time UI elements into one date/time string
// NOTE: our various "date/time" metadata elements don't always utilize the same formatting string
// so make sure we're passing back the correct format
metadata
[
'start'
]
=
getEdxTimeFromDateTimeInputs
(
'start_date'
,
'start_time'
);
metadata
[
'due'
]
=
getEdxTimeFromDateTimeInputs
(
'due_date'
,
'due_time'
,
'MMMM dd HH:mm'
);
$
.
ajax
({
url
:
"/save_item"
,
type
:
"POST"
,
dataType
:
"json"
,
contentType
:
"application/json"
,
data
:
JSON
.
stringify
({
'id'
:
id
,
'metadata'
:
metadata
}),
success
:
function
()
{
$spinner
.
delay
(
500
).
fadeOut
(
150
);
},
error
:
function
()
{
showToastMessage
(
'There has been an error while saving your changes.'
);
}
});
}
}
function
createNewUnit
(
e
)
{
function
createNewUnit
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
parent
=
$
(
this
).
data
(
'parent'
);
parent
=
$
(
this
).
data
(
'parent'
);
template
=
$
(
this
).
data
(
'template'
);
template
=
$
(
this
).
data
(
'template'
);
$
.
post
(
'/clone_item'
,
$
.
post
(
'/clone_item'
,
{
'parent_location'
:
parent
,
{
'parent_location'
:
parent
,
'template'
:
template
,
'template'
:
template
,
'display_name'
:
'New Unit'
'display_name'
:
'New Unit'
},
},
function
(
data
)
{
function
(
data
)
{
// redirect to the edit page
// redirect to the edit page
window
.
location
=
"/edit/"
+
data
[
'id'
];
window
.
location
=
"/edit/"
+
data
[
'id'
];
});
});
}
}
function
deleteUnit
(
e
)
{
function
deleteUnit
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
_deleteItem
(
$
(
this
).
parents
(
'li.leaf'
));
_deleteItem
(
$
(
this
).
parents
(
'li.leaf'
));
}
}
function
deleteSubsection
(
e
)
{
function
deleteSubsection
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
_deleteItem
(
$
(
this
).
parents
(
'li.branch'
));
_deleteItem
(
$
(
this
).
parents
(
'li.branch'
));
}
}
function
deleteSection
(
e
)
{
function
deleteSection
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
_deleteItem
(
$
(
this
).
parents
(
'section.branch'
));
_deleteItem
(
$
(
this
).
parents
(
'section.branch'
));
}
}
function
_deleteItem
(
$el
)
{
function
_deleteItem
(
$el
)
{
if
(
!
confirm
(
'Are you sure you wish to delete this item. It cannot be reversed!'
))
if
(
!
confirm
(
'Are you sure you wish to delete this item. It cannot be reversed!'
))
return
;
return
;
var
id
=
$el
.
data
(
'id'
);
var
id
=
$el
.
data
(
'id'
);
$
.
post
(
'/delete_item'
,
$
.
post
(
'/delete_item'
,
{
'id'
:
id
,
'delete_children'
:
true
,
'delete_all_versions'
:
true
},
{
'id'
:
id
,
'delete_children'
:
true
,
'delete_all_versions'
:
true
},
function
(
data
)
{
function
(
data
)
{
$el
.
remove
();
$el
.
remove
();
});
});
}
}
function
showUploadModal
(
e
)
{
function
showUploadModal
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$modal
=
$
(
'.upload-modal'
).
show
();
$modal
=
$
(
'.upload-modal'
).
show
();
$
(
'.file-input'
).
bind
(
'change'
,
startUpload
);
$
(
'.file-input'
).
bind
(
'change'
,
startUpload
);
$modalCover
.
show
();
$modalCover
.
show
();
}
}
function
showFileSelectionMenu
(
e
)
{
function
showFileSelectionMenu
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
'.file-input'
).
click
();
$
(
'.file-input'
).
click
();
}
}
function
startUpload
(
e
)
{
function
startUpload
(
e
)
{
$
(
'.upload-modal h1'
).
html
(
'Uploading…'
);
$
(
'.upload-modal h1'
).
html
(
'Uploading…'
);
$
(
'.upload-modal .file-name'
).
html
(
$
(
'.file-input'
).
val
().
replace
(
'C:
\\
fakepath
\
\'
, ''));
$
(
'.upload-modal .file-name'
).
html
(
$
(
'.file-input'
).
val
().
replace
(
'C:
\\
fakepath
\
\'
, ''));
$('
.
upload
-
modal
.
file
-
chooser
').ajaxSubmit({
$('
.
upload
-
modal
.
file
-
chooser
').ajaxSubmit({
beforeSend: resetUploadBar,
beforeSend: resetUploadBar,
uploadProgress: showUploadFeedback,
uploadProgress: showUploadFeedback,
complete: displayFinishedUpload
complete: displayFinishedUpload
});
});
$('
.
upload
-
modal
.
choose
-
file
-
button
').hide();
$('
.
upload
-
modal
.
choose
-
file
-
button
').hide();
$('
.
upload
-
modal
.
progress
-
bar
').removeClass('
loaded
').show();
$('
.
upload
-
modal
.
progress
-
bar
').removeClass('
loaded
').show();
}
}
function resetUploadBar(){
function resetUploadBar()
{
var percentVal = '
0
%
';
var percentVal = '
0
%
';
$('
.
upload
-
modal
.
progress
-
fill
').width(percentVal);
$('
.
upload
-
modal
.
progress
-
fill
').width(percentVal);
$('
.
upload
-
modal
.
progress
-
fill
').html(percentVal);
$('
.
upload
-
modal
.
progress
-
fill
').html(percentVal);
}
}
function showUploadFeedback(event, position, total, percentComplete) {
function showUploadFeedback(event, position, total, percentComplete) {
var percentVal = percentComplete + '
%
';
var percentVal = percentComplete + '
%
';
$('
.
upload
-
modal
.
progress
-
fill
').width(percentVal);
$('
.
upload
-
modal
.
progress
-
fill
').width(percentVal);
$('
.
upload
-
modal
.
progress
-
fill
').html(percentVal);
$('
.
upload
-
modal
.
progress
-
fill
').html(percentVal);
}
}
function displayFinishedUpload(xhr) {
function displayFinishedUpload(xhr) {
if(xhr.status = 200)
{
if (xhr.status = 200)
{
markAsLoaded();
markAsLoaded();
}
}
var resp = JSON.parse(xhr.responseText);
var resp = JSON.parse(xhr.responseText);
$('
.
upload
-
modal
.
embeddable
-
xml
-
input
').val(xhr.getResponseHeader('
asset_url
'));
$('
.
upload
-
modal
.
embeddable
-
xml
-
input
').val(xhr.getResponseHeader('
asset_url
'));
$('
.
upload
-
modal
.
embeddable
').show();
$('
.
upload
-
modal
.
embeddable
').show();
$('
.
upload
-
modal
.
file
-
name
').hide();
$('
.
upload
-
modal
.
file
-
name
').hide();
$('
.
upload
-
modal
.
progress
-
fill
').html(resp.msg);
$('
.
upload
-
modal
.
progress
-
fill
').html(resp.msg);
$('
.
upload
-
modal
.
choose
-
file
-
button
').html('
Load
Another
File
').show();
$('
.
upload
-
modal
.
choose
-
file
-
button
').html('
Load
Another
File
').show();
$('
.
upload
-
modal
.
progress
-
fill
').width('
100
%
');
$('
.
upload
-
modal
.
progress
-
fill
').width('
100
%
');
// see if this id already exists, if so, then user must have updated an existing piece of content
// see if this id already exists, if so, then user must have updated an existing piece of content
$("tr[data-id='
" + resp.url + "
']").remove();
$("tr[data-id='
" + resp.url + "
']").remove();
var template = $('
#
new
-
asset
-
element
').html();
var template = $('
#
new
-
asset
-
element
').html();
var html = Mustache.to_html(template, resp);
var html = Mustache.to_html(template, resp);
$('
table
>
tbody
').prepend(html);
$('
table
>
tbody
').prepend(html);
}
}
function markAsLoaded() {
function markAsLoaded() {
$('
.
upload
-
modal
.
copy
-
button
').css('
display
', '
inline
-
block
');
$('
.
upload
-
modal
.
copy
-
button
').css('
display
', '
inline
-
block
');
$('
.
upload
-
modal
.
progress
-
bar
').addClass('
loaded
');
$('
.
upload
-
modal
.
progress
-
bar
').addClass('
loaded
');
}
}
function hideModal(e) {
function hideModal(e) {
if
(e) {
if
(e) {
e.preventDefault();
e.preventDefault();
}
}
// Unit editors do not want the modal cover to hide when users click outside
// Unit editors do not want the modal cover to hide when users click outside
// of the editor. Users must press Cancel or Save to exit the editor.
// of the editor. Users must press Cancel or Save to exit the editor.
// module_edit adds and removes the "is-fixed" class.
// module_edit adds and removes the "is-fixed" class.
if (!$modalCover.hasClass("is-fixed")) {
if (!$modalCover.hasClass("is-fixed")) {
$('
.
file
-
input
').unbind('
change
', startUpload);
$('
.
file
-
input
').unbind('
change
', startUpload);
$modal.hide();
$modal.hide();
$modalCover.hide();
$modalCover.hide();
}
}
}
}
function onKeyUp(e) {
function onKeyUp(e) {
if
(e.which == 87) {
if
(e.which == 87) {
$body.toggleClass('
show
-
wip
hide
-
wip
');
$body.toggleClass('
show
-
wip
hide
-
wip
');
}
}
}
}
function toggleSubmodules(e) {
function toggleSubmodules(e) {
e.preventDefault();
e.preventDefault();
$(this).toggleClass('
expand
').toggleClass('
collapse
');
$(this).toggleClass('
expand
').toggleClass('
collapse
');
$(this).closest('
.
branch
,
.
window
').toggleClass('
collapsed
');
$(this).closest('
.
branch
,
.
window
').toggleClass('
collapsed
');
}
}
function setVisibility(e) {
function setVisibility(e) {
$(this).find('
.
checked
').removeClass('
checked
');
$(this).find('
.
checked
').removeClass('
checked
');
$(e.target).closest('
.
option
').addClass('
checked
');
$(e.target).closest('
.
option
').addClass('
checked
');
}
}
function editComponent(e) {
function editComponent(e) {
e.preventDefault();
e.preventDefault();
$(this).closest('
.
xmodule_edit
').addClass('
editing
').find('
.
component
-
editor
').slideDown(150);
$(this).closest('
.
xmodule_edit
').addClass('
editing
').find('
.
component
-
editor
').slideDown(150);
}
}
function closeComponentEditor(e) {
function closeComponentEditor(e) {
e.preventDefault();
e.preventDefault();
$(this).closest('
.
xmodule_edit
').removeClass('
editing
').find('
.
component
-
editor
').slideUp(150);
$(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
');
$(this).hide();
$(this).hide();
$block.find('
.
date
-
setter
').show();
$block.find('
.
date
-
setter
').show();
}
}
function removeDateSetter(e) {
function removeDateSetter(e) {
e.preventDefault();
e.preventDefault();
var $block = $(this).closest('
.
due
-
date
-
input
');
var $block = $(this).closest('
.
due
-
date
-
input
');
$block.find('
.
date
-
setter
').hide();
$block.find('
.
date
-
setter
').hide();
$block.find('
.
set
-
date
').show();
$block.find('
.
set
-
date
').show();
// clear out the values
// clear out the values
$block.find('
.
date
').val('');
$block.find('
.
date
').val('');
$block.find('
.
time
').val('');
$block.find('
.
time
').val('');
}
}
function showToastMessage(message, $button, lifespan) {
function showToastMessage(message, $button, lifespan) {
var $toast = $('
<
div
class
=
"toast-notification"
><
/div>'
)
;
var $toast = $('
<
div
class
=
"toast-notification"
><
/div>'
)
;
var
$closeBtn
=
$
(
'<a href="#" class="close-button">×</a>'
);
var
$closeBtn
=
$
(
'<a href="#" class="close-button">×</a>'
);
$toast
.
append
(
$closeBtn
);
$toast
.
append
(
$closeBtn
);
var
$content
=
$
(
'<div class="notification-content"></div>'
);
var
$content
=
$
(
'<div class="notification-content"></div>'
);
$content
.
html
(
message
);
$content
.
html
(
message
);
$toast
.
append
(
$content
);
$toast
.
append
(
$content
);
if
(
$button
)
{
if
(
$button
)
{
$button
.
addClass
(
'action-button'
);
$button
.
addClass
(
'action-button'
);
$button
.
bind
(
'click'
,
hideToastMessage
);
$button
.
bind
(
'click'
,
hideToastMessage
);
$content
.
append
(
$button
);
$content
.
append
(
$button
);
}
}
$closeBtn
.
bind
(
'click'
,
hideToastMessage
);
$closeBtn
.
bind
(
'click'
,
hideToastMessage
);
if
(
$
(
'.toast-notification'
)[
0
])
{
if
(
$
(
'.toast-notification'
)[
0
])
{
var
targetY
=
$
(
'.toast-notification'
).
offset
().
top
+
$
(
'.toast-notification'
).
outerHeight
();
var
targetY
=
$
(
'.toast-notification'
).
offset
().
top
+
$
(
'.toast-notification'
).
outerHeight
();
$toast
.
css
(
'top'
,
(
targetY
+
10
)
+
'px'
);
$toast
.
css
(
'top'
,
(
targetY
+
10
)
+
'px'
);
}
}
$body
.
prepend
(
$toast
);
$body
.
prepend
(
$toast
);
$toast
.
fadeIn
(
200
);
$toast
.
fadeIn
(
200
);
if
(
lifespan
)
{
if
(
lifespan
)
{
$toast
.
timer
=
setTimeout
(
function
()
{
$toast
.
timer
=
setTimeout
(
function
()
{
$toast
.
fadeOut
(
300
);
$toast
.
fadeOut
(
300
);
},
lifespan
*
1000
);
},
lifespan
*
1000
);
}
}
}
}
function
hideToastMessage
(
e
)
{
function
hideToastMessage
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
this
).
closest
(
'.toast-notification'
).
remove
();
$
(
this
).
closest
(
'.toast-notification'
).
remove
();
}
}
function
addNewSection
(
e
,
isTemplate
)
{
function
addNewSection
(
e
,
isTemplate
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
e
.
target
).
addClass
(
'disabled'
);
$
(
e
.
target
).
addClass
(
'disabled'
);
var
$newSection
=
$
(
$
(
'#new-section-template'
).
html
());
var
$newSection
=
$
(
$
(
'#new-section-template'
).
html
());
var
$cancelButton
=
$newSection
.
find
(
'.new-section-name-cancel'
);
var
$cancelButton
=
$newSection
.
find
(
'.new-section-name-cancel'
);
$
(
'.courseware-overview'
).
prepend
(
$newSection
);
$
(
'.courseware-overview'
).
prepend
(
$newSection
);
$newSection
.
find
(
'.new-section-name'
).
focus
().
select
();
$newSection
.
find
(
'.new-section-name'
).
focus
().
select
();
$newSection
.
find
(
'.section-name-form'
).
bind
(
'submit'
,
saveNewSection
);
$newSection
.
find
(
'.section-name-form'
).
bind
(
'submit'
,
saveNewSection
);
$cancelButton
.
bind
(
'click'
,
cancelNewSection
);
$cancelButton
.
bind
(
'click'
,
cancelNewSection
);
$body
.
bind
(
'keyup'
,
{
$cancelButton
:
$cancelButton
},
checkForCancel
);
$body
.
bind
(
'keyup'
,
{
$cancelButton
:
$cancelButton
},
checkForCancel
);
}
}
function
checkForCancel
(
e
)
{
function
checkForCancel
(
e
)
{
if
(
e
.
which
==
27
)
{
if
(
e
.
which
==
27
)
{
$body
.
unbind
(
'keyup'
,
checkForCancel
);
$body
.
unbind
(
'keyup'
,
checkForCancel
);
e
.
data
.
$cancelButton
.
click
();
e
.
data
.
$cancelButton
.
click
();
}
}
}
}
function
saveNewSection
(
e
)
{
function
saveNewSection
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
var
$saveButton
=
$
(
this
).
find
(
'.new-section-name-save'
);
var
$saveButton
=
$
(
this
).
find
(
'.new-section-name-save'
);
var
parent
=
$saveButton
.
data
(
'parent'
);
var
parent
=
$saveButton
.
data
(
'parent'
);
var
template
=
$saveButton
.
data
(
'template'
);
var
template
=
$saveButton
.
data
(
'template'
);
var
display_name
=
$
(
this
).
find
(
'.new-section-name'
).
val
();
var
display_name
=
$
(
this
).
find
(
'.new-section-name'
).
val
();
$
.
post
(
'/clone_item'
,
{
$
.
post
(
'/clone_item'
,
{
'parent_location'
:
parent
,
'parent_location'
:
parent
,
'template'
:
template
,
'template'
:
template
,
'display_name'
:
display_name
,
'display_name'
:
display_name
,
},
},
function
(
data
)
{
function
(
data
)
{
if
(
data
.
id
!=
undefined
)
if
(
data
.
id
!=
undefined
)
location
.
reload
();
location
.
reload
();
}
}
);
);
}
}
function
cancelNewSection
(
e
)
{
function
cancelNewSection
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
'.new-courseware-section-button'
).
removeClass
(
'disabled'
);
$
(
'.new-courseware-section-button'
).
removeClass
(
'disabled'
);
$
(
this
).
parents
(
'section.new-section'
).
remove
();
$
(
this
).
parents
(
'section.new-section'
).
remove
();
}
}
function
addNewCourse
(
e
)
{
function
addNewCourse
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
e
.
target
).
hide
();
$
(
e
.
target
).
hide
();
var
$newCourse
=
$
(
$
(
'#new-course-template'
).
html
());
var
$newCourse
=
$
(
$
(
'#new-course-template'
).
html
());
var
$cancelButton
=
$newCourse
.
find
(
'.new-course-cancel'
);
var
$cancelButton
=
$newCourse
.
find
(
'.new-course-cancel'
);
$
(
'.new-course-button'
).
after
(
$newCourse
);
$
(
'.new-course-button'
).
after
(
$newCourse
);
$newCourse
.
find
(
'.new-course-name'
).
focus
().
select
();
$newCourse
.
find
(
'.new-course-name'
).
focus
().
select
();
$newCourse
.
find
(
'form'
).
bind
(
'submit'
,
saveNewCourse
);
$newCourse
.
find
(
'form'
).
bind
(
'submit'
,
saveNewCourse
);
$cancelButton
.
bind
(
'click'
,
cancelNewCourse
);
$cancelButton
.
bind
(
'click'
,
cancelNewCourse
);
$body
.
bind
(
'keyup'
,
{
$cancelButton
:
$cancelButton
},
checkForCancel
);
$body
.
bind
(
'keyup'
,
{
$cancelButton
:
$cancelButton
},
checkForCancel
);
}
}
function
saveNewCourse
(
e
)
{
function
saveNewCourse
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
var
$newCourse
=
$
(
this
).
closest
(
'.new-course'
);
var
$newCourse
=
$
(
this
).
closest
(
'.new-course'
);
var
template
=
$
(
this
).
find
(
'.new-course-save'
).
data
(
'template'
);
var
template
=
$
(
this
).
find
(
'.new-course-save'
).
data
(
'template'
);
var
org
=
$newCourse
.
find
(
'.new-course-org'
).
val
();
var
org
=
$newCourse
.
find
(
'.new-course-org'
).
val
();
var
number
=
$newCourse
.
find
(
'.new-course-number'
).
val
();
var
number
=
$newCourse
.
find
(
'.new-course-number'
).
val
();
var
display_name
=
$newCourse
.
find
(
'.new-course-name'
).
val
();
var
display_name
=
$newCourse
.
find
(
'.new-course-name'
).
val
();
if
(
org
==
''
||
number
==
''
||
display_name
==
''
)
{
if
(
org
==
''
||
number
==
''
||
display_name
==
''
)
{
alert
(
'You must specify all fields in order to create a new course.'
);
alert
(
'You must specify all fields in order to create a new course.'
);
return
;
return
;
}
}
$
.
post
(
'/create_new_course'
,
{
$
.
post
(
'/create_new_course'
,
{
'template'
:
template
,
'template'
:
template
,
'org'
:
org
,
'org'
:
org
,
'number'
:
number
,
'number'
:
number
,
'display_name'
:
display_name
'display_name'
:
display_name
},
},
function
(
data
)
{
function
(
data
)
{
if
(
data
.
id
!=
undefined
)
{
if
(
data
.
id
!=
undefined
)
{
window
.
location
=
'/'
+
data
.
id
.
replace
(
/.*:
\/\/
/
,
''
);
window
.
location
=
'/'
+
data
.
id
.
replace
(
/.*:
\/\/
/
,
''
);
}
else
if
(
data
.
ErrMsg
!=
undefined
)
{
}
else
if
(
data
.
ErrMsg
!=
undefined
)
{
alert
(
data
.
ErrMsg
);
alert
(
data
.
ErrMsg
);
}
}
});
});
}
}
function
cancelNewCourse
(
e
)
{
function
cancelNewCourse
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
'.new-course-button'
).
show
();
$
(
'.new-course-button'
).
show
();
$
(
this
).
parents
(
'section.new-course'
).
remove
();
$
(
this
).
parents
(
'section.new-course'
).
remove
();
}
}
function
addNewSubsection
(
e
)
{
function
addNewSubsection
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
var
$section
=
$
(
this
).
closest
(
'.courseware-section'
);
var
$section
=
$
(
this
).
closest
(
'.courseware-section'
);
var
$newSubsection
=
$
(
$
(
'#new-subsection-template'
).
html
());
var
$newSubsection
=
$
(
$
(
'#new-subsection-template'
).
html
());
$section
.
find
(
'.subsection-list > ol'
).
append
(
$newSubsection
);
$section
.
find
(
'.subsection-list > ol'
).
append
(
$newSubsection
);
$section
.
find
(
'.new-subsection-name-input'
).
focus
().
select
();
$section
.
find
(
'.new-subsection-name-input'
).
focus
().
select
();
var
$saveButton
=
$newSubsection
.
find
(
'.new-subsection-name-save'
);
var
$saveButton
=
$newSubsection
.
find
(
'.new-subsection-name-save'
);
var
$cancelButton
=
$newSubsection
.
find
(
'.new-subsection-name-cancel'
);
var
$cancelButton
=
$newSubsection
.
find
(
'.new-subsection-name-cancel'
);
var
parent
=
$
(
this
).
parents
(
"section.branch"
).
data
(
"id"
);
var
parent
=
$
(
this
).
parents
(
"section.branch"
).
data
(
"id"
);
$saveButton
.
data
(
'parent'
,
parent
);
$saveButton
.
data
(
'parent'
,
parent
);
$saveButton
.
data
(
'template'
,
$
(
this
).
data
(
'template'
));
$saveButton
.
data
(
'template'
,
$
(
this
).
data
(
'template'
));
$newSubsection
.
find
(
'.new-subsection-form'
).
bind
(
'submit'
,
saveNewSubsection
);
$newSubsection
.
find
(
'.new-subsection-form'
).
bind
(
'submit'
,
saveNewSubsection
);
$cancelButton
.
bind
(
'click'
,
cancelNewSubsection
);
$cancelButton
.
bind
(
'click'
,
cancelNewSubsection
);
$body
.
bind
(
'keyup'
,
{
$cancelButton
:
$cancelButton
},
checkForCancel
);
$body
.
bind
(
'keyup'
,
{
$cancelButton
:
$cancelButton
},
checkForCancel
);
}
}
function
saveNewSubsection
(
e
)
{
function
saveNewSubsection
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
var
parent
=
$
(
this
).
find
(
'.new-subsection-name-save'
).
data
(
'parent'
);
var
parent
=
$
(
this
).
find
(
'.new-subsection-name-save'
).
data
(
'parent'
);
var
template
=
$
(
this
).
find
(
'.new-subsection-name-save'
).
data
(
'template'
);
var
template
=
$
(
this
).
find
(
'.new-subsection-name-save'
).
data
(
'template'
);
var
display_name
=
$
(
this
).
find
(
'.new-subsection-name-input'
).
val
();
var
display_name
=
$
(
this
).
find
(
'.new-subsection-name-input'
).
val
();
$
.
post
(
'/clone_item'
,
{
$
.
post
(
'/clone_item'
,
{
'parent_location'
:
parent
,
'parent_location'
:
parent
,
'template'
:
template
,
'template'
:
template
,
'display_name'
:
display_name
'display_name'
:
display_name
},
},
function
(
data
)
{
function
(
data
)
{
if
(
data
.
id
!=
undefined
)
{
if
(
data
.
id
!=
undefined
)
{
location
.
reload
();
location
.
reload
();
}
}
}
}
);
);
}
}
function
cancelNewSubsection
(
e
)
{
function
cancelNewSubsection
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
this
).
parents
(
'li.branch'
).
remove
();
$
(
this
).
parents
(
'li.branch'
).
remove
();
}
}
function
editSectionName
(
e
)
{
function
editSectionName
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
this
).
unbind
(
'click'
,
editSectionName
);
$
(
this
).
unbind
(
'click'
,
editSectionName
);
$
(
this
).
children
(
'.section-name-edit'
).
show
();
$
(
this
).
children
(
'.section-name-edit'
).
show
();
$
(
this
).
find
(
'.edit-section-name'
).
focus
();
$
(
this
).
find
(
'.edit-section-name'
).
focus
();
$
(
this
).
children
(
'.section-name-span'
).
hide
();
$
(
this
).
children
(
'.section-name-span'
).
hide
();
$
(
this
).
find
(
'.section-name-edit'
).
bind
(
'submit'
,
saveEditSectionName
);
$
(
this
).
find
(
'.section-name-edit'
).
bind
(
'submit'
,
saveEditSectionName
);
$
(
this
).
find
(
'.edit-section-name-cancel'
).
bind
(
'click'
,
cancelNewSection
);
$
(
this
).
find
(
'.edit-section-name-cancel'
).
bind
(
'click'
,
cancelNewSection
);
$body
.
bind
(
'keyup'
,
{
$cancelButton
:
$
(
this
).
find
(
'.edit-section-name-cancel'
)
},
checkForCancel
);
$body
.
bind
(
'keyup'
,
{
$cancelButton
:
$
(
this
).
find
(
'.edit-section-name-cancel'
)
},
checkForCancel
);
}
}
function
cancelEditSectionName
(
e
)
{
function
cancelEditSectionName
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
this
).
parent
().
hide
();
$
(
this
).
parent
().
hide
();
$
(
this
).
parent
().
siblings
(
'.section-name-span'
).
show
();
$
(
this
).
parent
().
siblings
(
'.section-name-span'
).
show
();
$
(
this
).
closest
(
'.section-name'
).
bind
(
'click'
,
editSectionName
);
$
(
this
).
closest
(
'.section-name'
).
bind
(
'click'
,
editSectionName
);
e
.
stopPropagation
();
e
.
stopPropagation
();
}
}
function
saveEditSectionName
(
e
)
{
function
saveEditSectionName
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
this
).
closest
(
'.section-name'
).
unbind
(
'click'
,
editSectionName
);
$
(
this
).
closest
(
'.section-name'
).
unbind
(
'click'
,
editSectionName
);
var
id
=
$
(
this
).
closest
(
'.courseware-section'
).
data
(
'id'
);
var
id
=
$
(
this
).
closest
(
'.courseware-section'
).
data
(
'id'
);
var
display_name
=
$
.
trim
(
$
(
this
).
find
(
'.edit-section-name'
).
val
());
var
display_name
=
$
.
trim
(
$
(
this
).
find
(
'.edit-section-name'
).
val
());
$
(
this
).
closest
(
'.courseware-section .section-name'
).
append
(
$spinner
);
$
(
this
).
closest
(
'.courseware-section .section-name'
).
append
(
$spinner
);
$spinner
.
show
();
$spinner
.
show
();
if
(
display_name
==
''
)
{
if
(
display_name
==
''
)
{
alert
(
"You must specify a name before saving."
);
alert
(
"You must specify a name before saving."
);
return
;
return
;
}
}
var
$_this
=
$
(
this
);
var
$_this
=
$
(
this
);
// call into server to commit the new order
// call into server to commit the new order
$
.
ajax
({
$
.
ajax
({
url
:
"/save_item"
,
url
:
"/save_item"
,
type
:
"POST"
,
type
:
"POST"
,
dataType
:
"json"
,
dataType
:
"json"
,
contentType
:
"application/json"
,
contentType
:
"application/json"
,
data
:
JSON
.
stringify
({
'id'
:
id
,
'metadata'
:
{
'display_name'
:
display_name
}})
data
:
JSON
.
stringify
({
'id'
:
id
,
'metadata'
:
{
'display_name'
:
display_name
}})
}).
success
(
function
()
}).
success
(
function
()
{
{
$spinner
.
delay
(
250
).
fadeOut
(
250
);
$spinner
.
delay
(
250
).
fadeOut
(
250
);
$_this
.
closest
(
'h3'
).
find
(
'.section-name-span'
).
html
(
display_name
).
show
();
$_this
.
closest
(
'h3'
).
find
(
'.section-name-span'
).
html
(
display_name
).
show
();
$_this
.
hide
();
$_this
.
hide
();
$_this
.
closest
(
'.section-name'
).
bind
(
'click'
,
editSectionName
);
$_this
.
closest
(
'.section-name'
).
bind
(
'click'
,
editSectionName
);
e
.
stopPropagation
();
e
.
stopPropagation
();
});
});
}
}
function
setSectionScheduleDate
(
e
)
{
function
setSectionScheduleDate
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
this
).
closest
(
"h4"
).
hide
();
$
(
this
).
closest
(
"h4"
).
hide
();
$
(
this
).
parent
().
siblings
(
".datepair"
).
show
();
$
(
this
).
parent
().
siblings
(
".datepair"
).
show
();
}
}
function
cancelSetSectionScheduleDate
(
e
)
{
function
cancelSetSectionScheduleDate
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
$
(
this
).
closest
(
".datepair"
).
hide
();
$
(
this
).
closest
(
".datepair"
).
hide
();
$
(
this
).
parent
().
siblings
(
"h4"
).
show
();
$
(
this
).
parent
().
siblings
(
"h4"
).
show
();
}
}
function
saveSetSectionScheduleDate
(
e
)
{
function
saveSetSectionScheduleDate
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
var
input_date
=
$
(
'.edit-subsection-publish-settings .start-date'
).
val
();
var
input_date
=
$
(
'.edit-subsection-publish-settings .start-date'
).
val
();
var
input_time
=
$
(
'.edit-subsection-publish-settings .start-time'
).
val
();
var
input_time
=
$
(
'.edit-subsection-publish-settings .start-time'
).
val
();
var
start
=
getEdxTimeFromDateTimeVals
(
input_date
,
input_time
);
var
start
=
getEdxTimeFromDateTimeVals
(
input_date
,
input_time
);
var
id
=
$modal
.
attr
(
'data-id'
);
var
id
=
$modal
.
attr
(
'data-id'
);
// call into server to commit the new order
// call into server to commit the new order
$
.
ajax
({
$
.
ajax
({
url
:
"/save_item"
,
url
:
"/save_item"
,
type
:
"POST"
,
type
:
"POST"
,
dataType
:
"json"
,
dataType
:
"json"
,
contentType
:
"application/json"
,
contentType
:
"application/json"
,
data
:
JSON
.
stringify
({
'id'
:
id
,
'metadata'
:
{
'start'
:
start
}})
data
:
JSON
.
stringify
({
'id'
:
id
,
'metadata'
:
{
'start'
:
start
}})
}).
success
(
function
()
}).
success
(
function
()
{
{
var
$thisSection
=
$
(
'.courseware-section[data-id="'
+
id
+
'"]'
);
var
$thisSection
=
$
(
'.courseware-section[data-id="'
+
id
+
'"]'
);
$thisSection
.
find
(
'.section-published-date'
).
html
(
'<span class="published-status"><strong>Will Release:</strong> '
+
input_date
+
' at '
+
input_time
+
'</span><a href="#" class="edit-button" data-date="'
+
input_date
+
'" data-time="'
+
input_time
+
'" data-id="'
+
id
+
'">Edit</a>'
);
$thisSection
.
find
(
'.section-published-date'
).
html
(
'<span class="published-status"><strong>Will Release:</strong> '
+
input_date
+
' at '
+
input_time
+
'</span><a href="#" class="edit-button" data-date="'
+
input_date
+
'" data-time="'
+
input_time
+
'" data-id="'
+
id
+
'">Edit</a>'
);
$thisSection
.
find
(
'.section-published-date'
).
animate
({
$thisSection
.
find
(
'.section-published-date'
).
animate
({
'background-color'
:
'rgb(182,37,104)'
'background-color'
:
'rgb(182,37,104)'
},
300
).
animate
({
},
300
).
animate
({
'background-color'
:
'#edf1f5'
'background-color'
:
'#edf1f5'
},
300
).
animate
({
},
300
).
animate
({
'background-color'
:
'rgb(182,37,104)'
'background-color'
:
'rgb(182,37,104)'
},
300
).
animate
({
},
300
).
animate
({
'background-color'
:
'#edf1f5'
'background-color'
:
'#edf1f5'
},
300
);
},
300
);
hideModal
();
hideModal
();
});
});
}
}
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