Main.js 30 KB

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