1 define(function(require) {
7 var _ = require('libs/underscore');
9 var descriptionText = gettext('Description goes here') + '...',
10 firstItemText = gettext('First item') + '...';
12 var createAction = function(actionConfig) {
15 name: actionConfig.name,
17 fragment: {type: 'context', name: 'fragment'}
20 icon: actionConfig.icon || null,
21 execute: function(callback, params) {
25 var node = params.fragment.node;
26 if(node.nodeType === Node.TEXT_NODE) {
30 node.document.transaction(function() {
31 var exerciseNode = node.after(node.document.edumedCreateExerciseNode(actionConfig.exercise)),
32 doc = params.fragment.document,
36 if(actionConfig.exercise === 'order') {
37 exerciseNode.object.addItem(firstItemText);
38 cursorTarget = exerciseNode.contents('.p')[0].append({text: descriptionText});
39 } else if(_.contains(['gap', 'replace'], actionConfig.exercise)) {
40 cursorTarget = _.first(exerciseNode.contents('.p'));
42 cursorTarget = cursorTarget.append({text: ''});
44 } else if(actionConfig.exercise.split('.')[0] === 'choice') {
45 _.first(exerciseNode.find('p')).append({text: descriptionText});
46 cursorTarget = _.first(exerciseNode.find('item.answer'));
48 cursorTarget = cursorTarget.append({text: ''});
52 callback(doc.createFragment(doc.CaretFragment, {node: cursorTarget, offset: cursorTarget.getText().length}));
58 getState: function(params) {
60 allowed: params.fragment && params.fragment.isValid() && params.fragment instanceof params.fragment.NodeFragment && !params.fragment.node.isInside('exercise'),
61 description: gettext('Insert exercise: ' + actionConfig.exerciseTitle)
69 createAction({name: 'insertOrderExercise', icon: 'random', exercise: 'order', exerciseTitle: gettext('Order')}),
70 createAction({name: 'insertChoiceSingleExercise', icon: 'ok-circle', exercise: 'choice.single', exerciseTitle: gettext('Single choice')}),
71 createAction({name: 'insertChoiceMultiExercise', icon: 'check', exercise: 'choice', exerciseTitle: gettext('Mutiple Choice')}),
72 createAction({name: 'insertChoiceTrueOrFalseExercise', icon: 'adjust', exercise: 'choice.true-or-false', exerciseTitle: gettext('True or False')}),
73 createAction({name: 'insertGapsExercise', icon: 'question-sign', exercise: 'gap', exerciseTitle: gettext('Gaps')}),
74 createAction({name: 'insertReplaceExercise', icon: 'thumbs-down', exercise: 'replace', exerciseTitle: gettext('Replace')})