Skip to content

Commit

Permalink
Merge pull request #85 from arbisoft/fix_js_lint_issues
Browse files Browse the repository at this point in the history
fix jshint indentified issue for all studio and edx_sga file
  • Loading branch information
carsongee committed Apr 28, 2015
2 parents 1a0b28d + ee26d64 commit bf7914c
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 94 deletions.
179 changes: 89 additions & 90 deletions edx_sga/static/js/src/edx_sga.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ function StaffGradedAssignmentXBlock(runtime, element) {
var uploadUrl = runtime.handlerUrl(element, 'upload_assignment');
var downloadUrl = runtime.handlerUrl(element, 'download_assignment');
var annotatedUrl = runtime.handlerUrl(element, 'download_annotated');
var getStaffGradingUrl = runtime.handlerUrl(element, 'get_staff_grading_data');
var getStaffGradingUrl = runtime.handlerUrl(
element, 'get_staff_grading_data'
);
var staffDownloadUrl = runtime.handlerUrl(element, 'staff_download');
var staffAnnotatedUrl = runtime.handlerUrl(element, 'staff_download_annotated');
var staffAnnotatedUrl = runtime.handlerUrl(
element, 'staff_download_annotated'
);
var staffUploadUrl = runtime.handlerUrl(element, 'staff_upload_annotated');
var enterGradeUrl = runtime.handlerUrl(element, 'enter_grade');
var removeGradeUrl = runtime.handlerUrl(element, 'remove_grade');
Expand All @@ -17,28 +21,29 @@ function StaffGradedAssignmentXBlock(runtime, element) {
// Add download urls to template context
state.downloadUrl = downloadUrl;
state.annotatedUrl = annotatedUrl;
state.error = state.error ? state.error : false;
state.error = state.error || false;

// Render template
var content = $(element).find("#sga-content").html(template(state));
var content = $(element).find('#sga-content').html(template(state));

// Set up file upload
$(content).find(".fileupload").fileupload({
$(content).find('.fileupload').fileupload({
url: uploadUrl,
add: function(e, data) {
var do_upload = $(content).find(".upload").html('');
$(content).find('p.error').html("");
var do_upload = $(content).find('.upload').html('');
$(content).find('p.error').html('');
$('<button/>')
.text('Upload ' + data.files[0].name)
.appendTo(do_upload)
.click(function() {
do_upload.text("Uploading...");
do_upload.text('Uploading...');
var block = $(element).find(".sga-block");
var data_max_size = block.attr("data-max-size");
var size = data.files[0].size;
if (!_.isUndefined(size)) {
if (size >= data_max_size) { //if file size is larger max file size define in env(django)
state.error = "The file you are trying to upload is too large.";
//if file size is larger max file size define in env(django)
if (size >= data_max_size) {
state.error = 'The file you are trying to upload is too large.';
render(state);
return;
}
Expand All @@ -48,100 +53,98 @@ function StaffGradedAssignmentXBlock(runtime, element) {
},
progressall: function(e, data) {
var percent = parseInt(data.loaded / data.total * 100, 10);
$(content).find(".upload").text(
"Uploading... " + percent + "%");
$(content).find('.upload').text(
'Uploading... ' + percent + '%');
},
fail: function(e, data) {
/**
* Nginx and other sanely implemented servers return a
* "413 Request entity too large" status code if an
* Nginx and other sanely implemented servers return a
* "413 Request entity too large" status code if an
* upload exceeds its limit. See the 'done' handler for
* the not sane way that Django handles the same thing.
*/
if (data.jqXHR.status == 413) {
if (data.jqXHR.status === 413) {
/* I guess we have no way of knowing what the limit is
* here, so no good way to inform the user of what the
* limit is.
*/
state.error = "The file you are trying to upload is too large."
}
else {
state.error = 'The file you are trying to upload is too large.';
} else {
// Suitably vague
state.error = "There was an error uploading your file.";
state.error = 'There was an error uploading your file.';

// Dump some information to the console to help someone
// debug.
console.log("There was an error with file upload.");
console.log("event: ", e);
console.log("data: ", data);
console.log('There was an error with file upload.');
console.log('event: ', e);
console.log('data: ', data);
}
render(state);
},
done: function(e, data) {
done: function(e, data) {
/* When you try to upload a file that exceeds Django's size
* limit for file uploads, Django helpfully returns a 200 OK
* response with a JSON payload of the form:
*
*
* {'success': '<error message'}
*
*
* Thanks Obama!
*/
if (data.result.success !== undefined) {
// Actually, this is an error
state.error = data.result.success;
render(state);
}
else {
} else {
// The happy path, no errors
render(data.result);
render(data.result);
}
}
});
}

function renderStaffGrading(data) {
$(".grade-modal").hide();
$('.grade-modal').hide();

if (data.display_name != ""){
$(".sga-block .display_name").html(data.display_name);
if (data.display_name !== '') {
$('.sga-block .display_name').html(data.display_name);
}

// Add download urls to template context
data.downloadUrl = staffDownloadUrl;
data.annotatedUrl = staffAnnotatedUrl;

// Render template
$(element).find("#grade-info")
$(element).find('#grade-info')
.html(gradingTemplate(data))
.data(data);

// Map data to table rows
data.assignments.map(function(assignment) {
$(element).find("#grade-info #row-" + assignment.module_id)
$(element).find('#grade-info #row-' + assignment.module_id)
.data(assignment);
});

// Set up grade entry modal
$(element).find(".enter-grade-button")
.leanModal({closeButton: "#enter-grade-cancel"})
.on("click", handleGradeEntry);
$(element).find('.enter-grade-button')
.leanModal({closeButton: '#enter-grade-cancel'})
.on('click', handleGradeEntry);

// Set up annotated file upload
$(element).find("#grade-info .fileupload").each(function() {
$(element).find('#grade-info .fileupload').each(function() {
var row = $(this).parents("tr");
var url = staffUploadUrl + "?module_id=" + row.data("module_id");
$(this).fileupload({
url: url,
progressall: function(e, data) {
var percent = parseInt(data.loaded / data.total * 100, 10);
row.find(".upload").text("Uploading... " + percent + "%");
row.find('.upload').text('Uploading... ' + percent + '%');
},
done: function(e, data) {
done: function(e, data) {
// Add a time delay so user will notice upload finishing
// for small files
setTimeout(
function() { renderStaffGrading(data.result); },
3000)
function() { renderStaffGrading(data.result); },
3000);
}
});
});
Expand All @@ -151,105 +154,101 @@ function StaffGradedAssignmentXBlock(runtime, element) {
function handleGradeEntry() {
var row = $(this).parents("tr");
var form = $(element).find("#enter-grade-form");
$(element).find("#student-name").text(row.data("fullname"));
form.find("#module_id-input").val(row.data("module_id"));
form.find("#submission_id-input").val(row.data("submission_id"));
form.find("#grade-input").val(row.data("score"));
form.find("#comment-input").text(row.data("comment"));
form.off("submit").on("submit", function(event) {
var max_score = row.parents("#grade-info").data("max_score");
var score = Number(form.find("#grade-input").val());
$(element).find('#student-name').text(row.data('fullname'));
form.find('#module_id-input').val(row.data('module_id'));
form.find('#submission_id-input').val(row.data('submission_id'));
form.find('#grade-input').val(row.data('score'));
form.find('#comment-input').text(row.data('comment'));
form.off('submit').on('submit', function(event) {
var max_score = row.parents('#grade-info').data('max_score');
var score = Number(form.find('#grade-input').val());
event.preventDefault();
if (isNaN(score)) {
form.find(".error").html("<br/>Grade must be a number.");
}
else if (score != parseInt(score)) {
form.find(".error").html("<br/>Grade must be an integer.");
}
else if (score < 0) {
form.find(".error").html("<br/>Grade must be positive.");
}
else if (score > max_score) {
form.find(".error").html("<br/>Maximum score is " + max_score);
}
else {
form.find('.error').html('<br/>Grade must be a number.');
} else if (score !== parseInt(score)) {
form.find('.error').html('<br/>Grade must be an integer.');
} else if (score < 0) {
form.find('.error').html('<br/>Grade must be positive.');
} else if (score > max_score) {
form.find('.error').html('<br/>Maximum score is ' + max_score);
} else {
// No errors
$.post(enterGradeUrl, form.serialize())
.success(renderStaffGrading);
}
});
form.find("#remove-grade").on("click", function() {
var url = removeGradeUrl + "?module_id=" +
row.data("module_id") + "&student_id=" +
row.data("student_id");
form.find('#remove-grade').on('click', function() {
var url = removeGradeUrl + '?module_id=' +
row.data('module_id') + '&student_id=' +
row.data('student_id');
$.get(url).success(renderStaffGrading);
});
form.find("#enter-grade-cancel").on("click", function() {
form.find('#enter-grade-cancel').on('click', function() {
/* We're kind of stretching the limits of leanModal, here,
* by nesting modals one on top of the other. One side effect
* is that when the enter grade modal is closed, it hides
* the overlay for itself and for the staff grading modal,
* so the overlay is no longer present to click on to close
* the staff grading modal. Since leanModal uses a fade out
* time of 200ms to hide the overlay, our work around is to
* time of 200ms to hide the overlay, our work around is to
* wait 225ms and then just "click" the 'Grade Submissions'
* button again. It would also probably be pretty
* button again. It would also probably be pretty
* straightforward to submit a patch to leanModal so that it
* would work properly with nested modals.
*
* See: https://github.com/mitodl/edx-sga/issues/13
*/
setTimeout(function() {
$("#grade-submissions-button").click();
$('#grade-submissions-button').click();
}, 225);
});
}

$(function($) { // onLoad
var block = $(element).find(".sga-block");
var state = block.attr("data-state");
var block = $(element).find('.sga-block');
var state = block.attr('data-state');
render(JSON.parse(state));

var is_staff = block.attr("data-staff") == "True";
var is_staff = block.attr('data-staff') == 'True';
if (is_staff) {
gradingTemplate = _.template(
$(element).find("#sga-grading-tmpl").text());
block.find("#grade-submissions-button")
$(element).find('#sga-grading-tmpl').text());
block.find('#grade-submissions-button')
.leanModal()
.on("click", function() {
.on('click', function() {
$.ajax({
url: getStaffGradingUrl,
success: renderStaffGrading
});
});
block.find("#staff-debug-info-button")
block.find('#staff-debug-info-button')
.leanModal();
}
});
}

if (require === undefined) {
/**
function loadjs(url) {
$('<script>')
.attr('type', 'text/javascript')
.attr('src', url)
.appendTo(element);
}

if (require === undefined) {
/**
* The LMS does not use require.js (although it loads it...) and
* does not already load jquery.fileupload. (It looks like it uses
* jquery.ajaxfileupload instead. But our XBlock uses
* jquery.ajaxfileupload instead. But our XBlock uses
* jquery.fileupload.
*/
function loadjs(url) {
$("<script>")
.attr("type", "text/javascript")
.attr("src", url)
.appendTo(element);
}
loadjs("/static/js/vendor/jQuery-File-Upload/js/jquery.iframe-transport.js");
loadjs("/static/js/vendor/jQuery-File-Upload/js/jquery.fileupload.js");
loadjs('/static/js/vendor/jQuery-File-Upload/js/jquery.iframe-transport.js');
loadjs('/static/js/vendor/jQuery-File-Upload/js/jquery.fileupload.js');
xblock($, _);
}
else {
} else {
/**
* Studio, on the other hand, uses require.js and already knows about
* jquery.fileupload.
*/
require(["jquery", "underscore", "jquery.fileupload"], xblock);
require(['jquery', 'underscore', 'jquery.fileupload'], xblock);
}
}
8 changes: 4 additions & 4 deletions edx_sga/static/js/src/studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ function StaffGradedAssignmentXBlock(runtime, element, server) {
'string': function(x) {
return !x ? null : x;
}
}
};

function save() {
var view = this;
view.runtime.notify('save', {state: 'start'});

var data = {};
$(element).find("input").each(function(index, input) {
$(element).find('input').each(function(index, input) {
data[input.name] = input.value;
});

$.ajax({
type: "POST",
type: 'POST',
url: saveUrl,
data: JSON.stringify(data),
success: function() {
Expand All @@ -31,5 +31,5 @@ function StaffGradedAssignmentXBlock(runtime, element, server) {

return {
save: save
}
};
}

0 comments on commit bf7914c

Please sign in to comment.