Main.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. MWF.xDesktop.requireApp("process.ApplicationExplorer", "", null, false);
  2. MWF.xApplication.query.QueryExplorer.Main = new Class({
  3. Extends: MWF.xApplication.process.ApplicationExplorer.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "query.QueryExplorer",
  8. "icon": "icon.png",
  9. "width": "1000",
  10. "height": "600",
  11. "title": MWF.QueryLP.title,
  12. "tooltip": {
  13. "cancel": MWF.QueryLP.application.action_cancel,
  14. "ok": MWF.QueryLP.application.action_ok,
  15. "create": MWF.QueryLP.application.create,
  16. "search": MWF.QueryLP.application.search,
  17. "searchText": MWF.QueryLP.application.searchText,
  18. "allCategory": MWF.QueryLP.application.allCategory,
  19. "unCategory": MWF.QueryLP.application.unCategory,
  20. "selectCategory": MWF.QueryLP.application.selectCategory,
  21. "nameLabel": MWF.QueryLP.application.name,
  22. "aliasLabel": MWF.QueryLP.application.alias,
  23. "descriptionLabel": MWF.QueryLP.application.description,
  24. "typeLabel": MWF.QueryLP.application.type,
  25. "iconLabel": MWF.QueryLP.application.icon,
  26. "createApplication_cancel_title": MWF.QueryLP.application.createApplication_cancel_title,
  27. "createApplication_cancel": MWF.QueryLP.application.createApplication_cancel,
  28. "inputApplicationName": MWF.QueryLP.application.inputApplicationName,
  29. "createApplicationSuccess": MWF.QueryLP.application.createApplicationSuccess,
  30. "unDescription": MWF.QueryLP.application.unDescription,
  31. "noPage": MWF.QueryLP.application.noPage,
  32. "noView": MWF.QueryLP.application.noView,
  33. "noStat": MWF.QueryLP.application.noStat,
  34. "noApplication": MWF.QueryLP.application.noApplication,
  35. "noApplicationCreate": MWF.QueryLP.application.noApplicationCreate,
  36. "loadding": MWF.QueryLP.application.loadding
  37. }
  38. },
  39. onQueryLoad: function(){
  40. this.lp = MWF.QueryLP;
  41. this.currentContentNode = null;
  42. },
  43. loadApplication: function(callback){
  44. if (!this.restActions) this.restActions = MWF.Actions.get("x_query_assemble_designer");
  45. //if (!this.restActions) this.restActions = new MWF.xApplication.process.ApplicationExplorer.Actions.RestActions();
  46. this.category = null;
  47. this.applications = [];
  48. this.deleteElements = [];
  49. this.createNode();
  50. this.loadApplicationContent();
  51. if (callback) callback();
  52. },
  53. hasCreatorRole: function(){
  54. return MWF.AC.isQueryPlatformCreator();
  55. },
  56. hasManagerRole: function(){
  57. if (MWF.AC.isAdministrator()) return true;
  58. if (MWF.AC.isQueryManager()) return true;
  59. return false;
  60. },
  61. loadApplicationByCategory: function(item){
  62. var name = "";
  63. if (item){name = item.retrieve("categoryName", "")}
  64. this.restActions.listApplicationSummary(name, function(json){
  65. this.applicationContentNode.empty();
  66. if (json.data.length){
  67. //for (var i=0; i<15; i++){
  68. json.data.each(function(appData){
  69. var application = new MWF.xApplication.query.QueryExplorer.Query(this, appData);
  70. application.load();
  71. this.applications.push(application);
  72. }.bind(this));
  73. //}
  74. }else {
  75. if (this.hasCreatorRole()){
  76. var noApplicationNode = new Element("div", {
  77. "styles": this.css.noApplicationNode,
  78. "text": this.options.tooltip.noApplicationCreate
  79. }).inject(this.applicationContentNode);
  80. noApplicationNode.addEvent("click", function(){
  81. this.createApplication();
  82. }.bind(this));
  83. }else{
  84. var noApplicationNode = new Element("div", {
  85. "styles": this.css.noApplicationNode,
  86. "text": this.options.tooltip.noApplication
  87. }).inject(this.applicationContentNode);
  88. }
  89. }
  90. }.bind(this));
  91. },
  92. importApplication: function(e){
  93. MWF.xDesktop.requireApp("query.QueryExplorer", "Importer", function(){
  94. (new MWF.xApplication.query.QueryExplorer.Importer(this, e)).load();
  95. }.bind(this));
  96. },
  97. okCreateApplication: function(e){
  98. var data = {
  99. "name": $("createApplicationName").get("value"),
  100. "alias": $("createApplicationAlias").get("value"),
  101. "description": $("createApplicationDescription").get("value"),
  102. "portalCategory": $("createApplicationType").get("value")
  103. };
  104. if (data.name){
  105. this.restActions.saveApplication(data, function(json){
  106. this.applicationCreateMarkNode.destroy();
  107. this.applicationCreateAreaNode.destroy();
  108. this.restActions.getApplication(json.data.id, function(json){
  109. json.data.processList = [];
  110. json.data.formList = [];
  111. var application = new MWF.xApplication.query.QueryExplorer.Query(this, json.data, {"where": "top"});
  112. application.load();
  113. this.applications.push(application);
  114. }.bind(this));
  115. this.notice(this.options.tooltip.createApplicationSuccess, "success");
  116. // this.app.processConfig();
  117. }.bind(this));
  118. }else{
  119. $("createApplicationName").setStyle("border-color", "red");
  120. $("createApplicationName").focus();
  121. this.notice(this.options.tooltip.inputApplicationName, "error");
  122. }
  123. },
  124. createCategoryNodes: function(){
  125. this.restActions.listApplicationCategory(function(json){
  126. var emptyCategory = null;
  127. json.data.each(function(category){
  128. if (category.name){
  129. this.createCategoryItemNode(category.name, category.count);
  130. }else{
  131. emptyCategory = category;
  132. }
  133. }.bind(this));
  134. // if (emptyCategory) this.createCategoryItemNode()
  135. }.bind(this));
  136. },
  137. deleteSelectedElements: function(e){
  138. var _self = this;
  139. var applicationList = [];
  140. this.deleteElements.each(function(app){
  141. applicationList.push(app.data.name);
  142. });
  143. var confirmStr = this.lp.application.deleteElementsConfirm+" ("+applicationList.join("、")+") ";
  144. //confirmStr += check;
  145. this.confirm("infor", e, this.lp.application.deleteElementsTitle, {"html":confirmStr}, 530, 210, function(){
  146. confirmStr = _self.lp.application.deleteElementsConfirmAgain+"<br/><br/><font style='color:red; font-size:14px; font-weight: bold'>"+applicationList.join("、")+"</font>";
  147. // var checkbox = this.content.getElement("#deleteApplicationAllCheckbox");
  148. //
  149. // var onlyRemoveNotCompleted = true;
  150. // if (checkbox.checked){
  151. // onlyRemoveNotCompleted = false;
  152. // confirmStr = _self.lp.application.deleteElementsAllConfirmAgain+"<br/><br/><font style='color:red; font-size:14px; font-weight: bold'>"+applicationList.join("、")+"</font>";
  153. // }
  154. this.close();
  155. _self.confirm("infor", e, _self.lp.application.deleteElementsTitle, {"html":confirmStr}, 500, 200, function(){
  156. var deleted = [];
  157. var doCount = 0;
  158. var readyCount = _self.deleteElements.length;
  159. var errorText = "";
  160. var complete = function(){
  161. if (doCount == readyCount){
  162. if (errorText){
  163. _self.app.notice(errorText, "error");
  164. }
  165. }
  166. };
  167. _self.deleteElements.each(function(application){
  168. application["delete"]("", function(){
  169. deleted.push(application);
  170. doCount++;
  171. if (_self.deleteElements.length==doCount){
  172. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  173. return !deleted.contains(item);
  174. });
  175. _self.checkDeleteApplication();
  176. }
  177. complete();
  178. }, function(error){
  179. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  180. doCount++;
  181. if (_self.deleteElements.length==doCount){
  182. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  183. return !deleted.contains(item);
  184. });
  185. _self.checkDeleteApplication();
  186. }
  187. complete();
  188. });
  189. });
  190. this.close();
  191. }, function(){
  192. this.close();
  193. });
  194. this.close();
  195. }, function(){
  196. this.close();
  197. });
  198. }
  199. });
  200. MWF.xApplication.query.QueryExplorer.Query = new Class({
  201. Extends: MWF.xApplication.process.ApplicationExplorer.Application,
  202. Implements: [Options, Events],
  203. options: {
  204. "where": "bottom",
  205. "bgColor": ["#30afdc", "#e9573e", "#8dc153", "#9d4a9c", "#ab8465", "#959801", "#434343", "#ffb400", "#9e7698", "#00a489"]
  206. },
  207. load: function(){
  208. this.node = new Element("div", {
  209. "styles": this.css.applicationItemNode
  210. });
  211. this.loadTopNode();
  212. this.loadIconNode();
  213. this.loadDeleteAction();
  214. this.loadExportAction();
  215. this.loadTitleNode();
  216. this.loadNewNode();
  217. this.loadInforNode();
  218. this.loadViewNode();
  219. this.loadStatNode();
  220. //this.loadFormNode();
  221. this.node.inject(this.container, this.options.where);
  222. },
  223. loadIconNode: function(){
  224. this.iconNode = new Element("div", {
  225. "styles": this.css.applicationItemIconNode
  226. }).inject(this.topNode);
  227. if (this.data.icon){
  228. this.iconNode.setStyle("background-image", "url(data:image/png;base64,"+this.data.icon+")");
  229. }else{
  230. this.iconNode.setStyle("background-image", "url("+"/x_component_query_QueryExplorer/$Main/default/icon/application.png)")
  231. }
  232. this.iconNode.makeLnk({
  233. "par": this._getLnkPar()
  234. });
  235. },
  236. exportApplication: function(){
  237. MWF.xDesktop.requireApp("query.QueryExplorer", "Exporter", function(){
  238. (new MWF.xApplication.query.QueryExplorer.Exporter(this.app, this.data)).load();
  239. }.bind(this));
  240. },
  241. _deleteElement: function(id, onlyRemoveNotCompleted, success, failure){
  242. this.app.restActions.deleteApplication(id, success, failure);
  243. },
  244. _getLnkPar: function(){
  245. var lnkIcon = "/x_component_query_QueryExplorer/$Main/default/lnk.png";
  246. if (this.data.icon) lnkIcon = "data:image/png;base64,"+this.data.icon;
  247. var appId = "query.QueryManager"+this.data.id;
  248. return {
  249. "icon": lnkIcon,
  250. "title": this.data.name,
  251. "par": "query.QueryManager#{\"application\": \""+this.data.id+"\", \"appId\": \""+appId+"\"}"
  252. };
  253. },
  254. loadViewNode: function(){
  255. this.viewNode = new Element("div", {
  256. "styles": this.css.applicationItemElNode
  257. }).inject(this.inforNode);
  258. this.viewTitleNode = new Element("div", {
  259. "styles": this.css.applicationItemElTitleNode,
  260. "text": this.app.lp.view
  261. }).inject(this.inforNode);
  262. this.viewListNode = new Element("div", {
  263. "styles": this.css.applicationItemElListNode
  264. }).inject(this.inforNode);
  265. this.loadViewList();
  266. },
  267. loadViewList: function(){
  268. if (this.data.viewList && this.data.viewList.length) {
  269. for (var i=0; i<(4).min(this.data.viewList.length); i++){
  270. var view = this.data.viewList[i];
  271. var viewNode = new Element("div", {
  272. "styles": this.css.listItemNode,
  273. "text": view.name
  274. }).inject(this.viewListNode);
  275. viewNode.store("viewId", view.id);
  276. var _self = this;
  277. viewNode.addEvents({
  278. "click": function(e){_self.openView(this, e)},
  279. "mouseover": function(){this.setStyle("color", "#3c5eed");},
  280. "mouseout": function(){this.setStyle("color", "#666");}
  281. });
  282. }
  283. }else{
  284. var node = new Element("div", {
  285. "text": this.app.options.tooltip.noView,
  286. "styles": {"cursor": "pointer", "line-height": "30px"}
  287. }).inject(this.viewListNode);
  288. node.addEvent("click", function(e){
  289. this.createNewView(e);
  290. }.bind(this));
  291. }
  292. // }.bind(this));
  293. },
  294. openView: function(node, e){
  295. var id = node.retrieve("viewId");
  296. if (id){
  297. var _self = this;
  298. var options = {
  299. "appId": "query.ViewDesigner"+id,
  300. "onQueryLoad": function(){
  301. this.actions = _self.app.actions;
  302. //this.category = _self;
  303. this.options.id = id;
  304. this.application = _self.data;
  305. }
  306. };
  307. this.app.desktop.openApplication(e, "query.ViewDesigner", options);
  308. }
  309. },
  310. loadStatNode: function(){
  311. this.statNode = new Element("div", {
  312. "styles": this.css.applicationItemElNode
  313. }).inject(this.inforNode);
  314. this.statTitleNode = new Element("div", {
  315. "styles": this.css.applicationItemElTitleNode,
  316. "text": this.app.lp.stat
  317. }).inject(this.inforNode);
  318. this.statListNode = new Element("div", {
  319. "styles": this.css.applicationItemElListNode
  320. }).inject(this.inforNode);
  321. this.loadStatList();
  322. },
  323. loadStatList: function(){
  324. if (this.data.statList && this.data.statList.length) {
  325. for (var i=0; i<(4).min(this.data.statList.length); i++){
  326. var stat = this.data.statList[i];
  327. var statNode = new Element("div", {
  328. "styles": this.css.listItemNode,
  329. "text": stat.name
  330. }).inject(this.statListNode);
  331. statNode.store("statId", stat.id);
  332. var _self = this;
  333. statNode.addEvents({
  334. "click": function(e){_self.openStat(this, e)},
  335. "mouseover": function(){this.setStyle("color", "#3c5eed");},
  336. "mouseout": function(){this.setStyle("color", "#666");}
  337. });
  338. }
  339. }else{
  340. var node = new Element("div", {
  341. "text": this.app.options.tooltip.noStat,
  342. "styles": {"cursor": "pointer", "line-height": "30px"}
  343. }).inject(this.statListNode);
  344. node.addEvent("click", function(e){
  345. this.createNewStat(e);
  346. }.bind(this));
  347. }
  348. // }.bind(this));
  349. },
  350. openStat: function(node, e){
  351. var id = node.retrieve("statId");
  352. if (id){
  353. var _self = this;
  354. var options = {
  355. "appId": "query.StatDesigner"+id,
  356. "onQueryLoad": function(){
  357. this.actions = _self.app.actions;
  358. //this.category = _self;
  359. this.options.id = id;
  360. this.application = _self.data;
  361. }
  362. };
  363. this.app.desktop.openApplication(e, "query.StatDesigner", options);
  364. }
  365. },
  366. createNewView: function(e){
  367. this.openApplication(e, 0);
  368. },
  369. createNewStat: function(e){
  370. this.openApplication(e, 1);
  371. },
  372. openApplication: function(e, navi){
  373. var appId = "query.QueryManager"+this.data.id;
  374. if (this.app.desktop.apps[appId]){
  375. this.app.desktop.apps[appId].setCurrent();
  376. }else {
  377. this.app.desktop.openApplication(e, "query.QueryManager", {
  378. "application": this.data,
  379. "appId": appId,
  380. "onQueryLoad": function(){
  381. this.status = {"navi": navi || null};
  382. }
  383. });
  384. }
  385. },
  386. openApplication: function(e, navi){
  387. var appId = "portal.PortalManager"+this.data.id;
  388. if (this.app.desktop.apps[appId]){
  389. this.app.desktop.apps[appId].setCurrent();
  390. }else {
  391. this.app.desktop.openApplication(e, "query.QueryManager", {
  392. "application": this.data,
  393. "appId": appId,
  394. "onQueryLoad": function(){
  395. this.status = {"navi": navi || null};
  396. }
  397. });
  398. }
  399. },
  400. loadDateNode: function(){
  401. this.dateNode = new Element("div", {
  402. "styles": this.css.applicationItemDateNode,
  403. "text": this.data.updateTime
  404. }).inject(this.inforNode);
  405. }
  406. });