Main.js 38 KB

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