Script.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.service = MWF.xApplication.service || {};
  3. MWF.xApplication.service.ScriptDesigner = MWF.xApplication.service.ScriptDesigner || {};
  4. MWF.xDesktop.requireApp("process.ScriptDesigner", "Script", null, false);
  5. MWF.xApplication.service.ScriptDesigner.Script = new Class({
  6. Extends: MWF.xApplication.process.ScriptDesigner.Script,
  7. initialize: function(designer, data, options){
  8. this.setOptions(options);
  9. this.path = "../x_component_process_ScriptDesigner/$Script/";
  10. this.cssPath = "../x_component_process_ScriptDesigner/$Script/"+this.options.style+"/css.wcss";
  11. this._loadCss();
  12. this.isChanged = false;
  13. this.designer = designer;
  14. this.data = data;
  15. if (!this.data.text) this.data.text = "";
  16. this.node = this.designer.designNode;
  17. this.tab = this.designer.scriptTab;
  18. this.areaNode = new Element("div", {"styles": {"overflow": "hidden", "height": "700px"}});
  19. this.propertyIncludeNode = this.designer.propertyDomArea;
  20. this.propertyNode = this.designer.propertyContentArea;
  21. this.isNewScript = (this.data.id) ? false : true;
  22. // this.createProperty();
  23. this.autoSave();
  24. this.designer.addEvent("queryClose", function(){
  25. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  26. }.bind(this));
  27. },
  28. save: function(callback){
  29. if (!this.isSave){
  30. var validated = this.editor.validated();
  31. var name = this.designer.propertyNameNode.get("value");
  32. var alias = this.designer.propertyAliasNode.get("value");
  33. var description = this.designer.propertyDescriptionNode.get("value");
  34. if (!name){
  35. this.designer.notice(this.designer.lp.notice.inputName, "error");
  36. return false;
  37. }
  38. this.data.name = name;
  39. this.data.alias = alias;
  40. this.data.description = description;
  41. this.data.validated = validated;
  42. this.data.text = this.editor.getValue();
  43. this.isSave = true;
  44. var successCallback = function (json) {
  45. this.isSave = false;
  46. this.data.isNewScript = false;
  47. this.isChanged = false;
  48. this.page.textNode.set("text", this.data.name);
  49. if (this.lisNode) {
  50. this.lisNode.getLast().set("text", this.data.name);
  51. }
  52. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  53. this.data.id = json.data.id;
  54. if (callback) callback();
  55. }.bind(this);
  56. var failCallback = function(xhr, text, error){
  57. this.isSave = false;
  58. var errorText = error+":"+text;
  59. if (xhr) errorText = xhr.responseText;
  60. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  61. }.bind(this);
  62. if (!this.data.id){
  63. this.designer.actions.addScript( this.data, successCallback, failCallback );
  64. }else{
  65. this.designer.actions.updateScript( this.data.id, this.data, successCallback, failCallback );
  66. }
  67. }else{
  68. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
  69. }
  70. },
  71. saveSilence: function(callback){
  72. if (!this.isSave){
  73. var validated = this.editor.validated();
  74. if( this.designer.currentScript == this ) {
  75. var name = this.designer.propertyNameNode.get("value");
  76. var alias = this.designer.propertyAliasNode.get("value");
  77. var description = this.designer.propertyDescriptionNode.get("value");
  78. if (!name) {
  79. this.designer.notice(this.designer.lp.notice.inputName, "error");
  80. return false;
  81. }
  82. this.data.name = name;
  83. this.data.alias = alias;
  84. this.data.description = description;
  85. this.data.validated = validated;
  86. }
  87. this.data.text = this.editor.getValue();
  88. this.isSave = true;
  89. var successCallback = function(json){
  90. this.isSave = false;
  91. this.data.isNewScript = false;
  92. this.isChanged = false;
  93. this.page.textNode.set("text", this.data.name);
  94. if (this.lisNode) {
  95. this.lisNode.getLast().set("text", this.data.name);
  96. }
  97. this.data.id = json.data.id;
  98. if (callback) callback();
  99. }.bind(this);
  100. var failCallback = function(xhr, text, error){
  101. this.isSave = false;
  102. }.bind(this);
  103. if (!this.data.id){
  104. this.designer.actions.addScript( this.data, successCallback, failCallback );
  105. }else{
  106. this.designer.actions.updateScript( this.data.id, this.data, successCallback, failCallback );
  107. }
  108. }else{
  109. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
  110. }
  111. }
  112. });