X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e3f4ff223c5acd7cf97b6a9ba1cdd83111dba63b..5028701711e4a1ee85e88f5ff7f1caf911dad8e5:/src/wlxml/extensions/edumed/edumed.js diff --git a/src/wlxml/extensions/edumed/edumed.js b/src/wlxml/extensions/edumed/edumed.js index 3176ae0..fb0885a 100644 --- a/src/wlxml/extensions/edumed/edumed.js +++ b/src/wlxml/extensions/edumed/edumed.js @@ -149,6 +149,59 @@ var extension = {wlxmlClass: {'exercise.order': { } }}}; +var choiceMethods = { + getChoiceList: function() { + return this.contents() + .filter(function(n) { return this.object.isChoiceList(n); }.bind(this))[0]; + }, + isChoiceList: function(node) { + return node.is('list') && this.sameNode(node.parent()); + }, + isChoiceListItem: function(node) { + return this.object.isChoiceList(node.parent()) && node.is('item.answer'); + } +}; + +extension.wlxmlClass['exercise.choice'] = { + transformations: { + setAnswer: function(itemNode, answer) { + if(!this.object.isChoiceListItem(itemNode)) { + return; + } + itemNode.setAttr('answer', answer ? 'true' : 'false'); + } + }, + methods: choiceMethods +}; + +extension.wlxmlClass['exercise.choice.single'] = { + transformations: { + markAsAnswer: function(itemNode) { + if(!this.object.isChoiceListItem(itemNode)) { + return; + } + this.object.getChoiceList().contents() + .filter(function(node) { return node.is('item.answer'); }) + .forEach(function(node) { + node.setAttr('answer', node.sameNode(itemNode) ? 'true' : 'false'); + }); + } + }, + methods: choiceMethods +}; + +extension.wlxmlClass['exercise.choice.true-or-false'] = { + transformations: { + setAnswer: function(itemNode, answer) { + if(!this.object.isChoiceListItem(itemNode)) { + return; + } + itemNode.setAttr('answer', answer ? 'true' : 'false'); + } + }, + methods: choiceMethods +}; + extension.document = { methods: { edumedCreateExerciseNode: function(klass) {