Commit 4d2b35d2 by Will Daly

Merge pull request #89 from edx/will/save-ui-tweaks

UI tweaks to save response
parents b05d1134 460c5997
...@@ -10,7 +10,7 @@ from django.template.loader import get_template ...@@ -10,7 +10,7 @@ from django.template.loader import get_template
from webob import Response from webob import Response
from xblock.core import XBlock from xblock.core import XBlock
from xblock.fields import List, Scope, String from xblock.fields import List, Scope, String, Boolean
from xblock.fragment import Fragment from xblock.fragment import Fragment
from openassessment.xblock.grade_mixin import GradeMixin from openassessment.xblock.grade_mixin import GradeMixin
...@@ -205,6 +205,12 @@ class OpenAssessmentBlock( ...@@ -205,6 +205,12 @@ class OpenAssessmentBlock(
help="The student's submission that others will be assessing." help="The student's submission that others will be assessing."
) )
has_saved = Boolean(
default=False,
scope=Scope.user_state,
help="Indicates whether the user has saved a response"
)
saved_response = String( saved_response = String(
default=u"", default=u"",
scope=Scope.user_state, scope=Scope.user_state,
......
...@@ -177,9 +177,10 @@ OpenAssessment.BaseUI.prototype = { ...@@ -177,9 +177,10 @@ OpenAssessment.BaseUI.prototype = {
// Retrieve the student's response from the DOM // Retrieve the student's response from the DOM
var submission = $('#submission__answer__value', this.element).val(); var submission = $('#submission__answer__value', this.element).val();
var ui = this; var ui = this;
$('#response__save_status', this.element).html('Saving...');
this.server.save(submission).done(function() { this.server.save(submission).done(function() {
// Update the "saved" icon // Update the "saved" icon
$('#response__save_status', this.element).replaceWith("Saved"); $('#response__save_status', this.element).html("Saved but not submitted");
}).fail(function(errMsg) { }).fail(function(errMsg) {
// TODO: display to the user // TODO: display to the user
console.log(errMsg); console.log(errMsg);
......
...@@ -92,6 +92,7 @@ class SubmissionMixin(object): ...@@ -92,6 +92,7 @@ class SubmissionMixin(object):
if 'submission' in data: if 'submission' in data:
try: try:
self.saved_response = unicode(data['submission']) self.saved_response = unicode(data['submission'])
self.has_saved = True
except: except:
return {'success': False, 'msg': _(u"Could not save response submission")} return {'success': False, 'msg': _(u"Could not save response submission")}
else: else:
...@@ -149,6 +150,16 @@ class SubmissionMixin(object): ...@@ -149,6 +150,16 @@ class SubmissionMixin(object):
pass pass
return submissions[0] if submissions else None return submissions[0] if submissions else None
@property
def save_status(self):
"""
Return a string indicating whether the response has been saved.
Returns:
unicode
"""
return _(u'Saved but not submitted') if self.has_saved else _(u'Not saved')
@XBlock.handler @XBlock.handler
def render_submission(self, data, suffix=''): def render_submission(self, data, suffix=''):
"""Renders the Submission HTML section of the XBlock """Renders the Submission HTML section of the XBlock
...@@ -183,7 +194,7 @@ class SubmissionMixin(object): ...@@ -183,7 +194,7 @@ class SubmissionMixin(object):
"student_score": student_score, "student_score": student_score,
"step_status": step_status, "step_status": step_status,
"saved_response": self.saved_response, "saved_response": self.saved_response,
"save_status": _('Saved but not submitted') if len(self.saved_response) > 0 else _("Not saved"), "save_status": self.save_status
} }
path = "openassessmentblock/response/oa_response.html" path = "openassessmentblock/response/oa_response.html"
......
...@@ -14,6 +14,7 @@ class SaveResponseTest(XBlockHandlerTestCase): ...@@ -14,6 +14,7 @@ class SaveResponseTest(XBlockHandlerTestCase):
def test_default_saved_response_blank(self, xblock): def test_default_saved_response_blank(self, xblock):
resp = self.request(xblock, 'render_submission', json.dumps({})) resp = self.request(xblock, 'render_submission', json.dumps({}))
self.assertIn('<textarea id="submission__answer__value" placeholder=""></textarea>', resp) self.assertIn('<textarea id="submission__answer__value" placeholder=""></textarea>', resp)
self.assertIn('<div id="response__save_status">Not saved</div>', resp)
@ddt.file_data('data/save_responses.json') @ddt.file_data('data/save_responses.json')
@scenario('data/save_scenario.xml', user_id="Perleman") @scenario('data/save_scenario.xml', user_id="Perleman")
...@@ -31,6 +32,7 @@ class SaveResponseTest(XBlockHandlerTestCase): ...@@ -31,6 +32,7 @@ class SaveResponseTest(XBlockHandlerTestCase):
submitted=submission_text submitted=submission_text
) )
self.assertIn(expected_html, resp.decode('utf-8')) self.assertIn(expected_html, resp.decode('utf-8'))
self.assertIn('<div id="response__save_status">Saved but not submitted</div>', resp)
@scenario('data/save_scenario.xml', user_id="Valchek") @scenario('data/save_scenario.xml', user_id="Valchek")
def test_overwrite_saved_response(self, xblock): def test_overwrite_saved_response(self, xblock):
......
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