Main.js 35 KB

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