From: Aleksander Ɓukasz Date: Thu, 17 Apr 2014 10:36:13 +0000 (+0200) Subject: template get state fix X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/68c9d615c3b5f4d6fefcd721f0315fde89fc3328?ds=sidebyside template get state fix --- diff --git a/src/editor/plugins/core/templates.js b/src/editor/plugins/core/templates.js index 2b1f730..1114258 100644 --- a/src/editor/plugins/core/templates.js +++ b/src/editor/plugins/core/templates.js @@ -13,12 +13,7 @@ var insertTemplateAction = { }, stateDefaults: { label: '+', - icon: 'core.plus', - execute: function(params) { - var node = params.fragment.node.getNearestElementNode(); - var toAdd = node.document.createDocumentNode(params.template.content); - node.after(toAdd); - } + icon: 'core.plus' }, getState: function(params) { if(!(params.template && params.template.id)) { @@ -26,15 +21,24 @@ var insertTemplateAction = { allowed: false, description: gettext('No template selected') }; - } else if(!params.fragment || !params.fragment.isValid() || !(params.fragment instanceof params.fragment.NodeFragment)) { - return { - allowed: false, - description: gettext('Wrong node selected') + } else if( + !params.fragment || !params.fragment.isValid() || + !(params.fragment instanceof params.fragment.NodeFragment) || + params.fragment.node.getNearestElementNode().isRoot() + ) { + return { + allowed: false, + description: gettext('Wrong node selected') }; } return { allowed: true, - description: interpolate(gettext('Insert template %s after %s'), [params.template.name, params.fragment.node.getNearestElementNode().getTagName()]) + description: interpolate(gettext('Insert template %s after %s'), [params.template.name, params.fragment.node.getNearestElementNode().getTagName()]), + execute: function(params) { + var node = params.fragment.node.getNearestElementNode(); + var toAdd = node.document.createDocumentNode(params.template.content); + node.after(toAdd); + } }; } };