From 314bc2164ef9e9b94bd57eba48211e5df6002bf1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 7 Aug 2014 16:18:38 +0200 Subject: [PATCH] editor: temporary fix for invalid answer values in new exercise.order items --- src/editor/plugins/core/core.js | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index 3921635..31ac09d 100644 --- a/src/editor/plugins/core/core.js +++ b/src/editor/plugins/core/core.js @@ -15,6 +15,27 @@ var _ = require('libs/underscore'), edumed = require('plugins/core/edumed/edumed'); +var exerciseFix = function(newNodes) { + var list, exercise, max, addedItem, answerValues; + if(newNodes.created.is('item')) { + list = newNodes.created.parent(); + exercise = list.parent(); + if(exercise && exercise.is('exercise')) { + if(exercise.is('exercise.order')) { + answerValues = exercise.object.getItems() + .map(function(item) { + if(!addedItem && item.node.sameNode(newNodes.created)) { + addedItem = item; + } + return item.getAnswer(); + }); + max = Math.max.apply(Math.max, answerValues); + addedItem.setAnswer(max + 1); + } + } + } +}; + plugin.documentExtension.textNode.transformations = { breakContent: { impl: function(args) { @@ -38,6 +59,21 @@ plugin.documentExtension.textNode.transformations = { return true; // break } }); + + /* + /* + This makes sure that adding a new item to the list in some of the edumed exercises + sets an answer attribute that makes sense (and not just copies it which would create + a duplicate value). + + This won't be neccessary when/if we introduce canvas element own key event handlers. + + Alternatively, WLXML elements could implement their own item split methods that we + would delegate to. + */ + exerciseFix(newNodes); + /* */ + parentDescribingNodes.forEach(function(node) { newNodes.first.append(node); }); -- 2.20.1