fnp
/
fnpeditor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
shuffle answers in exercise order + fix answer numbering
[fnpeditor.git]
/
src
/
editor
/
plugins
/
core
/
edumed
/
order
/
view.js
diff --git
a/src/editor/plugins/core/edumed/order/view.js
b/src/editor/plugins/core/edumed/order/view.js
index
a90ded4
..
4b470e6
100644
(file)
--- a/
src/editor/plugins/core/edumed/order/view.js
+++ b/
src/editor/plugins/core/edumed/order/view.js
@@
-14,21
+14,20
@@
var OrderExerciseView = function(element) {
this.dom = $(_.template(viewTemplate)());
this.modePills = this.dom.find('.modePills');
this.list = this.dom.find('ol');
this.dom = $(_.template(viewTemplate)());
this.modePills = this.dom.find('.modePills');
this.list = this.dom.find('ol');
- this.addButton = this.dom.find('button.add');
this.description = this.dom.find('.description');
this.description = this.dom.find('.description');
+ this.shuffleButton = this.dom.find('.shuffle');
this.itemViews = [];
this.itemViews = [];
- this.
addButton
.on('click', function(e) {
+ this.
modePills.find('a')
.on('click', function(e) {
e.stopPropagation();
e.preventDefault();
e.stopPropagation();
e.preventDefault();
- this.trigger('newItemRequested');
- //_.last(this.itemViews).editStart();
+ this.setMode($(e.target).parent().attr('mode'));
}.bind(this));
}.bind(this));
- this.
modePills.find('a')
.on('click', function(e) {
+ this.
shuffleButton
.on('click', function(e) {
e.stopPropagation();
e.preventDefault();
e.stopPropagation();
e.preventDefault();
- this.
setMode($(e.target).parent().attr('mode')
);
+ this.
trigger('shuffleItems'
);
}.bind(this));
this.mode = 'initial';
}.bind(this));
this.mode = 'initial';
@@
-42,13
+41,7
@@
var OrderExerciseView = function(element) {
dropTargets.on('dragenter', function() {
var first = this.itemViews[0];
if(this.mode === 'correct') {
dropTargets.on('dragenter', function() {
var first = this.itemViews[0];
if(this.mode === 'correct') {
- first = this.itemViews.slice(0)
- .sort(function(view1, view2) {
- if(view1.item.getAnswer() > view2.item.getAnswer()) {
- return 1;
- }
- return -1;
- })[0];
+ first = this.sortedItemViews()[0];
}
if(!this.allowDropAt(first, true)) {
return;
}
if(!this.allowDropAt(first, true)) {
return;
@@
-71,13
+64,7
@@
var OrderExerciseView = function(element) {
var first = this.itemViews[0];
if(this.mode === 'correct') {
var first = this.itemViews[0];
if(this.mode === 'correct') {
- first = this.itemViews.slice(0)
- .sort(function(view1, view2) {
- if(view1.item.getAnswer() > view2.item.getAnswer()) {
- return 1;
- }
- return -1;
- })[0];
+ first = this.sortedItemViews()[0];
}
this.trigger(this.mode === 'initial' ? 'moveItem' : 'moveAnswer', droppedItem.item, first.item, 'before');
}
this.trigger(this.mode === 'initial' ? 'moveItem' : 'moveAnswer', droppedItem.item, first.item, 'before');
@@
-88,9
+75,6
@@
var OrderExerciseView = function(element) {
_.extend(OrderExerciseView.prototype, Backbone.Events, {
addItem: function(item) {
var view = new ItemView(item, this);
_.extend(OrderExerciseView.prototype, Backbone.Events, {
addItem: function(item) {
var view = new ItemView(item, this);
- view.on('edit', function(text) {
- this.trigger('itemEdited', item, text);
- }.bind(this));
view.on('receivedDrop', function(droppedItem) {
this.trigger(this.mode === 'initial' ? 'moveItem' : 'moveAnswer', droppedItem.item, item, 'after');
}.bind(this));
view.on('receivedDrop', function(droppedItem) {
this.trigger(this.mode === 'initial' ? 'moveItem' : 'moveAnswer', droppedItem.item, item, 'after');
}.bind(this));
@@
-121,19
+105,24
@@
_.extend(OrderExerciseView.prototype, Backbone.Events, {
this.itemViews.forEach(function(itemView) {
this.list.append(itemView.dom);
}.bind(this));
this.itemViews.forEach(function(itemView) {
this.list.append(itemView.dom);
}.bind(this));
+ this.shuffleButton.show();
} else {
} else {
- this.itemViews.slice(0)
- .sort(function(view1, view2) {
- if(view1.item.getAnswer() > view2.item.getAnswer()) {
- return 1;
- }
- return -1;
- })
+ this.sortedItemViews()
.forEach(function(itemView) {
this.list.append(itemView.dom);
}.bind(this));
.forEach(function(itemView) {
this.list.append(itemView.dom);
}.bind(this));
+ this.shuffleButton.hide();
}
},
}
},
+ sortedItemViews: function () {
+ return this.itemViews.slice(0)
+ .sort(function(view1, view2) {
+ if(view1.item.getAnswer() > view2.item.getAnswer()) {
+ return 1;
+ }
+ return -1;
+ });
+ },
allowDropAt: function(view, up) {
var arr = [this.draggedView.dom[0]];
if(!up) {
allowDropAt: function(view, up) {
var arr = [this.draggedView.dom[0]];
if(!up) {