Main.js 44 KB

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