Main.js 31 KB

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