Commit c9a80ded by Steve Strassmann

formatted using sublime/formatjs

parent 485d07a7
...@@ -10,7 +10,7 @@ var $newComponentTypePicker; ...@@ -10,7 +10,7 @@ var $newComponentTypePicker;
var $newComponentTemplatePickers; var $newComponentTemplatePickers;
var $newComponentButton; var $newComponentButton;
$(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">');
...@@ -35,7 +35,7 @@ $(document).ready(function () { ...@@ -35,7 +35,7 @@ $(document).ready(function () {
$('.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 () { $body.on('click', '.embeddable-xml-input', function() {
$(this).select(); $(this).select();
}); });
...@@ -45,8 +45,11 @@ $(document).ready(function () { ...@@ -45,8 +45,11 @@ $(document).ready(function () {
$('.new-unit-item').bind('click', createNewUnit); $('.new-unit-item').bind('click', createNewUnit);
// lean/simple modal // lean/simple modal
$('a[rel*=modal]').leanModal({overlay : 0.80, closeButton: '.action-modal-close' }); $('a[rel*=modal]').leanModal({
$('a.action-modal-close').click(function(e){ overlay: 0.80,
closeButton: '.action-modal-close'
});
$('a.action-modal-close').click(function(e) {
(e).preventDefault(); (e).preventDefault();
}); });
...@@ -55,12 +58,12 @@ $(document).ready(function () { ...@@ -55,12 +58,12 @@ $(document).ready(function () {
$('.action-notification-close').bind('click', hideNotification); $('.action-notification-close').bind('click', hideNotification);
// nav - dropdown related // nav - dropdown related
$body.click(function (e) { $body.click(function(e) {
$('.nav-dropdown .nav-item .wrapper-nav-sub').removeClass('is-shown'); $('.nav-dropdown .nav-item .wrapper-nav-sub').removeClass('is-shown');
$('.nav-dropdown .nav-item .title').removeClass('is-selected'); $('.nav-dropdown .nav-item .title').removeClass('is-selected');
}); });
$('.nav-dropdown .nav-item .title').click(function (e) { $('.nav-dropdown .nav-item .title').click(function(e) {
$subnav = $(this).parent().find('.wrapper-nav-sub'); $subnav = $(this).parent().find('.wrapper-nav-sub');
$title = $(this).parent().find('.title'); $title = $(this).parent().find('.title');
...@@ -70,9 +73,7 @@ $(document).ready(function () { ...@@ -70,9 +73,7 @@ $(document).ready(function () {
if ($subnav.hasClass('is-shown')) { if ($subnav.hasClass('is-shown')) {
$subnav.removeClass('is-shown'); $subnav.removeClass('is-shown');
$title.removeClass('is-selected'); $title.removeClass('is-selected');
} } else {
else {
$('.nav-dropdown .nav-item .title').removeClass('is-selected'); $('.nav-dropdown .nav-item .title').removeClass('is-selected');
$('.nav-dropdown .nav-item .wrapper-nav-sub').removeClass('is-shown'); $('.nav-dropdown .nav-item .wrapper-nav-sub').removeClass('is-shown');
$title.addClass('is-selected'); $title.addClass('is-selected');
...@@ -84,8 +85,11 @@ $(document).ready(function () { ...@@ -84,8 +85,11 @@ $(document).ready(function () {
$('a[rel="external"]').attr('title', 'This link will open in a new browser window/tab').bind('click', linkNewWindow); $('a[rel="external"]').attr('title', 'This link will open in a new browser window/tab').bind('click', linkNewWindow);
// general link management - lean modal window // general link management - lean modal window
$('a[rel="modal"]').attr('title', 'This link will open in a modal window').leanModal({overlay: 0.50, closeButton: '.action-modal-close' }); $('a[rel="modal"]').attr('title', 'This link will open in a modal window').leanModal({
$('.action-modal-close').click(function (e) { overlay: 0.50,
closeButton: '.action-modal-close'
});
$('.action-modal-close').click(function(e) {
(e).preventDefault(); (e).preventDefault();
}); });
...@@ -99,7 +103,7 @@ $(document).ready(function () { ...@@ -99,7 +103,7 @@ $(document).ready(function () {
$('.cta-show-sock').bind('click', toggleSock); $('.cta-show-sock').bind('click', toggleSock);
// toggling overview section details // toggling overview section details
$(function () { $(function() {
if ($('.courseware-section').length > 0) { if ($('.courseware-section').length > 0) {
$('.toggle-button-sections').addClass('is-shown'); $('.toggle-button-sections').addClass('is-shown');
} }
...@@ -108,7 +112,7 @@ $(document).ready(function () { ...@@ -108,7 +112,7 @@ $(document).ready(function () {
// autosave when leaving input field // autosave when leaving input field
$body.on('change', '.subsection-display-name-input', saveSubsection); $body.on('change', '.subsection-display-name-input', saveSubsection);
$('.subsection-display-name-input').each(function () { $('.subsection-display-name-input').each(function() {
this.val = $(this).val(); this.val = $(this).val();
}); });
$("#start_date, #start_time, #due_date, #due_time").bind('change', autosaveInput); $("#start_date, #start_time, #due_date, #due_time").bind('change', autosaveInput);
...@@ -129,7 +133,7 @@ $(document).ready(function () { ...@@ -129,7 +133,7 @@ $(document).ready(function () {
// import form setup // import form setup
$('.import .file-input').bind('change', showImportSubmit); $('.import .file-input').bind('change', showImportSubmit);
$('.import .choose-file-button, .import .choose-file-button-inline').bind('click', function (e) { $('.import .choose-file-button, .import .choose-file-button-inline').bind('click', function(e) {
e.preventDefault(); e.preventDefault();
$('.import .file-input').click(); $('.import .file-input').click();
}); });
...@@ -152,12 +156,12 @@ $(document).ready(function () { ...@@ -152,12 +156,12 @@ $(document).ready(function () {
$body.on('click', '.section-published-date .schedule-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 .save-button', saveSetSectionScheduleDate);
$body.on('click', '.edit-subsection-publish-settings .cancel-button', hideModal); $body.on('click', '.edit-subsection-publish-settings .cancel-button', hideModal);
$body.on('change', '.edit-subsection-publish-settings .start-date', function () { $body.on('change', '.edit-subsection-publish-settings .start-date', function() {
if ($('.edit-subsection-publish-settings').find('.start-time').val() == '') { if ($('.edit-subsection-publish-settings').find('.start-time').val() == '') {
$('.edit-subsection-publish-settings').find('.start-time').val('12:00am'); $('.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').on('change', '.start-date, .start-time', function() {
$('.edit-subsection-publish-settings').find('.save-button').show(); $('.edit-subsection-publish-settings').find('.save-button').show();
}); });
}); });
...@@ -177,7 +181,7 @@ function smoothScrollLink(e) { ...@@ -177,7 +181,7 @@ function smoothScrollLink(e) {
// On AWS instances, this base.js gets wrapped in a separate scope as part of Django static // On AWS instances, this base.js gets 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, // 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 Course Advanced Settings). // when we can access it from other scopes (namely Course Advanced Settings).
window.CmsUtils.smoothScrollTop = function (e) { window.CmsUtils.smoothScrollTop = function(e) {
(e).preventDefault(); (e).preventDefault();
$.smoothScroll({ $.smoothScroll({
...@@ -260,8 +264,7 @@ function getEdxTimeFromDateTimeVals(date_val, time_val) { ...@@ -260,8 +264,7 @@ function getEdxTimeFromDateTimeVals(date_val, time_val) {
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
var date = Date.parse(date_val + " " + time_val); var date = Date.parse(date_val + " " + time_val);
...@@ -284,7 +287,7 @@ function autosaveInput(e) { ...@@ -284,7 +287,7 @@ function autosaveInput(e) {
clearTimeout(this.saveTimer); clearTimeout(this.saveTimer);
} }
this.saveTimer = setTimeout(function () { this.saveTimer = setTimeout(function() {
$changedInput = $(e.target); $changedInput = $(e.target);
saveSubsection(); saveSubsection();
self.saveTimer = null; self.saveTimer = null;
...@@ -324,12 +327,15 @@ function saveSubsection() { ...@@ -324,12 +327,15 @@ function saveSubsection() {
type: "POST", type: "POST",
dataType: "json", dataType: "json",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify({ 'id': id, 'metadata': metadata}), data: JSON.stringify({
success: function () { 'id': id,
'metadata': metadata
}),
success: function() {
$spinner.delay(500).fadeOut(150); $spinner.delay(500).fadeOut(150);
$changedInput = null; $changedInput = null;
}, },
error: function () { error: function() {
showToastMessage('There has been an error while saving your changes.'); showToastMessage('There has been an error while saving your changes.');
} }
}); });
...@@ -348,15 +354,16 @@ function createNewUnit(e) { ...@@ -348,15 +354,16 @@ function createNewUnit(e) {
}); });
$.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) {
// redirect to the edit page function(data) {
window.location = "/edit/" + data['id']; // redirect to the edit page
}); window.location = "/edit/" + data['id'];
});
} }
function deleteUnit(e) { function deleteUnit(e) {
...@@ -375,8 +382,7 @@ function deleteSection(e) { ...@@ -375,8 +382,7 @@ function deleteSection(e) {
} }
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');
...@@ -386,11 +392,15 @@ function _deleteItem($el) { ...@@ -386,11 +392,15 @@ function _deleteItem($el) {
}); });
$.post('/delete_item', $.post('/delete_item', {
{'id': id, 'delete_children': true, 'delete_all_versions': true}, 'id': id,
function (data) { 'delete_children': true,
$el.remove(); 'delete_all_versions': true
}); },
function(data) {
$el.remove();
});
} }
function showUploadModal(e) { function showUploadModal(e) {
...@@ -492,18 +502,16 @@ function toggleSock(e) { ...@@ -492,18 +502,16 @@ function toggleSock(e) {
$sockContent.toggle('fast'); $sockContent.toggle('fast');
$.smoothScroll({ $.smoothScroll({
offset: -200, offset: -200,
easing: 'swing', easing: 'swing',
speed: 1000, speed: 1000,
scrollElement: null, scrollElement: null,
scrollTarget: $sock scrollTarget: $sock
}); });
if($sock.hasClass('is-shown')) { if ($sock.hasClass('is-shown')) {
$btnLabel.text(gettext('Hide Studio Help')); $btnLabel.text(gettext('Hide Studio Help'));
} } else {
else {
$btnLabel.text(gettext('Looking for Help with Studio?')); $btnLabel.text(gettext('Looking for Help with Studio?'));
} }
} }
...@@ -549,7 +557,7 @@ function removeDateSetter(e) { ...@@ -549,7 +557,7 @@ function removeDateSetter(e) {
function hideNotification(e) { function hideNotification(e) {
(e).preventDefault(); (e).preventDefault();
$(this).closest('.wrapper-notification').removeClass('is-shown').addClass('is-hiding').attr('aria-hidden','true'); $(this).closest('.wrapper-notification').removeClass('is-shown').addClass('is-hiding').attr('aria-hidden', 'true');
} }
function hideAlert(e) { function hideAlert(e) {
...@@ -580,7 +588,7 @@ function showToastMessage(message, $button, lifespan) { ...@@ -580,7 +588,7 @@ function showToastMessage(message, $button, lifespan) {
$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);
} }
...@@ -602,7 +610,9 @@ function addNewSection(e, isTemplate) { ...@@ -602,7 +610,9 @@ function addNewSection(e, isTemplate) {
$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) {
...@@ -627,15 +637,14 @@ function saveNewSection(e) { ...@@ -627,15 +637,14 @@ function saveNewSection(e) {
}); });
$.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) {
if (data.id != undefined) function(data) {
location.reload(); if (data.id != undefined) location.reload();
} });
);
} }
function cancelNewSection(e) { function cancelNewSection(e) {
...@@ -654,7 +663,9 @@ function addNewCourse(e) { ...@@ -654,7 +663,9 @@ function addNewCourse(e) {
$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) {
...@@ -678,18 +689,19 @@ function saveNewCourse(e) { ...@@ -678,18 +689,19 @@ function saveNewCourse(e) {
}); });
$.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) {
if (data.id != undefined) { function(data) {
window.location = '/' + data.id.replace(/.*:\/\//, ''); if (data.id != undefined) {
} else if (data.ErrMsg != undefined) { window.location = '/' + data.id.replace(/.*:\/\//, '');
alert(data.ErrMsg); } else if (data.ErrMsg != undefined) {
} alert(data.ErrMsg);
}); }
});
} }
function cancelNewCourse(e) { function cancelNewCourse(e) {
...@@ -715,7 +727,9 @@ function addNewSubsection(e) { ...@@ -715,7 +727,9 @@ function addNewSubsection(e) {
$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) {
...@@ -732,16 +746,16 @@ function saveNewSubsection(e) { ...@@ -732,16 +746,16 @@ function saveNewSubsection(e) {
$.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) {
if (data.id != undefined) { function(data) {
location.reload(); if (data.id != undefined) {
} location.reload();
} }
); });
} }
function cancelNewSubsection(e) { function cancelNewSubsection(e) {
...@@ -757,7 +771,9 @@ function editSectionName(e) { ...@@ -757,7 +771,9 @@ function editSectionName(e) {
$(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) {
...@@ -798,14 +814,19 @@ function saveEditSectionName(e) { ...@@ -798,14 +814,19 @@ function saveEditSectionName(e) {
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({
}).success(function () { 'id': id,
$spinner.delay(250).fadeOut(250); 'metadata': {
$_this.closest('h3').find('.section-name-span').html(display_name).show(); 'display_name': display_name
$_this.hide(); }
$_this.closest('.section-name').bind('click', editSectionName); })
e.stopPropagation(); }).success(function() {
}); $spinner.delay(250).fadeOut(250);
$_this.closest('h3').find('.section-name-span').html(display_name).show();
$_this.hide();
$_this.closest('.section-name').bind('click', editSectionName);
e.stopPropagation();
});
} }
function setSectionScheduleDate(e) { function setSectionScheduleDate(e) {
...@@ -842,31 +863,36 @@ function saveSetSectionScheduleDate(e) { ...@@ -842,31 +863,36 @@ function saveSetSectionScheduleDate(e) {
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({
}).success(function () { 'id': id,
var $thisSection = $('.courseware-section[data-id="' + id + '"]'); 'metadata': {
var format = gettext('<strong>Will Release:</strong> %(date)s at %(time)s UTC'); 'start': start
var willReleaseAt = interpolate(format, }
{'date': input_date, })
'time': input_time}, }).success(function() {
true); var $thisSection = $('.courseware-section[data-id="' + id + '"]');
$thisSection.find('.section-published-date').html( var format = gettext('<strong>Will Release:</strong> %(date)s at %(time)s UTC');
'<span class="published-status">' + willReleaseAt + '</span>' + var willReleaseAt = interpolate(format, {
'<a href="#" class="edit-button" ' + 'date': input_date,
'" data-date="' + input_date + 'time': input_time
'" data-time="' + input_time + },
'" data-id="' + id + '">' + true);
gettext('Edit') + '</a>'); $thisSection.find('.section-published-date').html(
$thisSection.find('.section-published-date').animate({ '<span class="published-status">' + willReleaseAt + '</span>' +
'background-color': 'rgb(182,37,104)' '<a href="#" class="edit-button" ' +
}, 300).animate({ '" data-date="' + input_date +
'background-color': '#edf1f5' '" data-time="' + input_time +
}, 300).animate({ '" data-id="' + id + '">' + gettext('Edit') + '</a>');
'background-color': 'rgb(182,37,104)' $thisSection.find('.section-published-date').animate({
}, 300).animate({ 'background-color': 'rgb(182,37,104)'
'background-color': '#edf1f5' }, 300).animate({
}, 300); 'background-color': '#edf1f5'
}, 300).animate({
hideModal(); 'background-color': 'rgb(182,37,104)'
}); }, 300).animate({
} 'background-color': '#edf1f5'
}, 300);
hideModal();
});
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment