Main.js 45 KB

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