Main.js 45 KB

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