Main.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  1. MWF.xDesktop.requireApp("process.ProcessManager", "package", null, false);
  2. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", null, false);
  3. MWF.xDesktop.requireApp("process.ProcessManager", "lp."+MWF.language, null, false);
  4. debugger;
  5. MWF.xDesktop.requireApp("Selector", "package", null, false);
  6. //MWF.require("MWF.xAction.org.express.RestActions", null,false);
  7. MWF.require("MWF.widget.O2Identity", null,false);
  8. MWF.xApplication.process.ProcessManager.Main = new Class({
  9. Extends: MWF.xApplication.Common.Main,
  10. Implements: [Options, Events],
  11. options: {
  12. "application": null,
  13. "style": "default",
  14. "name": "process.ProcessManager",
  15. "icon": "icon.png",
  16. "width": "1100",
  17. "height": "700",
  18. "title": MWF.xApplication.process.ProcessManager.LP.title
  19. },
  20. onQueryLoad: function(){
  21. this.lp = MWF.xApplication.process.ProcessManager.LP;
  22. this.currentContentNode = null;
  23. this.restActions = MWF.Actions.get("x_processplatform_assemble_designer");
  24. //this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  25. },
  26. loadApplication: function(callback){
  27. //if (this.status){
  28. // if (!this.options.application){
  29. // if (this.status.application){
  30. // this.restActions.getApplication(this.status.application, function(json){
  31. // if (json.data){
  32. // this.options.application = json.data;
  33. // alert("sds"+this.options.application);
  34. // }else{
  35. // this.close();
  36. // }
  37. // }.bind(this), function(){this.close();}.bind(this), false)
  38. // }else{
  39. // this.close();
  40. // }
  41. // }
  42. //}
  43. this.getApplication(function(){
  44. this.createNode();
  45. this.loadApplicationContent();
  46. if (callback) callback();
  47. //var clipboardEvent = new ClipboardEvent("copy", {dataType: "text/plain", data:""});
  48. if (window.clipboardData){
  49. this.addKeyboardEvents();
  50. }else{
  51. this.keyCopyItemsFun = this.keyCopyItems.bind(this);
  52. this.keyPasteItemsFun = this.keyPasteItems.bind(this);
  53. document.addEventListener('copy', this.keyCopyItemsFun);
  54. document.addEventListener('paste', this.keyPasteItemsFun);
  55. this.addEvent("queryClose", function(){
  56. debugger;
  57. if (this.keyCopyItemsFun) document.removeEventListener('copy', this.keyCopyItemsFun);
  58. if (this.keyPasteItemsFun) document.removeEventListener('paste', this.keyPasteItemsFun);
  59. }.bind(this));
  60. }
  61. }.bind(this), function(){
  62. this.close();
  63. }.bind(this));
  64. },
  65. addKeyboardEvents: function(){
  66. this.addEvent("copy", function(){
  67. this.keyCopyItems();
  68. }.bind(this));
  69. this.addEvent("paste", function(){
  70. this.keyPasteItems();
  71. }.bind(this));
  72. },
  73. keyCopyItems: function(e){
  74. debugger;
  75. if (layout.desktop.currentApp && layout.desktop.currentApp.appId===this.appId){
  76. if (this.formConfigurator){
  77. this.formConfigurator.keyCopy(e);
  78. if (e) e.preventDefault();
  79. }
  80. if (this.processConfigurator){
  81. this.processConfigurator.keyCopy(e);
  82. if (e) e.preventDefault();
  83. }
  84. if (this.dataConfigurator){
  85. this.dataConfigurator.keyCopy(e);
  86. if (e) e.preventDefault();
  87. }
  88. if (this.scriptConfigurator){
  89. this.scriptConfigurator.keyCopy(e);
  90. if (e) e.preventDefault();
  91. }
  92. }
  93. },
  94. keyPasteItems: function(e){
  95. debugger;
  96. if (layout.desktop.currentApp && layout.desktop.currentApp.appId===this.appId) {
  97. if (this.formConfigurator) {
  98. this.formConfigurator.keyPaste(e);
  99. }
  100. if (this.processConfigurator) {
  101. this.processConfigurator.keyPaste(e);
  102. }
  103. if (this.dataConfigurator) {
  104. this.dataConfigurator.keyPaste(e);
  105. }
  106. if (this.scriptConfigurator) {
  107. this.scriptConfigurator.keyPaste(e);
  108. }
  109. }
  110. },
  111. getApplication: function(success, failure){
  112. if (!this.options.application){
  113. if (this.status) {
  114. if (this.status.application){
  115. this.restActions.getApplication(this.status.application, function(json){
  116. if (json.data){
  117. this.options.application = json.data;
  118. if (success) success();
  119. }else{
  120. if (failure) failure();
  121. }
  122. }.bind(this), function(){if (failure) failure();}.bind(this), false)
  123. }else{
  124. if (failure) failure();
  125. }
  126. }else{
  127. if (failure) failure();
  128. }
  129. }else{
  130. if (success) success();
  131. }
  132. },
  133. loadApplicationContent: function(){
  134. this.loadStartMenu();
  135. this.loadApplicationLayout();
  136. },
  137. createNode: function(){
  138. this.content.setStyle("overflow", "hidden");
  139. this.node = new Element("div", {
  140. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  141. }).inject(this.content);
  142. },
  143. loadApplicationLayout: function(){
  144. // this.topMenuNode = new Element("div").inject(this.node);
  145. // MWF.require("MWF.widget.Toolbar", function(){
  146. // this.toobar = new MWF.widget.Toolbar(this.topMenuNode);
  147. // this.toobar.load();
  148. // alert("ok")
  149. // }.bind(this));
  150. },
  151. loadStartMenu: function(callback){
  152. this.startMenuNode = new Element("div", {
  153. "styles": this.css.startMenuNode
  154. }).inject(this.node);
  155. this.menu = new MWF.xApplication.process.ProcessManager.Menu(this, this.startMenuNode, {
  156. "onPostLoad": function(){
  157. if (this.status){
  158. if (this.status.navi!=null){
  159. this.menu.doAction(this.menu.startNavis[this.status.navi]);
  160. }else{
  161. this.menu.doAction(this.menu.startNavis[0]);
  162. }
  163. }else{
  164. this.menu.doAction(this.menu.startNavis[0]);
  165. }
  166. }.bind(this)
  167. });
  168. this.addEvent("resize", function(){
  169. if (this.menu) this.menu.onResize();
  170. }.bind(this));
  171. },
  172. clearContent: function(){
  173. if (this.processConfiguratorContent){
  174. if (this.processConfigurator) delete this.processConfigurator;
  175. this.processConfiguratorContent.destroy();
  176. this.processConfiguratorContent = null;
  177. }
  178. if (this.formConfiguratorContent){
  179. if (this.formConfigurator) delete this.formConfigurator;
  180. this.formConfiguratorContent.destroy();
  181. this.formConfiguratorContent = null;
  182. }
  183. if (this.viewConfiguratorContent){
  184. if (this.viewConfigurator) delete this.viewConfigurator;
  185. this.viewConfiguratorContent.destroy();
  186. this.viewConfiguratorContent = null;
  187. }
  188. if (this.statConfiguratorContent){
  189. if (this.statConfigurator) delete this.statConfigurator;
  190. this.statConfiguratorContent.destroy();
  191. this.statConfiguratorContent = null;
  192. }
  193. if (this.propertyConfiguratorContent){
  194. if (this.property) delete this.property;
  195. this.propertyConfiguratorContent.destroy();
  196. this.propertyConfiguratorContent = null;
  197. }
  198. if (this.dataConfiguratorContent){
  199. if (this.dataConfigurator) delete this.dataConfigurator;
  200. this.dataConfiguratorContent.destroy();
  201. this.dataConfiguratorContent = null;
  202. }
  203. if (this.scriptConfiguratorContent){
  204. if (this.scriptConfigurator) delete this.scriptConfigurator;
  205. this.scriptConfiguratorContent.destroy();
  206. this.scriptConfiguratorContent = null;
  207. }
  208. if (this.fileConfiguratorContent){
  209. if (this.fileConfigurator) delete this.fileConfigurator;
  210. this.fileConfiguratorContent.destroy();
  211. this.fileConfiguratorContent = null;
  212. }
  213. },
  214. applicationProperty: function(){
  215. this.clearContent();
  216. this.propertyConfiguratorContent = new Element("div", {
  217. "styles": this.css.rightContentNode
  218. }).inject(this.node);
  219. this.property = new MWF.xApplication.process.ProcessManager.ApplicationProperty(this, this.propertyConfiguratorContent);
  220. this.property.load();
  221. },
  222. processConfig: function(){
  223. this.clearContent();
  224. this.processConfiguratorContent = new Element("div", {
  225. "styles": this.css.rightContentNode
  226. }).inject(this.node);
  227. this.loadProcessConfig();
  228. },
  229. loadProcessConfig: function(){
  230. MWF.xDesktop.requireApp("process.ProcessManager", "ProcessExplorer", function(){
  231. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", function(){
  232. // if (!this.restActions) this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  233. this.restActions = MWF.Actions.get("x_processplatform_assemble_designer");
  234. this.processConfigurator = new MWF.xApplication.process.ProcessManager.ProcessExplorer(this.processConfiguratorContent, this.restActions);
  235. this.processConfigurator.app = this;
  236. this.processConfigurator.load();
  237. //}.bind(this));
  238. }.bind(this));
  239. },
  240. formConfig: function(){
  241. this.clearContent();
  242. this.formConfiguratorContent = new Element("div", {
  243. "styles": this.css.rightContentNode
  244. }).inject(this.node);
  245. this.loadFormConfig();
  246. },
  247. loadFormConfig: function(){
  248. MWF.xDesktop.requireApp("process.ProcessManager", "FormExplorer", function(){
  249. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", function(){
  250. // if (!this.restActions) this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  251. this.restActions = MWF.Actions.get("x_processplatform_assemble_designer");
  252. this.formConfigurator = new MWF.xApplication.process.ProcessManager.FormExplorer(this.formConfiguratorContent, this.restActions);
  253. this.formConfigurator.app = this;
  254. this.formConfigurator.load();
  255. //}.bind(this));
  256. }.bind(this));
  257. },
  258. viewConfig: function(){
  259. this.clearContent();
  260. this.viewConfiguratorContent = new Element("div", {
  261. "styles": this.css.rightContentNode
  262. }).inject(this.node);
  263. this.loadViewConfig();
  264. },
  265. loadViewConfig: function(){
  266. MWF.xDesktop.requireApp("process.ProcessManager", "ViewExplorer", function(){
  267. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", function(){
  268. // if (!this.restActions) this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  269. this.restActions = MWF.Actions.get("x_processplatform_assemble_designer");
  270. this.viewConfigurator = new MWF.xApplication.process.ProcessManager.ViewExplorer(this.viewConfiguratorContent, this.restActions);
  271. this.viewConfigurator.app = this;
  272. this.viewConfigurator.load();
  273. //}.bind(this));
  274. }.bind(this));
  275. },
  276. statConfig: function(){
  277. this.clearContent();
  278. this.statConfiguratorContent = new Element("div", {
  279. "styles": this.css.rightContentNode
  280. }).inject(this.node);
  281. this.loadStatConfig();
  282. },
  283. loadStatConfig: function(){
  284. MWF.xDesktop.requireApp("process.ProcessManager", "StatExplorer", function(){
  285. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", function(){
  286. // if (!this.restActions) this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  287. this.restActions = MWF.Actions.get("x_processplatform_assemble_designer");
  288. this.statConfigurator = new MWF.xApplication.process.ProcessManager.StatExplorer(this.statConfiguratorContent, this.restActions);
  289. this.statConfigurator.app = this;
  290. this.statConfigurator.load();
  291. //}.bind(this));
  292. }.bind(this));
  293. },
  294. dataConfig: function(){
  295. this.clearContent();
  296. this.dataConfiguratorContent = new Element("div", {
  297. "styles": this.css.rightContentNode
  298. }).inject(this.node);
  299. this.loadDataConfig();
  300. },
  301. loadDataConfig: function(){
  302. MWF.xDesktop.requireApp("process.ProcessManager", "DictionaryExplorer", function(){
  303. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", function(){
  304. // if (!this.restActions) this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  305. this.restActions = MWF.Actions.get("x_processplatform_assemble_designer");
  306. this.dataConfigurator = new MWF.xApplication.process.ProcessManager.DictionaryExplorer(this.dataConfiguratorContent, this.restActions);
  307. this.dataConfigurator.app = this;
  308. this.dataConfigurator.load();
  309. //}.bind(this));
  310. }.bind(this));
  311. },
  312. scriptConfig: function(){
  313. this.clearContent();
  314. this.scriptConfiguratorContent = new Element("div", {
  315. "styles": this.css.rightContentNode
  316. }).inject(this.node);
  317. this.loadScriptConfig();
  318. },
  319. loadScriptConfig: function(){
  320. MWF.xDesktop.requireApp("process.ProcessManager", "ScriptExplorer", function(){
  321. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", function(){
  322. // if (!this.restActions) this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  323. this.restActions = MWF.Actions.get("x_processplatform_assemble_designer");
  324. this.scriptConfigurator = new MWF.xApplication.process.ProcessManager.ScriptExplorer(this.scriptConfiguratorContent, this.restActions);
  325. this.scriptConfigurator.app = this;
  326. this.scriptConfigurator.load();
  327. //}.bind(this));
  328. }.bind(this));
  329. },
  330. fileConfig: function(){
  331. this.clearContent();
  332. this.fileConfiguratorContent = new Element("div", {
  333. "styles": this.css.rightContentNode
  334. }).inject(this.node);
  335. this.loadFileConfig();
  336. },
  337. loadFileConfig: function(){
  338. MWF.xDesktop.requireApp("process.ProcessManager", "FileExplorer", function(){
  339. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", function(){
  340. // if (!this.restActions) this.restActions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  341. this.restActions = MWF.Actions.get("x_processplatform_assemble_designer");
  342. this.fileConfigurator = new MWF.xApplication.process.ProcessManager.FileExplorer(this.fileConfiguratorContent, this.restActions);
  343. this.fileConfigurator.app = this;
  344. this.fileConfigurator.load();
  345. //}.bind(this));
  346. }.bind(this));
  347. },
  348. getCategoryCount: function(){
  349. var size = this.processConfiguratorContent.getSize();
  350. categoryCount = parseInt(size.x/182)+5;
  351. return categoryCount;
  352. },
  353. getProcessCount: function(){
  354. if (this.processConfigurator){
  355. var size = this.processConfigurator.processNode.getSize();
  356. processCount = (parseInt(size.x/401)*parseInt(size.y/101))+10;
  357. return processCount;
  358. }
  359. return 20;
  360. },
  361. showContentNode: function(node){
  362. if (this.currentContentNode){
  363. // this.currentContentNode.setStyles({
  364. // "position": "absolute"
  365. // });
  366. this.currentContentNode.fade("hide");
  367. node.fade("show");
  368. node.setStyle("display", "node");
  369. this.currentContentNode = null;
  370. }
  371. node.setStyle("display", "block");
  372. node.fade("show");
  373. this.currentContentNode = node;
  374. },
  375. recordStatus: function(){
  376. var idx = null;
  377. if (this.menu.currentNavi){
  378. idx = this.menu.startNavis.indexOf(this.menu.currentNavi);
  379. }
  380. return {"navi": idx, "application": this.options.application.id};
  381. }
  382. // onResize: function(){
  383. // if (this.menu) this.menu.onResize();
  384. // }
  385. });
  386. MWF.xApplication.process.ProcessManager.Menu = new Class({
  387. Implements: [Options, Events],
  388. initialize: function(app, node, options){
  389. this.setOptions(options);
  390. this.app = app;
  391. this.node = $(node);
  392. this.currentNavi = null;
  393. this.status = "start";
  394. this.startNavis = [];
  395. this.load();
  396. },
  397. load: function(){
  398. var menuUrl = this.app.path+"startMenu.json";
  399. MWF.getJSON(menuUrl, function(json){
  400. json.each(function(navi){
  401. var naviNode = new Element("div", {
  402. "styles": this.app.css.startMenuNaviNode
  403. });
  404. naviNode.store("naviData", navi);
  405. var iconNode = new Element("div", {
  406. "styles": this.app.css.startMenuIconNode
  407. }).inject(naviNode);
  408. iconNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/"+navi.icon+")");
  409. var textNode = new Element("div", {
  410. "styles": this.app.css.startMenuTextNode,
  411. "text": navi.title
  412. });
  413. textNode.inject(naviNode);
  414. naviNode.inject(this.node);
  415. this.startNavis.push(naviNode);
  416. this.setStartNaviEvent(naviNode, navi);
  417. this.setNodeCenter(this.node);
  418. }.bind(this));
  419. this.setStartMenuWidth();
  420. this.fireEvent("postLoad");
  421. }.bind(this));
  422. },
  423. setStartNaviEvent: function(naviNode){
  424. var _self = this;
  425. naviNode.addEvents({
  426. "mouseover": function(){ if (_self.currentNavi!=this) this.setStyles(_self.app.css.startMenuNaviNode_over);},
  427. "mouseout": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.startMenuNaviNode);},
  428. "mousedown": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.startMenuNaviNode_down);},
  429. "mouseup": function(){if (_self.currentNavi!=this) this.setStyles(_self.app.css.startMenuNaviNode_over);},
  430. "click": function(){
  431. //if (_self.currentNavi!=this) _self.doAction.apply(_self, [this]);
  432. _self.doAction.apply(_self, [this]);
  433. }
  434. });
  435. },
  436. doAction: function(naviNode){
  437. var navi = naviNode.retrieve("naviData");
  438. var action = navi.action;
  439. if (this.currentNavi) this.currentNavi.setStyles(this.app.css.startMenuNaviNode);
  440. naviNode.setStyles(this.app.css.startMenuNaviNode_current);
  441. this.currentNavi = naviNode;
  442. if (this.app[action]) this.app[action].apply(this.app);
  443. if (this.status == "start"){
  444. this.toNormal();
  445. this.status = "normal";
  446. }
  447. },
  448. toNormal: function(){
  449. // var size = this.getStartMenuNormalSize();
  450. var css = this.app.css.normalStartMenuNode;
  451. //css.height = size.height+"px";
  452. // css.height = "100%";
  453. // css.width = size.width+"px";
  454. //// this.node.setStyles(css);
  455. //
  456. if (!this.morph){
  457. this.morph = new Fx.Morph(this.node, {duration: 50, link: "chain"});
  458. }
  459. // this.morph.start(css).chain(function(){
  460. this.node.setStyles(css);
  461. MWF.require("MWF.widget.ScrollBar", function(){
  462. new MWF.widget.ScrollBar(this.node, {
  463. "style":"xApp_ProcessManager_StartMenu", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  464. });
  465. }.bind(this));
  466. // }.bind(this));
  467. //
  468. //// this.node.setStyles(css);
  469. ////
  470. //// this.startNavis.each(function(naviNode){
  471. //// if (this.currentNavi!=naviNode) naviNode.setStyles(this.app.css.startMenuNaviNode);
  472. //// }.bind(this));
  473. //
  474. // this.node.set("morph", {duration: 50});
  475. // this.node.morph(css);
  476. },
  477. setNodeCenter: function(node){
  478. var size = node.getSize();
  479. var contentSize = this.app.node.getSize();
  480. var top = contentSize.y/2 - size.y/2;
  481. var left = contentSize.x/2 - size.x/2;
  482. if (left<0) left = 0;
  483. if (top<0) top = 0;
  484. node.setStyles({"left": left, "top": top});
  485. },
  486. getStartMenuNormalSize: function(){
  487. var naviItemNode = this.node.getFirst();
  488. var size = naviItemNode.getComputedSize();
  489. var mt = naviItemNode.getStyle("margin-top").toFloat();
  490. var mb = naviItemNode.getStyle("margin-bottom").toFloat();
  491. var height = size.totalWidth+mt+mb;
  492. var ml = naviItemNode.getStyle("margin-left").toFloat();
  493. var mr = naviItemNode.getStyle("margin-right").toFloat();
  494. var width = size.totalWidth+ml+mr;
  495. return {"width": width, "height": height*this.startNavis.length};
  496. },
  497. setStartMenuWidth: function(){
  498. var naviItemNode = this.node.getFirst();
  499. var size = naviItemNode.getComputedSize();
  500. var ml = naviItemNode.getStyle("margin-left").toFloat();
  501. var mr = naviItemNode.getStyle("margin-right").toFloat();
  502. var width = size.totalWidth+ml+mr;
  503. this.node.setStyle("width", (width*this.startNavis.length)+"px");
  504. },
  505. onResize: function(){
  506. if (this.status == "start"){
  507. this.setNodeCenter(this.node);
  508. }
  509. }
  510. });
  511. MWF.xApplication.process.ProcessManager.ApplicationProperty = new Class({
  512. initialize: function(app, node){
  513. this.app = app;
  514. this.node = $(node);
  515. this.data = this.app.options.application;
  516. },
  517. load: function(){
  518. this.app.restActions.getApplication(this.app.options.application.id, function(json){
  519. this.data = json.data;
  520. this.propertyTitleBar = new Element("div", {
  521. "styles": this.app.css.propertyTitleBar,
  522. "text": this.data.name
  523. }).inject(this.node);
  524. this.contentNode = new Element("div", {
  525. "styles": this.app.css.propertyContentNode
  526. }).inject(this.node);
  527. this.contentAreaNode = new Element("div", {
  528. "styles": this.app.css.propertyContentAreaNode
  529. }).inject(this.contentNode);
  530. this.setContentHeight();
  531. this.setContentHeightFun = this.setContentHeight.bind(this);
  532. this.app.addEvent("resize", this.setContentHeightFun);
  533. MWF.require("MWF.widget.ScrollBar", function(){
  534. new MWF.widget.ScrollBar(this.contentNode, {"indent": false});
  535. }.bind(this));
  536. this.baseActionAreaNode = new Element("div", {
  537. "styles": this.app.css.baseActionAreaNode
  538. }).inject(this.contentAreaNode);
  539. this.baseActionNode = new Element("div", {
  540. "styles": this.app.css.propertyInforActionNode
  541. }).inject(this.baseActionAreaNode);
  542. this.baseTextNode = new Element("div", {
  543. "styles": this.app.css.baseTextNode,
  544. "text": this.app.lp.application.property
  545. }).inject(this.baseActionAreaNode);
  546. this.createEditBaseNode();
  547. this.createPropertyContentNode();
  548. this.createIconContentNode();
  549. this.createAvailableNode();
  550. this.createControllerListNode();
  551. }.bind(this));
  552. },
  553. setContentHeight: function(){
  554. var size = this.app.content.getSize();
  555. var titleSize = this.propertyTitleBar.getSize();
  556. var y = size.y-titleSize.y;
  557. this.contentNode.setStyle("height", ""+y+"px");
  558. },
  559. createIconContentNode: function(){
  560. this.iconContentTitleNode = new Element("div", {
  561. "styles": this.app.css.iconContentTitleNode,
  562. "text": this.app.lp.application.icon
  563. }).inject(this.contentAreaNode);
  564. this.iconContentNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.contentAreaNode);
  565. var html = "<table cellspacing='0' cellpadding='0' border='0' width='95%' align='center' style='margin-top: 20px'>";
  566. html += "<tr><td class='formTitle'><div id='formIconPreview'></div></td><td id='formChangeIconAction'></td></tr>";
  567. html += "</table>";
  568. this.iconContentNode.set("html", html);
  569. this.iconContentNode.getElements("td.formTitle").setStyles(this.app.css.propertyBaseContentTdTitle);
  570. this.iconPreviewNode = this.iconContentNode.getElement("div#formIconPreview");
  571. this.iconActionNode = this.iconContentNode.getElement("td#formChangeIconAction");
  572. this.iconPreviewNode.setStyles({
  573. "height": "72px",
  574. "width": "72px",
  575. "float": "right"
  576. });
  577. if (this.data.icon){
  578. this.iconPreviewNode.setStyle("background", "url(data:image/png;base64,"+this.data.icon+") center center no-repeat");
  579. }else{
  580. //this.iconPreviewNode.setStyle("background", "url("+"/x_component_process_ApplicationExplorer/$Main/default/icon/application.png) center center no-repeat")
  581. this.iconPreviewNode.setStyle("background", "url("+this.app.path+this.app.options.style+"/icon/application.png) center center no-repeat")
  582. }
  583. var changeIconAction = new Element("div", {
  584. "styles": {
  585. "margin-left": "20px",
  586. "float": "left",
  587. "background-color": "#FFF",
  588. "padding": "4px 14px",
  589. "border": "1px solid #999",
  590. "border-radius": "3px",
  591. "margin-top": "10px",
  592. "font-size": "14px",
  593. "color": "#666",
  594. "cursor": "pointer"
  595. },
  596. "text": "更改图标"
  597. }).inject(this.iconActionNode);
  598. changeIconAction.addEvent("click", function(){
  599. this.changeIcon();
  600. }.bind(this));
  601. },
  602. changeIcon: function(){
  603. debugger;
  604. MWF.require("MWF.widget.Upload", function(){
  605. var upload = new MWF.widget.Upload(this.app.content, {
  606. "data": null,
  607. "parameter": {"id": this.data.id},
  608. "action": this.app.restActions.action,
  609. "method": "updateApplicationIcon",
  610. "onCompleted": function(json){
  611. this.app.restActions.getApplication(this.data.id, function(json){
  612. if (json.data){
  613. this.data = json.data;
  614. if (this.data.icon){
  615. this.iconPreviewNode.setStyle("background", "url(data:image/png;base64,"+this.data.icon+") center center no-repeat");
  616. }else{
  617. this.iconPreviewNode.setStyle("background", "url("+"/x_component_process_ApplicationExplorer/$Main/default/icon/application.png) center center no-repeat")
  618. }
  619. }
  620. }.bind(this), false)
  621. }.bind(this)
  622. });
  623. upload.load();
  624. }.bind(this));
  625. },
  626. changeIcon_1: function(){
  627. if (!this.uploadFileAreaNode){
  628. this.uploadFileAreaNode = new Element("div");
  629. var html = "<input name=\"file\" type=\"file\"/>";
  630. this.uploadFileAreaNode.set("html", html);
  631. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  632. this.fileUploadNode.addEvent("change", function(){
  633. var files = fileNode.files;
  634. if (files.length){
  635. for (var i = 0; i < files.length; i++) {
  636. var file = files.item(i);
  637. var formData = new FormData();
  638. formData.append('file', file);
  639. //formData.append('name', file.name);
  640. //formData.append('folder', folderId);
  641. this.app.restActions.changeApplicationIcon(this.data.id ,function(){
  642. this.app.restActions.getApplication(this.data.id, function(json){
  643. if (json.data){
  644. this.data = json.data;
  645. if (this.data.icon){
  646. this.iconPreviewNode.setStyle("background", "url(data:image/png;base64,"+this.data.icon+") center center no-repeat");
  647. }else{
  648. this.iconPreviewNode.setStyle("background", "url("+"/x_component_process_ApplicationExplorer/$Main/default/icon/application.png) center center no-repeat")
  649. }
  650. }
  651. }.bind(this), false)
  652. }.bind(this), null, formData, file);
  653. }
  654. }
  655. }.bind(this));
  656. }
  657. var fileNode = this.uploadFileAreaNode.getFirst();
  658. fileNode.click();
  659. },
  660. createPropertyContentNode: function(){
  661. this.propertyContentNode = new Element("div", {"styles": {
  662. "overflow": "hidden",
  663. "-webkit-user-select": "text",
  664. "-moz-user-select": "text"
  665. }}).inject(this.contentAreaNode);
  666. var html = "<table cellspacing='0' cellpadding='0' border='0' width='95%' align='center' style='margin-top: 20px'>";
  667. html += "<tr><td class='formTitle'>"+this.app.lp.application.name+"</td><td id='formApplicationName'></td></tr>";
  668. html += "<tr><td class='formTitle'>"+this.app.lp.application.alias+"</td><td id='formApplicationAlias'></td></tr>";
  669. html += "<tr><td class='formTitle'>"+this.app.lp.application.description+"</td><td id='formApplicationDescription'></td></tr>";
  670. html += "<tr><td class='formTitle'>"+this.app.lp.application.type+"</td><td id='formApplicationType'></td></tr>";
  671. html += "<tr><td class='formTitle'>"+this.app.lp.application.id+"</td><td id='formApplicationId'></td></tr>";
  672. // html += "<tr><td class='formTitle'>"+this.app.lp.application.icon+"</td><td id='formApplicationIcon'></td></tr>";
  673. html += "</table>";
  674. this.propertyContentNode.set("html", html);
  675. this.propertyContentNode.getElements("td.formTitle").setStyles(this.app.css.propertyBaseContentTdTitle);
  676. this.nameInput = new MWF.xApplication.process.ProcessManager.Input(this.propertyContentNode.getElement("#formApplicationName"), this.data.name, this.app.css.formInput);
  677. this.aliasInput = new MWF.xApplication.process.ProcessManager.Input(this.propertyContentNode.getElement("#formApplicationAlias"), this.data.alias, this.app.css.formInput);
  678. this.descriptionInput = new MWF.xApplication.process.ProcessManager.Input(this.propertyContentNode.getElement("#formApplicationDescription"), this.data.description, this.app.css.formInput);
  679. this.typeInput = new MWF.xApplication.process.ProcessManager.Input(this.propertyContentNode.getElement("#formApplicationType"), this.data.applicationCategory, this.app.css.formInput);
  680. this.idInput = new MWF.xApplication.process.ProcessManager.Input(this.propertyContentNode.getElement("#formApplicationId"), this.data.id, this.app.css.formInput);
  681. },
  682. createControllerListNode: function(){
  683. //if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  684. this.controllerListTitleNode = new Element("div", {
  685. "styles": this.app.css.controllerListTitleNode,
  686. "text": this.app.lp.application.controllerList
  687. }).inject(this.contentAreaNode);
  688. this.controllerListContentNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.contentAreaNode);
  689. this.administratorsContentNode = new Element("div", {"styles": this.app.css.administratorsContentNode}).inject(this.controllerListContentNode);
  690. var changeAdministrators = new Element("div", {
  691. "styles": {
  692. "margin-left": "40px",
  693. "float": "left",
  694. "background-color": "#FFF",
  695. "padding": "4px 14px",
  696. "border": "1px solid #999",
  697. "border-radius": "3px",
  698. "margin-top": "10px",
  699. "margin-bottom": "20px",
  700. "font-size": "14px",
  701. "color": "#666",
  702. "cursor": "pointer"
  703. },
  704. "text": "设置管理者"
  705. }).inject(this.contentAreaNode);
  706. changeAdministrators.addEvent("click", function(){
  707. this.changeAdministrators();
  708. }.bind(this));
  709. if (this.data.controllerList){
  710. this.data.controllerList.each(function(name){
  711. if (name) var admin = new MWF.widget.O2Person({"name": name}, this.administratorsContentNode, {"style": "application"});
  712. }.bind(this));
  713. }
  714. },
  715. changeAdministrators: function(){
  716. debugger;
  717. var options = {
  718. "type": "person",
  719. "title": "设置应用管理者",
  720. "values": this.data.controllerList || [],
  721. "onComplete": function(items){
  722. this.administratorsContentNode.empty();
  723. var controllerList = [];
  724. items.each(function(item){
  725. controllerList.push(item.data.distinguishedName);
  726. var admin = new MWF.widget.O2Person(item.data, this.administratorsContentNode, {"style": "application"});
  727. }.bind(this));
  728. this.data.controllerList = controllerList;
  729. this.app.restActions.saveApplication(this.data, function(json){
  730. }.bind(this));
  731. }.bind(this)
  732. };
  733. var selector = new MWF.O2Selector(this.app.content, options);
  734. },
  735. createAvailableNode: function(){
  736. //if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  737. this.availableTitleNode = new Element("div", {
  738. "styles": this.app.css.availableTitleNode,
  739. "text": this.app.lp.application.available
  740. }).inject(this.contentAreaNode);
  741. this.availableContentNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.contentAreaNode);
  742. this.availableItemsContentNode = new Element("div", {"styles": this.app.css.availableItemsContentNode}).inject(this.availableContentNode);
  743. this.availableActionAreaNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.contentAreaNode);
  744. var changeIdentityList = new Element("div", {
  745. "styles": this.app.css.selectButtonStyle,
  746. "text": "设置可用身份"
  747. }).inject(this.availableActionAreaNode);
  748. changeIdentityList.addEvent("click", function(){
  749. this.changeAvailableIdentitys();
  750. }.bind(this));
  751. var changeUnitList = new Element("div", {
  752. "styles": this.app.css.selectButtonStyle,
  753. "text": "设置可用组织"
  754. }).inject(this.availableActionAreaNode);
  755. changeUnitList.addEvent("click", function(){
  756. this.changeAvailableUnit();
  757. }.bind(this));
  758. // var changeDepartmentList = new Element("div", {
  759. // "styles": this.app.css.selectButtonStyle,
  760. // "text": "设置可用部门"
  761. // }).inject(this.availableActionAreaNode);
  762. // changeDepartmentList.addEvent("click", function(){
  763. // this.changeAvailableDepartments();
  764. // }.bind(this));
  765. //
  766. // var changeCompanyList = new Element("div", {
  767. // "styles": this.app.css.selectButtonStyle,
  768. // "text": "设置可用公司"
  769. // }).inject(this.availableActionAreaNode);
  770. // changeCompanyList.addEvent("click", function(){
  771. // this.changeAvailableCompanys();
  772. // }.bind(this));
  773. this.setAvailableItems();
  774. },
  775. setAvailableItems: function(){
  776. if (this.data.availableIdentityList){
  777. this.data.availableIdentityList.each(function(name){
  778. if (name) new MWF.widget.O2Identity({"name": name}, this.availableItemsContentNode, {"style": "application"});
  779. }.bind(this));
  780. }
  781. if (this.data.availableUnitList){
  782. this.data.availableUnitList.each(function(name){
  783. if (name) new MWF.widget.O2Unit({"name": name}, this.availableItemsContentNode, {"style": "application"});
  784. }.bind(this));
  785. }
  786. // if (this.data.availableDepartmentList){
  787. // this.data.availableDepartmentList.each(function(name){
  788. // if (name) new MWF.widget.Department({"name": name}, this.availableItemsContentNode, explorer, false, null, {"style": "application"});
  789. // }.bind(this));
  790. // }
  791. // if (this.data.availableCompanyList){
  792. // this.data.availableCompanyList.each(function(name){
  793. // if (name) new MWF.widget.Company({"name": name}, this.availableItemsContentNode, explorer, false, null, {"style": "application"});
  794. // }.bind(this));
  795. // }
  796. },
  797. changeAvailableIdentitys: function(){
  798. var options = {
  799. "type": "identity",
  800. "title": "设置应用可用身份",
  801. "values": this.data.availableIdentityList || [],
  802. "onComplete": function(items){
  803. var availableIdentityList = [];
  804. items.each(function(item){
  805. availableIdentityList.push(item.data.distinguishedName);
  806. }.bind(this));
  807. this.data.availableIdentityList = availableIdentityList;
  808. this.app.restActions.saveApplication(this.data, function(json){
  809. this.availableItemsContentNode.empty();
  810. this.setAvailableItems();
  811. }.bind(this));
  812. }.bind(this)
  813. };
  814. var selector = new MWF.O2Selector(this.app.content, options);
  815. },
  816. changeAvailableUnit: function(){
  817. var options = {
  818. "type": "unit",
  819. "title": "设置应用可用组织",
  820. "values": this.data.availableUnitList || [],
  821. "onComplete": function(items){
  822. var availableUnitList = [];
  823. items.each(function(item){
  824. availableUnitList.push(item.data.distinguishedName);
  825. }.bind(this));
  826. this.data.availableUnitList = availableUnitList;
  827. this.app.restActions.saveApplication(this.data, function(json){
  828. this.availableItemsContentNode.empty();
  829. this.setAvailableItems();
  830. }.bind(this));
  831. }.bind(this)
  832. };
  833. var selector = new MWF.O2Selector(this.app.content, options);
  834. },
  835. createEditBaseNode: function(){
  836. this.editBaseNode = new Element("button", {
  837. "styles": this.app.css.editBaseNode,
  838. "text": this.app.lp.edit,
  839. "events": {"click": this.editBaseInfor.bind(this)}
  840. }).inject(this.baseActionNode);
  841. },
  842. createCancelBaseNode: function(){
  843. this.cancelBaseNode = new Element("button", {
  844. "styles": this.app.css.cancelBaseNode,
  845. "text": this.app.lp.cancel,
  846. "events": {"click": this.cancelBaseInfor.bind(this)}
  847. }).inject(this.baseActionNode);
  848. },
  849. createSaveBaseNode: function(){
  850. this.saveBaseNode = new Element("button", {
  851. "styles": this.app.css.saveBaseNode,
  852. "text": this.app.lp.save,
  853. "events": {"click": this.saveBaseInfor.bind(this)}
  854. }).inject(this.baseActionNode);
  855. },
  856. editBaseInfor: function(){
  857. this.baseActionNode.empty();
  858. this.editBaseNode = null;
  859. this.createCancelBaseNode();
  860. this.createSaveBaseNode();
  861. this.editMode();
  862. },
  863. editMode: function(){
  864. this.nameInput.editMode();
  865. this.aliasInput.editMode();
  866. this.descriptionInput.editMode();
  867. this.typeInput.editMode();
  868. this.isEdit = true;
  869. },
  870. readMode: function(){
  871. this.nameInput.readMode();
  872. this.aliasInput.readMode();
  873. this.descriptionInput.readMode();
  874. this.typeInput.readMode();
  875. this.isEdit = false;
  876. },
  877. cancelBaseInfor: function(){
  878. if (this.data.name){
  879. this.baseActionNode.empty();
  880. this.cancelBaseNode = null;
  881. this.saveBaseNode = null;
  882. this.createEditBaseNode();
  883. this.readMode();
  884. }else{
  885. this.destroy();
  886. }
  887. },
  888. saveBaseInfor: function(){
  889. if (!this.nameInput.input.get("value")){
  890. this.app.notice(this.app.lp.application.inputApplicationName, "error", this.node);
  891. return false;
  892. }
  893. this.node.mask({
  894. "style": {
  895. "opacity": 0.7,
  896. "background-color": "#999"
  897. }
  898. });
  899. this.save(function(){
  900. this.baseActionNode.empty();
  901. this.cancelBaseNode = null;
  902. this.saveBaseNode = null;
  903. this.createEditBaseNode();
  904. this.readMode();
  905. this.node.unmask();
  906. }.bind(this), function(xhr, text, error){
  907. var errorText = error;
  908. if (xhr) errorText = xhr.responseText;
  909. this.app.notice("request json error: "+errorText, "error");
  910. this.node.unmask();
  911. }.bind(this));
  912. },
  913. save: function(callback, cancel){
  914. this.data.name = this.nameInput.input.get("value");
  915. this.data.alias = this.aliasInput.input.get("value");
  916. this.data.description = this.descriptionInput.input.get("value");
  917. this.data.applicationCategory = this.typeInput.input.get("value");
  918. this.app.restActions.saveApplication(this.data, function(json){
  919. this.propertyTitleBar.set("text", this.data.name);
  920. this.data.id = json.data.id;
  921. this.nameInput.save();
  922. this.aliasInput.save();
  923. this.descriptionInput.save();
  924. this.typeInput.save();
  925. if (callback) callback();
  926. }.bind(this), function(xhr, text, error){
  927. if (cancel) cancel(xhr, text, error);
  928. }.bind(this));
  929. }
  930. });
  931. MWF.xApplication.process.ProcessManager.Input = new Class({
  932. Implements: [Events],
  933. initialize: function(node, value, style){
  934. this.node = $(node);
  935. this.value = value || "";
  936. this.style = style;
  937. this.load();
  938. },
  939. load: function(){
  940. this.content = new Element("div", {
  941. "styles": this.style.content,
  942. "text": this.value
  943. }).inject(this.node);
  944. },
  945. editMode: function(){
  946. this.content.empty();
  947. this.input = new Element("input",{
  948. "styles": this.style.input,
  949. "value": this.value
  950. }).inject(this.content);
  951. this.input.addEvents({
  952. "focus": function(){
  953. this.input.setStyles(this.style.input_focus);
  954. }.bind(this),
  955. "blur": function(){
  956. this.input.setStyles(this.style.input);
  957. }.bind(this)
  958. });
  959. },
  960. readMode: function(){
  961. this.content.empty();
  962. this.input = null;
  963. this.content.set("text", this.value);
  964. },
  965. save: function(){
  966. if (this.input) this.value = this.input.get("value");
  967. return this.value;
  968. }
  969. });