Main.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  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. 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. }.bind(this), false);
  440. //MWF.require("MWF.widget.ScrollBar", function(){
  441. // new MWF.widget.ScrollBar(this.designNode, {"distance": 100});
  442. //}.bind(this));
  443. },
  444. //loadProperty------------------------
  445. loadProperty: function(){
  446. this.propertyTitleNode = new Element("div", {
  447. "styles": this.css.propertyTitleNode,
  448. "text": MWF.APPSD.LP.property
  449. }).inject(this.propertyNode);
  450. this.propertyResizeBar = new Element("div", {
  451. "styles": this.css.propertyResizeBar
  452. }).inject(this.propertyNode);
  453. this.loadPropertyResize();
  454. this.propertyContentNode = new Element("div", {
  455. "styles": this.css.propertyContentNode
  456. }).inject(this.propertyNode);
  457. this.propertyDomArea = new Element("div", {
  458. "styles": this.css.propertyDomArea
  459. }).inject(this.propertyContentNode);
  460. this.propertyDomPercent = 0.3;
  461. this.propertyContentResizeNode = new Element("div", {
  462. "styles": this.css.propertyContentResizeNode
  463. }).inject(this.propertyContentNode);
  464. this.propertyContentArea = new Element("div", {
  465. "styles": this.css.propertyContentArea
  466. }).inject(this.propertyContentNode);
  467. this.loadPropertyContentResize();
  468. this.setPropertyContent();
  469. this.setIncludeNode();
  470. },
  471. setIncludeNode: function(){
  472. this.includeTitleNode = new Element("div", {"styles": this.css.includeTitleNode}).inject(this.propertyDomArea);
  473. this.includeTitleActionNode = new Element("div", {"styles": this.css.includeTitleActionNode}).inject(this.includeTitleNode);
  474. this.includeTitleTextNode = new Element("div", {"styles": this.css.includeTitleTextNode, "text": this.lp.include}).inject(this.includeTitleNode);
  475. this.includeTitleActionNode.addEvent("click", function(){
  476. this.addInclude();
  477. }.bind(this));
  478. this.propertyIncludeListArea = new Element("div", {
  479. "styles": {"overflow": "hidden"}
  480. }).inject(this.propertyDomArea);
  481. },
  482. addInclude: function(){
  483. },
  484. setPropertyContent: function(){
  485. var node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.id+":"}).inject(this.propertyContentArea);
  486. this.propertyIdNode = new Element("div", {"styles": this.css.propertyTextNode, "text": ""}).inject(this.propertyContentArea);
  487. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.name+":"}).inject(this.propertyContentArea);
  488. this.propertyNameNode = new Element("input", {"styles": this.css.propertyInputNode, "value": ""}).inject(this.propertyContentArea);
  489. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.alias+":"}).inject(this.propertyContentArea);
  490. this.propertyAliasNode = new Element("input", {"styles": this.css.propertyInputNode, "value": ""}).inject(this.propertyContentArea);
  491. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.description+":"}).inject(this.propertyContentArea);
  492. this.propertyDescriptionNode = new Element("textarea", {"styles": this.css.propertyInputAreaNode, "value": ""}).inject(this.propertyContentArea);
  493. },
  494. loadPropertyResize: function(){
  495. // var size = this.propertyNode.getSize();
  496. // var position = this.propertyResizeBar.getPosition();
  497. this.propertyResize = new Drag(this.propertyResizeBar,{
  498. "snap": 1,
  499. "onStart": function(el, e){
  500. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  501. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  502. el.store("position", {"x": x, "y": y});
  503. var size = this.propertyNode.getSize();
  504. el.store("initialWidth", size.x);
  505. }.bind(this),
  506. "onDrag": function(el, e){
  507. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  508. // var y = e.event.y;
  509. var bodySize = this.content.getSize();
  510. var position = el.retrieve("position");
  511. var initialWidth = el.retrieve("initialWidth").toFloat();
  512. var dx = position.x.toFloat()-x.toFloat();
  513. var width = initialWidth+dx;
  514. if (width> bodySize.x/2) width = bodySize.x/2;
  515. if (width<40) width = 40;
  516. this.contentNode.setStyle("margin-right", width+1);
  517. this.propertyNode.setStyle("width", width);
  518. }.bind(this)
  519. });
  520. },
  521. loadPropertyContentResize: function(){
  522. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  523. "snap": 1,
  524. "onStart": function(el, e){
  525. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  526. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  527. el.store("position", {"x": x, "y": y});
  528. var size = this.propertyDomArea.getSize();
  529. el.store("initialHeight", size.y);
  530. }.bind(this),
  531. "onDrag": function(el, e){
  532. var size = this.propertyContentNode.getSize();
  533. // var x = e.event.x;
  534. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  535. var position = el.retrieve("position");
  536. var dy = y.toFloat()-position.y.toFloat();
  537. var initialHeight = el.retrieve("initialHeight").toFloat();
  538. var height = initialHeight+dy;
  539. if (height<40) height = 40;
  540. if (height> size.y-40) height = size.y-40;
  541. this.propertyDomPercent = height/size.y;
  542. this.setPropertyContentResize();
  543. }.bind(this)
  544. });
  545. },
  546. setPropertyContentResize: function(){
  547. var size = this.propertyContentNode.getSize();
  548. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  549. var height = size.y-resizeNodeSize.y;
  550. var domHeight = this.propertyDomPercent*height;
  551. var contentHeight = height-domHeight;
  552. this.propertyDomArea.setStyle("height", ""+domHeight+"px");
  553. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  554. },
  555. //resizeNode------------------------------------------------
  556. resizeNode: function(){
  557. if (!this.isMax){
  558. var nodeSize = this.node.getSize();
  559. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  560. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  561. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  562. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  563. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  564. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  565. this.editContentNode.setStyle("height", ""+y+"px");
  566. if (this.designNode){
  567. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  568. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  569. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  570. this.designNode.setStyle("height", ""+y+"px");
  571. }
  572. titleSize = this.propertyTitleNode.getSize();
  573. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  574. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  575. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  576. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  577. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  578. y = nodeSize.y-y;
  579. this.propertyContentNode.setStyle("height", ""+y+"px");
  580. this.propertyResizeBar.setStyle("height", ""+y+"px");
  581. this.setPropertyContentResize();
  582. titleSize = this.scriptListTitleNode.getSize();
  583. titleMarginTop = this.scriptListTitleNode.getStyle("margin-top").toFloat();
  584. titleMarginBottom = this.scriptListTitleNode.getStyle("margin-bottom").toFloat();
  585. titlePaddingTop = this.scriptListTitleNode.getStyle("padding-top").toFloat();
  586. titlePaddingBottom = this.scriptListTitleNode.getStyle("padding-bottom").toFloat();
  587. nodeMarginTop = this.scriptListAreaSccrollNode.getStyle("margin-top").toFloat();
  588. nodeMarginBottom = this.scriptListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  589. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  590. y = nodeSize.y-y;
  591. this.scriptListAreaSccrollNode.setStyle("height", ""+y+"px");
  592. this.scriptListResizeNode.setStyle("height", ""+y+"px");
  593. }
  594. },
  595. //loadForm------------------------------------------
  596. loadScript: function(){
  597. //this.scriptTab.addTab(node, title);
  598. this.getScriptData(this.options.id, function(data){
  599. this.script = new MWF.xApplication.process.ScriptDesigner.Script(this, data);
  600. this.script.load();
  601. if (this.status){
  602. if (this.status.openScripts){
  603. this.status.openScripts.each(function(id){
  604. this.loadScriptData(id, function(data){
  605. var showTab = true;
  606. if (this.status.currentId){
  607. if (this.status.currentId!=data.id) showTab = false;
  608. }
  609. var script = new MWF.xApplication.process.ScriptDesigner.Script(this, data, {"showTab": showTab});
  610. script.load();
  611. }.bind(this), true);
  612. }.bind(this));
  613. }
  614. };
  615. if (!this.scriptHelpMenu){
  616. MWF.require("MWF.widget.ScriptHelp", function(){
  617. this.scriptHelpMenu = new MWF.widget.ScriptHelp($("MWFScriptAutoCode"), this.script.editor);
  618. this.scriptHelpMenu.getEditor = function(){
  619. if (this.scriptTab.showPage) return this.scriptTab.showPage.script.editor.editor;
  620. return null;
  621. }.bind(this)
  622. }.bind(this));
  623. }
  624. }.bind(this));
  625. },
  626. getScriptData: function(id, callback){
  627. if (!id){
  628. this.loadNewScriptData(callback);
  629. }else{
  630. this.loadScriptData(id, callback);
  631. }
  632. },
  633. loadNewScriptData: function(callback){
  634. this.actions.getUUID(function(id){
  635. var data = {
  636. "name": "",
  637. "id": id,
  638. "application": this.application.id,
  639. "alias": "",
  640. "description": "",
  641. "language": "javascript",
  642. "dependScriptList": [],
  643. "isNewScript": true,
  644. "text": ""
  645. };
  646. this.createListScriptItem(data, true);
  647. if (callback) callback(data);
  648. }.bind(this))
  649. },
  650. loadScriptData: function(id, callback, notSetTile){
  651. this.actions.getScript(id, function(json){
  652. if (json){
  653. var data = json.data;
  654. if (!notSetTile){
  655. this.setTitle(this.options.appTitle + "-"+data.name);
  656. this.taskitem.setText(this.options.appTitle + "-"+data.name);
  657. this.options.appTitle = this.options.appTitle + "-"+data.name;
  658. }
  659. if (!this.application){
  660. this.actions.getApplication(this.data.application, function(json){
  661. this.application = {"name": json.data.name, "id": json.data.id};
  662. if (callback) callback(data);
  663. }.bind(this));
  664. }else{
  665. if (callback) callback(data);
  666. }
  667. }
  668. }.bind(this));
  669. },
  670. saveScript: function(){
  671. if (this.scriptTab.showPage){
  672. var script = this.scriptTab.showPage.script;
  673. script.save(function(){
  674. if (script==this.script){
  675. var name = script.data.name;
  676. this.setTitle(MWF.APPSD.LP.title + "-"+name);
  677. this.options.desktopReload = true;
  678. this.options.id = script.data.id;
  679. }
  680. }.bind(this));
  681. }
  682. },
  683. saveDictionaryAs: function(){
  684. this.dictionary.saveAs();
  685. },
  686. dictionaryExplode: function(){
  687. this.dictionary.explode();
  688. },
  689. dictionaryImplode: function(){
  690. this.dictionary.implode();
  691. },
  692. recordStatus: function(){
  693. if (this.scriptTab){
  694. var openScripts = [];
  695. this.scriptTab.pages.each(function(page){
  696. if (page.script.data.id!=this.options.id) openScripts.push(page.script.data.id);
  697. }.bind(this));
  698. var currentId = this.scriptTab.showPage.script.data.id;
  699. var status = {
  700. "id": this.options.id,
  701. "application": this.application,
  702. "openScripts": openScripts,
  703. "currentId": currentId
  704. };
  705. return status;
  706. }
  707. return {"id": this.options.id, "application": this.application};
  708. }
  709. });