Main.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. MWF.xApplication.query.Query.options.multitask = true;
  2. MWF.xApplication.query.Query.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "query.Query",
  8. "icon": "icon.png",
  9. "width": "1200",
  10. "height": "700",
  11. "title": MWF.xApplication.query.Query.LP.title,
  12. "isControl": false,
  13. "taskObject": null,
  14. "parameters": "",
  15. "readonly": false
  16. },
  17. onQueryLoad: function(){
  18. this.lp = MWF.xApplication.query.Query.LP;
  19. if (this.status){
  20. this.options.id = this.status.id;
  21. this.options.viewId = this.status.viewId;
  22. this.options.statId = this.status.statId;
  23. this.options.statementId = this.status.statementId;
  24. this.options.importerId = this.status.importerId;
  25. }
  26. },
  27. loadApplication: function(callback){
  28. this.content.setStyle("background-color", "#F0F0F0");
  29. this.node = new Element("div", {"styles": this.css.content}).inject(this.content);
  30. this.formNode = new Element("div", {"styles": {"min-height": "100%", "font-size": "14px"}}).inject(this.node);
  31. this.action = MWF.Actions.get("x_query_assemble_surface");
  32. // if (!this.options.isRefresh){
  33. // this.maxSize(function(){
  34. // this.loadQuery(this.options.parameters);
  35. // }.bind(this));
  36. // }else{
  37. this.loadQuery(this.options.parameters);
  38. // }
  39. if (callback) callback();
  40. },
  41. loadQuery: function(par){
  42. this.action.getQuery(this.options.id, function(json){
  43. this.query = json.data;
  44. this.setTitle(this.query.name);
  45. if (this.query.icon){
  46. if (this.taskitem){
  47. this.taskitem.iconNode.setStyles({
  48. "background-image": "url(data:image/png;base64,"+this.query.icon+")",
  49. "background-size": "24px 24px"
  50. });
  51. }
  52. }
  53. var lp = this.lp;
  54. var iData = this.query.data ? JSON.parse(this.query.data) : "";
  55. this.interfaceData = Object.merge({
  56. viewShow: "true",
  57. viewNumber: 1,
  58. viewName: lp.view,
  59. viewIcon: "../x_component_query_Query/$Main/"+this.options.style+"/icon/view_new.png",
  60. statShow: "true",
  61. statNumber: 2,
  62. statName: lp.stat,
  63. statIcon: "../x_component_query_Query/$Main/"+this.options.style+"/icon/stat_new.png",
  64. statementShow: "true",
  65. statementNumber: 3,
  66. statementName: lp.statement,
  67. statementIcon: "../x_component_query_Query/$Main/"+this.options.style+"/icon/statement_new.png",
  68. importerShow: "true",
  69. importerNumber: 4,
  70. importerName: lp.importer,
  71. importerIcon: "../x_component_query_Query/$Main/"+this.options.style+"/icon/importer_new.png",
  72. }, iData || {} );
  73. this.createLayout();
  74. this.createNavi();
  75. this.addEvent("resize", function(){
  76. if (this.currentItem){
  77. if (this.currentItem.viewer && this.currentItem.viewer.setContentHeight){
  78. this.currentItem.viewer.setContentHeight();
  79. }
  80. }
  81. }.bind(this));
  82. }.bind(this));
  83. },
  84. createLayout: function(){
  85. if (!layout.mobile){
  86. this.createLayoutPC();
  87. }else{
  88. this.createLayoutMobile();
  89. }
  90. },
  91. createLayoutPC: function(){
  92. this.naviNode = new Element("div", {"styles": this.css.naviNode}).inject(this.content);
  93. this.contentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.content);
  94. this.naviTitleNode = new Element("div", {"styles": this.css.naviTitleNode}).inject(this.naviNode);
  95. this.naviContentNode = new Element("div", {"styles": this.css.naviContentNode}).inject(this.naviNode);
  96. var lp = this.lp;
  97. var data = this.interfaceData;
  98. var object = [];
  99. this.naviArray = object;
  100. if( data.viewShow !== "false" && data.viewShow !== false ) {
  101. this.naviViewTitleNode = new Element("div", {"styles": this.css.naviCategoryNode });
  102. // this.naviViewTitleNode = new Element("div", {"styles": this.css.naviViewTitleNode, "text": data.viewName});
  103. this.naviViewContentNode = new Element("div", {"styles": this.css.naviViewContentNode});
  104. object.push({
  105. "type": "view",
  106. "index": data.viewNumber,
  107. "titleNode": this.naviViewTitleNode,
  108. "contentNode": this.naviViewContentNode
  109. });
  110. }
  111. if( data.statShow !== "false" && data.statShow !== false ) {
  112. this.naviStatTitleNode = new Element("div", {"styles": this.css.naviCategoryNode });
  113. // this.naviStatTitleNode = new Element("div", {"styles": this.css.naviStatTitleNode, "text": data.statName});
  114. this.naviStatContentNode = new Element("div", {"styles": this.css.naviStatContentNode});
  115. object.push({
  116. "type": "stat",
  117. "index": data.statNumber,
  118. "titleNode": this.naviStatTitleNode,
  119. "contentNode": this.naviStatContentNode
  120. });
  121. }
  122. if( data.statementShow !== "false" && data.statementShow !== false ) {
  123. this.naviStatementTitleNode = new Element("div", {"styles": this.css.naviCategoryNode });
  124. // this.naviStatementTitleNode = new Element("div", {"styles": this.css.naviStatementTitleNode, "text": data.statementName});
  125. this.naviStatementContentNode = new Element("div", {"styles": this.css.naviStatementContentNode});
  126. object.push({
  127. "type": "statement",
  128. "index": data.statementNumber,
  129. "titleNode": this.naviStatementTitleNode,
  130. "contentNode": this.naviStatementContentNode
  131. });
  132. }
  133. if( data.importerShow !== "false" && data.importerShow !== false ) {
  134. this.naviImporterTitleNode = new Element("div", {"styles": this.css.naviCategoryNode });
  135. // this.naviImporterTitleNode = new Element("div", {
  136. // "styles": this.css.naviImporterTitleNode,
  137. // "text": data.importerName
  138. // });
  139. this.naviImporterContentNode = new Element("div", {"styles": this.css.naviImporterContentNode});
  140. object.push({
  141. "type": "importer",
  142. "index": data.importerNumber,
  143. "titleNode": this.naviImporterTitleNode,
  144. "contentNode": this.naviImporterContentNode
  145. });
  146. }
  147. object.sort(function(a, b){
  148. return a.index - b.index
  149. });
  150. object.each(function(a){
  151. a.titleNode.inject(this.naviContentNode);
  152. var actionNode = new Element("div", {"styles": this.css.naviExpandNode }).inject(a.titleNode);
  153. var textNode = new Element("div", {"styles": this.css.naviTitleTextNode, "text": data[a.type+"Name"] }).inject(a.titleNode);
  154. textNode.setStyle("background-image", "url('"+ data[a.type+"Icon"] +"')");
  155. a.titleNode.addEvents({
  156. "mouseover": function () {
  157. a.titleNode.setStyles(this.css.naviCategoryNode_over)
  158. }.bind(this),
  159. "mouseout": function () {
  160. a.titleNode.setStyles(this.css.naviCategoryNode)
  161. }.bind(this),
  162. "click": function () {
  163. if( actionNode.retrieve("collapse") ){
  164. actionNode.setStyles(this.css.naviExpandNode);
  165. actionNode.store("collapse",false);
  166. a.contentNode.show();
  167. }else{
  168. actionNode.setStyles(this.css.naviCollapseNode);
  169. actionNode.store("collapse",true);
  170. a.contentNode.hide();
  171. }
  172. }.bind(this)
  173. });
  174. a.contentNode.inject(this.naviContentNode);
  175. }.bind(this))
  176. this.setContentHeightFun = this.setContentHeight.bind(this);
  177. this.addEvent("resize", this.setContentHeightFun);
  178. this.setContentHeightFun();
  179. this.naviIconTitleNode = new Element("div", {"styles": this.css.naviIconTitleNode}).inject(this.naviTitleNode);
  180. if (this.query.icon){
  181. this.naviIconTitleNode.setStyles({
  182. "background-image": "url(data:image/png;base64,"+this.query.icon+")",
  183. });
  184. }
  185. this.naviRightTitleNode = new Element("div", {"styles": this.css.naviRightTitleNode}).inject(this.naviTitleNode);
  186. this.naviTextTitleNode = new Element("div", {"styles": this.css.naviTextTitleNode, "text": this.query.name}).inject(this.naviRightTitleNode);
  187. this.naviDescriptionTitleNode = new Element("div", {"styles": this.css.naviDescriptionTitleNode, "text": this.query.description || this.lp.noDescription}).inject(this.naviRightTitleNode);
  188. },
  189. createLayoutMobile: function(){},
  190. setContentHeight: function(){
  191. var size = this.content.getSize();
  192. var titleSize = this.naviTitleNode.getSize();
  193. var y = size.y-titleSize.y;
  194. this.naviContentNode.setStyle("height", ""+y+"px");
  195. },
  196. createNavi: function(){
  197. debugger;
  198. var viewLoaded,statLoaded, statementLoaded,importerLoaded;
  199. var callback = function () {
  200. if( this.viewItemSelected || this.statItemSelected || this.statementItemSelected || this.importerItemSelected )return;
  201. if(viewLoaded && statLoaded && statementLoaded && importerLoaded){
  202. for( var i=0; i<this.naviArray.length; i++ ){
  203. var items = this[this.naviArray[i].type+'Items'];
  204. if( items && items.length ){
  205. items[0].selected();
  206. return;
  207. }
  208. }
  209. }
  210. }.bind(this);
  211. this.createViewNavi(function () {
  212. viewLoaded = true;
  213. callback();
  214. }.bind(this));
  215. this.createStatNavi(function () {
  216. statLoaded = true;
  217. callback();
  218. }.bind(this));
  219. this.createStatementNavi(function () {
  220. statementLoaded = true;
  221. callback();
  222. }.bind(this));
  223. this.createImporterNavi(function () {
  224. importerLoaded = true;
  225. callback();
  226. }.bind(this));
  227. },
  228. createViewNavi: function( callback ){
  229. var data = this.interfaceData;
  230. this.viewItems = [];
  231. this.viewItemSelected = false;
  232. if( data.viewShow !== "flase" && data.viewShow !== false ) {
  233. this.action.listView(this.options.id, function (json) {
  234. if (json.data) {
  235. if(json.data.length === 0){
  236. this.naviViewTitleNode.hide();
  237. this.naviViewContentNode.hide();
  238. }
  239. (json.data || []).sort(function(a, b){
  240. return (a.orderNumber || 999999999) - (b.orderNumber || 999999999 );
  241. });
  242. json.data.each(function (view) {
  243. if (view.display) {
  244. var item = this.createViewNaviItem(view);
  245. this.viewItems.push(item);
  246. if (view.id === this.options.viewId) {
  247. item.selected();
  248. this.viewItemSelected = true;
  249. }
  250. }
  251. }.bind(this));
  252. }
  253. callback();
  254. }.bind(this));
  255. }else{
  256. callback();
  257. }
  258. },
  259. createStatNavi: function(callback){
  260. var data = this.interfaceData;
  261. this.statItems = [];
  262. this.statItemSelected = false;
  263. if( data.statShow !== "flase" && data.statShow !== false ) {
  264. MWF.Actions.get("x_query_assemble_surface").listStat(this.options.id, function (json) {
  265. //this.action.listStat(this.options.id, function(json){
  266. if (json.data) {
  267. if(json.data.length === 0){
  268. this.naviStatTitleNode.hide();
  269. this.naviStatContentNode.hide();
  270. }
  271. (json.data || []).sort(function(a, b){
  272. return (a.orderNumber || 999999999) - (b.orderNumber || 999999999 );
  273. });
  274. json.data.each(function (stat) {
  275. if (stat.display !== false ) {
  276. var item = this.createStatNaviItem(stat);
  277. this.statItems.push(item);
  278. if (stat.id === this.options.statId) {
  279. item.selected();
  280. this.statItemSelected = true;
  281. }
  282. }
  283. }.bind(this));
  284. }
  285. callback();
  286. }.bind(this));
  287. }else{
  288. callback();
  289. }
  290. },
  291. createStatementNavi: function(callback){
  292. var data = this.interfaceData;
  293. this.statementItems = [];
  294. this.statementItemSelected = false;
  295. if( data.statementShow !== "flase" && data.statementShow !== false ) {
  296. MWF.Actions.load("x_query_assemble_surface").StatementAction.listWithQuery(this.options.id, {
  297. "justSelect": true,
  298. "hasView": true
  299. }, function (json) {
  300. //this.action.listStat(this.options.id, function(json){
  301. if (json.data) {
  302. if(json.data.length === 0){
  303. this.naviStatementTitleNode.hide();
  304. this.naviStatementContentNode.hide();
  305. }
  306. (json.data || []).sort(function(a, b){
  307. return (a.orderNumber || 999999999) - (b.orderNumber || 999999999 );
  308. });
  309. json.data.each(function (statement) {
  310. if (statement.display !== false && statement.viewEnable !== false ) {
  311. var item = this.createStatementNaviItem(statement);
  312. this.statementItems.push(item);
  313. if (statement.id === this.options.statementId) {
  314. item.selected();
  315. this.statementItemSelected = true;
  316. }
  317. }
  318. }.bind(this));
  319. }
  320. callback();
  321. }.bind(this));
  322. }else{
  323. callback();
  324. }
  325. },
  326. createImporterNavi: function(callback){
  327. var data = this.interfaceData;
  328. this.importerItems = [];
  329. this.importerItemSelected = false;
  330. if( data.importerShow !== "flase" && data.importerShow !== false ) {
  331. MWF.Actions.load("x_query_assemble_surface").ImportModelAction.listWithQuery(this.options.id, function (json) {
  332. //this.action.listStat(this.options.id, function(json){
  333. if (json.data) {
  334. if(json.data.length === 0){
  335. this.naviImporterTitleNode.hide();
  336. this.naviImporterContentNode.hide();
  337. }
  338. (json.data || []).sort(function(a, b){
  339. return (a.orderNumber || 999999999) - (b.orderNumber || 999999999 );
  340. });
  341. json.data.each(function (importer) {
  342. if (importer.display !== false ) {
  343. var item = this.createImporterNaviItem(importer);
  344. this.importerItems.push(item);
  345. if (importer.id === this.options.importerId) {
  346. item.selected();
  347. this.importerItemSelected = true;
  348. }
  349. }
  350. }.bind(this));
  351. }
  352. callback();
  353. }.bind(this));
  354. }else{
  355. callback();
  356. }
  357. },
  358. createViewNaviItem: function(view){
  359. var item = new MWF.xApplication.query.Query.ViewItem(view, this);
  360. return item;
  361. },
  362. createStatNaviItem: function(stat){
  363. var item = new MWF.xApplication.query.Query.StatItem(stat, this);
  364. return item;
  365. },
  366. createStatementNaviItem: function(statement){
  367. var item = new MWF.xApplication.query.Query.StatementItem(statement, this);
  368. return item;
  369. },
  370. createImporterNaviItem: function(importer){
  371. var item = new MWF.xApplication.query.Query.ImporterItem(importer, this);
  372. return item;
  373. },
  374. recordStatus: function(){
  375. return {"id": this.options.id};
  376. }
  377. });
  378. MWF.xApplication.query.Query.ViewItem = new Class({
  379. initialize: function(view, app){
  380. this.view = view;
  381. this.app = app;
  382. this.css = this.app.css;
  383. this.lp = this.app.lp;
  384. this.isSelected = false;
  385. this.content = this.getContentNode();
  386. this.viewContent = this.getViewContentNode();
  387. this.load();
  388. },
  389. getContentNode: function(){
  390. return this.app.naviViewContentNode;
  391. },
  392. getViewContentNode: function(){
  393. return this.app.contentNode;
  394. },
  395. load: function(){
  396. this.node = new Element("div", {
  397. "styles": this.css.naviContentItemNode,
  398. "text": this.view.name,
  399. "title": this.view.name
  400. }).inject(this.content);
  401. this.node.addEvents({
  402. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.naviContentItemNode_over); }.bind(this),
  403. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.naviContentItemNode); }.bind(this),
  404. "click": function(){this.selected();}.bind(this)
  405. });
  406. },
  407. selected: function(){
  408. if (this.app.currentItem) this.app.currentItem.unselected();
  409. this.node.setStyles(this.css.naviContentItemNode_selected);
  410. this.app.currentItem = this;
  411. this.isSelected = true;
  412. this.loadView();
  413. },
  414. unselected: function(){
  415. this.node.setStyles(this.css.naviContentItemNode);
  416. this.app.currentItem = null;
  417. this.isSelected = false;
  418. },
  419. loadView: function(){
  420. MWF.xDesktop.requireApp("query.Query", "Viewer",function(){
  421. this.viewContent.empty();
  422. var data = JSON.parse(this.view.data);
  423. this.viewer = new MWF.QViewer(this.viewContent, {
  424. "application": this.view.query,
  425. "viewName": this.view.name,
  426. "isExpand": data.isExpand
  427. }, {
  428. "export": true,
  429. "onLoadLayout": function () {
  430. this.viewAreaNode.setStyles({
  431. "padding-left": "10px",
  432. "padding-right": "10px"
  433. });
  434. if( this.viewJson && this.viewJson.customFilterList && this.viewJson.customFilterList.length ) {
  435. }else{
  436. this.viewAreaNode.setStyles({"padding-top": "10px"})
  437. }
  438. }
  439. }, this.app);
  440. }.bind(this));
  441. }
  442. });
  443. MWF.xApplication.query.Query.StatItem = new Class({
  444. Extends: MWF.xApplication.query.Query.ViewItem,
  445. getContentNode: function(){
  446. return this.app.naviStatContentNode;
  447. },
  448. loadView: function(){
  449. MWF.xDesktop.requireApp("query.Query", "Statistician",function(){
  450. this.viewContent.empty();
  451. this.viewer = new MWF.QStatistician(this.app, this.viewContent, {
  452. "application": this.view.query,
  453. "statName": this.view.name,
  454. "isTable": true,
  455. "isChart": true,
  456. "isLegend": true
  457. }, {
  458. "onLoadLayout": function () {
  459. this.node.setStyles({
  460. "padding-left": "10px",
  461. "padding-right": "10px",
  462. "padding-top": "10px",
  463. "padding-bottom": "10px"
  464. });
  465. },
  466. "onLoaded": function () {
  467. this._setContentHeight();
  468. }
  469. });
  470. }.bind(this));
  471. }
  472. });
  473. MWF.xApplication.query.Query.StatementItem = new Class({
  474. Extends: MWF.xApplication.query.Query.ViewItem,
  475. getContentNode: function(){
  476. return this.app.naviStatementContentNode;
  477. },
  478. loadView: function(){
  479. MWF.xDesktop.requireApp("query.Query", "Statement",function(){
  480. this.viewContent.empty();
  481. this.viewer = new MWF.QStatement( this.viewContent, {
  482. "application": this.view.query,
  483. "statementName": this.view.name,
  484. "statementId" : this.view.id
  485. },{
  486. "onLoadLayout": function () {
  487. this.viewAreaNode.setStyles({
  488. "padding-left": "10px",
  489. "padding-right": "10px"
  490. });
  491. if( this.viewJson && this.viewJson.customFilterList && this.viewJson.customFilterList.length ) {
  492. }else{
  493. this.viewAreaNode.setStyles({"padding-top": "10px"})
  494. }
  495. }
  496. }, this.app);
  497. }.bind(this));
  498. }
  499. });
  500. MWF.xApplication.query.Query.ImporterItem = new Class({
  501. Extends: MWF.xApplication.query.Query.ViewItem,
  502. getContentNode: function(){
  503. return this.app.naviImporterContentNode;
  504. },
  505. loadView: function(){
  506. MWF.xDesktop.requireApp("query.Query", "ImporterRecord", function(){
  507. this.viewContent.empty();
  508. this.viewer = new MWF.xApplication.query.Query.ImporterRecord( this.viewContent, this.app, {
  509. "application": this.view.query,
  510. "importerName": this.view.name,
  511. "importerId" : this.view.id,
  512. "onLoadLayout": function () {
  513. this.viewContainer.setStyles({
  514. "padding-left": "10px",
  515. "padding-right": "10px",
  516. "padding-top": "10px"
  517. });
  518. }
  519. });
  520. this.viewer.load()
  521. }.bind(this));
  522. }
  523. });