Main.js 32 KB

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