Main.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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. MWF.getRequestText(toolbarUrl, function(responseText, responseXML){
  419. var htmlString = responseText;
  420. htmlString = o2.bindJson(htmlString, {"lp": this.lp.formToolbar});
  421. var temp = new Element('div').set('html', htmlString);
  422. if (callback) callback( temp.childNodes[0] );
  423. }.bind(this));
  424. },
  425. maxOrReturnEditor: function(){
  426. if (!this.isMax){
  427. this.designNode.inject(this.node);
  428. this.designNode.setStyles({
  429. "position": "absolute",
  430. "width": "100%",
  431. "height": "100%",
  432. "top": "0px",
  433. "margin": "0px",
  434. "left": "0px"
  435. });
  436. this.scriptTab.pages.each(function(page){
  437. page.script.setAreaNodeSize();
  438. });
  439. this.isMax = true;
  440. }else{
  441. this.isMax = false;
  442. this.designNode.inject(this.editContentNode);
  443. this.designNode.setStyles(this.css.designNode);
  444. this.designNode.setStyles({
  445. "position": "static"
  446. });
  447. this.resizeNode();
  448. this.scriptTab.pages.each(function(page){
  449. page.script.setAreaNodeSize();
  450. });
  451. }
  452. },
  453. loadEditContent: function(callback){
  454. this.designNode = new Element("div", {
  455. "styles": this.css.designNode
  456. }).inject(this.editContentNode);
  457. o2.require("o2.widget.Tab", function(){
  458. this.scriptTab = new o2.widget.Tab(this.designNode, {"style": "script"});
  459. this.scriptTab.load();
  460. }.bind(this), false);
  461. //o2.require("o2.widget.ScrollBar", function(){
  462. // new o2.widget.ScrollBar(this.designNode, {"distance": 100});
  463. //}.bind(this));
  464. },
  465. //loadProperty------------------------
  466. loadProperty: function(){
  467. this.propertyTitleNode = new Element("div", {
  468. "styles": this.css.propertyTitleNode,
  469. "text": o2.xApplication.ConfigDesigner.LP.property
  470. }).inject(this.propertyNode);
  471. this.propertyResizeBar = new Element("div", {
  472. "styles": this.css.propertyResizeBar
  473. }).inject(this.propertyNode);
  474. this.loadPropertyResize();
  475. this.propertyContentNode = new Element("div", {
  476. "styles": this.css.propertyContentNode
  477. }).inject(this.propertyNode);
  478. this.propertyDomArea = new Element("div", {
  479. "styles": this.css.propertyDomArea
  480. }).inject(this.propertyContentNode);
  481. this.propertyDomPercent = 0.3;
  482. this.propertyContentResizeNode = new Element("div", {
  483. "styles": this.css.propertyContentResizeNode
  484. }).inject(this.propertyContentNode);
  485. this.propertyContentArea = new Element("div", {
  486. "styles": this.css.propertyContentArea
  487. }).inject(this.propertyContentNode);
  488. this.loadPropertyContentResize();
  489. this.setPropertyContent();
  490. this.setIncludeNode();
  491. },
  492. setIncludeNode: function(){
  493. this.includeTitleNode = new Element("div", {"styles": this.css.includeTitleNode}).inject(this.propertyDomArea);
  494. this.includeTitleActionNode = new Element("div", {"styles": this.css.includeTitleActionNode}).inject(this.includeTitleNode);
  495. this.includeTitleTextNode = new Element("div", {"styles": this.css.includeTitleTextNode, "text": this.lp.include}).inject(this.includeTitleNode);
  496. this.includeTitleActionNode.addEvent("click", function(){
  497. this.addInclude();
  498. }.bind(this));
  499. this.propertyIncludeListArea = new Element("div", {
  500. "styles": {"overflow": "hidden"}
  501. }).inject(this.propertyDomArea);
  502. },
  503. addInclude: function(){
  504. },
  505. setPropertyContent: function(){
  506. var node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.id+":"}).inject(this.propertyContentArea);
  507. this.propertyIdNode = new Element("div", {"styles": this.css.propertyTextNode, "text": ""}).inject(this.propertyContentArea);
  508. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.name+":"}).inject(this.propertyContentArea);
  509. this.propertyNameNode = new Element("div", {"styles": this.css.propertyTextNode, "text": ""}).inject(this.propertyContentArea);
  510. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.node+":"}).inject(this.propertyContentArea);
  511. this.propertyServerNode = new Element("select", {"styles": this.css.propertyTextNode}).inject(this.propertyContentArea);
  512. o2.Actions.load("x_program_center").CommandAction.getNodeInfoList(
  513. function( json ){
  514. var nodeList = json.data.nodeList;
  515. if(nodeList.length>1){
  516. new Element("option", {"value": "*", "text": "*"}).inject(this.propertyServerNode);
  517. }
  518. nodeList.each(function (node) {
  519. new Element("option", {
  520. "value": node.node.nodeAgentPort,
  521. "text": node.nodeAddress
  522. }).inject(this.propertyServerNode);
  523. }.bind(this));
  524. }.bind(this),null, false
  525. );
  526. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.description+":"}).inject(this.propertyContentArea);
  527. this.propertyDescriptionNode = new Element("div", {"styles": this.css.propertyTextNode, "text": ""}).inject(this.propertyContentArea);
  528. },
  529. loadPropertyResize: function(){
  530. // var size = this.propertyNode.getSize();
  531. // var position = this.propertyResizeBar.getPosition();
  532. this.propertyResize = new Drag(this.propertyResizeBar,{
  533. "snap": 1,
  534. "onStart": function(el, e){
  535. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  536. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  537. el.store("position", {"x": x, "y": y});
  538. var size = this.propertyNode.getSize();
  539. el.store("initialWidth", size.x);
  540. }.bind(this),
  541. "onDrag": function(el, e){
  542. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  543. // var y = e.event.y;
  544. var bodySize = this.content.getSize();
  545. var position = el.retrieve("position");
  546. var initialWidth = el.retrieve("initialWidth").toFloat();
  547. var dx = position.x.toFloat()-x.toFloat();
  548. var width = initialWidth+dx;
  549. if (width> bodySize.x/2) width = bodySize.x/2;
  550. if (width<40) width = 40;
  551. this.contentNode.setStyle("margin-right", width+1);
  552. this.propertyNode.setStyle("width", width);
  553. }.bind(this)
  554. });
  555. },
  556. loadPropertyContentResize: function(){
  557. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  558. "snap": 1,
  559. "onStart": function(el, e){
  560. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  561. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  562. el.store("position", {"x": x, "y": y});
  563. var size = this.propertyDomArea.getSize();
  564. el.store("initialHeight", size.y);
  565. }.bind(this),
  566. "onDrag": function(el, e){
  567. var size = this.propertyContentNode.getSize();
  568. // var x = e.event.x;
  569. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  570. var position = el.retrieve("position");
  571. var dy = y.toFloat()-position.y.toFloat();
  572. var initialHeight = el.retrieve("initialHeight").toFloat();
  573. var height = initialHeight+dy;
  574. if (height<40) height = 40;
  575. if (height> size.y-40) height = size.y-40;
  576. this.propertyDomPercent = height/size.y;
  577. this.setPropertyContentResize();
  578. }.bind(this)
  579. });
  580. },
  581. setPropertyContentResize: function(){
  582. var size = this.propertyContentNode.getSize();
  583. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  584. var height = size.y-resizeNodeSize.y;
  585. var domHeight = this.propertyDomPercent*height;
  586. var contentHeight = height-domHeight;
  587. this.propertyDomArea.setStyle("height", ""+domHeight+"px");
  588. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  589. },
  590. //resizeNode------------------------------------------------
  591. resizeNode: function(){
  592. if (!this.isMax){
  593. var nodeSize = this.node.getSize();
  594. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  595. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  596. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  597. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  598. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  599. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  600. this.editContentNode.setStyle("height", ""+y+"px");
  601. if (this.designNode){
  602. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  603. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  604. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  605. this.designNode.setStyle("height", ""+y+"px");
  606. }
  607. titleSize = this.propertyTitleNode.getSize();
  608. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  609. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  610. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  611. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  612. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  613. y = nodeSize.y-y;
  614. this.propertyContentNode.setStyle("height", ""+y+"px");
  615. this.propertyResizeBar.setStyle("height", ""+y+"px");
  616. this.setPropertyContentResize();
  617. titleSize = this.scriptListTitleNode.getSize();
  618. titleMarginTop = this.scriptListTitleNode.getStyle("margin-top").toFloat();
  619. titleMarginBottom = this.scriptListTitleNode.getStyle("margin-bottom").toFloat();
  620. titlePaddingTop = this.scriptListTitleNode.getStyle("padding-top").toFloat();
  621. titlePaddingBottom = this.scriptListTitleNode.getStyle("padding-bottom").toFloat();
  622. nodeMarginTop = this.scriptListAreaSccrollNode.getStyle("margin-top").toFloat();
  623. nodeMarginBottom = this.scriptListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  624. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  625. y = nodeSize.y-y;
  626. this.scriptListAreaSccrollNode.setStyle("height", ""+y+"px");
  627. this.scriptListResizeNode.setStyle("height", ""+y+"px");
  628. }
  629. },
  630. //loadForm------------------------------------------
  631. loadScript: function(){
  632. //this.scriptTab.addTab(node, title);
  633. this.getScriptData(this.options.id, function(data){
  634. data.name = this.config[this.options.id];
  635. this.script = new o2.xApplication.ConfigDesigner.Script(this, data);
  636. this.script.load();
  637. }.bind(this));
  638. },
  639. getScriptData: function(id, callback){
  640. this.loadScriptData(id, callback);
  641. },
  642. loadScriptData: function(id, callback, notSetTile){
  643. this.actions.ConfigAction.open({fileName:id}, function(json){
  644. if (json){
  645. var data = json.data;
  646. data.id = id;
  647. data.text = data.fileContent;
  648. if (callback) callback(data);
  649. }
  650. }.bind(this));
  651. },
  652. saveScript: function(){
  653. if (this.scriptTab.showPage){
  654. var script = this.scriptTab.showPage.script;
  655. script.save(function(){
  656. if (script==this.script){
  657. var name = script.data.name;
  658. this.setTitle(o2.xApplication.ConfigDesigner.LP.title + "-"+name);
  659. this.options.desktopReload = true;
  660. this.options.id = script.data.id;
  661. }
  662. }.bind(this));
  663. }
  664. },
  665. saveDictionaryAs: function(){
  666. this.dictionary.saveAs();
  667. },
  668. dictionaryExplode: function(){
  669. this.dictionary.explode();
  670. },
  671. dictionaryImplode: function(){
  672. this.dictionary.implode();
  673. }
  674. });