From: Aleksander Ɓukasz Date: Wed, 6 Aug 2014 11:58:44 +0000 (+0200) Subject: editor: Missing exercise actions X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/b77bfa044453a746889284a4fd9a433a96b17619?hp=533315fd2da2d90c678e54801dd97c9114335a20 editor: Missing exercise actions --- diff --git a/src/editor/plugins/core/edumed/actions.js b/src/editor/plugins/core/edumed/actions.js index 8b968b8..97237ba 100644 --- a/src/editor/plugins/core/edumed/actions.js +++ b/src/editor/plugins/core/edumed/actions.js @@ -1,9 +1,13 @@ -define(function() { +define(function(require) { 'use strict'; /* globals gettext */ +var _ = require('libs/underscore'); + +var descriptionText = gettext('Description goes here') + '...', + firstItemText = gettext('First item') + '...'; var createAction = function(actionConfig) { @@ -24,12 +28,28 @@ var createAction = function(actionConfig) { } node.document.transaction(function() { - var exerciseNode = node.after(node.document.edumedCreateExerciseNode(actionConfig.exercise)); + var exerciseNode = node.after(node.document.edumedCreateExerciseNode(actionConfig.exercise)), + doc = params.fragment.document, + cursorTarget; //@@ if(actionConfig.exercise === 'order') { - exerciseNode.object.addItem('first item'); - exerciseNode.contents('.p')[0].append({text: 'Write here...'}); + exerciseNode.object.addItem(firstItemText); + cursorTarget = exerciseNode.contents('.p')[0].append({text: descriptionText}); + } else if(_.contains(['gap', 'replace'], actionConfig.exercise)) { + cursorTarget = _.first(exerciseNode.contents('.p')); + if(cursorTarget) { + cursorTarget = cursorTarget.append({text: ''}); + } + } else if(actionConfig.exercise.split('.')[0] === 'choice') { + _.first(exerciseNode.find('p')).append({text: descriptionText}); + cursorTarget = _.first(exerciseNode.find('item.answer')); + if(cursorTarget) { + cursorTarget = cursorTarget.append({text: ''}); + } + } + if(cursorTarget) { + callback(doc.createFragment(doc.CaretFragment, {node: cursorTarget, offset: cursorTarget.getText().length})); } }); @@ -46,7 +66,12 @@ var createAction = function(actionConfig) { }; return [ - createAction({name: 'insertOrderExercise', icon: 'random', exercise: 'order', exerciseTitle: gettext('Order') }) + createAction({name: 'insertOrderExercise', icon: 'random', exercise: 'order', exerciseTitle: gettext('Order')}), + createAction({name: 'insertChoiceSingleExercise', icon: 'ok-circle', exercise: 'choice.single', exerciseTitle: gettext('Single choice')}), + createAction({name: 'insertChoiceMultiExercise', icon: 'check', exercise: 'choice', exerciseTitle: gettext('Mutiple Choice')}), + createAction({name: 'insertChoiceTrueOrFalseExercise', icon: 'adjust', exercise: 'choice.true-or-false', exerciseTitle: gettext('True or False')}), + createAction({name: 'insertGapsExercise', icon: 'question-sign', exercise: 'gap', exerciseTitle: gettext('Gaps')}), + createAction({name: 'insertReplaceExercise', icon: 'thumbs-down', exercise: 'replace', exerciseTitle: gettext('Replace')}) ]; -}); \ No newline at end of file +});