Main.js 29 KB

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