Commit 1a576b47 by swdanielli

move error msg to server and add UnderscoreJs

parent 5348193d
......@@ -440,6 +440,7 @@ class RecommenderXBlock(XBlock):
tracker.emit('upload_screenshot',
{'uploadedFileName': 'FILE_TYPE_ERROR'})
response.status = 415
response.body = json.dumps({'error': 'Please upload an image in GIF/JPG/PNG'})
return response
# Check whether file size exceeds threshold (30MB)
......@@ -448,6 +449,7 @@ class RecommenderXBlock(XBlock):
tracker.emit('upload_screenshot',
{'uploadedFileName': 'FILE_SIZE_ERROR'})
response.status = 413
response.body = json.dumps({'error': 'Size of uploaded file exceeds threshold'})
return response
try:
......@@ -463,6 +465,7 @@ class RecommenderXBlock(XBlock):
tracker.emit('upload_screenshot',
{'uploadedFileName': 'IMPROPER_S3_SETUP'})
response.status = 404
response.body = json.dumps({'error': 'The configuration of Amazon S3 is not properly set'})
return response
response = Response()
......@@ -707,6 +710,7 @@ class RecommenderXBlock(XBlock):
response.headers['Content-Type'] = 'text/plain'
if not self.get_user_is_staff():
response.status = 403
response.body = json.dumps({'error': 'Only staff can import resources'})
tracker.emit('import_resources', {'Status': 'NOT_A_STAFF'})
return response
......@@ -731,6 +735,7 @@ class RecommenderXBlock(XBlock):
return response
except:
response.status = 415
response.body = json.dumps({'error': 'Please submit the JSON file obtained with the download resources button'})
tracker.emit('import_resources', {'Status': 'FILE_FORMAT_ERROR', 'data': raw_data})
return response
......@@ -819,6 +824,7 @@ class RecommenderXBlock(XBlock):
frag.add_css(self.resource_string("static/css/tooltipster.css"))
frag.add_css(self.resource_string("static/css/recommender.css"))
frag.add_css(self.resource_string("static/css/introjs.css"))
frag.add_javascript(self.resource_string("static/js/src/underscore-min.js"))
frag.add_javascript(self.resource_string("static/js/src/jquery.tooltipster.min.js"))
frag.add_javascript(self.resource_string("static/js/src/cats.js"))
frag.add_javascript(self.resource_string("static/js/src/recommender.js"))
......
......@@ -63,12 +63,6 @@ var tooltipsCatsText = {
'.resourceRankingForRemovalButton.removeMode': '<span>Click to view resources in ordinary decreasing-vote order</span>'
};
var uploadFileErrorText = {
415: 'Please upload an image in GIF/JPG/PNG',
404: 'The configuration of Amazon S3 is not properly set',
413: 'Size of uploaded file exceeds threshold'
};
var importResourceErrorText = {
403: 'Only staff can import resources',
415: 'Please submit the JSON file obtained with the download resources button'
......
if (typeof Logger === 'undefined') {
var Logger = {
log: function(a) { return; }
log: function(a, b) { return; }
}
}
......@@ -27,16 +27,10 @@ function RecommenderXBlock(runtime, element, init_data) {
* @returns {dictionary} The dictionary for logging an event.
*/
function generateLog(status, information) {
if (!information) {
return { 'status': status, 'element': $(element).attr('data-usage-id') };
}
else {
return {
'status': status,
'information': information,
'element': $(element).attr('data-usage-id')
}
}
return _.find([
{'status': status, 'element': $(element).attr('data-usage-id')},
{'status': status, 'element': $(element).attr('data-usage-id'), 'information': information}
], function(log) { return information === log.information; });
}
/**
......@@ -238,8 +232,9 @@ function RecommenderXBlock(runtime, element, init_data) {
backToView();
Logger.log('mit.recommender.importResource', generateLog(loggerStatus['importResource']['complete'], result));
},
error: function(result, status) {
alert(importResourceErrorText[result.status]);
error: function(result) {
var data = JSON.parse(result.responseText)
if (data.error) { alert(data.error); }
resetImportResourcePage();
},
});
......@@ -454,7 +449,8 @@ function RecommenderXBlock(runtime, element, init_data) {
* 404: The filesystem (e.g., Amazon S3) is not properly set
* 413: Size of uploaded file exceeds threshold
*/
alert(uploadFileErrorText[result.status]);
var data = JSON.parse(result.responseText)
if (data.error) { alert(data.error); }
$("input[name='file']", formDiv).val('');
if (writeType === writeDatabaseEnum.ADD) { enableAddSubmit(); }
else if (writeType === writeDatabaseEnum.EDIT) { enableEditSubmit(); }
......@@ -671,7 +667,7 @@ function RecommenderXBlock(runtime, element, init_data) {
data['title'] = $('.editTitle', element).val();
data['descriptionText'] = $('.editDescriptionText', element).val();
data['description'] = ''
if (data['url'] === '' || data['title'] === '') { return; }
if (!data.url || data.title) { return; }
var formDiv = $('.editResourceForm', element);
var file = new FormData($(formDiv)[0]);
......
......@@ -20,6 +20,9 @@ function RecommenderXBlock(runtime, element) {
success: function(result) {
alert('The configurations have been updated');
}
error: function(result) {
alert('An internal error happened. We cannot set the configurations right now. Please try again later.');
}
});
});
}
......
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