Main.js 39 KB

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