Main.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.xApplication.process.ApplicationExplorer = MWF.xApplication.process.ApplicationExplorer || {};
  3. MWF.xDesktop.requireApp("process.ApplicationExplorer", "lp."+MWF.language, null, false);
  4. MWF.xApplication.process.ApplicationExplorer.Main = new Class({
  5. Extends: MWF.xApplication.Common.Main,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "mvcStyle": "style.css",
  10. "name": "process.ApplicationExplorer",
  11. "icon": "icon.png",
  12. "width": "1500",
  13. "height": "760",
  14. "isResize": true,
  15. "isMax": true,
  16. "title": MWF.xApplication.process.ApplicationExplorer.LP.title,
  17. // "maxWidth": 840,
  18. // "minWidth": 720
  19. "maxWidth": 840,
  20. "minWidth": 540
  21. },
  22. onQueryLoad: function(){
  23. this.lp = MWF.xApplication.process.ApplicationExplorer.LP;
  24. this.viewPath = this.path+this.options.style+"/view.html";
  25. this.restActions = MWF.Actions.get("x_processplatform_assemble_designer");
  26. this.deleteElements = [];
  27. },
  28. loadApplication: function(callback){
  29. this.loadControl();
  30. this.content.loadHtml(this.viewPath, {"bind": {"lp": this.lp, "control": this.control}}, function(){
  31. if (!this.options.isRefresh){
  32. this.maxSize(function(){
  33. this.loadApp(callback);
  34. }.bind(this));
  35. }else{
  36. this.loadApp(callback);
  37. }
  38. }.bind(this));
  39. },
  40. loadApp: function(callback){
  41. this.loadNodes();
  42. this.resizeContent();
  43. this.addEvent("resize", this.resizeContent.bind(this));
  44. this.loadApplicationCategoryList();
  45. //this.loadApplicationList();
  46. this.clickAllCategoryNode();
  47. if (callback) callback();
  48. },
  49. loadControl: function(){
  50. this.control = {};
  51. this.control.canCreate = MWF.AC.isProcessPlatformCreator();
  52. this.control.canManage = !!(MWF.AC.isAdministrator() || MWF.AC.isProcessManager());
  53. },
  54. loadNodes: function(){
  55. this.node = this.content.getElement(".o2_process_AppExp_content");
  56. this.topNode = this.content.getElement(".o2_process_AppExp_top");
  57. this.allCategoryNode = this.content.getElement(".o2_process_AppExp_All");
  58. this.category = this.allCategoryNode;
  59. if (this.allCategoryNode) this.allCategoryNode.addEvent("click", this.clickAllCategoryNode.bind(this));
  60. this.createNode = this.content.getElement(".o2_process_AppExp_create");
  61. if (this.createNode) this.createNode.addEvent("click", this.createApplication.bind(this));
  62. this.importNode = this.content.getElement(".o2_process_AppExp_import");
  63. this.findNode = this.content.getElement(".o2_process_AppExp_find");
  64. this.categoryAreaNode = this.content.getElement(".o2_process_AppExp_category");
  65. this.contentArea = this.content.getElement(".o2_process_AppExp_contentArea");
  66. this.contentNode = this.content.getElement(".o2_process_AppExp_contentNode");
  67. this.bottomNode = this.content.getElement(".o2_process_AppExp_bottom");
  68. if (this.importNode){
  69. this.importNode.addEvent("click", function(e){
  70. this.importApplicationNew(e);
  71. }.bind(this));
  72. }
  73. if (this.findNode){
  74. this.findNode.addEvent("click", function(e){
  75. this.openFindDesigner();
  76. }.bind(this));
  77. }
  78. },
  79. openFindDesigner: function(){
  80. var options = {
  81. "filter": {
  82. "moduleList": ["processPlatform"]
  83. }
  84. };
  85. layout.openApplication(null, "FindDesigner", options);
  86. },
  87. importApplicationNew: function(e){
  88. MWF.xDesktop.requireApp("AppCenter", "", function(){
  89. if (!this.uploadFileAreaNode){
  90. this.uploadFileAreaNode = new Element("div");
  91. var html = "<input name=\"file\" type=\"file\" accept=\".xapp\"/>";
  92. this.uploadFileAreaNode.set("html", html);
  93. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  94. this.fileUploadNode.addEvent("change", this.importLocalFile.bind(this));
  95. }else{
  96. if (this.fileUploadNode) this.fileUploadNode.destroy();
  97. this.uploadFileAreaNode.empty();
  98. var html = "<input name=\"file\" type=\"file\" accept=\".xapp\"/>";
  99. this.uploadFileAreaNode.set("html", html);
  100. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  101. this.fileUploadNode.addEvent("change", this.importLocalFile.bind(this));
  102. }
  103. this.fileUploadNode.click();
  104. }.bind(this));
  105. return ;
  106. //老版导出
  107. MWF.xDesktop.requireApp("process.ApplicationExplorer", "Importer", function(){
  108. (new MWF.xApplication.process.ApplicationExplorer.Importer(this, e)).load();
  109. }.bind(this));
  110. },
  111. importLocalFile: function(){
  112. var files = this.fileUploadNode.files;
  113. if (files.length){
  114. var file = files[0];
  115. var position = this.topNode.getPosition(this.node);
  116. var size = this.contentArea.getSize();
  117. var width = size.x*0.9;
  118. if (width>600) width = 600;
  119. var height = size.y*0.9;
  120. var x = (size.x-width)/2;
  121. var y = (size.y-height)/2;
  122. var setupModule = null;
  123. var appCenter = new MWF.xApplication.AppCenter.Main();
  124. appCenter.inBrowser = true;
  125. appCenter.load(true);
  126. MWF.require("MWF.xDesktop.Dialog", function(){
  127. var dlg = new MWF.xDesktop.Dialog({
  128. "title": this.lp.setupTitle,
  129. "style": "appMarket",
  130. "top": y+20,
  131. "left": x,
  132. "fromTop":position.y,
  133. "fromLeft": position.x,
  134. "width": width,
  135. "height": height,
  136. "html": "",
  137. "maskNode": this.node,
  138. "container": this.node,
  139. "buttonList": [
  140. {
  141. "text": appCenter.lp.ok,
  142. "action": function(){
  143. if (setupModule) setupModule.setup();
  144. this.close();
  145. }
  146. },
  147. {
  148. "text": appCenter.lp.cancel,
  149. "action": function(){this.close();}
  150. }
  151. ]
  152. });
  153. dlg.show();
  154. setupModule = new MWF.xApplication.AppCenter.Module.SetupLocal(file, dlg, appCenter);
  155. debugger
  156. }.bind(this));
  157. }
  158. },
  159. createApplication: function(){
  160. this.createApplicationCreateMarkNode();
  161. this.createApplicationCreateAreaNode();
  162. this.createApplicationCreateNode();
  163. this.applicationCreateAreaNode.inject(this.applicationCreateMarkNode, "after");
  164. this.applicationCreateAreaNode.fade("in");
  165. $("createApplicationName").focus();
  166. this.setApplicationCreateNodeSize();
  167. this.setApplicationCreateNodeSizeFun = this.setApplicationCreateNodeSize.bind(this);
  168. this.addEvent("resize", this.setApplicationCreateNodeSizeFun);
  169. },
  170. createApplicationCreateMarkNode: function(){
  171. this.applicationCreateMarkNode = new Element("div.o2_process_AppExp_applicationCreateMarkNode", {
  172. "events": {
  173. "mouseover": function(e){e.stopPropagation();},
  174. "mouseout": function(e){e.stopPropagation();}
  175. }
  176. }).inject(this.node, "after");
  177. },
  178. createApplicationCreateAreaNode: function(){
  179. this.applicationCreateAreaNode = new Element("div.o2_process_AppExp_applicationCreateAreaNode");
  180. },
  181. createApplicationCreateNode: function(){
  182. this.applicationCreateNode = new Element("div.o2_process_AppExp_applicationCreateNode").inject(this.applicationCreateAreaNode);
  183. this.applicationCreateNewNode = new Element("div.o2_process_AppExp_applicationCreateNewNode").inject(this.applicationCreateNode);
  184. this.applicationCreateFormNode = new Element("div.o2_process_AppExp_applicationCreateFormNode").inject(this.applicationCreateNode);
  185. var html = "<table width=\"100%\" height=\"80%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  186. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left; min-width: 80px; width:25%\">" +
  187. this.lp.name+":</td>" +
  188. "<td style=\"; text-align: right;\"><input type=\"text\" class='o2_process_AppExp_createApplicationName' id=\"createApplicationName\" " +
  189. "style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  190. "height: 26px;\"/></td></tr>" +
  191. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.alias+":</td>" +
  192. "<td style=\"; text-align: right;\"><input type=\"text\" class='o2_process_AppExp_createApplicationAlias' id=\"createApplicationAlias\" " +
  193. "style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  194. "height: 26px;\"/></td></tr>" +
  195. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.description+":</td>" +
  196. "<td style=\"; text-align: right;\"><input type=\"text\" class='o2_process_AppExp_createApplicationDescription' id=\"createApplicationDescription\" " +
  197. "style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  198. "height: 26px;\"/></td></tr>" +
  199. "<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.type+":</td>" +
  200. "<td style=\"; text-align: right;\"><input type=\"text\" class='o2_process_AppExp_createApplicationType' id=\"createApplicationType\" " +
  201. "style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  202. "height: 26px;\"/></td></tr>" +
  203. //"<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.options.tooltip.iconLabel+":</td>" +
  204. //"<td style=\"; text-align: right;\"><input type=\"text\" id=\"createApplicationType\" " +
  205. //"style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  206. //"height: 26px;\"/></td></tr>" +
  207. "</table>";
  208. this.applicationCreateFormNode.set("html", html);
  209. this.applicationCancelActionNode = new Element("div.o2_process_AppExp_applicationCreateCancelActionNode", {
  210. "text": this.lp.action_cancel
  211. }).inject(this.applicationCreateFormNode);
  212. this.applicationCreateOkActionNode = new Element("div.o2_process_AppExp_applicationCreateOkActionNode", {
  213. "text": this.lp.action_ok
  214. }).inject(this.applicationCreateFormNode);
  215. this.applicationCancelActionNode.addEvent("click", function(e){
  216. this.cancelCreateApplication(e);
  217. }.bind(this));
  218. this.applicationCreateOkActionNode.addEvent("click", function(e){
  219. this.okCreateApplication(e);
  220. }.bind(this));
  221. },
  222. setApplicationCreateNodeSize: function(){
  223. var size = this.node.getSize();
  224. var allSize = this.content.getSize();
  225. this.applicationCreateMarkNode.setStyles({
  226. "width": ""+allSize.x+"px",
  227. "height": ""+allSize.y+"px"
  228. });
  229. this.applicationCreateAreaNode.setStyles({
  230. "width": ""+size.x+"px",
  231. "height": ""+size.y+"px"
  232. });
  233. var hY = size.y*0.8;
  234. var mY = size.y*0.2/2;
  235. this.applicationCreateNode.setStyles({
  236. "height": ""+hY+"px",
  237. "margin-top": ""+mY+"px"
  238. });
  239. var iconSize = this.applicationCreateNewNode.getSize();
  240. var formHeight = hY*0.7;
  241. if (formHeight>250) formHeight = 250;
  242. var formMargin = hY*0.3/2-iconSize.y;
  243. this.applicationCreateFormNode.setStyles({
  244. "height": ""+formHeight+"px",
  245. "margin-top": ""+formMargin+"px"
  246. });
  247. },
  248. cancelCreateApplication: function(e){
  249. var _self = this;
  250. var nameNode = this.applicationCreateFormNode.getElement(".o2_process_AppExp_createApplicationName");
  251. var aliasNode = this.applicationCreateFormNode.getElement(".o2_process_AppExp_createApplicationAlias");
  252. var descriptionNode = this.applicationCreateFormNode.getElement(".o2_process_AppExp_createApplicationDescription");
  253. if (nameNode.get("value") || aliasNode.get("value") || descriptionNode.get("value")){
  254. this.confirm("warn", e, this.lp.createApplication_cancel_title, this.lp.createApplication_cancel, 320, 100, function(){
  255. _self.applicationCreateMarkNode.destroy();
  256. _self.applicationCreateAreaNode.destroy();
  257. this.close();
  258. },function(){
  259. this.close();
  260. });
  261. }else{
  262. this.applicationCreateMarkNode.destroy();
  263. this.applicationCreateAreaNode.destroy();
  264. }
  265. },
  266. okCreateApplication: function(e){
  267. var nameNode = this.applicationCreateFormNode.getElement(".o2_process_AppExp_createApplicationName");
  268. var aliasNode = this.applicationCreateFormNode.getElement(".o2_process_AppExp_createApplicationAlias");
  269. var descriptionNode = this.applicationCreateFormNode.getElement(".o2_process_AppExp_createApplicationDescription");
  270. var typeNode = this.applicationCreateFormNode.getElement(".o2_process_AppExp_createApplicationType");
  271. var data = {
  272. "name": nameNode.get("value"),
  273. "alias": aliasNode.get("value"),
  274. "description": descriptionNode.get("value"),
  275. "applicationCategory": typeNode.get("value")
  276. };
  277. if (data.name){
  278. this.restActions.saveApplication(data, function(json){
  279. this.applicationCreateMarkNode.destroy();
  280. this.applicationCreateAreaNode.destroy();
  281. this.restActions.getApplication(json.data.id, function(json){
  282. json.data.processList = [];
  283. json.data.formList = [];
  284. this.createApplicationItem(json.data, "top");
  285. // var application = new MWF.xApplication.process.ApplicationExplorer.Application(this, json.data, "top");
  286. // application.load();
  287. //this.applications.push(application);
  288. }.bind(this));
  289. this.reloadApplicationCategoryList(true);
  290. this.notice(this.lp.application.createApplicationSuccess, "success");
  291. // this.app.processConfig();
  292. }.bind(this));
  293. }else{
  294. nameNode.setStyle("border-color", "red");
  295. nameNode.focus();
  296. this.notice(this.lp.application.inputApplicationName, "error");
  297. }
  298. },
  299. clickAllCategoryNode: function(){
  300. if (this.category){
  301. this.category.removeClass("o2_process_AppExp_categoryItem_current");
  302. this.category.removeClass("o2_process_AppExp_All_current");
  303. this.category.removeClass("o2_process_AppExp_categoryItem_over");
  304. this.category.removeClass("o2_process_AppExp_All_over");
  305. }
  306. this.allCategoryNode.removeClass("o2_process_AppExp_categoryItem_over");
  307. this.allCategoryNode.addClass("o2_process_AppExp_All_current");
  308. this.category = this.allCategoryNode;
  309. this.loadApplicationList(this.allCategoryNode);
  310. },
  311. resizeContent: function(){
  312. var size = this.content.getSize();
  313. var topSize = this.topNode.getComputedSize();
  314. var bottomSize = this.bottomNode.getComputedSize();
  315. var pt = this.contentArea.getStyle("padding-top").toInt() || 0;
  316. var pb = this.contentArea.getStyle("padding-bottom").toInt() || 0;
  317. var h = size.y-topSize.totalHeight-bottomSize.totalHeight-pt-pb;
  318. this.contentArea.setStyle("height", ""+h+"px");
  319. this.getApplicationDimension();
  320. if (this.contentNode){
  321. this.contentNode.setStyles({
  322. "margin-left": ""+this.dimension.marginLeft+"px",
  323. "margin-right": ""+this.dimension.marginRight+"px"
  324. });
  325. }
  326. },
  327. createCategoryExpandButton: function(){
  328. //this.categoryExpandButtonArea = new Element("div.o2_process_AppExp_categoryExpandButtonArea").inject(this.categoryAreaNode);
  329. this.categoryExpandButton = new Element("div.o2_process_AppExp_categoryExpandButton").inject(this.categoryAreaNode, "before");
  330. this.categoryExpandButton.addEvent("click", this.expandOrCollapseCategory.bind(this));
  331. },
  332. expandOrCollapseCategory: function(e){
  333. if (!this.categoryMorph) this.categoryMorph = new Fx.Morph(this.categoryAreaNode, {"duration": 100});
  334. if (this.categoryAreaNode.hasClass("o2_process_AppExp_category_more")){
  335. this.categoryAreaNode.removeClass("o2_process_AppExp_category_more");
  336. this.categoryMorph.start({"height": ""+this.topNode.getSize().y+"px"});
  337. if (this.expandOrCollapseCategoryFun) this.content.removeEvent("click", this.expandOrCollapseCategoryFun);
  338. }else{
  339. this.categoryAreaNode.addClass("o2_process_AppExp_category_more");
  340. this.categoryMorph.start({"height": ""+this.categoryAreaNode.getScrollSize().y+"px"});
  341. this.expandOrCollapseCategoryFun = this.expandOrCollapseCategory.bind(this);
  342. this.content.addEvent("click", this.expandOrCollapseCategoryFun);
  343. }
  344. e.stopPropagation();
  345. },
  346. loadApplicationCategoryList: function( currentCategoryName, noRefreshContent ){
  347. if (this.control.canCreate){
  348. this.restActions.listApplicationCategory(function(json){
  349. var emptyCategory = null;
  350. json.data.each(function(category){
  351. var categoryName = category.applicationCategory || category.portalCategory || category.protalCategory || category.name;
  352. if( categoryName === "null" )categoryName = "";
  353. if (categoryName){
  354. this.createCategoryItemNode(categoryName, category.count);
  355. }else{
  356. emptyCategory = category;
  357. }
  358. }.bind(this));
  359. if (this.categoryAreaNode.getScrollSize().y>this.categoryAreaNode.getSize().y) this.createCategoryExpandButton();
  360. if( currentCategoryName ){
  361. var itemList = this.categoryAreaNode.getElements("div.o2_process_AppExp_categoryItem");
  362. if( itemList.length > 0 ){
  363. for( var i=0; i<itemList.length; i++ ){
  364. if( itemList[i].retrieve("categoryName") === currentCategoryName ){
  365. this.clickCategoryNode( itemList[i], noRefreshContent)
  366. }
  367. }
  368. }
  369. }
  370. }.bind(this));
  371. }
  372. },
  373. reloadApplicationCategoryList: function( noRefreshContent ){
  374. var categoryName = "";
  375. if( this.category ){
  376. categoryName = this.category.retrieve("categoryName") || "";
  377. }
  378. this.categoryAreaNode.empty();
  379. this.loadApplicationCategoryList( categoryName, noRefreshContent );
  380. },
  381. createCategoryItemNode: function(text, count){
  382. var categoryName = text;
  383. var itemNode = new Element("div.o2_process_AppExp_categoryItem", {
  384. "text": (count) ? categoryName+" ("+count+") " : categoryName
  385. }).inject(this.categoryAreaNode);
  386. itemNode.store("categoryName", categoryName);
  387. var _self = this;
  388. itemNode.addEvents({
  389. "mouseover": function(){if (_self.category != this) this.addClass("o2_process_AppExp_categoryItem_over");},
  390. "mouseout": function(){if (_self.category != this) this.removeClass("o2_process_AppExp_categoryItem_over");},
  391. "click": function(){_self.clickCategoryNode(this)}
  392. });
  393. },
  394. clickCategoryNode: function(item, noRefreshContent){
  395. // var node = this.categoryListAreaNode.getFirst("div");
  396. // node.setStyles(this.css.allCategoryItemNode);
  397. if (this.category){
  398. this.category.removeClass("o2_process_AppExp_categoryItem_current");
  399. this.category.removeClass("o2_process_AppExp_All_current");
  400. this.category.removeClass("o2_process_AppExp_categoryItem_over");
  401. this.category.removeClass("o2_process_AppExp_All_over");
  402. }
  403. item.removeClass("o2_process_AppExp_categoryItem_over");
  404. item.addClass("o2_process_AppExp_categoryItem_current");
  405. var p = item.getPosition(this.categoryAreaNode);
  406. var size = this.topNode.getSize();
  407. if (p.y>=size.y) item.inject(this.categoryAreaNode, "top");
  408. this.category = item;
  409. if( !noRefreshContent ){
  410. this.loadApplicationList(item);
  411. }
  412. },
  413. getApplicationDimension: function(){
  414. if (!this.dimension) this.dimension = {};
  415. this.dimension.count = 2;
  416. this.dimension.width = this.options.maxWidth;
  417. this.dimension.marginLeft = 40;
  418. this.dimension.marginRight = 20;
  419. //var size = this.contentNode.getSize();
  420. var areaSize = this.content.getSize();
  421. //var areaSize = this.contentArea.getSize();
  422. var x = areaSize.x-60;
  423. if (areaSize.y>=this.contentArea.getScrollSize().y) x = x-18;
  424. var n = (x/this.dimension.count).toInt();
  425. if (n<this.options.minWidth){
  426. this.dimension.count = 1;
  427. this.dimension.width = Math.min(x, this.options.maxWidth)-2;
  428. }else{
  429. while(n>this.options.maxWidth){
  430. this.dimension.count++;
  431. n = (x/this.dimension.count).toInt();
  432. if (n<this.options.minWidth){
  433. this.dimension.count--;
  434. n = this.options.maxWidth;
  435. break;
  436. }
  437. }
  438. this.dimension.width = n;
  439. }
  440. var margin = areaSize.x-(this.dimension.width*this.dimension.count);
  441. this.dimension.width = this.dimension.width-(this.dimension.count*2);
  442. this.dimension.marginLeft = margin/2;
  443. this.dimension.marginRight = margin/2-20;
  444. },
  445. loadApplicationList: function(item){
  446. var name = "";
  447. if (item){name = item.retrieve("categoryName", "")};
  448. this.restActions.listApplicationSummary(name, function(json){
  449. this.contentNode.empty();
  450. if (json.data.length){
  451. this.getApplicationDimension();
  452. json.data.each(function(appData){
  453. this.createApplicationItem(appData);
  454. // var application = new MWF.xApplication.process.ApplicationExplorer.Application(this, appData);
  455. // application.load();
  456. //this.applications.push(application);
  457. }.bind(this));
  458. }else {
  459. if (this.control.canCreate){
  460. var noApplicationNode = new Element("div.o2_process_AppExp_noApplicationNode", {
  461. "html": this.lp.noApplicationCreate
  462. }).inject(this.contentNode);
  463. noApplicationNode.addEvent("click", function(){
  464. this.createApplication();
  465. }.bind(this));
  466. }else{
  467. var noApplicationNode = new Element("div.o2_process_AppExp_noApplicationNode", {
  468. "text": this.lp.noApplication
  469. }).inject(this.contentNode);
  470. }
  471. }
  472. }.bind(this));
  473. },
  474. createApplicationItem: function(appData, where){
  475. var application = new MWF.xApplication.process.ApplicationExplorer.Application(this, appData, where);
  476. application.load();
  477. },
  478. checkDeleteApplication: function(){
  479. if (this.deleteElements.length){
  480. if (!this.deleteElementsNode){
  481. this.deleteElementsNode = new Element("div.o2_process_AppExp_deleteElements", {
  482. "text": this.lp.application.deleteElements
  483. }).inject(this.node);
  484. this.deleteElementsNode.position({
  485. relativeTo: this.contentArea,
  486. position: "centerTop",
  487. edge: "centerTop"
  488. });
  489. this.deleteElementsNode.addEvent("click", function(e){
  490. this.deleteSelectedElements(e);
  491. }.bind(this));
  492. }
  493. }else{
  494. if (this.deleteElementsNode){
  495. this.deleteElementsNode.destroy();
  496. this.deleteElementsNode = null;
  497. delete this.deleteElementsNode;
  498. }
  499. }
  500. },
  501. deleteSelectedElements: function(e){
  502. var _self = this;
  503. var applicationList = [];
  504. this.deleteElements.each(function(app){
  505. applicationList.push(app.data.name);
  506. });
  507. var confirmStr = this.lp.application.deleteElementsConfirm+" ("+applicationList.join("、")+") ";
  508. var check = "<br/><br/><input type=\"checkbox\" id=\"deleteApplicationAllCheckbox\" value=\"yes\">"+this.lp.application.deleteApplicationAllConfirm;
  509. confirmStr += check;
  510. this.confirm("infor", e, this.lp.application.deleteElementsTitle, {"html":confirmStr}, 530, 250, function(){
  511. confirmStr = _self.lp.application.deleteElementsConfirmAgain+"<br/><br/><font style='color:red; font-size:14px; font-weight: bold'>"+applicationList.join("、")+"</font>";
  512. var checkbox = this.content.getElement("#deleteApplicationAllCheckbox");
  513. var onlyRemoveNotCompleted = true;
  514. if (checkbox.checked){
  515. onlyRemoveNotCompleted = false;
  516. confirmStr = _self.lp.application.deleteElementsAllConfirmAgain+"<br/><br/><font style='color:red; font-size:14px; font-weight: bold'>"+applicationList.join("、")+"</font>";
  517. }
  518. this.close();
  519. _self.confirm("infor", e, _self.lp.application.deleteElementsTitle, {"html":confirmStr}, 500, 200, function(){
  520. var deleted = [];
  521. var doCount = 0;
  522. var readyCount = _self.deleteElements.length;
  523. var errorText = "";
  524. var complete = function(){
  525. if (doCount == readyCount){
  526. _self.reloadApplicationCategoryList( true );
  527. if (errorText){
  528. _self.app.notice(errorText, "error");
  529. }
  530. }
  531. };
  532. _self.deleteElements.each(function(application){
  533. application["delete"](onlyRemoveNotCompleted, function(){
  534. deleted.push(application);
  535. doCount++;
  536. if (_self.deleteElements.length==doCount){
  537. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  538. return !deleted.contains(item);
  539. });
  540. _self.checkDeleteApplication();
  541. }
  542. complete();
  543. }, function(error){
  544. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  545. doCount++;
  546. if (_self.deleteElements.length==doCount){
  547. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  548. return !deleted.contains(item);
  549. });
  550. _self.checkDeleteApplication();
  551. }
  552. complete();
  553. });
  554. });
  555. this.close();
  556. }, function(){
  557. this.close();
  558. });
  559. this.close();
  560. }, function(){
  561. this.close();
  562. });
  563. },
  564. createAppCenterApp: function(id){
  565. var size = this.content.getSize();
  566. var content = new Element("div", {
  567. "styles": {
  568. "width": size.x+"px",
  569. "height": size.y+"px",
  570. "position": "absolute",
  571. "top": "0px"
  572. }
  573. }).inject(this.content, "after");
  574. var app = new new Class({Implements: [Events]})();
  575. app.lp = MWF.xApplication.AppCenter.LP;
  576. app.css = MWF.xApplication.AppCenter.LP;
  577. app.actions = MWF.Actions.get("x_program_center");
  578. app.curAppId = id;
  579. app.createApplicationNode = content;
  580. app.content = content;
  581. app.notice = this.notice;
  582. app.path = "../x_component_AppCenter/$Main/";
  583. app.options = {"style": "default"};
  584. app.cssPath = app.path + app.options.style + "/css.wcss";
  585. o2.JSON.get(app.cssPath, function(json){
  586. app.css = json;
  587. }, false);
  588. app.addEvent("exporterClose", function(){
  589. this.content.hide();
  590. });
  591. this.appCenterApp = app;
  592. },
  593. });
  594. MWF.xApplication.process.ApplicationExplorer.Application = new Class({
  595. Implements: [Events],
  596. initialize: function (app, data, where) {
  597. this.app = app;
  598. this.lp = this.app.lp;
  599. this.dimension = this.app.dimension;
  600. this.container = this.app.contentNode;
  601. this.data = data;
  602. this.where = where || "bottom";
  603. this.canManage = this.checkManage();
  604. },
  605. checkManage: function(){
  606. if (this.app.control.canManage) return true;
  607. if (this.app.control.canCreate && (this.data.creatorPerson==layout.desktop.session.user.name)) return true;
  608. //if (this.data.controllerList.indexOf(layout.desktop.session.user.distinguishedName)!==-1) return true;
  609. return false;
  610. },
  611. load: function(){
  612. this.node = new Element("div.o2_process_AppExp_item_node").inject(this.container, this.where);
  613. // this.node.addEvents({
  614. // "mouseover": function(){this.node.addClass("o2_process_AppExp_item_node_over");}.bind(this),
  615. // "mouseout": function(){this.node.removeClass("o2_process_AppExp_item_node_over");}.bind(this)
  616. // });
  617. var w = this.dimension.width-20;
  618. this.node.setStyle("width", ""+w+"px");
  619. this.node.loadHtml(this.app.path+this.app.options.style+"/application.html", {"bind": {"lp": this.lp, "data": this.data, "canManage": this.canManage}}, function(){
  620. this.loadNodes();
  621. this.loadElements();
  622. this.loadNewNode();
  623. }.bind(this));
  624. this.resizeContentFun = this.resizeContent.bind(this);
  625. this.app.addEvent("resize", this.resizeContentFun);
  626. },
  627. loadElements: function(){
  628. this.loadElementList("formList", this.formListNode, this.openForm.bind(this), this.lp.noForm, this.createNewForm.bind(this));
  629. this.loadElementList("processList", this.processListNode, this.openProcess.bind(this), this.lp.noProcess, this.createNewProcess.bind(this));
  630. },
  631. loadNewNode: function(){
  632. this.newNode = this.node.getElement(".o2_process_AppExp_item_newNode");
  633. if (this.data.updateTime){
  634. var createDate = Date.parse(this.data.createTime);
  635. var currentDate = new Date();
  636. if (createDate.diff(currentDate, "hour")<12) {
  637. this.newNode.show();
  638. }else{
  639. this.newNode.hide();
  640. }
  641. }
  642. },
  643. loadElementList: function(list, container, click, noElement, noElementClick){
  644. if (this.data[list].length){
  645. this.data[list].each(function(el){
  646. var item = new Element("div.o2_process_AppExp_item_content_element").inject(container);
  647. item.set("text", el.name);
  648. //item.set("title", (el.description) ? el.name+"\n"+el.description : el.name);
  649. item.store("elementId", el.id);
  650. item.addEvents({
  651. "mouseover": function(){this.addClass("o2_process_AppExp_item_content_element_over")},
  652. "mouseout": function(){this.removeClass("o2_process_AppExp_item_content_element_over")},
  653. "click": function(e){
  654. var id = this.retrieve("elementId");
  655. if (click) click(id, e);
  656. }
  657. });
  658. }.bind(this));
  659. }else{
  660. var node = new Element("div.o2_process_AppExp_item_content_element", {
  661. "text": noElement,
  662. "styles": { "color": "#999999" }
  663. }).inject(container);
  664. node.addEvent("click", function(e){ if (noElementClick) noElementClick(e); }.bind(this));
  665. }
  666. },
  667. createNewForm: function(e){
  668. this.openApplication(e, 0);
  669. },
  670. createNewProcess: function(e){
  671. this.openApplication(e, 1);
  672. },
  673. openApplication: function(e, navi){
  674. var appId = "process.ProcessManager"+this.data.id;
  675. if (this.app.desktop.apps[appId]){
  676. this.app.desktop.apps[appId].setCurrent();
  677. }else {
  678. this.app.desktop.openApplication(e, "process.ProcessManager", {
  679. "application": this.data,
  680. "appId": appId,
  681. "onQueryLoad": function(){
  682. this.status = {"navi": navi || null};
  683. }
  684. });
  685. }
  686. },
  687. openForm: function(id, e){
  688. if (id){
  689. layout.desktop.getFormDesignerStyle(function(){
  690. var _self = this;
  691. var options = {
  692. "style": layout.desktop.formDesignerStyle,
  693. "appId": "process.FormDesigner"+id,
  694. "onQueryLoad": function(){
  695. this.actions = _self.app.actions;
  696. this.options.id = id;
  697. this.application = _self.data;
  698. }
  699. };
  700. this.app.desktop.openApplication(e, "process.FormDesigner", options);
  701. }.bind(this));
  702. }
  703. },
  704. openProcess: function(id, e){
  705. if (id){
  706. var _self = this;
  707. var options = {
  708. "appId": "process.ProcessDesigner"+id,
  709. "onQueryLoad": function(){
  710. this.actions = _self.app.actions;
  711. this.options.id = id;
  712. this.application = _self.data;
  713. }
  714. };
  715. this.app.desktop.openApplication(e, "process.ProcessDesigner", options);
  716. }
  717. },
  718. setIconNode: function(){
  719. if (this.data.icon){
  720. this.iconNode.setStyle("background-image", "url(data:image/png;base64,"+this.data.icon+")");
  721. }else{
  722. this.iconNode.setStyle("background-image", "url("+"../x_component_process_ApplicationExplorer/$Main/default/icon/application.png)")
  723. }
  724. this.iconNode.makeLnk({
  725. "par": this._getLnkPar()
  726. });
  727. },
  728. _getLnkPar: function(){
  729. var lnkIcon = "../x_component_process_ApplicationExplorer/$Main/default/lnk.png";
  730. if (this.data.icon) lnkIcon = "data:image/png;base64,"+this.data.icon;
  731. var appId = "process.ProcessManager"+this.data.id;
  732. return {
  733. "icon": lnkIcon,
  734. "title": this.data.name,
  735. "par": "process.ProcessManager#{\"application\": \""+this.data.id+"\", \"appId\": \""+appId+"\"}"
  736. };
  737. },
  738. loadNodes: function(){
  739. this.iconNode = this.node.getElement(".o2_process_AppExp_item_icon");
  740. this.setIconNode();
  741. this.titleNode = this.node.getElement(".o2_process_AppExp_item_titleNode");
  742. this.formListNode = this.node.getElement(".o2_process_AppExp_item_contentFormList");
  743. this.processListNode = this.node.getElement(".o2_process_AppExp_item_contentProcessList");
  744. this.pageListNode = this.node.getElement(".o2_process_AppExp_item_contentPageList");
  745. this.viewListNode = this.node.getElement(".o2_process_AppExp_item_contentViewList");
  746. this.statListNode = this.node.getElement(".o2_process_AppExp_item_contentStatList");
  747. this.titleNode.addEvent("click", function(e){
  748. this.openApplication(e);
  749. }.bind(this));
  750. this.categoryNode = this.node.getElement(".o2_process_AppExp_item_categoryNode");
  751. var category = this.data.applicationCategory || this.data.portalCategory || this.data.protalCategory;
  752. var categoryText = category;
  753. if( !category || category === "null" )categoryText = this.lp.unCategory;
  754. this.categoryNode.set("text", categoryText );
  755. if ( category && category !== "null" ){
  756. this.categoryNode.set("title", category );
  757. this.categoryNode.addClass("o2_process_AppExp_item_categoryColorNode");
  758. }
  759. this.actionArea = this.node.getElement(".o2_process_AppExp_item_ActionArea");
  760. this.actionDelete = this.node.getElement(".o2_process_AppExp_item_Action_delete");
  761. this.actionExport = this.node.getElement(".o2_process_AppExp_item_Action_export");
  762. if (this.actionArea) this.setActionEvent();
  763. },
  764. setActionEvent: function(){
  765. this.node.addEvents({
  766. "mouseover": function(){
  767. if (!this.readyDelete) this.actionArea.fade("in");
  768. this.node.addClass("o2_process_AppExp_item_node_over");
  769. }.bind(this),
  770. "mouseout": function(){
  771. if (!this.readyDelete) this.actionArea.fade("out");
  772. this.node.removeClass("o2_process_AppExp_item_node_over");
  773. }.bind(this)
  774. });
  775. this.actionDelete.addEvent("click", function(e){
  776. this.checkDeleteApplication(e);
  777. e.stopPropagation();
  778. }.bind(this));
  779. this.actionExport.addEvent("click", function(e){
  780. MWF.xDesktop.requireApp("AppCenter", "", function(){
  781. // var appCenter = new MWF.xApplication.AppCenter.Main();
  782. // appCenter.inBrowser = true;
  783. // appCenter.load(true, content);
  784. if (!this.app.appCenterApp) this.app.createAppCenterApp(this.data.id);
  785. this.app.appCenterApp.curAppId = this.data.id;
  786. this.app.appCenterApp.content.show();
  787. new MWF.xApplication.AppCenter.Exporter(this.app.appCenterApp);
  788. //appCenter.createApplication(this.app.content,this.data.id);
  789. //appCenter.createApplication(null,this.data.id);
  790. }.bind(this));
  791. e.stopPropagation();
  792. //老版本导出
  793. // this.exportApplication(e);
  794. // e.stopPropagation();
  795. }.bind(this));
  796. },
  797. checkDeleteApplication: function(e){
  798. if (!this.readyDelete){
  799. this.actionDelete.addClass("o2_process_AppExp_item_Action_delete_select");
  800. this.node.addClass("o2_process_AppExp_item_node_del");
  801. this.readyDelete = true;
  802. this.app.deleteElements.push(this);
  803. }else{
  804. this.actionDelete.removeClass("o2_process_AppExp_item_Action_delete_select");
  805. this.node.removeClass("o2_process_AppExp_item_node_del");
  806. this.readyDelete = false;
  807. this.app.deleteElements.erase(this);
  808. }
  809. this.app.checkDeleteApplication();
  810. },
  811. exportApplication: function(){
  812. MWF.xDesktop.requireApp("process.ApplicationExplorer", "Exporter", function(){
  813. (new MWF.xApplication.process.ApplicationExplorer.Exporter(this.app, this.data)).load();
  814. }.bind(this));
  815. },
  816. resizeContent: function(){
  817. var w = this.dimension.width-20;
  818. this.node.setStyle("width", ""+w+"px");
  819. },
  820. "delete": function(onlyRemoveNotCompleted, success, failure){
  821. this._deleteElement(this.data.id, onlyRemoveNotCompleted, function(){
  822. this.destroy();
  823. if (success) success();
  824. }.bind(this), function(xhr, text, error){
  825. var errorText = error;
  826. if (xhr) errorText = xhr.responseText;
  827. // this.explorer.app.notice(errorText, "error", this.explorer.propertyContentNode, {x: "left", y:"top"});
  828. if (failure) failure(errorText);
  829. }.bind(this));
  830. },
  831. _deleteElement: function(id, onlyRemoveNotCompleted, success, failure){
  832. this.app.restActions.deleteApplication(id, onlyRemoveNotCompleted, success, failure);
  833. },
  834. destroy: function(){
  835. if (this.resizeContentFun) this.app.removeEvent("resize", this.resizeContentFun);
  836. this.node.destroy();
  837. o2.release(this);
  838. }
  839. });