Main.js 33 KB

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