Main.js 32 KB

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