Main.js 36 KB

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