From: Aleksander Ɓukasz Date: Thu, 7 Aug 2014 14:18:38 +0000 (+0200) Subject: editor: temporary fix for invalid answer values in new exercise.order items X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/314bc2164ef9e9b94bd57eba48211e5df6002bf1?ds=inline;hp=-c editor: temporary fix for invalid answer values in new exercise.order items --- 314bc2164ef9e9b94bd57eba48211e5df6002bf1 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); });