Main.js 31 KB

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