Main.js 45 KB

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