2b1f730d5e3a59adb9b377d53b4ac55d2bc7b2d5
[fnpeditor.git] / src / editor / plugins / core / templates.js
1 define(function() {
2     
3 'use strict';
4 /* globals gettext, interpolate */
5
6
7 var insertTemplateAction = {
8     name: 'template',
9     params: {
10         fragment: {type: 'context', name: 'fragment'},
11         template: {type: 'select', options: []},
12         ctrl: {type: 'key', key: 'ctrl'}
13     },
14     stateDefaults: {
15         label: '+',
16         icon: 'core.plus',
17         execute: function(params) {
18             var node = params.fragment.node.getNearestElementNode();
19             var toAdd = node.document.createDocumentNode(params.template.content);
20             node.after(toAdd);
21         }
22     },
23     getState: function(params) {
24         if(!(params.template && params.template.id)) {
25             return {
26                 allowed: false,
27                 description: gettext('No template selected')
28             };
29         } else if(!params.fragment || !params.fragment.isValid() || !(params.fragment instanceof params.fragment.NodeFragment)) {
30             return {
31                 allowed: false,
32                 description: gettext('Wrong node selected')
33             };
34         }
35         return {
36             allowed: true,
37             description: interpolate(gettext('Insert template %s after %s'), [params.template.name, params.fragment.node.getNearestElementNode().getTagName()])
38         };
39     }
40 };
41
42
43 return {
44     actions: [insertTemplateAction]
45 };
46
47 });