Main.js 29 KB

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