Main.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  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.reloadApplicationCategoryList(true);
  276. this.notice(this.lp.application.createApplicationSuccess, "success");
  277. // this.app.processConfig();
  278. }.bind(this));
  279. }else{
  280. nameNode.setStyle("border-color", "red");
  281. nameNode.focus();
  282. this.notice(this.lp.application.inputApplicationName, "error");
  283. }
  284. },
  285. clickAllCategoryNode: function(){
  286. if (this.category){
  287. this.category.removeClass("o2_process_AppExp_categoryItem_current");
  288. this.category.removeClass("o2_process_AppExp_All_current");
  289. this.category.removeClass("o2_process_AppExp_categoryItem_over");
  290. this.category.removeClass("o2_process_AppExp_All_over");
  291. }
  292. this.allCategoryNode.removeClass("o2_process_AppExp_categoryItem_over");
  293. this.allCategoryNode.addClass("o2_process_AppExp_All_current");
  294. this.category = this.allCategoryNode;
  295. this.loadApplicationList(this.allCategoryNode);
  296. },
  297. resizeContent: function(){
  298. var size = this.content.getSize();
  299. var topSize = this.topNode.getComputedSize();
  300. var bottomSize = this.bottomNode.getComputedSize();
  301. var pt = this.contentArea.getStyle("padding-top").toInt() || 0;
  302. var pb = this.contentArea.getStyle("padding-bottom").toInt() || 0;
  303. var h = size.y-topSize.totalHeight-bottomSize.totalHeight-pt-pb;
  304. this.contentArea.setStyle("height", ""+h+"px");
  305. this.getApplicationDimension();
  306. if (this.contentNode){
  307. this.contentNode.setStyles({
  308. "margin-left": ""+this.dimension.marginLeft+"px",
  309. "margin-right": ""+this.dimension.marginRight+"px"
  310. });
  311. }
  312. },
  313. createCategoryExpandButton: function(){
  314. //this.categoryExpandButtonArea = new Element("div.o2_process_AppExp_categoryExpandButtonArea").inject(this.categoryAreaNode);
  315. this.categoryExpandButton = new Element("div.o2_process_AppExp_categoryExpandButton").inject(this.categoryAreaNode, "before");
  316. this.categoryExpandButton.addEvent("click", this.expandOrCollapseCategory.bind(this));
  317. },
  318. expandOrCollapseCategory: function(e){
  319. if (!this.categoryMorph) this.categoryMorph = new Fx.Morph(this.categoryAreaNode, {"duration": 100});
  320. if (this.categoryAreaNode.hasClass("o2_process_AppExp_category_more")){
  321. this.categoryAreaNode.removeClass("o2_process_AppExp_category_more");
  322. this.categoryMorph.start({"height": ""+this.topNode.getSize().y+"px"});
  323. if (this.expandOrCollapseCategoryFun) this.content.removeEvent("click", this.expandOrCollapseCategoryFun);
  324. }else{
  325. this.categoryAreaNode.addClass("o2_process_AppExp_category_more");
  326. this.categoryMorph.start({"height": ""+this.categoryAreaNode.getScrollSize().y+"px"});
  327. this.expandOrCollapseCategoryFun = this.expandOrCollapseCategory.bind(this);
  328. this.content.addEvent("click", this.expandOrCollapseCategoryFun);
  329. }
  330. e.stopPropagation();
  331. },
  332. loadApplicationCategoryList: function( currentCategoryName, noRefreshContent ){
  333. if (this.control.canCreate){
  334. this.restActions.listApplicationCategory(function(json){
  335. var emptyCategory = null;
  336. json.data.each(function(category){
  337. var categoryName = category.applicationCategory || category.portalCategory || category.protalCategory || category.name;
  338. if( categoryName === "null" )categoryName = "";
  339. if (categoryName){
  340. this.createCategoryItemNode(categoryName, category.count);
  341. }else{
  342. emptyCategory = category;
  343. }
  344. }.bind(this));
  345. if (this.categoryAreaNode.getScrollSize().y>this.categoryAreaNode.getSize().y) this.createCategoryExpandButton();
  346. if( currentCategoryName ){
  347. var itemList = this.categoryAreaNode.getElements("div.o2_process_AppExp_categoryItem");
  348. if( itemList.length > 0 ){
  349. for( var i=0; i<itemList.length; i++ ){
  350. if( itemList[i].retrieve("categoryName") === currentCategoryName ){
  351. this.clickCategoryNode( itemList[i], noRefreshContent)
  352. }
  353. }
  354. }
  355. }
  356. }.bind(this));
  357. }
  358. },
  359. reloadApplicationCategoryList: function( noRefreshContent ){
  360. var categoryName = "";
  361. if( this.category ){
  362. categoryName = this.category.retrieve("categoryName") || "";
  363. }
  364. this.categoryAreaNode.empty();
  365. this.loadApplicationCategoryList( categoryName, noRefreshContent );
  366. },
  367. createCategoryItemNode: function(text, count){
  368. var categoryName = text;
  369. var itemNode = new Element("div.o2_process_AppExp_categoryItem", {
  370. "text": (count) ? categoryName+" ("+count+") " : categoryName
  371. }).inject(this.categoryAreaNode);
  372. itemNode.store("categoryName", categoryName);
  373. var _self = this;
  374. itemNode.addEvents({
  375. "mouseover": function(){if (_self.category != this) this.addClass("o2_process_AppExp_categoryItem_over");},
  376. "mouseout": function(){if (_self.category != this) this.removeClass("o2_process_AppExp_categoryItem_over");},
  377. "click": function(){_self.clickCategoryNode(this)}
  378. });
  379. },
  380. clickCategoryNode: function(item, noRefreshContent){
  381. // var node = this.categoryListAreaNode.getFirst("div");
  382. // node.setStyles(this.css.allCategoryItemNode);
  383. if (this.category){
  384. this.category.removeClass("o2_process_AppExp_categoryItem_current");
  385. this.category.removeClass("o2_process_AppExp_All_current");
  386. this.category.removeClass("o2_process_AppExp_categoryItem_over");
  387. this.category.removeClass("o2_process_AppExp_All_over");
  388. }
  389. item.removeClass("o2_process_AppExp_categoryItem_over");
  390. item.addClass("o2_process_AppExp_categoryItem_current");
  391. var p = item.getPosition(this.categoryAreaNode);
  392. var size = this.topNode.getSize();
  393. if (p.y>=size.y) item.inject(this.categoryAreaNode, "top");
  394. this.category = item;
  395. if( !noRefreshContent ){
  396. this.loadApplicationList(item);
  397. }
  398. },
  399. getApplicationDimension: function(){
  400. if (!this.dimension) this.dimension = {};
  401. this.dimension.count = 2;
  402. this.dimension.width = this.options.maxWidth;
  403. this.dimension.marginLeft = 40;
  404. this.dimension.marginRight = 20;
  405. //var size = this.contentNode.getSize();
  406. var areaSize = this.content.getSize();
  407. //var areaSize = this.contentArea.getSize();
  408. var x = areaSize.x-60;
  409. if (areaSize.y>=this.contentArea.getScrollSize().y) x = x-18;
  410. var n = (x/this.dimension.count).toInt();
  411. if (n<this.options.minWidth){
  412. this.dimension.count = 1;
  413. this.dimension.width = Math.min(x, this.options.maxWidth)-2;
  414. }else{
  415. while(n>this.options.maxWidth){
  416. this.dimension.count++;
  417. n = (x/this.dimension.count).toInt();
  418. if (n<this.options.minWidth){
  419. this.dimension.count--;
  420. n = this.options.maxWidth;
  421. break;
  422. }
  423. }
  424. this.dimension.width = n;
  425. }
  426. var margin = areaSize.x-(this.dimension.width*this.dimension.count);
  427. this.dimension.width = this.dimension.width-(this.dimension.count*2);
  428. this.dimension.marginLeft = margin/2;
  429. this.dimension.marginRight = margin/2-20;
  430. },
  431. loadApplicationList: function(item){
  432. var name = "";
  433. if (item){name = item.retrieve("categoryName", "")};
  434. this.restActions.listApplicationSummary(name, function(json){
  435. this.contentNode.empty();
  436. if (json.data.length){
  437. this.getApplicationDimension();
  438. json.data.each(function(appData){
  439. this.createApplicationItem(appData);
  440. // var application = new MWF.xApplication.process.ApplicationExplorer.Application(this, appData);
  441. // application.load();
  442. //this.applications.push(application);
  443. }.bind(this));
  444. }else {
  445. if (this.control.canCreate){
  446. var noApplicationNode = new Element("div.o2_process_AppExp_noApplicationNode", {
  447. "html": this.lp.noApplicationCreate
  448. }).inject(this.contentNode);
  449. noApplicationNode.addEvent("click", function(){
  450. this.createApplication();
  451. }.bind(this));
  452. }else{
  453. var noApplicationNode = new Element("div.o2_process_AppExp_noApplicationNode", {
  454. "text": this.lp.noApplication
  455. }).inject(this.contentNode);
  456. }
  457. }
  458. }.bind(this));
  459. },
  460. createApplicationItem: function(appData, where){
  461. var application = new MWF.xApplication.process.ApplicationExplorer.Application(this, appData, where);
  462. application.load();
  463. },
  464. checkDeleteApplication: function(){
  465. if (this.deleteElements.length){
  466. if (!this.deleteElementsNode){
  467. this.deleteElementsNode = new Element("div.o2_process_AppExp_deleteElements", {
  468. "text": this.lp.application.deleteElements
  469. }).inject(this.node);
  470. this.deleteElementsNode.position({
  471. relativeTo: this.contentArea,
  472. position: "centerTop",
  473. edge: "centerTop"
  474. });
  475. this.deleteElementsNode.addEvent("click", function(e){
  476. this.deleteSelectedElements(e);
  477. }.bind(this));
  478. }
  479. }else{
  480. if (this.deleteElementsNode){
  481. this.deleteElementsNode.destroy();
  482. this.deleteElementsNode = null;
  483. delete this.deleteElementsNode;
  484. }
  485. }
  486. },
  487. deleteSelectedElements: function(e){
  488. var _self = this;
  489. var applicationList = [];
  490. this.deleteElements.each(function(app){
  491. applicationList.push(app.data.name);
  492. });
  493. var confirmStr = this.lp.application.deleteElementsConfirm+" ("+applicationList.join("、")+") ";
  494. var check = "<br/><br/><input type=\"checkbox\" id=\"deleteApplicationAllCheckbox\" value=\"yes\">"+this.lp.application.deleteApplicationAllConfirm;
  495. confirmStr += check;
  496. this.confirm("infor", e, this.lp.application.deleteElementsTitle, {"html":confirmStr}, 530, 250, function(){
  497. confirmStr = _self.lp.application.deleteElementsConfirmAgain+"<br/><br/><font style='color:red; font-size:14px; font-weight: bold'>"+applicationList.join("、")+"</font>";
  498. var checkbox = this.content.getElement("#deleteApplicationAllCheckbox");
  499. var onlyRemoveNotCompleted = true;
  500. if (checkbox.checked){
  501. onlyRemoveNotCompleted = false;
  502. confirmStr = _self.lp.application.deleteElementsAllConfirmAgain+"<br/><br/><font style='color:red; font-size:14px; font-weight: bold'>"+applicationList.join("、")+"</font>";
  503. }
  504. this.close();
  505. _self.confirm("infor", e, _self.lp.application.deleteElementsTitle, {"html":confirmStr}, 500, 200, function(){
  506. var deleted = [];
  507. var doCount = 0;
  508. var readyCount = _self.deleteElements.length;
  509. var errorText = "";
  510. var complete = function(){
  511. if (doCount == readyCount){
  512. _self.reloadApplicationCategoryList( true );
  513. if (errorText){
  514. _self.app.notice(errorText, "error");
  515. }
  516. }
  517. };
  518. _self.deleteElements.each(function(application){
  519. application["delete"](onlyRemoveNotCompleted, function(){
  520. deleted.push(application);
  521. doCount++;
  522. if (_self.deleteElements.length==doCount){
  523. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  524. return !deleted.contains(item);
  525. });
  526. _self.checkDeleteApplication();
  527. }
  528. complete();
  529. }, function(error){
  530. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  531. doCount++;
  532. if (_self.deleteElements.length==doCount){
  533. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  534. return !deleted.contains(item);
  535. });
  536. _self.checkDeleteApplication();
  537. }
  538. complete();
  539. });
  540. });
  541. this.close();
  542. }, function(){
  543. this.close();
  544. });
  545. this.close();
  546. }, function(){
  547. this.close();
  548. });
  549. },
  550. createAppCenterApp: function(id){
  551. var size = this.content.getSize();
  552. var content = new Element("div", {
  553. "styles": {
  554. "width": size.x+"px",
  555. "height": size.y+"px",
  556. "position": "absolute",
  557. "top": "0px"
  558. }
  559. }).inject(this.content, "after");
  560. var app = new new Class({Implements: [Events]})();
  561. app.lp = MWF.xApplication.AppCenter.LP;
  562. app.css = MWF.xApplication.AppCenter.LP;
  563. app.actions = MWF.Actions.get("x_program_center");
  564. app.curAppId = id;
  565. app.createApplicationNode = content;
  566. app.content = content;
  567. app.notice = this.notice;
  568. app.path = "../x_component_AppCenter/$Main/";
  569. app.options = {"style": "default"};
  570. app.cssPath = app.path + app.options.style + "/css.wcss";
  571. o2.JSON.get(app.cssPath, function(json){
  572. app.css = json;
  573. }, false);
  574. app.addEvent("exporterClose", function(){
  575. this.content.hide();
  576. });
  577. this.appCenterApp = app;
  578. },
  579. });
  580. MWF.xApplication.process.ApplicationExplorer.Application = new Class({
  581. Implements: [Events],
  582. initialize: function (app, data, where) {
  583. this.app = app;
  584. this.lp = this.app.lp;
  585. this.dimension = this.app.dimension;
  586. this.container = this.app.contentNode;
  587. this.data = data;
  588. this.where = where || "bottom";
  589. this.canManage = this.checkManage();
  590. },
  591. checkManage: function(){
  592. if (this.app.control.canManage) return true;
  593. if (this.app.control.canCreate && (this.data.creatorPerson==layout.desktop.session.user.name)) return true;
  594. //if (this.data.controllerList.indexOf(layout.desktop.session.user.distinguishedName)!==-1) return true;
  595. return false;
  596. },
  597. load: function(){
  598. this.node = new Element("div.o2_process_AppExp_item_node").inject(this.container, this.where);
  599. // this.node.addEvents({
  600. // "mouseover": function(){this.node.addClass("o2_process_AppExp_item_node_over");}.bind(this),
  601. // "mouseout": function(){this.node.removeClass("o2_process_AppExp_item_node_over");}.bind(this)
  602. // });
  603. var w = this.dimension.width-20;
  604. this.node.setStyle("width", ""+w+"px");
  605. this.node.loadHtml(this.app.path+this.app.options.style+"/application.html", {"bind": {"lp": this.lp, "data": this.data, "canManage": this.canManage}}, function(){
  606. this.loadNodes();
  607. this.loadElements();
  608. this.loadNewNode();
  609. }.bind(this));
  610. this.resizeContentFun = this.resizeContent.bind(this);
  611. this.app.addEvent("resize", this.resizeContentFun);
  612. },
  613. loadElements: function(){
  614. this.loadElementList("formList", this.formListNode, this.openForm.bind(this), this.lp.noForm, this.createNewForm.bind(this));
  615. this.loadElementList("processList", this.processListNode, this.openProcess.bind(this), this.lp.noProcess, this.createNewProcess.bind(this));
  616. },
  617. loadNewNode: function(){
  618. this.newNode = this.node.getElement(".o2_process_AppExp_item_newNode");
  619. if (this.data.updateTime){
  620. var createDate = Date.parse(this.data.createTime);
  621. var currentDate = new Date();
  622. if (createDate.diff(currentDate, "hour")<12) {
  623. this.newNode.show();
  624. }else{
  625. this.newNode.hide();
  626. }
  627. }
  628. },
  629. loadElementList: function(list, container, click, noElement, noElementClick){
  630. if (this.data[list].length){
  631. this.data[list].each(function(el){
  632. var item = new Element("div.o2_process_AppExp_item_content_element").inject(container);
  633. item.set("text", el.name);
  634. //item.set("title", (el.description) ? el.name+"\n"+el.description : el.name);
  635. item.store("elementId", el.id);
  636. item.addEvents({
  637. "mouseover": function(){this.addClass("o2_process_AppExp_item_content_element_over")},
  638. "mouseout": function(){this.removeClass("o2_process_AppExp_item_content_element_over")},
  639. "click": function(e){
  640. var id = this.retrieve("elementId");
  641. if (click) click(id, e);
  642. }
  643. });
  644. }.bind(this));
  645. }else{
  646. var node = new Element("div.o2_process_AppExp_item_content_element", {
  647. "text": noElement,
  648. "styles": { "color": "#999999" }
  649. }).inject(container);
  650. node.addEvent("click", function(e){ if (noElementClick) noElementClick(e); }.bind(this));
  651. }
  652. },
  653. createNewForm: function(e){
  654. this.openApplication(e, 0);
  655. },
  656. createNewProcess: function(e){
  657. this.openApplication(e, 1);
  658. },
  659. openApplication: function(e, navi){
  660. var appId = "process.ProcessManager"+this.data.id;
  661. if (this.app.desktop.apps[appId]){
  662. this.app.desktop.apps[appId].setCurrent();
  663. }else {
  664. this.app.desktop.openApplication(e, "process.ProcessManager", {
  665. "application": this.data,
  666. "appId": appId,
  667. "onQueryLoad": function(){
  668. this.status = {"navi": navi || null};
  669. }
  670. });
  671. }
  672. },
  673. openForm: function(id, e){
  674. if (id){
  675. layout.desktop.getFormDesignerStyle(function(){
  676. var _self = this;
  677. var options = {
  678. "style": layout.desktop.formDesignerStyle,
  679. "appId": "process.FormDesigner"+id,
  680. "onQueryLoad": function(){
  681. this.actions = _self.app.actions;
  682. this.options.id = id;
  683. this.application = _self.data;
  684. }
  685. };
  686. this.app.desktop.openApplication(e, "process.FormDesigner", options);
  687. }.bind(this));
  688. }
  689. },
  690. openProcess: function(id, e){
  691. if (id){
  692. var _self = this;
  693. var options = {
  694. "appId": "process.ProcessDesigner"+id,
  695. "onQueryLoad": function(){
  696. this.actions = _self.app.actions;
  697. this.options.id = id;
  698. this.application = _self.data;
  699. }
  700. };
  701. this.app.desktop.openApplication(e, "process.ProcessDesigner", options);
  702. }
  703. },
  704. setIconNode: function(){
  705. if (this.data.icon){
  706. this.iconNode.setStyle("background-image", "url(data:image/png;base64,"+this.data.icon+")");
  707. }else{
  708. this.iconNode.setStyle("background-image", "url("+"../x_component_process_ApplicationExplorer/$Main/default/icon/application.png)")
  709. }
  710. this.iconNode.makeLnk({
  711. "par": this._getLnkPar()
  712. });
  713. },
  714. _getLnkPar: function(){
  715. var lnkIcon = "../x_component_process_ApplicationExplorer/$Main/default/lnk.png";
  716. if (this.data.icon) lnkIcon = "data:image/png;base64,"+this.data.icon;
  717. var appId = "process.ProcessManager"+this.data.id;
  718. return {
  719. "icon": lnkIcon,
  720. "title": this.data.name,
  721. "par": "process.ProcessManager#{\"application\": \""+this.data.id+"\", \"appId\": \""+appId+"\"}"
  722. };
  723. },
  724. loadNodes: function(){
  725. this.iconNode = this.node.getElement(".o2_process_AppExp_item_icon");
  726. this.setIconNode();
  727. this.titleNode = this.node.getElement(".o2_process_AppExp_item_titleNode");
  728. this.formListNode = this.node.getElement(".o2_process_AppExp_item_contentFormList");
  729. this.processListNode = this.node.getElement(".o2_process_AppExp_item_contentProcessList");
  730. this.pageListNode = this.node.getElement(".o2_process_AppExp_item_contentPageList");
  731. this.viewListNode = this.node.getElement(".o2_process_AppExp_item_contentViewList");
  732. this.statListNode = this.node.getElement(".o2_process_AppExp_item_contentStatList");
  733. this.titleNode.addEvent("click", function(e){
  734. this.openApplication(e);
  735. }.bind(this));
  736. this.categoryNode = this.node.getElement(".o2_process_AppExp_item_categoryNode");
  737. var category = this.data.applicationCategory || this.data.portalCategory || this.data.protalCategory;
  738. var categoryText = category;
  739. if( !category || category === "null" )categoryText = this.lp.unCategory;
  740. this.categoryNode.set("text", categoryText );
  741. if ( category && category !== "null" ){
  742. this.categoryNode.set("title", category );
  743. this.categoryNode.addClass("o2_process_AppExp_item_categoryColorNode");
  744. }
  745. this.actionArea = this.node.getElement(".o2_process_AppExp_item_ActionArea");
  746. this.actionDelete = this.node.getElement(".o2_process_AppExp_item_Action_delete");
  747. this.actionExport = this.node.getElement(".o2_process_AppExp_item_Action_export");
  748. if (this.actionArea) this.setActionEvent();
  749. },
  750. setActionEvent: function(){
  751. this.node.addEvents({
  752. "mouseover": function(){
  753. if (!this.readyDelete) this.actionArea.fade("in");
  754. this.node.addClass("o2_process_AppExp_item_node_over");
  755. }.bind(this),
  756. "mouseout": function(){
  757. if (!this.readyDelete) this.actionArea.fade("out");
  758. this.node.removeClass("o2_process_AppExp_item_node_over");
  759. }.bind(this)
  760. });
  761. this.actionDelete.addEvent("click", function(e){
  762. this.checkDeleteApplication(e);
  763. e.stopPropagation();
  764. }.bind(this));
  765. this.actionExport.addEvent("click", function(e){
  766. MWF.xDesktop.requireApp("AppCenter", "", function(){
  767. // var appCenter = new MWF.xApplication.AppCenter.Main();
  768. // appCenter.inBrowser = true;
  769. // appCenter.load(true, content);
  770. if (!this.app.appCenterApp) this.app.createAppCenterApp(this.data.id);
  771. this.app.appCenterApp.curAppId = this.data.id;
  772. this.app.appCenterApp.content.show();
  773. new MWF.xApplication.AppCenter.Exporter(this.app.appCenterApp);
  774. //appCenter.createApplication(this.app.content,this.data.id);
  775. //appCenter.createApplication(null,this.data.id);
  776. }.bind(this));
  777. e.stopPropagation();
  778. //老版本导出
  779. // this.exportApplication(e);
  780. // e.stopPropagation();
  781. }.bind(this));
  782. },
  783. checkDeleteApplication: function(e){
  784. if (!this.readyDelete){
  785. this.actionDelete.addClass("o2_process_AppExp_item_Action_delete_select");
  786. this.node.addClass("o2_process_AppExp_item_node_del");
  787. this.readyDelete = true;
  788. this.app.deleteElements.push(this);
  789. }else{
  790. this.actionDelete.removeClass("o2_process_AppExp_item_Action_delete_select");
  791. this.node.removeClass("o2_process_AppExp_item_node_del");
  792. this.readyDelete = false;
  793. this.app.deleteElements.erase(this);
  794. }
  795. this.app.checkDeleteApplication();
  796. },
  797. exportApplication: function(){
  798. MWF.xDesktop.requireApp("process.ApplicationExplorer", "Exporter", function(){
  799. (new MWF.xApplication.process.ApplicationExplorer.Exporter(this.app, this.data)).load();
  800. }.bind(this));
  801. },
  802. resizeContent: function(){
  803. var w = this.dimension.width-20;
  804. this.node.setStyle("width", ""+w+"px");
  805. },
  806. "delete": function(onlyRemoveNotCompleted, success, failure){
  807. this._deleteElement(this.data.id, onlyRemoveNotCompleted, function(){
  808. this.destroy();
  809. if (success) success();
  810. }.bind(this), function(xhr, text, error){
  811. var errorText = error;
  812. if (xhr) errorText = xhr.responseText;
  813. // this.explorer.app.notice(errorText, "error", this.explorer.propertyContentNode, {x: "left", y:"top"});
  814. if (failure) failure(errorText);
  815. }.bind(this));
  816. },
  817. _deleteElement: function(id, onlyRemoveNotCompleted, success, failure){
  818. this.app.restActions.deleteApplication(id, onlyRemoveNotCompleted, success, failure);
  819. },
  820. destroy: function(){
  821. if (this.resizeContentFun) this.app.removeEvent("resize", this.resizeContentFun);
  822. this.node.destroy();
  823. o2.release(this);
  824. }
  825. });