Main.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  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 && this.explorer.app && this.explorer.app.window){
  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. this.styleSelectNode = toolbarNode.getElement("select[MWFnodetype='theme']");
  334. this.styleSelectNode.addEvent("change", function(){
  335. _self.changeEditorStyle(this);
  336. });
  337. this.fontsizeSelectNode = toolbarNode.getElement("select[MWFnodetype='fontSize']");
  338. this.fontsizeSelectNode.addEvent("change", function(){
  339. _self.changeFontSize(this);
  340. });
  341. if (callback) callback();
  342. }.bind(this));
  343. }.bind(this));
  344. },
  345. changeFontSize: function(node){
  346. var idx = node.selectedIndex;
  347. var value = node.options[idx].value;
  348. //var editorData = null;
  349. this.scriptTab.pages.each(function(page){
  350. //if (!editorData) editorData = page.invoke.editor.editorData;
  351. var editor = page.script.editor.editor;
  352. if (editor) editor.setFontSize(value);
  353. }.bind(this));
  354. //if (!editorData) editorData = MWF.editorData;
  355. //editorData.javainvokeEditor.theme = value;
  356. if (!MWF.editorData){
  357. MWF.editorData = {
  358. "javascriptEditor": {
  359. "theme": "tomorrow",
  360. "fontSize" : "12px"
  361. }
  362. };
  363. }
  364. MWF.editorData.javascriptEditor["fontSize"] = value;
  365. MWF.UD.putData("editor", MWF.editorData);
  366. },
  367. changeEditorStyle: function(node){
  368. var idx = node.selectedIndex;
  369. var value = node.options[idx].value;
  370. //var editorData = null;
  371. this.scriptTab.pages.each(function(page){
  372. //if (!editorData) editorData = page.script.editor.editorData;
  373. var editor = page.script.editor.editor;
  374. if (editor) editor.setTheme("ace/theme/"+value);
  375. }.bind(this));
  376. //if (!editorData) editorData = MWF.editorData;
  377. //editorData.javascriptEditor.theme = value;
  378. if (!MWF.editorData){
  379. MWF.editorData = {
  380. "javascriptEditor": {
  381. "theme": "tomorrow",
  382. "fontSize" : "12px"
  383. }
  384. };
  385. }
  386. MWF.editorData.javascriptEditor.theme = value;
  387. MWF.UD.putData("editor", MWF.editorData);
  388. },
  389. getFormToolbarHTML: function(callback){
  390. var toolbarUrl = this.path+this.options.style+"/toolbars.html";
  391. var r = new Request.HTML({
  392. url: toolbarUrl,
  393. method: "get",
  394. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  395. var toolbarNode = responseTree[0];
  396. if (callback) callback(toolbarNode);
  397. }.bind(this),
  398. onFailure: function(xhr){
  399. this.notice("request processToolbars error: "+xhr.responseText, "error");
  400. }.bind(this)
  401. });
  402. r.send();
  403. },
  404. maxOrReturnEditor: function(){
  405. if (!this.isMax){
  406. this.designNode.inject(this.node);
  407. this.designNode.setStyles({
  408. "position": "absolute",
  409. "width": "100%",
  410. "height": "100%",
  411. "top": "0px",
  412. "margin": "0px",
  413. "left": "0px"
  414. });
  415. this.scriptTab.pages.each(function(page){
  416. page.script.setAreaNodeSize();
  417. });
  418. this.isMax = true;
  419. }else{
  420. this.isMax = false;
  421. this.designNode.inject(this.editContentNode);
  422. this.designNode.setStyles(this.css.designNode);
  423. this.designNode.setStyles({
  424. "position": "static"
  425. });
  426. this.resizeNode();
  427. this.scriptTab.pages.each(function(page){
  428. page.script.setAreaNodeSize();
  429. });
  430. }
  431. },
  432. loadEditContent: function(callback){
  433. this.designNode = new Element("div", {
  434. "styles": this.css.designNode
  435. }).inject(this.editContentNode);
  436. MWF.require("MWF.widget.Tab", function(){
  437. this.scriptTab = new MWF.widget.Tab(this.designNode, {"style": "script"});
  438. this.scriptTab.load();
  439. this.addEvent("queryClose", function(){
  440. debugger;
  441. while (this.scriptTab.pages.length){
  442. this.scriptTab.pages[0].closeTab();
  443. }
  444. }.bind(this));
  445. }.bind(this), false);
  446. //MWF.require("MWF.widget.ScrollBar", function(){
  447. // new MWF.widget.ScrollBar(this.designNode, {"distance": 100});
  448. //}.bind(this));
  449. },
  450. //loadProperty------------------------
  451. loadProperty: function(){
  452. this.propertyTitleNode = new Element("div", {
  453. "styles": this.css.propertyTitleNode,
  454. "text": MWF.APPSD.LP.property
  455. }).inject(this.propertyNode);
  456. this.propertyResizeBar = new Element("div", {
  457. "styles": this.css.propertyResizeBar
  458. }).inject(this.propertyNode);
  459. this.loadPropertyResize();
  460. this.propertyContentNode = new Element("div", {
  461. "styles": this.css.propertyContentNode
  462. }).inject(this.propertyNode);
  463. this.propertyDomArea = new Element("div", {
  464. "styles": this.css.propertyDomArea
  465. }).inject(this.propertyContentNode);
  466. this.propertyDomPercent = 0.3;
  467. this.propertyContentResizeNode = new Element("div", {
  468. "styles": this.css.propertyContentResizeNode
  469. }).inject(this.propertyContentNode);
  470. this.propertyContentArea = new Element("div", {
  471. "styles": this.css.propertyContentArea
  472. }).inject(this.propertyContentNode);
  473. this.loadPropertyContentResize();
  474. this.setPropertyContent();
  475. this.setIncludeNode();
  476. },
  477. setIncludeNode: function(){
  478. this.includeTitleNode = new Element("div", {"styles": this.css.includeTitleNode}).inject(this.propertyDomArea);
  479. this.includeTitleActionNode = new Element("div", {"styles": this.css.includeTitleActionNode}).inject(this.includeTitleNode);
  480. this.includeTitleTextNode = new Element("div", {"styles": this.css.includeTitleTextNode, "text": this.lp.include}).inject(this.includeTitleNode);
  481. this.includeTitleActionNode.addEvent("click", function(){
  482. this.addInclude();
  483. }.bind(this));
  484. this.propertyIncludeListArea = new Element("div", {
  485. "styles": {"overflow": "hidden"}
  486. }).inject(this.propertyDomArea);
  487. },
  488. addInclude: function(){
  489. },
  490. setPropertyContent: function(){
  491. var node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.id+":"}).inject(this.propertyContentArea);
  492. this.propertyIdNode = new Element("div", {"styles": this.css.propertyTextNode, "text": ""}).inject(this.propertyContentArea);
  493. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.name+":"}).inject(this.propertyContentArea);
  494. this.propertyNameNode = new Element("input", {"styles": this.css.propertyInputNode, "value": ""}).inject(this.propertyContentArea);
  495. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.alias+":"}).inject(this.propertyContentArea);
  496. this.propertyAliasNode = new Element("input", {"styles": this.css.propertyInputNode, "value": ""}).inject(this.propertyContentArea);
  497. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.description+":"}).inject(this.propertyContentArea);
  498. this.propertyDescriptionNode = new Element("textarea", {"styles": this.css.propertyInputAreaNode, "value": ""}).inject(this.propertyContentArea);
  499. },
  500. loadPropertyResize: function(){
  501. // var size = this.propertyNode.getSize();
  502. // var position = this.propertyResizeBar.getPosition();
  503. this.propertyResize = new Drag(this.propertyResizeBar,{
  504. "snap": 1,
  505. "onStart": function(el, e){
  506. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  507. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  508. el.store("position", {"x": x, "y": y});
  509. var size = this.propertyNode.getSize();
  510. el.store("initialWidth", size.x);
  511. }.bind(this),
  512. "onDrag": function(el, e){
  513. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  514. // var y = e.event.y;
  515. var bodySize = this.content.getSize();
  516. var position = el.retrieve("position");
  517. var initialWidth = el.retrieve("initialWidth").toFloat();
  518. var dx = position.x.toFloat()-x.toFloat();
  519. var width = initialWidth+dx;
  520. if (width> bodySize.x/2) width = bodySize.x/2;
  521. if (width<40) width = 40;
  522. this.contentNode.setStyle("margin-right", width+1);
  523. this.propertyNode.setStyle("width", width);
  524. }.bind(this)
  525. });
  526. },
  527. loadPropertyContentResize: function(){
  528. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  529. "snap": 1,
  530. "onStart": function(el, e){
  531. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  532. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  533. el.store("position", {"x": x, "y": y});
  534. var size = this.propertyDomArea.getSize();
  535. el.store("initialHeight", size.y);
  536. }.bind(this),
  537. "onDrag": function(el, e){
  538. var size = this.propertyContentNode.getSize();
  539. // var x = e.event.x;
  540. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  541. var position = el.retrieve("position");
  542. var dy = y.toFloat()-position.y.toFloat();
  543. var initialHeight = el.retrieve("initialHeight").toFloat();
  544. var height = initialHeight+dy;
  545. if (height<40) height = 40;
  546. if (height> size.y-40) height = size.y-40;
  547. this.propertyDomPercent = height/size.y;
  548. this.setPropertyContentResize();
  549. }.bind(this)
  550. });
  551. },
  552. setPropertyContentResize: function(){
  553. var size = this.propertyContentNode.getSize();
  554. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  555. var height = size.y-resizeNodeSize.y;
  556. var domHeight = this.propertyDomPercent*height;
  557. var contentHeight = height-domHeight;
  558. this.propertyDomArea.setStyle("height", ""+domHeight+"px");
  559. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  560. },
  561. //resizeNode------------------------------------------------
  562. resizeNode: function(){
  563. if (!this.isMax){
  564. var nodeSize = this.node.getSize();
  565. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  566. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  567. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  568. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  569. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  570. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  571. this.editContentNode.setStyle("height", ""+y+"px");
  572. if (this.designNode){
  573. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  574. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  575. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  576. this.designNode.setStyle("height", ""+y+"px");
  577. }
  578. titleSize = this.propertyTitleNode.getSize();
  579. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  580. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  581. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  582. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  583. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  584. y = nodeSize.y-y;
  585. this.propertyContentNode.setStyle("height", ""+y+"px");
  586. this.propertyResizeBar.setStyle("height", ""+y+"px");
  587. this.setPropertyContentResize();
  588. titleSize = this.scriptListTitleNode.getSize();
  589. titleMarginTop = this.scriptListTitleNode.getStyle("margin-top").toFloat();
  590. titleMarginBottom = this.scriptListTitleNode.getStyle("margin-bottom").toFloat();
  591. titlePaddingTop = this.scriptListTitleNode.getStyle("padding-top").toFloat();
  592. titlePaddingBottom = this.scriptListTitleNode.getStyle("padding-bottom").toFloat();
  593. nodeMarginTop = this.scriptListAreaSccrollNode.getStyle("margin-top").toFloat();
  594. nodeMarginBottom = this.scriptListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  595. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  596. y = nodeSize.y-y;
  597. this.scriptListAreaSccrollNode.setStyle("height", ""+y+"px");
  598. this.scriptListResizeNode.setStyle("height", ""+y+"px");
  599. }
  600. },
  601. //loadForm------------------------------------------
  602. loadScript: function(){
  603. //this.scriptTab.addTab(node, title);
  604. this.getScriptData(this.options.id, function(data){
  605. this.script = new MWF.xApplication.process.ScriptDesigner.Script(this, data);
  606. this.script.load();
  607. if (this.status){
  608. if (this.status.openScripts){
  609. this.status.openScripts.each(function(id){
  610. this.loadScriptData(id, function(data){
  611. var showTab = true;
  612. if (this.status.currentId){
  613. if (this.status.currentId!=data.id) showTab = false;
  614. }
  615. var script = new MWF.xApplication.process.ScriptDesigner.Script(this, data, {"showTab": showTab});
  616. script.load();
  617. }.bind(this), true);
  618. }.bind(this));
  619. }
  620. };
  621. if (!this.scriptHelpMenu){
  622. MWF.require("MWF.widget.ScriptHelp", function(){
  623. this.scriptHelpMenu = new MWF.widget.ScriptHelp($("MWFScriptAutoCode"), this.script.editor);
  624. this.scriptHelpMenu.getEditor = function(){
  625. if (this.scriptTab.showPage) return this.scriptTab.showPage.script.editor.editor;
  626. return null;
  627. }.bind(this)
  628. }.bind(this));
  629. }
  630. }.bind(this));
  631. },
  632. getScriptData: function(id, callback){
  633. if (!id){
  634. this.loadNewScriptData(callback);
  635. }else{
  636. this.loadScriptData(id, callback);
  637. }
  638. },
  639. loadNewScriptData: function(callback){
  640. this.actions.getUUID(function(id){
  641. var data = {
  642. "name": "",
  643. "id": id,
  644. "application": this.application.id,
  645. "alias": "",
  646. "description": "",
  647. "language": "javascript",
  648. "dependScriptList": [],
  649. "isNewScript": true,
  650. "text": ""
  651. };
  652. this.createListScriptItem(data, true);
  653. if (callback) callback(data);
  654. }.bind(this))
  655. },
  656. loadScriptData: function(id, callback, notSetTile){
  657. this.actions.getScript(id, function(json){
  658. if (json){
  659. var data = json.data;
  660. if (!notSetTile){
  661. this.setTitle(this.options.appTitle + "-"+data.name);
  662. this.taskitem.setText(this.options.appTitle + "-"+data.name);
  663. this.options.appTitle = this.options.appTitle + "-"+data.name;
  664. }
  665. if (!this.application){
  666. this.actions.getApplication(this.data.application, function(json){
  667. this.application = {"name": json.data.name, "id": json.data.id};
  668. if (callback) callback(data);
  669. }.bind(this));
  670. }else{
  671. if (callback) callback(data);
  672. }
  673. }
  674. }.bind(this));
  675. },
  676. saveScript: function(){
  677. if (this.scriptTab.showPage){
  678. var script = this.scriptTab.showPage.script;
  679. script.save(function(){
  680. if (script==this.script){
  681. var name = script.data.name;
  682. this.setTitle(MWF.APPSD.LP.title + "-"+name);
  683. this.options.desktopReload = true;
  684. this.options.id = script.data.id;
  685. }
  686. }.bind(this));
  687. }
  688. },
  689. saveDictionaryAs: function(){
  690. this.dictionary.saveAs();
  691. },
  692. dictionaryExplode: function(){
  693. this.dictionary.explode();
  694. },
  695. dictionaryImplode: function(){
  696. this.dictionary.implode();
  697. },
  698. recordStatus: function(){
  699. if (this.scriptTab){
  700. var openScripts = [];
  701. this.scriptTab.pages.each(function(page){
  702. if (page.script.data.id!=this.options.id) openScripts.push(page.script.data.id);
  703. }.bind(this));
  704. var currentId = this.scriptTab.showPage.script.data.id;
  705. var status = {
  706. "id": this.options.id,
  707. "application": this.application,
  708. "openScripts": openScripts,
  709. "currentId": currentId
  710. };
  711. return status;
  712. }
  713. return {"id": this.options.id, "application": this.application};
  714. }
  715. });