Main.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.xApplication.process.ScriptDesigner = MWF.xApplication.process.ScriptDesigner || {};
  3. MWF.xDesktop.requireApp("process.ScriptDesigner", "Main", null, false);
  4. MWF.xApplication.service.ScriptDesigner.options = {
  5. "multitask": true,
  6. "executable": false
  7. };
  8. MWF.xDesktop.requireApp("service.ScriptDesigner", "Script", null, false);
  9. MWF.xApplication.service.ScriptDesigner.Main = new Class({
  10. Extends: MWF.xApplication.process.ScriptDesigner.Main,
  11. Implements: [Options, Events],
  12. options: {
  13. "style": "default",
  14. "name": "service.ScriptDesigner",
  15. "icon": "icon.png",
  16. "title": MWF.APPSD.LP.title,
  17. "appTitle": MWF.APPSD.LP.title,
  18. "id": "",
  19. "actions": null,
  20. "category": null
  21. },
  22. onQueryLoad: function(){
  23. if (this.status){
  24. this.options.id = this.status.id;
  25. }
  26. if (!this.options.id){
  27. this.options.desktopReload = false;
  28. this.options.title = this.options.title + "-"+MWF.APPSD.LP.newScript;
  29. }
  30. this.actions = MWF.Actions.get("x_program_center");
  31. this.lp = MWF.xApplication.process.ScriptDesigner.LP;
  32. this.addEvent("queryClose", function(e){
  33. if (this.explorer && this.explorer.app && this.explorer.app.window){
  34. this.explorer.reload();
  35. }
  36. }.bind(this));
  37. },
  38. getApplication:function(callback){
  39. if (callback) callback();
  40. },
  41. loadScriptList: function() {
  42. this.actions.listScript(function (json) {
  43. json.data.each(function(script){
  44. this.createListScriptItem(script);
  45. }.bind(this));
  46. }.bind(this), null, false);
  47. },
  48. addIncludeToList: function(name){
  49. this.actions.getScriptByName(name, function(json){
  50. var script = json.data;
  51. var includeScriptItem = new Element("div", {"styles": this.css.includeScriptItem}).inject(this.propertyIncludeListArea);
  52. var includeScriptItemAction = new Element("div", {"styles": this.css.includeScriptItemAction}).inject(includeScriptItem);
  53. var includeScriptItemText = new Element("div", {"styles": this.css.includeScriptItemText}).inject(includeScriptItem);
  54. includeScriptItemText.set("text", script.name+" ("+script.alias+")");
  55. includeScriptItem.store("script", script);
  56. var _self = this;
  57. includeScriptItemAction.addEvent("click", function(){
  58. var node = this.getParent();
  59. var script = node.retrieve("script");
  60. if (script){
  61. _self.scriptTab.showPage.script.data.dependScriptList.erase(script.name);
  62. }
  63. node.destroy();
  64. });
  65. }.bind(this), function(){
  66. this.scriptTab.showPage.script.data.dependScriptList.erase(name);
  67. }.bind(this));
  68. },
  69. loadScriptByData: function(node, e){
  70. var script = node.retrieve("script");
  71. var openNew = true;
  72. for (var i = 0; i<this.scriptTab.pages.length; i++){
  73. if (script.id==this.scriptTab.pages[i].script.data.id){
  74. this.scriptTab.pages[i].showTabIm();
  75. openNew = false;
  76. break;
  77. }
  78. }
  79. if (openNew){
  80. this.loadScriptData(script.id, function(data){
  81. var script = new MWF.xApplication.service.ScriptDesigner.Script(this, data);
  82. script.load();
  83. }.bind(this), true);
  84. }
  85. //var _self = this;
  86. //var options = {
  87. // "onQueryLoad": function(){
  88. // this.actions = _self.actions;
  89. // this.options.id = script.id;
  90. // this.application = _self.application;
  91. // }
  92. //};
  93. //this.desktop.openApplication(e, "process.ScriptDesigner", options);
  94. },
  95. //loadForm------------------------------------------
  96. loadScript: function(){
  97. //this.scriptTab.addTab(node, title);
  98. this.getScriptData(this.options.id, function(data){
  99. this.script = new MWF.xApplication.service.ScriptDesigner.Script(this, data);
  100. this.script.load();
  101. if (this.status){
  102. if (this.status.openScripts){
  103. this.status.openScripts.each(function(id){
  104. this.loadScriptData(id, function(data){
  105. var showTab = true;
  106. if (this.status.currentId){
  107. if (this.status.currentId!=data.id) showTab = false;
  108. }
  109. var script = new MWF.xApplication.service.ScriptDesigner.Script(this, data, {"showTab": showTab});
  110. script.load();
  111. }.bind(this), true);
  112. }.bind(this));
  113. }
  114. }
  115. }.bind(this));
  116. },
  117. loadNewScriptData: function(callback){
  118. // this.actions.getUUID(function(id){
  119. var data = {
  120. "name": "",
  121. // "id": id,
  122. "alias": "",
  123. "description": "",
  124. "language": "javascript",
  125. "dependScriptList": [],
  126. "isNewScript": true,
  127. "text": ""
  128. };
  129. this.createListScriptItem(data, true);
  130. if (callback) callback(data);
  131. // }.bind(this))
  132. },
  133. loadScriptData: function(id, callback, notSetTile){
  134. this.actions.getScript(id, function(json){
  135. if (json){
  136. var data = json.data;
  137. if (!notSetTile){
  138. this.setTitle(this.options.appTitle + "-"+data.name);
  139. if(this.taskitem)this.taskitem.setText(this.options.appTitle + "-"+data.name);
  140. this.options.appTitle = this.options.appTitle + "-"+data.name;
  141. }
  142. if (callback) callback(data);
  143. }
  144. }.bind(this));
  145. },
  146. recordStatus: function(){
  147. if (this.scriptTab){
  148. var openScripts = [];
  149. this.scriptTab.pages.each(function(page){
  150. if (page.script.data.id!=this.options.id) openScripts.push(page.script.data.id);
  151. }.bind(this));
  152. var currentId = this.scriptTab.showPage.script.data.id;
  153. var status = {
  154. "id": this.options.id,
  155. "openScripts": openScripts,
  156. "currentId": currentId
  157. };
  158. return status;
  159. }
  160. return {"id": this.options.id};
  161. },
  162. getFormToolbarHTML: function(callback){
  163. var toolbarUrl = "../x_component_service_ScriptDesigner/$Main/default/toolbars.html";
  164. MWF.getRequestText(toolbarUrl, function(responseText, responseXML){
  165. var htmlString = responseText;
  166. htmlString = o2.bindJson(htmlString, {"lp": MWF.APPSD.LP.formToolbar});
  167. var temp = new Element('div').set('html', htmlString);
  168. if (callback) callback( temp.childNodes[0] );
  169. }.bind(this));
  170. // var r = new Request.HTML({
  171. // url: toolbarUrl,
  172. // method: "get",
  173. // onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  174. // var toolbarNode = responseTree[0];
  175. // if (callback) callback(toolbarNode);
  176. // }.bind(this),
  177. // onFailure: function(xhr){
  178. // this.notice("request cmsToolbars error: "+xhr.responseText, "error");
  179. // }.bind(this)
  180. // });
  181. // r.send();
  182. }
  183. });