Main.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. MWF.APPSD = MWF.xApplication.process.ScriptDesigner;
  2. MWF.APPSD.options = {
  3. "multitask": true,
  4. "executable": false
  5. };
  6. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", null, false);
  7. MWF.xDesktop.requireApp("process.ScriptDesigner", "Script", null, false);
  8. MWF.require("MWF.xDesktop.UserData", null, false);
  9. MWF.xApplication.process.ScriptDesigner.Main = new Class({
  10. Extends: MWF.xApplication.Common.Main,
  11. Implements: [Options, Events],
  12. options: {
  13. "style": "default",
  14. "name": "process.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. "processData": null
  22. },
  23. onQueryLoad: function(){
  24. if (this.status){
  25. this.options.application = this.status.applicationId;
  26. this.application = this.status.application;
  27. this.options.id = this.status.id;
  28. }
  29. if (!this.options.id){
  30. this.options.desktopReload = false;
  31. this.options.title = this.options.title + "-"+MWF.APPSD.LP.newScript;
  32. }
  33. this.actions = MWF.Actions.get("x_processplatform_assemble_designer");
  34. //this.actions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  35. this.lp = MWF.xApplication.process.ScriptDesigner.LP;
  36. this.addEvent("queryClose", function(e){
  37. if (this.explorer){
  38. this.explorer.reload();
  39. }
  40. }.bind(this));
  41. // this.processData = this.options.processData;
  42. },
  43. loadApplication: function(callback){
  44. this.createNode();
  45. if (!this.options.isRefresh){
  46. this.maxSize(function(){
  47. this.openScript();
  48. }.bind(this));
  49. }else{
  50. this.openScript();
  51. }
  52. if (callback) callback();
  53. },
  54. createNode: function(){
  55. this.content.setStyle("overflow", "hidden");
  56. this.node = new Element("div", {
  57. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  58. }).inject(this.content);
  59. },
  60. getApplication:function(callback){
  61. if (!this.application){
  62. this.actions.getApplication(this.options.application, function(json){
  63. this.application = {"name": json.data.name, "id": json.data.id};
  64. if (callback) callback();
  65. }.bind(this));
  66. }else{
  67. if (callback) callback();
  68. }
  69. },
  70. openScript: function(){
  71. this.getApplication(function(){
  72. this.loadNodes();
  73. this.loadScriptListNodes();
  74. this.loadContentNode(function(){
  75. this.loadProperty();
  76. // this.loadTools();
  77. this.resizeNode();
  78. this.addEvent("resize", this.resizeNode.bind(this));
  79. this.loadScript();
  80. if (this.toolbarContentNode){
  81. this.setScrollBar(this.toolbarContentNode, null, {
  82. "V": {"x": 0, "y": 0},
  83. "H": {"x": 0, "y": 0}
  84. });
  85. this.setScrollBar(this.propertyDomArea, null, {
  86. "V": {"x": 0, "y": 0},
  87. "H": {"x": 0, "y": 0}
  88. });
  89. }
  90. }.bind(this));
  91. }.bind(this));
  92. },
  93. loadNodes: function(){
  94. this.scriptListNode = new Element("div", {
  95. "styles": this.css.scriptListNode
  96. }).inject(this.node);
  97. this.propertyNode = new Element("div", {
  98. "styles": this.css.propertyNode
  99. }).inject(this.node);
  100. this.contentNode = new Element("div", {
  101. "styles": this.css.contentNode
  102. }).inject(this.node);
  103. },
  104. //loadScriptList-------------------------------
  105. loadScriptListNodes: function(){
  106. this.scriptListTitleNode = new Element("div", {
  107. "styles": this.css.scriptListTitleNode,
  108. "text": MWF.APPSD.LP.scriptLibrary
  109. }).inject(this.scriptListNode);
  110. this.scriptListResizeNode = new Element("div", {"styles": this.css.scriptListResizeNode}).inject(this.scriptListNode);
  111. this.scriptListAreaSccrollNode = new Element("div", {"styles": this.css.scriptListAreaSccrollNode}).inject(this.scriptListNode);
  112. this.scriptListAreaNode = new Element("div", {"styles": this.css.scriptListAreaNode}).inject(this.scriptListAreaSccrollNode);
  113. this.loadScriptListResize();
  114. this.loadScriptList();
  115. },
  116. loadScriptListResize: function(){
  117. // var size = this.propertyNode.getSize();
  118. // var position = this.propertyResizeBar.getPosition();
  119. this.scriptListResize = new Drag(this.scriptListResizeNode,{
  120. "snap": 1,
  121. "onStart": function(el, e){
  122. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  123. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  124. el.store("position", {"x": x, "y": y});
  125. var size = this.scriptListAreaSccrollNode.getSize();
  126. el.store("initialWidth", size.x);
  127. }.bind(this),
  128. "onDrag": function(el, e){
  129. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  130. // var y = e.event.y;
  131. var bodySize = this.content.getSize();
  132. var position = el.retrieve("position");
  133. var initialWidth = el.retrieve("initialWidth").toFloat();
  134. var dx = x.toFloat() - position.x.toFloat();
  135. var width = initialWidth+dx;
  136. if (width> bodySize.x/2) width = bodySize.x/2;
  137. if (width<40) width = 40;
  138. this.contentNode.setStyle("margin-left", width+1);
  139. this.scriptListNode.setStyle("width", width);
  140. }.bind(this)
  141. });
  142. },
  143. loadScriptList: function() {
  144. this.actions.listScript(this.application.id, function (json) {
  145. json.data.each(function(script){
  146. this.createListScriptItem(script);
  147. }.bind(this));
  148. }.bind(this), null, false);
  149. },
  150. createListScriptItem: function(script, isNew){
  151. var _self = this;
  152. var listScriptItem = new Element("div", {"styles": this.css.listScriptItem}).inject(this.scriptListAreaNode, (isNew) ? "top": "bottom");
  153. var listScriptItemIcon = new Element("div", {"styles": this.css.listScriptItemIcon}).inject(listScriptItem);
  154. var listScriptItemText = new Element("div", {"styles": this.css.listScriptItemText, "text": (script.name) ? script.name+" ("+script.alias+")" : this.lp.newScript}).inject(listScriptItem);
  155. listScriptItem.store("script", script);
  156. listScriptItem.addEvents({
  157. "dblclick": function(e){_self.loadScriptByData(this, e);},
  158. "mouseover": function(){if (_self.currentListScriptItem!=this) this.setStyles(_self.css.listScriptItem_over);},
  159. "mouseout": function(){if (_self.currentListScriptItem!=this) this.setStyles(_self.css.listScriptItem);}
  160. });
  161. this.listScriptItemMove(listScriptItem);
  162. },
  163. createScriptListCopy: function(node){
  164. var copyNode = node.clone().inject(this.node);
  165. copyNode.position({
  166. "relativeTo": node,
  167. "position": "upperLeft",
  168. "edge": "upperLeft"
  169. });
  170. var size = copyNode.getSize();
  171. copyNode.setStyles({
  172. "width": ""+size.x+"px",
  173. "height": ""+size.y+"px",
  174. "z-index": 50001
  175. });
  176. return copyNode;
  177. },
  178. listDragEnter: function(dragging, inObj){
  179. var markNode = inObj.retrieve("markNode");
  180. if (!markNode){
  181. var size = inObj.getSize();
  182. markNode = new Element("div", {"styles": this.css.dragListItemMark}).inject(this.node);
  183. markNode.setStyles({
  184. "width": ""+size.x+"px",
  185. "height": ""+size.y+"px",
  186. "position": "absolute",
  187. "background-color": "#666",
  188. "z-index": 50000,
  189. "opacity": 0.3
  190. // "border": "2px solid #ffba00"
  191. });
  192. markNode.position({
  193. "relativeTo": inObj,
  194. "position": "upperLeft",
  195. "edge": "upperLeft"
  196. });
  197. var y = markNode.getStyle("top").toFloat()-1;
  198. var x = markNode.getStyle("left").toFloat()-2;
  199. markNode.setStyles({
  200. "left": ""+x+"px",
  201. "top": ""+y+"px"
  202. });
  203. inObj.store("markNode", markNode);
  204. }
  205. },
  206. listDragLeave: function(dragging, inObj){
  207. var markNode = inObj.retrieve("markNode");
  208. if (markNode) markNode.destroy();
  209. inObj.eliminate("markNode");
  210. },
  211. listScriptItemMove: function(node){
  212. var iconNode = node.getFirst();
  213. iconNode.addEvent("mousedown", function(e){
  214. var script = node.retrieve("script");
  215. if (script.id!=this.scriptTab.showPage.script.data.id){
  216. var copyNode = this.createScriptListCopy(node);
  217. var droppables = [this.designNode, this.propertyDomArea];
  218. var listItemDrag = new Drag.Move(copyNode, {
  219. "droppables": droppables,
  220. "onEnter": function(dragging, inObj){
  221. this.listDragEnter(dragging, inObj);
  222. }.bind(this),
  223. "onLeave": function(dragging, inObj){
  224. this.listDragLeave(dragging, inObj);
  225. }.bind(this),
  226. "onDrag": function(e){
  227. //nothing
  228. }.bind(this),
  229. "onDrop": function(dragging, inObj){
  230. if (inObj){
  231. this.addIncludeScript(script);
  232. this.listDragLeave(dragging, inObj);
  233. copyNode.destroy();
  234. }else{
  235. copyNode.destroy();
  236. }
  237. }.bind(this),
  238. "onCancel": function(dragging){
  239. copyNode.destroy();
  240. }.bind(this)
  241. });
  242. listItemDrag.start(e);
  243. }
  244. }.bind(this));
  245. },
  246. addIncludeScript: function(script){
  247. var currentScript = this.scriptTab.showPage.script;
  248. if (currentScript.data.dependScriptList.indexOf(script.name)==-1){
  249. currentScript.data.dependScriptList.push(script.name);
  250. this.addIncludeToList(script.name);
  251. }
  252. },
  253. addIncludeToList: function(name){
  254. this.actions.getScriptByName(name, this.application.id, function(json){
  255. var script = json.data;
  256. var includeScriptItem = new Element("div", {"styles": this.css.includeScriptItem}).inject(this.propertyIncludeListArea);
  257. var includeScriptItemAction = new Element("div", {"styles": this.css.includeScriptItemAction}).inject(includeScriptItem);
  258. var includeScriptItemText = new Element("div", {"styles": this.css.includeScriptItemText}).inject(includeScriptItem);
  259. includeScriptItemText.set("text", script.name+" ("+script.alias+")");
  260. includeScriptItem.store("script", script);
  261. var _self = this;
  262. includeScriptItemAction.addEvent("click", function(){
  263. var node = this.getParent();
  264. var script = node.retrieve("script");
  265. if (script){
  266. _self.scriptTab.showPage.script.data.dependScriptList.erase(script.name);
  267. }
  268. node.destroy();
  269. });
  270. }.bind(this), function(){
  271. this.scriptTab.showPage.script.data.dependScriptList.erase(name);
  272. }.bind(this));
  273. },
  274. loadScriptByData: function(node, e){
  275. var script = node.retrieve("script");
  276. var openNew = true;
  277. for (var i = 0; i<this.scriptTab.pages.length; i++){
  278. if (script.id==this.scriptTab.pages[i].script.data.id){
  279. this.scriptTab.pages[i].showTabIm();
  280. openNew = false;
  281. break;
  282. }
  283. }
  284. if (openNew){
  285. this.loadScriptData(script.id, function(data){
  286. var script = new MWF.xApplication.process.ScriptDesigner.Script(this, data);
  287. script.load();
  288. }.bind(this), true);
  289. }
  290. //var _self = this;
  291. //var options = {
  292. // "onQueryLoad": function(){
  293. // this.actions = _self.actions;
  294. // this.options.id = script.id;
  295. // this.application = _self.application;
  296. // }
  297. //};
  298. //this.desktop.openApplication(e, "process.ScriptDesigner", options);
  299. },
  300. //loadContentNode------------------------------
  301. loadContentNode: function(toolbarCallback, contentCallback){
  302. this.contentToolbarNode = new Element("div#contentToolbarNode", {
  303. "styles": this.css.contentToolbarNode
  304. }).inject(this.contentNode);
  305. this.loadContentToolbar(toolbarCallback);
  306. this.editContentNode = new Element("div", {
  307. "styles": this.css.editContentNode
  308. }).inject(this.contentNode);
  309. this.loadEditContent(function(){
  310. // if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  311. if (this.designNode) this.designNode.setStyles(this.css.designNode);
  312. if (contentCallback) contentCallback();
  313. }.bind(this));
  314. },
  315. loadContentToolbar: function(callback){
  316. this.getFormToolbarHTML(function(toolbarNode){
  317. var spans = toolbarNode.getElements("span");
  318. spans.each(function(item, idx){
  319. var img = item.get("MWFButtonImage");
  320. if (img){
  321. item.set("MWFButtonImage", this.path+""+this.options.style+"/toolbar/"+img);
  322. }
  323. }.bind(this));
  324. $(toolbarNode).inject(this.contentToolbarNode);
  325. MWF.require("MWF.widget.Toolbar", function(){
  326. this.toolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  327. this.toolbar.load();
  328. var _self = this;
  329. this.styleSelectNode = toolbarNode.getElement("select");
  330. this.styleSelectNode.addEvent("change", function(){
  331. _self.changeEditorStyle(this);
  332. });
  333. if (callback) callback();
  334. }.bind(this));
  335. }.bind(this));
  336. },
  337. changeEditorStyle: function(node){
  338. var idx = node.selectedIndex;
  339. var value = node.options[idx].value;
  340. //var editorData = null;
  341. this.scriptTab.pages.each(function(page){
  342. //if (!editorData) editorData = page.script.editor.editorData;
  343. var editor = page.script.editor.editor;
  344. if (editor) editor.setTheme("ace/theme/"+value);
  345. }.bind(this));
  346. //if (!editorData) editorData = MWF.editorData;
  347. //editorData.javascriptEditor.theme = value;
  348. if (!MWF.editorData){
  349. MWF.editorData = {
  350. "javascriptEditor": {
  351. "theme": "tomorrow"
  352. }
  353. };
  354. }
  355. MWF.editorData.javascriptEditor.theme = value;
  356. MWF.UD.putData("editor", MWF.editorData);
  357. },
  358. getFormToolbarHTML: function(callback){
  359. var toolbarUrl = this.path+this.options.style+"/toolbars.html";
  360. var r = new Request.HTML({
  361. url: toolbarUrl,
  362. method: "get",
  363. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  364. var toolbarNode = responseTree[0];
  365. if (callback) callback(toolbarNode);
  366. }.bind(this),
  367. onFailure: function(xhr){
  368. this.notice("request processToolbars error: "+xhr.responseText, "error");
  369. }.bind(this)
  370. });
  371. r.send();
  372. },
  373. maxOrReturnEditor: function(){
  374. if (!this.isMax){
  375. this.designNode.inject(this.node);
  376. this.designNode.setStyles({
  377. "position": "absolute",
  378. "width": "100%",
  379. "height": "100%",
  380. "top": "0px",
  381. "margin": "0px",
  382. "left": "0px"
  383. });
  384. this.scriptTab.pages.each(function(page){
  385. page.script.setAreaNodeSize();
  386. });
  387. this.isMax = true;
  388. }else{
  389. this.isMax = false;
  390. this.designNode.inject(this.editContentNode);
  391. this.designNode.setStyles(this.css.designNode);
  392. this.designNode.setStyles({
  393. "position": "static"
  394. });
  395. this.resizeNode();
  396. this.scriptTab.pages.each(function(page){
  397. page.script.setAreaNodeSize();
  398. });
  399. }
  400. },
  401. loadEditContent: function(callback){
  402. this.designNode = new Element("div", {
  403. "styles": this.css.designNode
  404. }).inject(this.editContentNode);
  405. MWF.require("MWF.widget.Tab", function(){
  406. this.scriptTab = new MWF.widget.Tab(this.designNode, {"style": "script"});
  407. this.scriptTab.load();
  408. }.bind(this), false);
  409. //MWF.require("MWF.widget.ScrollBar", function(){
  410. // new MWF.widget.ScrollBar(this.designNode, {"distance": 100});
  411. //}.bind(this));
  412. },
  413. //loadProperty------------------------
  414. loadProperty: function(){
  415. this.propertyTitleNode = new Element("div", {
  416. "styles": this.css.propertyTitleNode,
  417. "text": MWF.APPSD.LP.property
  418. }).inject(this.propertyNode);
  419. this.propertyResizeBar = new Element("div", {
  420. "styles": this.css.propertyResizeBar
  421. }).inject(this.propertyNode);
  422. this.loadPropertyResize();
  423. this.propertyContentNode = new Element("div", {
  424. "styles": this.css.propertyContentNode
  425. }).inject(this.propertyNode);
  426. this.propertyDomArea = new Element("div", {
  427. "styles": this.css.propertyDomArea
  428. }).inject(this.propertyContentNode);
  429. this.propertyDomPercent = 0.3;
  430. this.propertyContentResizeNode = new Element("div", {
  431. "styles": this.css.propertyContentResizeNode
  432. }).inject(this.propertyContentNode);
  433. this.propertyContentArea = new Element("div", {
  434. "styles": this.css.propertyContentArea
  435. }).inject(this.propertyContentNode);
  436. this.loadPropertyContentResize();
  437. this.setPropertyContent();
  438. this.setIncludeNode();
  439. },
  440. setIncludeNode: function(){
  441. this.includeTitleNode = new Element("div", {"styles": this.css.includeTitleNode}).inject(this.propertyDomArea);
  442. this.includeTitleActionNode = new Element("div", {"styles": this.css.includeTitleActionNode}).inject(this.includeTitleNode);
  443. this.includeTitleTextNode = new Element("div", {"styles": this.css.includeTitleTextNode, "text": this.lp.include}).inject(this.includeTitleNode);
  444. this.includeTitleActionNode.addEvent("click", function(){
  445. this.addInclude();
  446. }.bind(this));
  447. this.propertyIncludeListArea = new Element("div", {
  448. "styles": {"overflow": "hidden"}
  449. }).inject(this.propertyDomArea);
  450. },
  451. addInclude: function(){
  452. },
  453. setPropertyContent: function(){
  454. var node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.id+":"}).inject(this.propertyContentArea);
  455. this.propertyIdNode = new Element("div", {"styles": this.css.propertyTextNode, "text": ""}).inject(this.propertyContentArea);
  456. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.name+":"}).inject(this.propertyContentArea);
  457. this.propertyNameNode = new Element("input", {"styles": this.css.propertyInputNode, "value": ""}).inject(this.propertyContentArea);
  458. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.alias+":"}).inject(this.propertyContentArea);
  459. this.propertyAliasNode = new Element("input", {"styles": this.css.propertyInputNode, "value": ""}).inject(this.propertyContentArea);
  460. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.description+":"}).inject(this.propertyContentArea);
  461. this.propertyDescriptionNode = new Element("textarea", {"styles": this.css.propertyInputAreaNode, "value": ""}).inject(this.propertyContentArea);
  462. },
  463. loadPropertyResize: function(){
  464. // var size = this.propertyNode.getSize();
  465. // var position = this.propertyResizeBar.getPosition();
  466. this.propertyResize = new Drag(this.propertyResizeBar,{
  467. "snap": 1,
  468. "onStart": function(el, e){
  469. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  470. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  471. el.store("position", {"x": x, "y": y});
  472. var size = this.propertyNode.getSize();
  473. el.store("initialWidth", size.x);
  474. }.bind(this),
  475. "onDrag": function(el, e){
  476. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  477. // var y = e.event.y;
  478. var bodySize = this.content.getSize();
  479. var position = el.retrieve("position");
  480. var initialWidth = el.retrieve("initialWidth").toFloat();
  481. var dx = position.x.toFloat()-x.toFloat();
  482. var width = initialWidth+dx;
  483. if (width> bodySize.x/2) width = bodySize.x/2;
  484. if (width<40) width = 40;
  485. this.contentNode.setStyle("margin-right", width+1);
  486. this.propertyNode.setStyle("width", width);
  487. }.bind(this)
  488. });
  489. },
  490. loadPropertyContentResize: function(){
  491. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  492. "snap": 1,
  493. "onStart": function(el, e){
  494. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  495. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  496. el.store("position", {"x": x, "y": y});
  497. var size = this.propertyDomArea.getSize();
  498. el.store("initialHeight", size.y);
  499. }.bind(this),
  500. "onDrag": function(el, e){
  501. var size = this.propertyContentNode.getSize();
  502. // var x = e.event.x;
  503. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  504. var position = el.retrieve("position");
  505. var dy = y.toFloat()-position.y.toFloat();
  506. var initialHeight = el.retrieve("initialHeight").toFloat();
  507. var height = initialHeight+dy;
  508. if (height<40) height = 40;
  509. if (height> size.y-40) height = size.y-40;
  510. this.propertyDomPercent = height/size.y;
  511. this.setPropertyContentResize();
  512. }.bind(this)
  513. });
  514. },
  515. setPropertyContentResize: function(){
  516. var size = this.propertyContentNode.getSize();
  517. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  518. var height = size.y-resizeNodeSize.y;
  519. var domHeight = this.propertyDomPercent*height;
  520. var contentHeight = height-domHeight;
  521. this.propertyDomArea.setStyle("height", ""+domHeight+"px");
  522. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  523. },
  524. //resizeNode------------------------------------------------
  525. resizeNode: function(){
  526. if (!this.isMax){
  527. var nodeSize = this.node.getSize();
  528. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  529. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  530. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  531. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  532. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  533. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  534. this.editContentNode.setStyle("height", ""+y+"px");
  535. if (this.designNode){
  536. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  537. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  538. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  539. this.designNode.setStyle("height", ""+y+"px");
  540. }
  541. titleSize = this.propertyTitleNode.getSize();
  542. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  543. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  544. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  545. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  546. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  547. y = nodeSize.y-y;
  548. this.propertyContentNode.setStyle("height", ""+y+"px");
  549. this.propertyResizeBar.setStyle("height", ""+y+"px");
  550. this.setPropertyContentResize();
  551. titleSize = this.scriptListTitleNode.getSize();
  552. titleMarginTop = this.scriptListTitleNode.getStyle("margin-top").toFloat();
  553. titleMarginBottom = this.scriptListTitleNode.getStyle("margin-bottom").toFloat();
  554. titlePaddingTop = this.scriptListTitleNode.getStyle("padding-top").toFloat();
  555. titlePaddingBottom = this.scriptListTitleNode.getStyle("padding-bottom").toFloat();
  556. nodeMarginTop = this.scriptListAreaSccrollNode.getStyle("margin-top").toFloat();
  557. nodeMarginBottom = this.scriptListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  558. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  559. y = nodeSize.y-y;
  560. this.scriptListAreaSccrollNode.setStyle("height", ""+y+"px");
  561. this.scriptListResizeNode.setStyle("height", ""+y+"px");
  562. }
  563. },
  564. //loadForm------------------------------------------
  565. loadScript: function(){
  566. //this.scriptTab.addTab(node, title);
  567. debugger;
  568. this.getScriptData(this.options.id, function(data){
  569. this.script = new MWF.xApplication.process.ScriptDesigner.Script(this, data);
  570. this.script.load();
  571. if (this.status){
  572. if (this.status.openScripts){
  573. this.status.openScripts.each(function(id){
  574. this.loadScriptData(id, function(data){
  575. var showTab = true;
  576. if (this.status.currentId){
  577. if (this.status.currentId!=data.id) showTab = false;
  578. }
  579. var script = new MWF.xApplication.process.ScriptDesigner.Script(this, data, {"showTab": showTab});
  580. script.load();
  581. }.bind(this), true);
  582. }.bind(this));
  583. }
  584. };
  585. if (!this.scriptHelpMenu){
  586. MWF.require("MWF.widget.ScriptHelp", function(){
  587. this.scriptHelpMenu = new MWF.widget.ScriptHelp($("MWFScriptAutoCode"), this.script.editor);
  588. this.scriptHelpMenu.getEditor = function(){
  589. if (this.scriptTab.showPage) return this.scriptTab.showPage.script.editor.editor;
  590. return null;
  591. }.bind(this)
  592. }.bind(this));
  593. }
  594. }.bind(this));
  595. },
  596. getScriptData: function(id, callback){
  597. if (!id){
  598. this.loadNewScriptData(callback);
  599. }else{
  600. this.loadScriptData(id, callback);
  601. }
  602. },
  603. loadNewScriptData: function(callback){
  604. this.actions.getUUID(function(id){
  605. var data = {
  606. "name": "",
  607. "id": id,
  608. "application": this.application.id,
  609. "alias": "",
  610. "description": "",
  611. "language": "javascript",
  612. "dependScriptList": [],
  613. "isNewScript": true,
  614. "text": ""
  615. };
  616. this.createListScriptItem(data, true);
  617. if (callback) callback(data);
  618. }.bind(this))
  619. },
  620. loadScriptData: function(id, callback, notSetTile){
  621. this.actions.getScript(id, function(json){
  622. if (json){
  623. var data = json.data;
  624. if (!notSetTile){
  625. this.setTitle(this.options.appTitle + "-"+data.name);
  626. this.taskitem.setText(this.options.appTitle + "-"+data.name);
  627. this.options.appTitle = this.options.appTitle + "-"+data.name;
  628. }
  629. if (!this.application){
  630. this.actions.getApplication(this.data.application, function(json){
  631. this.application = {"name": json.data.name, "id": json.data.id};
  632. if (callback) callback(data);
  633. }.bind(this));
  634. }else{
  635. if (callback) callback(data);
  636. }
  637. }
  638. }.bind(this));
  639. },
  640. saveScript: function(){
  641. if (this.scriptTab.showPage){
  642. var script = this.scriptTab.showPage.script;
  643. script.save(function(){
  644. if (script==this.script){
  645. var name = script.data.name;
  646. this.setTitle(MWF.APPSD.LP.title + "-"+name);
  647. this.options.desktopReload = true;
  648. this.options.id = script.data.id;
  649. }
  650. }.bind(this));
  651. }
  652. },
  653. saveDictionaryAs: function(){
  654. this.dictionary.saveAs();
  655. },
  656. dictionaryExplode: function(){
  657. this.dictionary.explode();
  658. },
  659. dictionaryImplode: function(){
  660. this.dictionary.implode();
  661. },
  662. recordStatus: function(){
  663. if (this.scriptTab){
  664. var openScripts = [];
  665. this.scriptTab.pages.each(function(page){
  666. if (page.script.data.id!=this.options.id) openScripts.push(page.script.data.id);
  667. }.bind(this));
  668. var currentId = this.scriptTab.showPage.script.data.id;
  669. var status = {
  670. "id": this.options.id,
  671. "application": this.application,
  672. "openScripts": openScripts,
  673. "currentId": currentId
  674. };
  675. return status;
  676. }
  677. return {"id": this.options.id, "application": this.application};
  678. }
  679. });