Main.js 33 KB

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