Main.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. MWF.xApplication.portal = MWF.xApplication.portal || {};
  2. MWF.xApplication.portal.PortalExplorer = MWF.xApplication.portal.PortalExplorer || {};
  3. MWF.xDesktop.requireApp("process.ApplicationExplorer", "", null, false);
  4. MWF.xApplication.portal.PortalExplorer.Main = new Class({
  5. Extends: MWF.xApplication.process.ApplicationExplorer.Main,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "name": "portal.PortalExplorer",
  10. "icon": "icon.png",
  11. "width": "1000",
  12. "height": "600",
  13. "title": MWF.PortalLP.title,
  14. "tooltip": {
  15. "cancel": MWF.PortalLP.application.action_cancel,
  16. "ok": MWF.PortalLP.application.action_ok,
  17. "create": MWF.PortalLP.application.create,
  18. "search": MWF.PortalLP.application.search,
  19. "searchText": MWF.PortalLP.application.searchText,
  20. "allCategory": MWF.PortalLP.application.allCategory,
  21. "unCategory": MWF.PortalLP.application.unCategory,
  22. "selectCategory": MWF.PortalLP.application.selectCategory,
  23. "nameLabel": MWF.PortalLP.application.name,
  24. "aliasLabel": MWF.PortalLP.application.alias,
  25. "descriptionLabel": MWF.PortalLP.application.description,
  26. "typeLabel": MWF.PortalLP.application.type,
  27. "iconLabel": MWF.PortalLP.application.icon,
  28. "createApplication_cancel_title": MWF.PortalLP.application.createApplication_cancel_title,
  29. "createApplication_cancel": MWF.PortalLP.application.createApplication_cancel,
  30. "inputApplicationName": MWF.PortalLP.application.inputApplicationName,
  31. "createApplicationSuccess": MWF.PortalLP.application.createApplicationSuccess,
  32. "unDescription": MWF.PortalLP.application.unDescription,
  33. "noPage": MWF.PortalLP.application.noPage,
  34. "noApplication": MWF.PortalLP.application.noApplication,
  35. "noApplicationCreate": MWF.PortalLP.application.noApplicationCreate,
  36. "loadding": MWF.PortalLP.application.loadding
  37. }
  38. },
  39. onQueryLoad: function(){
  40. this.lp = MWF.PortalLP;
  41. this.currentContentNode = null;
  42. },
  43. loadApplication: function(callback){
  44. this.restActions = MWF.Actions.get("x_portal_assemble_designer");
  45. //if (!this.restActions) this.restActions = new MWF.xApplication.portal.PortalExplorer.Actions.RestActions();
  46. //if (!this.restActions) this.restActions = new MWF.xApplication.process.ApplicationExplorer.Actions.RestActions();
  47. this.category = null;
  48. this.applications = [];
  49. this.deleteElements = [];
  50. this.createNode();
  51. this.loadApplicationContent();
  52. if (callback) callback();
  53. },
  54. loadApplicationByCategory: function(item){
  55. var name = "";
  56. if (item){name = item.retrieve("categoryName", "")}
  57. this.restActions.listApplicationSummary(name, function(json){
  58. this.applicationContentNode.empty();
  59. if (json.data.length){
  60. //for (var i=0; i<15; i++){
  61. json.data.each(function(appData){
  62. var application = new MWF.xApplication.portal.PortalExplorer.Portal(this, appData);
  63. application.load();
  64. this.applications.push(application);
  65. }.bind(this));
  66. //}
  67. }else {
  68. if (MWF.AC.isProcessPlatformCreator()){
  69. var noApplicationNode = new Element("div", {
  70. "styles": this.css.noApplicationNode,
  71. "text": this.options.tooltip.noApplicationCreate
  72. }).inject(this.applicationContentNode);
  73. noApplicationNode.addEvent("click", function(){
  74. this.createApplication();
  75. }.bind(this));
  76. }else{
  77. var noApplicationNode = new Element("div", {
  78. "styles": this.css.noApplicationNode,
  79. "text": this.options.tooltip.noApplication
  80. }).inject(this.applicationContentNode);
  81. }
  82. }
  83. }.bind(this));
  84. },
  85. importApplication: function(e){
  86. MWF.xDesktop.requireApp("portal.PortalExplorer", "Importer", function(){
  87. (new MWF.xApplication.portal.PortalExplorer.Importer(this, e)).load();
  88. }.bind(this));
  89. },
  90. okCreateApplication: function(e){
  91. var data = {
  92. "name": $("createApplicationName").get("value"),
  93. "alias": $("createApplicationAlias").get("value"),
  94. "description": $("createApplicationDescription").get("value"),
  95. "portalCategory": $("createApplicationType").get("value")
  96. };
  97. if (data.name){
  98. this.restActions.saveApplication(data, function(json){
  99. this.applicationCreateMarkNode.destroy();
  100. this.applicationCreateAreaNode.destroy();
  101. this.restActions.getApplication(json.data.id, function(json){
  102. json.data.processList = [];
  103. json.data.formList = [];
  104. var application = new MWF.xApplication.portal.PortalExplorer.Portal(this, json.data, {"where": "top"});
  105. application.load();
  106. this.applications.push(application);
  107. }.bind(this));
  108. this.notice(this.options.tooltip.createApplicationSuccess, "success");
  109. // this.app.processConfig();
  110. }.bind(this));
  111. }else{
  112. $("createApplicationName").setStyle("border-color", "red");
  113. $("createApplicationName").focus();
  114. this.notice(this.options.tooltip.inputApplicationName, "error");
  115. }
  116. },
  117. deleteSelectedElements: function(e){
  118. var _self = this;
  119. var applicationList = [];
  120. this.deleteElements.each(function(app){
  121. applicationList.push(app.data.name);
  122. });
  123. var confirmStr = this.lp.application.deleteElementsConfirm+" ("+applicationList.join("、")+") ";
  124. //confirmStr += check;
  125. this.confirm("infor", e, this.lp.application.deleteElementsTitle, {"html":confirmStr}, 530, 210, function(){
  126. confirmStr = _self.lp.application.deleteElementsConfirmAgain+"<br/><br/><font style='color:red; font-size:14px; font-weight: bold'>"+applicationList.join("、")+"</font>";
  127. // var checkbox = this.content.getElement("#deleteApplicationAllCheckbox");
  128. //
  129. // var onlyRemoveNotCompleted = true;
  130. // if (checkbox.checked){
  131. // onlyRemoveNotCompleted = false;
  132. // confirmStr = _self.lp.application.deleteElementsAllConfirmAgain+"<br/><br/><font style='color:red; font-size:14px; font-weight: bold'>"+applicationList.join("、")+"</font>";
  133. // }
  134. this.close();
  135. _self.confirm("infor", e, _self.lp.application.deleteElementsTitle, {"html":confirmStr}, 500, 200, function(){
  136. var deleted = [];
  137. var doCount = 0;
  138. var readyCount = _self.deleteElements.length;
  139. var errorText = "";
  140. var complete = function(){
  141. if (doCount == readyCount){
  142. if (errorText){
  143. _self.app.notice(errorText, "error");
  144. }
  145. }
  146. };
  147. _self.deleteElements.each(function(application){
  148. application["delete"]("", function(){
  149. deleted.push(application);
  150. doCount++;
  151. if (_self.deleteElements.length==doCount){
  152. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  153. return !deleted.contains(item);
  154. });
  155. _self.checkDeleteApplication();
  156. }
  157. complete();
  158. }, function(error){
  159. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  160. doCount++;
  161. if (_self.deleteElements.length==doCount){
  162. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  163. return !deleted.contains(item);
  164. });
  165. _self.checkDeleteApplication();
  166. }
  167. complete();
  168. });
  169. });
  170. this.close();
  171. }, function(){
  172. this.close();
  173. });
  174. this.close();
  175. }, function(){
  176. this.close();
  177. });
  178. }
  179. });
  180. MWF.xApplication.portal.PortalExplorer.Portal = new Class({
  181. Extends: MWF.xApplication.process.ApplicationExplorer.Application,
  182. Implements: [Options, Events],
  183. options: {
  184. "where": "bottom",
  185. "bgColor": ["#30afdc", "#e9573e", "#8dc153", "#9d4a9c", "#ab8465", "#959801", "#434343", "#ffb400", "#9e7698", "#00a489"]
  186. },
  187. load: function(){
  188. this.node = new Element("div", {
  189. "styles": this.css.applicationItemNode
  190. });
  191. this.loadTopNode();
  192. this.loadIconNode();
  193. this.loadDeleteAction();
  194. this.loadExportAction();
  195. this.loadTitleNode();
  196. this.loadNewNode();
  197. this.loadInforNode();
  198. this.loadPageNode();
  199. //this.loadFormNode();
  200. this.node.inject(this.container, this.options.where);
  201. },
  202. loadIconNode: function(){
  203. this.iconNode = new Element("div", {
  204. "styles": this.css.applicationItemIconNode
  205. }).inject(this.topNode);
  206. if (this.data.icon){
  207. this.iconNode.setStyle("background-image", "url(data:image/png;base64,"+this.data.icon+")");
  208. }else{
  209. this.iconNode.setStyle("background-image", "url("+"/x_component_portal_PortalExplorer/$Main/default/icon/application.png)")
  210. }
  211. this.iconNode.makeLnk({
  212. "par": this._getLnkPar()
  213. });
  214. },
  215. exportApplication: function(){
  216. MWF.xDesktop.requireApp("portal.PortalExplorer", "Exporter", function(){
  217. (new MWF.xApplication.portal.PortalExplorer.Exporter(this.app, this.data)).load();
  218. }.bind(this));
  219. },
  220. _deleteElement: function(id, onlyRemoveNotCompleted, success, failure){
  221. this.app.restActions.deleteApplication(id, success, failure);
  222. },
  223. _getLnkPar: function(){
  224. var lnkIcon = "/x_component_portal_PortalExplorer/$Main/default/lnk.png";
  225. if (this.data.icon) lnkIcon = "data:image/png;base64,"+this.data.icon;
  226. var appId = "portal.PortalManager"+this.data.id;
  227. return {
  228. "icon": lnkIcon,
  229. "title": this.data.name,
  230. "par": "portal.PortalManager#{\"application\": \""+this.data.id+"\", \"appId\": \""+appId+"\"}"
  231. };
  232. },
  233. loadPageNode: function(){
  234. this.pageNode = new Element("div", {
  235. "styles": this.css.applicationItemElNode
  236. }).inject(this.inforNode);
  237. this.pageTitleNode = new Element("div", {
  238. "styles": this.css.applicationItemElTitleNode,
  239. "text": "页面"
  240. }).inject(this.inforNode);
  241. this.pageListNode = new Element("div", {
  242. "styles": this.css.applicationItemElListNode
  243. }).inject(this.inforNode);
  244. this.loadPageList();
  245. },
  246. loadPageList: function(){
  247. if (this.data.pageList && this.data.pageList.length) {
  248. for (var i=0; i<(8).min(this.data.pageList.length); i++){
  249. var page = this.data.pageList[i];
  250. var pageNode = new Element("div", {
  251. "styles": this.css.listItemNode,
  252. "text": page.name
  253. }).inject(this.pageListNode);
  254. pageNode.store("pageId", page.id);
  255. var _self = this;
  256. pageNode.addEvents({
  257. "click": function(e){_self.openPage(this, e)},
  258. "mouseover": function(){this.setStyle("color", "#3c5eed");},
  259. "mouseout": function(){this.setStyle("color", "#666");}
  260. });
  261. }
  262. }else{
  263. var node = new Element("div", {
  264. "text": this.app.options.tooltip.noPage,
  265. "styles": {"cursor": "pointer", "line-height": "30px"}
  266. }).inject(this.pageListNode);
  267. node.addEvent("click", function(e){
  268. this.createNewPage(e);
  269. }.bind(this));
  270. }
  271. // }.bind(this));
  272. },
  273. openPage: function(node, e){
  274. var id = node.retrieve("pageId");
  275. if (id){
  276. var _self = this;
  277. var options = {
  278. "onQueryLoad": function(){
  279. this.actions = _self.app.actions;
  280. //this.category = _self;
  281. this.options.id = id;
  282. this.application = _self.data;
  283. }
  284. };
  285. this.app.desktop.openApplication(e, "portal.PageDesigner", options);
  286. }
  287. },
  288. openApplication: function(e, navi){
  289. var appId = "portal.PortalManager"+this.data.id;
  290. if (this.app.desktop.apps[appId]){
  291. this.app.desktop.apps[appId].setCurrent();
  292. }else {
  293. this.app.desktop.openApplication(e, "portal.PortalManager", {
  294. "application": this.data,
  295. "appId": appId,
  296. "onQueryLoad": function(){
  297. this.status = {"navi": navi || null};
  298. }
  299. });
  300. }
  301. },
  302. loadDateNode: function(){
  303. this.dateNode = new Element("div", {
  304. "styles": this.css.applicationItemDateNode,
  305. "text": this.data.updateTime
  306. }).inject(this.inforNode);
  307. }
  308. });