Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep items in dropped position in assessment mode. #82

Merged
merged 1 commit into from
Jul 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions drag_and_drop_v2/drag_and_drop_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def items_without_answers():
return items

return {
"mode": self.mode,
"zones": self._get_zones(),
# SDK doesn't supply url_name.
"url_name": getattr(self, 'url_name', ''),
Expand Down Expand Up @@ -337,12 +338,18 @@ def do_attempt(self, attempt, suffix=''):
'is_correct': is_correct,
})

return {
'correct': is_correct,
'finished': self._is_finished(),
'overall_feedback': overall_feedback,
'feedback': feedback
}
if self.mode == self.ASSESSMENT_MODE:
# In assessment mode we don't send any feedback on drop.
result = {}
else:
result = {
'correct': is_correct,
'finished': self._is_finished(),
'overall_feedback': overall_feedback,
'feedback': feedback
}

return result

@XBlock.json_handler
def reset(self, data, suffix=''):
Expand Down
52 changes: 34 additions & 18 deletions drag_and_drop_v2/public/js/drag_and_drop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function DragNDropTemplates(url_name) {
function DragAndDropTemplates(configuration) {
"use strict";
var h = virtualDom.h;
// Set up a mock for gettext if it isn't available in the client runtime:
Expand Down Expand Up @@ -107,13 +107,22 @@ function DragNDropTemplates(url_name) {
var item_content = h('div', { innerHTML: item_content_html, className: "item-content" });
if (item.is_placed) {
// Insert information about zone in which this item has been placed
var item_description_id = url_name + '-item-' + item.value + '-description';
var item_description_id = configuration.url_name + '-item-' + item.value + '-description';
item_content.properties.attributes = { 'aria-describedby': item_description_id };
var zone_title = (zone.title || "Unknown Zone"); // This "Unknown" text should never be seen, so does not need i18n
var description_content;
if (configuration.mode === DragAndDropBlock.ASSESSMENT_MODE) {
// In assessment mode placed items will "stick" even when not in correct zone.
description_content = gettext('Placed in: {zone_title}').replace('{zone_title}', zone_title);
} else {
// In standard mode item is immediately returned back to the bank if dropped on a wrong zone,
// so all placed items are always in the correct zone.
description_content = gettext('Correctly placed in: {zone_title}').replace('{zone_title}', zone_title);
}
var item_description = h(
'div',
{ id: item_description_id, className: 'sr' },
gettext('Correctly placed in: ') + zone_title
description_content
);
children.splice(1, 0, item_description);
}
Expand Down Expand Up @@ -283,14 +292,17 @@ function DragNDropTemplates(url_name) {
);
};

DragAndDropBlock.renderView = mainTemplate;

return mainTemplate;
}

function DragAndDropBlock(runtime, element, configuration) {
"use strict";

DragNDropTemplates(configuration.url_name);
DragAndDropBlock.STANDARD_MODE = 'standard';
DragAndDropBlock.ASSESSMENT_MODE = 'assessment';

var renderView = DragAndDropTemplates(configuration);

// Set up a mock for gettext if it isn't available in the client runtime:
if (!window.gettext) { window.gettext = function gettext_stub(string) { return string; }; }

Expand Down Expand Up @@ -747,17 +759,21 @@ function DragAndDropBlock(runtime, element, configuration) {

$.post(url, JSON.stringify(data), 'json')
.done(function(data){
state.last_action_correct = data.correct;
if (data.correct) {
state.items[item_id].correct = true;
state.items[item_id].submitting_location = false;
} else {
delete state.items[item_id];
}
state.feedback = data.feedback;
if (data.finished) {
state.finished = true;
state.overall_feedback = data.overall_feedback;
state.items[item_id].submitting_location = false;
// In standard mode we immediately return item to the bank if dropped on wrong zone.
// In assessment mode we leave it in the chosen zone until explicit answer submission.
if (configuration.mode === DragAndDropBlock.STANDARD_MODE) {
state.last_action_correct = data.correct;
if (data.correct) {
state.items[item_id].correct = true;
} else {
delete state.items[item_id];
}
state.feedback = data.feedback;
if (data.finished) {
state.finished = true;
state.overall_feedback = data.overall_feedback;
}
}
applyState();
})
Expand Down Expand Up @@ -866,7 +882,7 @@ function DragAndDropBlock(runtime, element, configuration) {
display_reset_button: Object.keys(state.items).length > 0,
};

return DragAndDropBlock.renderView(context);
return renderView(context);
};

/**
Expand Down
4 changes: 4 additions & 0 deletions drag_and_drop_v2/translations/en/LC_MESSAGES/text.po
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ msgstr ""
msgid "ok"
msgstr ""

#: public/js/drag_and_drop.js
msgid "Placed in: "
msgstr ""

#: public/js/drag_and_drop.js
msgid "Correctly placed in: "
msgstr ""
Expand Down
4 changes: 4 additions & 0 deletions drag_and_drop_v2/translations/eo/LC_MESSAGES/text.po
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ msgstr "Çänçél Ⱡ'σяєм ιρѕυ#"
msgid "ok"
msgstr "ök Ⱡ'σя#"

#: public/js/drag_and_drop.js
msgid "Placed in: "
msgstr "Pläçéd ïn: Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, #"

#: public/js/drag_and_drop.js
msgid "Correctly placed in: "
msgstr "Çörréçtlý pläçéd ïn: Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, #"
Expand Down
Loading