Main.js 32 KB

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