X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e3f4ff223c5acd7cf97b6a9ba1cdd83111dba63b..856f00d24d37590a78b78833a8aa305983e58e45:/src/editor/plugins/core/edumed/actions.js diff --git a/src/editor/plugins/core/edumed/actions.js b/src/editor/plugins/core/edumed/actions.js new file mode 100644 index 0000000..8b968b8 --- /dev/null +++ b/src/editor/plugins/core/edumed/actions.js @@ -0,0 +1,52 @@ +define(function() { + +'use strict'; + +/* globals gettext */ + + +var createAction = function(actionConfig) { + + return { + name: actionConfig.name, + params: { + fragment: {type: 'context', name: 'fragment'} + }, + stateDefaults: { + icon: actionConfig.icon || null, + execute: function(callback, params) { + /* globals Node */ + void(callback); + + var node = params.fragment.node; + if(node.nodeType === Node.TEXT_NODE) { + node = node.parent(); + } + + node.document.transaction(function() { + var exerciseNode = node.after(node.document.edumedCreateExerciseNode(actionConfig.exercise)); + + //@@ + if(actionConfig.exercise === 'order') { + exerciseNode.object.addItem('first item'); + exerciseNode.contents('.p')[0].append({text: 'Write here...'}); + } + }); + + } + }, + getState: function(params) { + return { + allowed: params.fragment && params.fragment.isValid() && params.fragment instanceof params.fragment.NodeFragment && !params.fragment.node.isInside('exercise'), + description: gettext('Insert exercise: ' + actionConfig.exerciseTitle) + }; + } + }; + +}; + +return [ + createAction({name: 'insertOrderExercise', icon: 'random', exercise: 'order', exerciseTitle: gettext('Order') }) +]; + +}); \ No newline at end of file