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) {
29 if(node.isInside('exercise')) {
30 node = node.getParent('exercise');
33 node.document.transaction(function() {
34 var exerciseNode = node.after(node.document.edumedCreateExerciseNode(actionConfig.exercise)),
35 doc = params.fragment.document,
39 if(actionConfig.exercise === 'order') {
40 exerciseNode.object.addItem(firstItemText);
41 cursorTarget = exerciseNode.contents('.p')[0].append({text: descriptionText});
42 } else if(_.contains(['gap', 'replace'], actionConfig.exercise)) {
43 cursorTarget = _.first(exerciseNode.contents('.p'));
45 cursorTarget = cursorTarget.append({text: ''});
47 } else if(actionConfig.exercise.split('.')[0] === 'choice') {
48 _.first(exerciseNode.find('p')).append({text: descriptionText});
49 cursorTarget = _.first(exerciseNode.find('item.answer'));
51 cursorTarget = cursorTarget.append({text: ''});
55 callback(doc.createFragment(doc.CaretFragment, {node: cursorTarget, offset: cursorTarget.getText().length}));
61 getState: function(params) {
63 allowed: params.fragment && params.fragment.isValid() && params.fragment instanceof params.fragment.NodeFragment,
64 description: gettext('Insert exercise: ' + actionConfig.exerciseTitle)
72 createAction({name: 'insertOrderExercise', icon: 'random', exercise: 'order', exerciseTitle: gettext('Order')}),
73 createAction({name: 'insertChoiceSingleExercise', icon: 'ok-circle', exercise: 'choice.single', exerciseTitle: gettext('Single choice')}),
74 createAction({name: 'insertChoiceMultiExercise', icon: 'check', exercise: 'choice', exerciseTitle: gettext('Mutiple Choice')}),
75 createAction({name: 'insertChoiceTrueOrFalseExercise', icon: 'adjust', exercise: 'choice.true-or-false', exerciseTitle: gettext('True or False')}),
76 createAction({name: 'insertGapsExercise', icon: 'question-sign', exercise: 'gap', exerciseTitle: gettext('Gaps')}),
77 createAction({name: 'insertReplaceExercise', icon: 'thumbs-down', exercise: 'replace', exerciseTitle: gettext('Replace')})