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