ScriptNode.js 980 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Created by jacky on 2016/7/18.
  3. */
  4. import scriptSVG from './svg/script.svg';
  5. import BaseNode from './BaseNode.js';
  6. export default class ScriptNode extends BaseNode{
  7. getSvgIcon(){
  8. return scriptSVG;
  9. }
  10. toXML(){
  11. const json=this.toJSON();
  12. json.type="ScriptNode";
  13. const nodeName=this.getNodeName(json.type);
  14. const nodeProps=this.getXMLNodeBaseProps(json);
  15. let xml=`<${nodeName} ${nodeProps}>`;
  16. xml+=this.getFromConnectionsXML();
  17. xml+=`<content>`;
  18. xml+=`<![CDATA[${this.script}]]>`;
  19. xml+=`</content>`;
  20. xml+=`</${nodeName}>`;
  21. return xml;
  22. }
  23. initFromJson(json){
  24. super.initFromJson(json);
  25. this.script=json.script;
  26. }
  27. validate(){
  28. let errorInfo=super.validate();
  29. if(errorInfo)return errorInfo;
  30. if(!this.script){
  31. errorInfo=`节点${this.name}的脚本不能为空`;
  32. }
  33. return errorInfo;
  34. }
  35. }