Main.js 43 KB

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