Commit 9eb02a8a by Brian Talbot

studio - resolving base.js spacing/conflicts

parents 3c6caa61 5acf9cb3
......@@ -5,7 +5,7 @@ var $newComponentItem;
var $changedInput;
var $spinner;
$(document).ready(function() {
$(document).ready(function () {
$body = $('body');
$modal = $('.history-modal');
$modalCover = $('<div class="modal-cover">');
......@@ -34,7 +34,9 @@ $(document).ready(function() {
$('.uploads .upload-button').bind('click', showUploadModal);
$('.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);
......@@ -48,12 +50,12 @@ $(document).ready(function() {
});
// 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 .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');
$title = $(this).parent().find('.title');
......@@ -74,20 +76,20 @@ $(document).ready(function() {
});
// general link management - new window/tab
$('a[rel="external"]').attr('title','This link will open in a new browser window/tab').click(function(e) {
$('a[rel="external"]').attr('title', 'This link will open in a new browser window/tab').click(function (e) {
window.open($(this).attr('href'));
e.preventDefault();
});
// 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' });
$('.action-modal-close').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
$(function(){
if($('.courseware-section').length > 0) {
$(function () {
if ($('.courseware-section').length > 0) {
$('.toggle-button-sections').addClass('is-shown');
}
});
......@@ -95,7 +97,7 @@ $(document).ready(function() {
// autosave when a field is updated on the subsection page
$body.on('keyup', '.subsection-display-name-input, .unit-subtitle, .policy-list-value', checkForNewValue);
$('.subsection-display-name-input, .unit-subtitle, .policy-list-name, .policy-list-value').each(function(i) {
$('.subsection-display-name-input, .unit-subtitle, .policy-list-name, .policy-list-value').each(function (i) {
this.val = $(this).val();
});
$("#start_date, #start_time, #due_date, #due_time").bind('change', autosaveInput);
......@@ -121,7 +123,7 @@ $(document).ready(function() {
// import form setup
$('.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();
$('.import .file-input').click();
});
......@@ -144,12 +146,12 @@ $(document).ready(function() {
$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() == '') {
$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').on('change', '.start-date, .start-time', function () {
$('.edit-subsection-publish-settings').find('.save-button').show();
});
});
......@@ -171,7 +173,7 @@ function toggleSections(e) {
var buttonLabel = $button.hasClass('is-activated') ? $labelCollapsed : $labelExpanded;
$button.toggleClass('is-activated').html(buttonLabel);
if($button.hasClass('is-activated')) {
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');
......@@ -189,7 +191,7 @@ function editSectionPublishDate(e) {
$modal.attr('data-id', $(this).attr('data-id'));
$modal.find('.start-date').val($(this).attr('data-date'));
$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('.section-name').html('"' + $(this).closest('.courseware-section').find('.section-name-span').text() + '"');
......@@ -198,7 +200,7 @@ function editSectionPublishDate(e) {
function showImportSubmit(e) {
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();
$('.file-name').html($(this).val().replace('C:\\fakepath\\', ''));
$('.file-name-block').show();
......@@ -219,7 +221,7 @@ function syncReleaseDate(e) {
function addPolicyMetadata(e) {
e.preventDefault();
var template =$('#add-new-policy-element-template > li');
var template = $('#add-new-policy-element-template > li');
var newNode = template.clone();
var _parent_el = $(this).parent('ol:.policy-list');
newNode.insertBefore('.add-policy-data');
......@@ -241,7 +243,7 @@ function cancelPolicyMetadata(e) {
e.preventDefault();
var $policyElement = $(this).parents('.policy-list-element');
if(!$policyElement.hasClass('editing')) {
if (!$policyElement.hasClass('editing')) {
$policyElement.remove();
} else {
$policyElement.removeClass('new-policy-list-element');
......@@ -254,7 +256,7 @@ function cancelPolicyMetadata(e) {
function removePolicyMetadata(e) {
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;
policy_name = $(this).data('policy-name');
......@@ -286,30 +288,30 @@ function getEdxTimeFromDateTimeVals(date_val, time_val, format) {
}
function getEdxTimeFromDateTimeInputs(date_id, time_id, format) {
var input_date = $('#'+date_id).val();
var input_time = $('#'+time_id).val();
var input_date = $('#' + date_id).val();
var input_time = $('#' + time_id).val();
return getEdxTimeFromDateTimeVals(input_date, input_time, format);
}
function checkForNewValue(e) {
if($(this).parents('.new-policy-list-element')[0]) {
if ($(this).parents('.new-policy-list-element')[0]) {
return;
}
if(this.val) {
if (this.val) {
this.hasChanged = this.val != $(this).val();
} else {
this.hasChanged = false;
}
this.val = $(this).val();
if(this.hasChanged) {
if(this.saveTimer) {
if (this.hasChanged) {
if (this.saveTimer) {
clearTimeout(this.saveTimer);
}
this.saveTimer = setTimeout(function() {
this.saveTimer = setTimeout(function () {
$changedInput = $(e.target);
saveSubsection();
this.saveTimer = null;
......@@ -318,11 +320,11 @@ function checkForNewValue(e) {
}
function autosaveInput(e) {
if(this.saveTimer) {
if (this.saveTimer) {
clearTimeout(this.saveTimer);
}
this.saveTimer = setTimeout(function() {
this.saveTimer = setTimeout(function () {
$changedInput = $(e.target);
saveSubsection();
this.saveTimer = null;
......@@ -330,7 +332,7 @@ function autosaveInput(e) {
}
function saveSubsection() {
if($changedInput && !$changedInput.hasClass('no-spinner')) {
if ($changedInput && !$changedInput.hasClass('no-spinner')) {
$spinner.css({
'position': 'absolute',
'top': Math.floor($changedInput.position().top + ($changedInput.outerHeight() / 2) + 3),
......@@ -347,20 +349,20 @@ function saveSubsection() {
var metadata_fields = $('input[data-metadata-name]');
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];
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) {
$('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) {
$("#policy-to-delete > li.policy-list-element").each(function (i, element) {
var name = $(element).children('.policy-list-name').val();
if (name != "")
metadata[name] = null;
......@@ -377,11 +379,11 @@ function saveSubsection() {
type: "POST",
dataType: "json",
contentType: "application/json",
data:JSON.stringify({ 'id' : id, 'metadata' : metadata}),
success: function() {
data: JSON.stringify({ 'id': id, 'metadata': metadata}),
success: function () {
$spinner.delay(500).fadeOut(150);
},
error: function() {
error: function () {
showToastMessage('There has been an error while saving your changes.');
}
});
......@@ -395,11 +397,11 @@ function createNewUnit(e) {
template = $(this).data('template');
$.post('/clone_item',
{'parent_location' : parent,
'template' : template,
{'parent_location': parent,
'template': template,
'display_name': 'New Unit'
},
function(data) {
function (data) {
// redirect to the edit page
window.location = "/edit/" + data['id'];
});
......@@ -421,14 +423,14 @@ function deleteSection(e) {
}
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;
var id = $el.data('id');
$.post('/delete_item',
{'id': id, 'delete_children' : true, 'delete_all_versions' : true},
function(data) {
{'id': id, 'delete_children': true, 'delete_all_versions': true},
function (data) {
$el.remove();
});
}
......@@ -457,7 +459,7 @@ function startUpload(e) {
$('.upload-modal .progress-bar').removeClass('loaded').show();
}
function resetUploadBar(){
function resetUploadBar() {
var percentVal = '0%';
$('.upload-modal .progress-fill').width(percentVal);
$('.upload-modal .progress-fill').html(percentVal);
......@@ -470,7 +472,7 @@ function showUploadFeedback(event, position, total, percentComplete) {
}
function displayFinishedUpload(xhr) {
if(xhr.status = 200){
if (xhr.status = 200) {
markAsLoaded();
}
......@@ -497,7 +499,7 @@ function markAsLoaded() {
}
function hideModal(e) {
if(e) {
if (e) {
e.preventDefault();
}
// Unit editors do not want the modal cover to hide when users click outside
......@@ -511,7 +513,7 @@ function hideModal(e) {
}
function onKeyUp(e) {
if(e.which == 87) {
if (e.which == 87) {
$body.toggleClass('show-wip hide-wip');
}
}
......@@ -561,14 +563,14 @@ function showToastMessage(message, $button, lifespan) {
var $content = $('<div class="notification-content"></div>');
$content.html(message);
$toast.append($content);
if($button) {
if ($button) {
$button.addClass('action-button');
$button.bind('click', hideToastMessage);
$content.append($button);
}
$closeBtn.bind('click', hideToastMessage);
if($('.toast-notification')[0]) {
if ($('.toast-notification')[0]) {
var targetY = $('.toast-notification').offset().top + $('.toast-notification').outerHeight();
$toast.css('top', (targetY + 10) + 'px');
}
......@@ -576,8 +578,8 @@ function showToastMessage(message, $button, lifespan) {
$body.prepend($toast);
$toast.fadeIn(200);
if(lifespan) {
$toast.timer = setTimeout(function() {
if (lifespan) {
$toast.timer = setTimeout(function () {
$toast.fadeOut(300);
}, lifespan * 1000);
}
......@@ -603,7 +605,7 @@ function addNewSection(e, isTemplate) {
}
function checkForCancel(e) {
if(e.which == 27) {
if (e.which == 27) {
$body.unbind('keyup', checkForCancel);
e.data.$cancelButton.click();
}
......@@ -619,11 +621,11 @@ function saveNewSection(e) {
var display_name = $(this).find('.new-section-name').val();
$.post('/clone_item', {
'parent_location' : parent,
'template' : template,
'parent_location': parent,
'template': template,
'display_name': display_name,
},
function(data) {
function (data) {
if (data.id != undefined)
location.reload();
}
......@@ -640,7 +642,6 @@ function addNewCourse(e) {
e.preventDefault();
$(e.target).hide();
$('.content .introduction').hide();
var $newCourse = $($('#new-course-template').html());
var $cancelButton = $newCourse.find('.new-course-cancel');
$('.inner-wrapper').prepend($newCourse);
......@@ -659,18 +660,18 @@ function saveNewCourse(e) {
var number = $newCourse.find('.new-course-number').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.');
return;
}
$.post('/create_new_course', {
'template' : template,
'org' : org,
'number' : number,
'template': template,
'org': org,
'number': number,
'display_name': display_name
},
function(data) {
function (data) {
if (data.id != undefined) {
window.location = '/' + data.id.replace(/.*:\/\//, '');
} else if (data.ErrMsg != undefined) {
......@@ -682,7 +683,6 @@ function saveNewCourse(e) {
function cancelNewCourse(e) {
e.preventDefault();
$('.new-course-button').show();
$('.content .introduction').show();
$(this).parents('section.new-course').remove();
}
......@@ -715,11 +715,11 @@ function saveNewSubsection(e) {
var display_name = $(this).find('.new-subsection-name-input').val();
$.post('/clone_item', {
'parent_location' : parent,
'template' : template,
'parent_location': parent,
'template': template,
'display_name': display_name
},
function(data) {
function (data) {
if (data.id != undefined) {
location.reload();
}
......@@ -774,9 +774,8 @@ function saveEditSectionName(e) {
type: "POST",
dataType: "json",
contentType: "application/json",
data:JSON.stringify({ 'id' : id, 'metadata' : {'display_name' : display_name}})
}).success(function()
{
data: JSON.stringify({ 'id': id, 'metadata': {'display_name': display_name}})
}).success(function () {
$spinner.delay(250).fadeOut(250);
$_this.closest('h3').find('.section-name-span').html(display_name).show();
$_this.hide();
......@@ -813,9 +812,8 @@ function saveSetSectionScheduleDate(e) {
type: "POST",
dataType: "json",
contentType: "application/json",
data:JSON.stringify({ 'id' : id, 'metadata' : {'start' : start}})
}).success(function()
{
data: JSON.stringify({ 'id': id, 'metadata': {'start': start}})
}).success(function () {
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').animate({
......
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