Main.js 43 KB

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