editor: Missing exercise actions
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 6 Aug 2014 11:58:44 +0000 (13:58 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 14 Aug 2014 14:26:14 +0000 (16:26 +0200)
src/editor/plugins/core/edumed/actions.js

index 8b968b8..97237ba 100644 (file)
@@ -1,9 +1,13 @@
-define(function() {
+define(function(require) {
     
 'use strict';
 
 /* globals gettext */
 
     
 'use strict';
 
 /* globals gettext */
 
+var _ = require('libs/underscore');
+
+var descriptionText = gettext('Description goes here') + '...',
+    firstItemText = gettext('First item') + '...';
 
 var createAction = function(actionConfig) {
 
 
 var createAction = function(actionConfig) {
 
@@ -24,12 +28,28 @@ var createAction = function(actionConfig) {
                 }
 
                 node.document.transaction(function() {
                 }
 
                 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') {
 
                     //@@
                     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 [
 };
 
 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
+});