8b968b87244286ead669a7e32ee02a58455f5fe8
[fnpeditor.git] / src / editor / plugins / core / edumed / actions.js
1 define(function() {
2     
3 'use strict';
4
5 /* globals gettext */
6
7
8 var createAction = function(actionConfig) {
9
10     return {
11         name: actionConfig.name,
12         params: {
13             fragment: {type: 'context', name: 'fragment'}
14         },
15         stateDefaults: {
16             icon: actionConfig.icon || null,
17             execute: function(callback, params) {
18                 /* globals Node */
19                 void(callback);
20
21                 var node = params.fragment.node;
22                 if(node.nodeType === Node.TEXT_NODE) {
23                     node = node.parent();
24                 }
25
26                 node.document.transaction(function() {
27                     var exerciseNode = node.after(node.document.edumedCreateExerciseNode(actionConfig.exercise));
28
29                     //@@
30                     if(actionConfig.exercise === 'order') {
31                         exerciseNode.object.addItem('first item');
32                         exerciseNode.contents('.p')[0].append({text: 'Write here...'});
33                     }
34                 });
35                 
36             }
37         },
38         getState: function(params) {
39             return {
40                 allowed: params.fragment && params.fragment.isValid() && params.fragment instanceof params.fragment.NodeFragment && !params.fragment.node.isInside('exercise'),
41                 description: gettext('Insert exercise: ' + actionConfig.exerciseTitle)
42             };
43         }
44     };
45
46 };
47
48 return [
49     createAction({name: 'insertOrderExercise', icon: 'random', exercise: 'order', exerciseTitle: gettext('Order') })
50 ];
51
52 });