Statement.js 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.query = MWF.xApplication.query || {};
  3. MWF.xApplication.query.StatementDesigner = MWF.xApplication.query.StatementDesigner || {};
  4. MWF.APPDSMD = MWF.xApplication.query.StatementDesigner;
  5. MWF.xDesktop.requireApp("query.StatementDesigner", "lp."+MWF.language, null, false);
  6. MWF.xDesktop.requireApp("query.StatementDesigner", "Property", null, false);
  7. MWF.xDesktop.requireApp("query.ViewDesigner", "View", null, false);
  8. o2.require("o2.widget.JavascriptEditor", null, false);
  9. MWF.xApplication.query.StatementDesigner.Statement = new Class({
  10. Extends: MWF.widget.Common,
  11. Implements: [Options, Events],
  12. options: {
  13. "style": "default",
  14. "isView": false,
  15. "showTab": true,
  16. "propertyPath": "../x_component_query_StatementDesigner/$Statement/statement.html"
  17. },
  18. initialize: function(designer, data, options){
  19. this.setOptions(options);
  20. this.path = "../x_component_query_StatementDesigner/$Statement/";
  21. this.cssPath = "../x_component_query_StatementDesigner/$Statement/"+this.options.style+"/css.wcss";
  22. this._loadCss();
  23. this.designer = designer;
  24. this.data = data;
  25. this.parseData();
  26. this.node = this.designer.designNode;
  27. this.areaNode = new Element("div", {"styles": {"height": "100%", "overflow": "auto"}});
  28. //this.statementRunNode = this.designer.designerStatementArea;
  29. if(this.designer.application) this.data.applicationName = this.designer.application.name;
  30. if(this.designer.application) this.data.application = this.designer.application.id;
  31. this.isNewStatement = (this.data.id) ? false : true;
  32. this.view = this;
  33. this.autoSave();
  34. this.designer.addEvent("queryClose", function(){
  35. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  36. }.bind(this));
  37. },
  38. parseData: function(){
  39. this.json = this.data;
  40. if (!this.json.type) this.json.type = "select";
  41. if (!this.json.format) this.json.format = "jpql";
  42. if (!this.json.entityCategory) this.json.entityCategory = "official";
  43. if (!this.json.entityClassName) this.json.entityClassName = "com.x.processplatform.core.entity.content.Task";
  44. },
  45. autoSave: function(){
  46. this.autoSaveTimerID = window.setInterval(function(){
  47. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFAutoSaveCheck");
  48. if (this.autoSaveCheckNode){
  49. if (this.autoSaveCheckNode.get("checked")){
  50. this.save();
  51. }
  52. }
  53. }.bind(this), 60000);
  54. },
  55. load : function(){
  56. // this.setAreaNodeSize();
  57. // this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  58. this.areaNode.inject(this.node);
  59. this.designer.statementListAreaNode.getChildren().each(function(node){
  60. var statement = node.retrieve("statement");
  61. if (statement.id==this.data.id){
  62. if (this.designer.currentListStatementItem){
  63. this.designer.currentListStatementItem.setStyles(this.designer.css.listStatementItem);
  64. }
  65. node.setStyles(this.designer.css.listStatementItem_current);
  66. this.designer.currentListStatementItem = node;
  67. this.lisNode = node;
  68. }
  69. }.bind(this));
  70. this.loadStatement();
  71. // this.showProperty();
  72. this.selected();
  73. },
  74. selected: function(){
  75. if (this.currentSelectedModule){
  76. if (this.currentSelectedModule==this){
  77. return true;
  78. }else{
  79. this.currentSelectedModule.unSelected();
  80. }
  81. }
  82. if( this.view && this.view.domListNode ){
  83. this.view.domListNode.hide();
  84. }
  85. this.currentSelectedModule = this;
  86. this.isSelected = true;
  87. this.showProperty();
  88. },
  89. unSelected: function(){
  90. this.currentSelectedModule = null;
  91. this.isSelected = false;
  92. this.hideProperty();
  93. },
  94. showProperty: function(){
  95. if (!this.property){
  96. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.designerContentArea, this.designer, {
  97. "path": this.options.propertyPath,
  98. "onPostLoad": function(){
  99. this.property.show();
  100. }.bind(this)
  101. });
  102. this.property.load();
  103. }else{
  104. this.property.show();
  105. }
  106. },
  107. hideProperty: function(){
  108. if (this.property) this.property.hide();
  109. },
  110. loadJpqlTab: function(callback){
  111. var _self = this;
  112. MWF.require("MWF.widget.Tab", null, false);
  113. this.jpqlTab = new MWF.widget.Tab(this.jpqlTabNode, {"style": "script"});
  114. this.jpqlTab.load();
  115. this.tabJpqlNode = Element("div");
  116. this.jpqlTabPageNode.inject( this.tabJpqlNode );
  117. this.tabCountJpqlNode = Element("div");
  118. this.countJpqlTabPageNode.inject( this.tabCountJpqlNode );
  119. this.jpqlPage = this.jpqlTab.addTab(this.tabJpqlNode, this.designer.lp.queryStatement);
  120. this.countJpqlPage = this.jpqlTab.addTab(this.tabCountJpqlNode, this.designer.lp.countStatement );
  121. this.jpqlPage.showTabIm();
  122. // this.jpqlPage.addEvent("postShow", function(){
  123. // if( this.view ){
  124. // this.view.setContentHeight();
  125. // this.view.selected();
  126. // }
  127. // }.bind(this));
  128. // this.countJpqlPage.addEvent("postShow", function(){
  129. // this.selected();
  130. // }.bind(this));
  131. },
  132. loadTab: function(callback){
  133. var _self = this;
  134. MWF.require("MWF.widget.Tab", null, false);
  135. this.tab = new MWF.widget.Tab(this.tabNode, {"style": "script"});
  136. this.tab.load();
  137. this.tabRunNode = Element("div");
  138. this.pageRunNode = new Element("div", {"styles": {"overflow": "auto","background-color":"#fff"}}).inject(this.tabRunNode);
  139. this.runArea.inject( this.pageRunNode );
  140. this.tabViewNode = Element("div", {"styles": { "height": "100%" }});
  141. this.pageViewNode = new Element("div.pageViewNode").inject(this.tabViewNode);
  142. this.viewArea.inject( this.pageViewNode );
  143. this.runPage = this.tab.addTab(this.tabRunNode, this.designer.lp.runTest);
  144. this.viewPage = this.tab.addTab(this.tabViewNode, this.designer.lp.view );
  145. this.runPage.showTabIm();
  146. this.viewPage.addEvent("postShow", function(){
  147. if( this.view ){
  148. this.view.setContentHeight();
  149. this.view.selected();
  150. }
  151. }.bind(this));
  152. this.runPage.addEvent("postShow", function(){
  153. this.selected();
  154. }.bind(this));
  155. },
  156. loadStatement: function(){
  157. //this.statementDesignerNode = new Element("div", {"styles": this.css.statementDesignerNode}).inject(this.areaNode);
  158. this.loadStatementHtml(function(){
  159. this.designerArea = this.areaNode.getElement(".o2_statement_statementDesignerNode");
  160. this.jpqlTabPageNode = this.areaNode.getElement(".o2_statement_statementJpqlTabPageNode");
  161. this.jpqlArea = this.areaNode.getElement(".o2_statement_statementDesignerJpql");
  162. this.scriptArea = this.areaNode.getElement(".o2_statement_statementDesignerScript");
  163. this.formatTypeArea = this.areaNode.getElement(".o2_statement_statementDesignerFormatContent");
  164. this.entityCategorySelect = this.areaNode.getElement(".o2_statement_statementDesignerCategoryContent").getElement("select");
  165. this.dynamicTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_dynamic");
  166. this.officialTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_official");
  167. this.customTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_custom");
  168. this.dynamicTableSelect = this.areaNode.getElement(".o2_statement_statementDesignerSelectTable");
  169. this.officialTableSelect = this.officialTableArea.getElement("select");
  170. this.dynamicTableContent = this.areaNode.getElement(".o2_statement_statementDesignerTableContent");
  171. this.jpqlTabNode = this.areaNode.getElement(".o2_statement_statementJpqlTabNode");
  172. this.jpqlTypeSelect = this.areaNode.getElement(".o2_statement_statementDesignerTypeContent").getElement("select");
  173. // this.jpqlSelectEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_select");
  174. // this.jpqlUpdateEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_update");
  175. // this.jpqlDeleteEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_sdelete");
  176. // this.jpqlSelectEditor_selectContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_selectContent");
  177. // this.jpqlSelectEditor_fromContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_fromContent");
  178. // this.jpqlSelectEditor_whereContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_whereContent");
  179. this.jpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerJpqlLine");
  180. this.countJpqlTabPageNode = this.areaNode.getElement(".o2_statement_statementCountJpqlTabPageNode");
  181. this.countJpqlArea = this.areaNode.getElement(".o2_statement_statementDesignerCountJpql");
  182. this.countScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerCountScript");
  183. this.countJpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerCountJpqlLine");
  184. this.loadJpqlTab();
  185. this.tabNode = this.areaNode.getElement(".o2_statement_tabNode");
  186. this.runArea = this.areaNode.getElement(".o2_statement_statementRunNode");
  187. // this.runTitleNode = this.areaNode.getElement(".o2_statement_statementRunTitleNode");
  188. this.runContentNode = this.areaNode.getElement(".o2_statement_statementRunContentNode");
  189. this.runJsonNode = this.runContentNode.getFirst();
  190. this.runActionNode = this.runJsonNode.getNext();
  191. this.runResultNode = this.runContentNode.getLast();
  192. this.setRunnerSize();
  193. this.designer.addEvent("resize", this.setRunnerSize.bind(this));
  194. if (this.json.format=="script"){
  195. this.loadStatementScriptEditor();
  196. this.loadStatementCountScriptEditor();
  197. }else{
  198. this.loadStatementEditor();
  199. this.loadStatementCountEditor();
  200. }
  201. this.loadStatementRunner();
  202. this.viewArea = this.areaNode.getElement(".o2_statement_viewNode");
  203. this.loadView();
  204. this.loadTab();
  205. this.setEvent();
  206. }.bind(this));
  207. },
  208. loadStatementScriptEditor: function(){
  209. if (! this.scriptEditor){
  210. debugger;
  211. o2.require("o2.widget.ScriptArea", function(){
  212. this.scriptEditor = new o2.widget.ScriptArea(this.scriptArea, {
  213. "isbind": false,
  214. "maxObj": this.designer.designNode,
  215. "title": this.designer.lp.scriptTitle,
  216. "onChange": function(){
  217. this.json.scriptText = this.scriptEditor.toJson().code;
  218. }.bind(this)
  219. });
  220. this.scriptEditor.load({"code": this.json.scriptText})
  221. }.bind(this), false);
  222. }
  223. },
  224. loadStatementCountScriptEditor: function(){
  225. if (! this.countScriptEditor){
  226. debugger;
  227. o2.require("o2.widget.ScriptArea", function(){
  228. this.countScriptEditor = new o2.widget.ScriptArea(this.countScriptArea, {
  229. "isbind": false,
  230. "maxObj": this.designer.designNode,
  231. "title": this.designer.lp.scriptTitle,
  232. "onChange": function(){
  233. this.json.countScriptText = this.countScriptEditor.toJson().code;
  234. }.bind(this)
  235. });
  236. this.countScriptEditor.load({"code": this.json.countScriptText})
  237. }.bind(this), false);
  238. }
  239. },
  240. setRunnerSize: function(){
  241. debugger;
  242. var size = this.areaNode.getSize();
  243. var designerSize = this.designerArea.getComputedSize();
  244. var y = size.y-designerSize.totalHeight;
  245. var mTop = this.runArea.getStyle("margin-top").toInt();
  246. var mBottom = this.runArea.getStyle("margin-bottom").toInt();
  247. var pTop = this.runArea.getStyle("padding-top").toInt();
  248. var pBottom = this.runArea.getStyle("padding-bottom").toInt();
  249. y = y-mTop-mBottom-pTop-pBottom-1;
  250. var tabSize = this.tabNode.getComputedSize();
  251. y = y - tabSize.totalHeight;
  252. this.runArea.setStyle("height", ""+y+"px");
  253. // var titleSize = this.runTitleNode.getComputedSize();
  254. // y = y - titleSize.totalHeight;
  255. this.runContentNode.setStyle("height", ""+y+"px");
  256. },
  257. loadStatementEditor: function(){
  258. if (!this.editor){
  259. o2.require("o2.widget.JavascriptEditor", function(){
  260. this.editor = new o2.widget.JavascriptEditor(this.jpqlEditorNode, {"title": "JPQL", "option": {"mode": "sql"}});
  261. this.editor.load(function(){
  262. if (this.json.data){
  263. this.editor.editor.setValue(this.json.data);
  264. }else{
  265. var table = "table";
  266. switch (this.json.type) {
  267. case "update":
  268. this.editor.editor.setValue("UPDATE "+table+" o SET ");
  269. break;
  270. case "delete":
  271. this.editor.editor.setValue("DELETE "+table+" o WHERE ");
  272. break;
  273. default:
  274. this.editor.editor.setValue("SELECT * FROM "+table+" o");
  275. }
  276. }
  277. this.json.data = this.editor.editor.getValue();
  278. this.editor.addEditorEvent("change", function(){
  279. debugger;
  280. this.data.data = this.editor.getValue();
  281. this.checkJpqlType();
  282. }.bind(this));
  283. // this.editor.editor.on("change", function(){
  284. // this.data.data = this.editor.getValue();
  285. // this.checkJpqlType();
  286. // }.bind(this));
  287. }.bind(this));
  288. }.bind(this), false);
  289. }
  290. },
  291. loadStatementCountEditor: function(){
  292. if (!this.countEditor){
  293. o2.require("o2.widget.JavascriptEditor", function(){
  294. this.countEditor = new o2.widget.JavascriptEditor(this.countJpqlEditorNode, {"title": "JPQL", "option": {"mode": "sql"}});
  295. this.countEditor.load(function(){
  296. if (this.json.countData){
  297. this.countEditor.editor.setValue(this.json.countData);
  298. }else{
  299. var table = "table";
  300. this.countEditor.editor.setValue("SELECT count(o.id) FROM "+table+" o");
  301. }
  302. this.json.countData = this.countEditor.editor.getValue();
  303. this.countEditor.addEditorEvent("change", function(){
  304. debugger;
  305. this.data.countData = this.countEditor.getValue();
  306. }.bind(this));
  307. // this.editor.editor.on("change", function(){
  308. // this.data.data = this.editor.getValue();
  309. // this.checkJpqlType();
  310. // }.bind(this));
  311. }.bind(this));
  312. }.bind(this), false);
  313. }
  314. },
  315. setSatementTable: function(){
  316. if (!this.json.type) this.json.type = "select";
  317. this.changeType(this.json.type, true);
  318. if (this.json.data){
  319. this.editor.editor.setValue(this.json.data);
  320. }else{
  321. var table = (this.json.tableObj) ? this.json.tableObj.name : "table";
  322. switch (this.json.type) {
  323. case "update":
  324. this.editor.editor.setValue("UPDATE "+table+" o SET ");
  325. break;
  326. case "delete":
  327. this.editor.editor.setValue("DELETE "+table+" o WHERE ");
  328. break;
  329. default:
  330. this.editor.editor.setValue("SELECT * FROM "+table+" o");
  331. }
  332. }
  333. },
  334. checkJpqlType: function(){
  335. var str = this.json.data;
  336. this.json.data = str;
  337. var jpql_select = /^select/i;
  338. var jpql_update = /^update/i;
  339. var jpql_delete = /^delete/i;
  340. if (jpql_select.test(str)) return this.changeType("select");
  341. if (jpql_update.test(str)) return this.changeType("update");
  342. if (jpql_delete.test(str)) return this.changeType("delete");
  343. },
  344. changeType: function(type, force){
  345. if (this.json.type!=type) this.json.type=type;
  346. if (type != this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value || force){
  347. for (var i=0; i<this.jpqlTypeSelect.options.length; i++){
  348. if (this.jpqlTypeSelect.options[i].value==type){
  349. this.jpqlTypeSelect.options[i].set("selected", true);
  350. break;
  351. }
  352. }
  353. }
  354. },
  355. loadStatementHtml: function(callback){
  356. this.areaNode.loadAll({
  357. "css": this.path+this.options.style+"/statement.css",
  358. "html": this.path+"statementDesigner.html"
  359. }, {
  360. "bind": {"lp": this.designer.lp, "data": this.data}
  361. },function(){
  362. if (callback) callback();
  363. }.bind(this));
  364. },
  365. loadStatementRunner: function(){
  366. o2.require("o2.widget.JavascriptEditor", function(){
  367. this.jsonEditor = new o2.widget.JavascriptEditor(this.runJsonNode, {"title": "JPQL", "option": {"mode": "json"}});
  368. this.jsonEditor.load(function(){
  369. this.jsonEditor.editor.setValue("{}");
  370. }.bind(this));
  371. }.bind(this), false);
  372. },
  373. setEvent: function(){
  374. this.designerArea.addEvent("click", function (e) {
  375. this.selected();
  376. e.stopPropagation();
  377. }.bind(this));
  378. this.formatTypeArea.getElements("input").addEvent("click", function(e){
  379. if (e.target.checked){
  380. var v = e.target.get("value");
  381. if (v==="script"){
  382. this.scriptArea.show();
  383. this.jpqlArea.hide();
  384. this.loadStatementScriptEditor();
  385. this.countScriptArea.show();
  386. this.countJpqlArea.hide();
  387. this.loadStatementCountScriptEditor();
  388. }else{
  389. this.scriptArea.hide();
  390. this.jpqlArea.show();
  391. this.loadStatementEditor();
  392. this.countScriptArea.hide();
  393. this.countJpqlArea.show();
  394. this.loadStatementCountEditor();
  395. }
  396. this.json.format = v;
  397. }
  398. }.bind(this));
  399. this.entityCategorySelect.addEvent("change", function(e){
  400. var entityCategory = e.target.options[e.target.selectedIndex].value;
  401. switch (entityCategory) {
  402. case "dynamic":
  403. this.officialTableArea.hide();
  404. this.dynamicTableArea.show();
  405. this.customTableArea.hide();
  406. break;
  407. case "custom":
  408. this.officialTableArea.hide();
  409. this.dynamicTableArea.hide();
  410. this.customTableArea.show();
  411. break;
  412. default:
  413. this.officialTableArea.show();
  414. this.dynamicTableArea.hide();
  415. this.customTableArea.hide();
  416. break;
  417. }
  418. this.json.entityCategory = entityCategory
  419. }.bind(this));
  420. //@todo change table
  421. this.officialTableSelect.addEvent("change", function(e){
  422. debugger;
  423. var entityClassName = e.target.options[e.target.selectedIndex].value;
  424. this.json.entityClassName = entityClassName;
  425. if (this.json.format=="jpql"){
  426. if (this.editor){
  427. var re = /(.*from\s*)/ig;
  428. if (this.json.type=="update") re = /(.*update\s*)/ig;
  429. //if (this.json.type=="select" && this.editor){
  430. var v = this.json.data;
  431. var re2 = /(\s+)/ig;
  432. var arr = re.exec(v);
  433. if (arr && arr[0]){
  434. var left = arr[0]
  435. v = v.substring(left.length, v.length);
  436. //var ar = re2.exec(v);
  437. var right = v.substring(v.indexOf(" "),v.length);
  438. this.json.data = left+entityClassName+right;
  439. this.editor.editor.setValue(this.json.data);
  440. }
  441. //}
  442. }
  443. }
  444. // var className = e.target.options[e.target.selectedIndex].value;
  445. // if (this.json.type=="select"){
  446. // this.json.data
  447. // /(select)*(where|)/g
  448. // }
  449. // }.bind(this));
  450. // this.jpqlTypeSelect.addEvent("change", function(){
  451. // var type = e.target.options[e.target.selectedIndex].value;
  452. // switch (entityCategory) {
  453. // case "update":
  454. // this.jpqlSelectEditor.hide();
  455. // this.jpqlUpdateEditor.show();
  456. // this.jpqlDeleteEditor.hide();
  457. // this.loadJpqlUpdateEditor();
  458. // break;
  459. // case "delete":
  460. // this.jpqlSelectEditor.hide();
  461. // this.jpqlUpdateEditor.hide();
  462. // this.jpqlDeleteEditor.show();
  463. // break;
  464. // default:
  465. // this.jpqlSelectEditor.show();
  466. // this.jpqlUpdateEditor.hide();
  467. // this.jpqlDeleteEditor.hide();
  468. // break;
  469. // }
  470. }.bind(this));
  471. this.runActionNode.getFirst().addEvent("click", this.runStatement.bind(this));
  472. this.dynamicTableSelect.addEvent("click", this.selectTable.bind(this));
  473. this.jpqlTypeSelect.addEvent("change", function(){
  474. var t = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value;
  475. if (t!=this.json.type){
  476. this.json.type = t;
  477. }
  478. if( t!="select"){
  479. this.jpqlPage.showTabIm();
  480. this.countJpqlPage.disableTab();
  481. this.runPage.showTabIm();
  482. this.viewPage.disableTab();
  483. }else{
  484. this.countJpqlPage.enableTab( true );
  485. this.viewPage.enableTab( true );
  486. }
  487. }.bind(this));
  488. },
  489. selectTable: function(){
  490. new MWF.O2Selector(this.designer.content, {
  491. "type": "queryTable",
  492. "count": 1,
  493. "values": (this.json.table) ? [this.json.table] : [],
  494. "title": this.designer.lp.selectTable,
  495. "onComplete": function(items){
  496. if (items.length){
  497. var id = items[0].data.id;
  498. var name = items[0].data.name;
  499. this.dynamicTableContent.set("text", name);
  500. this.json.table = name;
  501. this.json.tableObj = items[0].data;
  502. }else{
  503. this.dynamicTableContent.set("text", "");
  504. this.json.table = "";
  505. }
  506. }.bind(this)
  507. });
  508. },
  509. runStatement:function(){
  510. debugger;
  511. // if (!this.json.data){
  512. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  513. // return false;
  514. // }
  515. o2.require("o2.widget.Mask", null, false);
  516. this.runMask = new o2.widget.Mask();
  517. this.runMask.loadNode(this.node);
  518. this.saveSilence(function(){
  519. var json = this.jsonEditor.editor.getValue();
  520. var o = JSON.parse(json);
  521. o2.Actions.get("x_query_assemble_designer").executeStatement(this.json.id, 1, 50 , o, function(json){
  522. o2.require("o2.widget.JsonParse", function(){
  523. this.runResultNode.empty();
  524. var jsonResult = new o2.widget.JsonParse(json.data, this.runResultNode);
  525. jsonResult.load();
  526. }.bind(this));
  527. this.runMask.hide();
  528. }.bind(this), function(xhr, text, error){
  529. debugger;
  530. if (this.runMask) this.runMask.hide();
  531. var errorText = error;
  532. if (xhr){
  533. var json = JSON.decode(xhr.responseText);
  534. if (json){
  535. errorText = json.message.trim() || "request json error";
  536. }else{
  537. errorText = "request json error: "+xhr.responseText;
  538. }
  539. }
  540. errorText = errorText.replace(/\</g, "&lt;");
  541. errorText = errorText.replace(/\</g, "&gt;");
  542. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  543. }.bind(this))
  544. }.bind(this));
  545. },
  546. save: function(callback){
  547. debugger;
  548. if (!this.data.name){
  549. this.designer.notice(this.designer.lp.inputStatementName, "error");
  550. return false;
  551. }
  552. //if( !this.data.tableType ){
  553. // this.data.tableType = "dynamic";
  554. //}
  555. if (this.editor) this.data.data = this.editor.editor.getValue();
  556. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  557. this.designer.actions.saveStatement(this.data, function(json){
  558. this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  559. this.data.id = json.data.id;
  560. if (this.lisNode) {
  561. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  562. }
  563. if (callback) callback();
  564. }.bind(this));
  565. },
  566. _setEditStyle: function(){},
  567. saveSilence: function(callback){
  568. if (!this.data.name){
  569. this.designer.notice(this.designer.lp.inputStatementName, "error");
  570. return false;
  571. }
  572. if (this.editor) this.data.data = this.editor.editor.getValue();
  573. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  574. this.designer.actions.saveStatement(this.data, function(json){
  575. //this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  576. this.data.id = json.data.id;
  577. if (this.lisNode) {
  578. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  579. }
  580. if (callback) callback();
  581. }.bind(this));
  582. },
  583. loadView : function( callback ){
  584. this.setViewSize();
  585. this.designer.addEvent("resize", this.setViewSize.bind(this));
  586. if( !this.data.view )this.data.view = {};
  587. this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.data.view, {});
  588. this.view.load( function () {
  589. this.view.setContentHeight();
  590. }.bind(this));
  591. },
  592. setViewSize: function(){
  593. debugger;
  594. var size = this.areaNode.getSize();
  595. var designerSize = this.designerArea.getComputedSize();
  596. var y = size.y-designerSize.totalHeight;
  597. var mTop = this.viewArea.getStyle("margin-top").toInt();
  598. var mBottom = this.viewArea.getStyle("margin-bottom").toInt();
  599. var pTop = this.viewArea.getStyle("padding-top").toInt();
  600. var pBottom = this.viewArea.getStyle("padding-bottom").toInt();
  601. y = y-mTop-mBottom-pTop-pBottom-1;
  602. var tabSize = this.tabNode.getComputedSize();
  603. y = y - tabSize.totalHeight;
  604. this.viewArea.setStyle("height", ""+y+"px");
  605. // var titleSize = this.runTitleNode.getComputedSize();
  606. // y = y - titleSize.totalHeight;
  607. // this.runContentNode.setStyle("height", ""+y+"px");
  608. }
  609. });
  610. MWF.xApplication.query.StatementDesigner.View = new Class({
  611. Extends: MWF.xApplication.query.ViewDesigner.View,
  612. Implements: [Options, Events],
  613. options: {
  614. "style": "default",
  615. "isView": false,
  616. "showTab": true,
  617. "propertyPath": "../x_component_query_StatementDesigner/$Statement/view.html"
  618. },
  619. initialize: function(designer, statement, data, options){
  620. this.setOptions(options);
  621. this.path = "../x_component_query_ViewDesigner/$View/";
  622. this.cssPath = "../x_component_query_ViewDesigner/$View/"+this.options.style+"/css.wcss";
  623. this._loadCss();
  624. this.statement = statement;
  625. this.designer = designer;
  626. this.data = data;
  627. // if (!this.data.data) this.data.data = {};
  628. this.parseData();
  629. this.node = this.statement.viewArea;
  630. //this.tab = this.designer.tab;
  631. this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto" }});
  632. this.areaNode.setStyles(this.css.areaNode);
  633. //MWF.require("MWF.widget.ScrollBar", function(){
  634. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  635. //}.bind(this));
  636. // this.propertyListNode = this.designer.propertyDomArea;
  637. //this.propertyNode = this.designer.propertyContentArea;
  638. // if(this.designer.application) this.data.applicationName = this.designer.application.name;
  639. // if(this.designer.application) this.data.application = this.designer.application.id;
  640. // this.isNewView = (this.data.name) ? false : true;
  641. this.items = [];
  642. this.view = this;
  643. // this.autoSave();
  644. // this.designer.addEvent("queryClose", function(){
  645. // if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  646. // }.bind(this));
  647. },
  648. load : function( callback ){
  649. this.setAreaNodeSize();
  650. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  651. this.areaNode.inject(this.node);
  652. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  653. this.loadTemplateStyle( function () {
  654. this.loadActionbar();
  655. this.loadView();
  656. this.loadPaging();
  657. // this.selected();
  658. this.setEvent();
  659. //if (this.options.showTab) this.page.showTabIm();
  660. this.setViewWidth();
  661. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  662. if(callback)callback();
  663. }.bind(this))
  664. },
  665. parseData: function(){
  666. this.json = this.data;
  667. if( !this.json.data || !this.json.data.events ){
  668. var url = "../x_component_query_StatementDesigner/$Statement/view.json";
  669. MWF.getJSON(url, {
  670. "onSuccess": function(obj){
  671. if(!this.json.data)this.json.data = obj.data;
  672. if(!this.json.data.events)this.json.data.events = obj.data.events;
  673. }.bind(this),
  674. "onerror": function(text){
  675. this.notice(text, "error");
  676. }.bind(this),
  677. "onRequestFailure": function(xhr){
  678. this.notice(xhr.responseText, "error");
  679. }.bind(this)
  680. },false);
  681. }
  682. },
  683. setEvent: function(){
  684. this.areaNode.addEvents({
  685. "click": function(e){ this.selected(); e.stopPropagation(); }.bind(this),
  686. "mouseover": function(){ if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode_over)}.bind(this),
  687. "mouseout": function(){if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode)}.bind(this)
  688. });
  689. this.refreshNode.addEvent("click", function(e){
  690. this.loadViewData();
  691. e.stopPropagation();
  692. }.bind(this));
  693. this.addColumnNode.addEvent("click", function(e){
  694. this.addColumn();
  695. e.stopPropagation();
  696. }.bind(this));
  697. },
  698. selected: function(){
  699. debugger;
  700. if (this.statement.currentSelectedModule){
  701. if (this.statement.currentSelectedModule==this){
  702. return true;
  703. }else{
  704. this.statement.currentSelectedModule.unSelected();
  705. }
  706. }
  707. this.areaNode.setStyles(this.css.areaNode_selected);
  708. this.statement.currentSelectedModule = this;
  709. this.domListNode.show();
  710. this.isSelected = true;
  711. this.showProperty();
  712. },
  713. unSelected: function(){
  714. this.statement.currentSelectedModule = null;
  715. this.isSelected = false;
  716. this.areaNode.setStyles(this.css.areaNode);
  717. this.hideProperty();
  718. },
  719. showProperty: function(){
  720. if (!this.property){
  721. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  722. "path": this.options.propertyPath,
  723. "onPostLoad": function(){
  724. this.property.show();
  725. }.bind(this)
  726. });
  727. this.property.load();
  728. }else{
  729. this.property.show();
  730. }
  731. },
  732. hideProperty: function(){
  733. if (this.property) this.property.hide();
  734. },
  735. loadViewData: function(){
  736. if (this.data.id){
  737. this.saveSilence(function(){
  738. this.viewContentBodyNode.empty();
  739. this.viewContentTableNode = new Element("table", {
  740. "styles": this.css.viewContentTableNode,
  741. "border": "0px",
  742. "cellPadding": "0",
  743. "cellSpacing": "0"
  744. }).inject(this.viewContentBodyNode);
  745. this.designer.actions.loadView(this.data.id, null,function(json){
  746. var entries = {};
  747. json.data.selectList.each(function(entry){entries[entry.column] = entry;}.bind(this));
  748. if (this.json.data.group.column){
  749. if (json.data.groupGrid.length){
  750. var groupColumn = null;
  751. for (var c = 0; c<json.data.selectList.length; c++){
  752. if (json.data.selectList[c].column === json.data.group.column){
  753. groupColumn = json.data.selectList[c];
  754. break;
  755. }
  756. }
  757. json.data.groupGrid.each(function(line, idx){
  758. var groupTr = new Element("tr", {
  759. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode,
  760. "data-is-group" : "yes"
  761. }).inject(this.viewContentTableNode);
  762. var colSpan = this.items.length ;
  763. var td = new Element("td", {
  764. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentGroupTd"] : this.css.viewContentGroupTdNode,
  765. "colSpan": colSpan
  766. }).inject(groupTr);
  767. var groupAreaNode;
  768. if( this.json.data.viewStyles ){
  769. groupAreaNode = new Element("div", {"styles": this.json.data.viewStyles["groupCollapseNode"]}).inject(td);
  770. groupAreaNode.set("text", line.group);
  771. }else{
  772. groupAreaNode = new Element("div", {"styles": this.css.viewContentTdGroupNode}).inject(td);
  773. var groupIconNode = new Element("div", {"styles": this.css.viewContentTdGroupIconNode}).inject(groupAreaNode);
  774. var groupTextNode = new Element("div", {"styles": this.css.viewContentTdGroupTextNode}).inject(groupAreaNode);
  775. if (groupColumn){
  776. //groupTextNode.set("text", (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": line.group, "gridData": json.data.groupGrid, "data": json.data, "entry": line}) : line.group);
  777. groupTextNode.set("text", line.group);
  778. }else{
  779. groupTextNode.set("text", line.group);
  780. }
  781. }
  782. var subtrs = [];
  783. line.list.each(function(entry){
  784. var tr = new Element("tr", {
  785. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  786. }).inject(this.viewContentTableNode);
  787. tr.setStyle("display", "none");
  788. //this.createViewCheckboxTd( tr );
  789. var td = new Element("td", {
  790. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  791. }).inject(tr);
  792. Object.each(entries, function(c, k){
  793. var d = entry.data[k];
  794. if (d!=undefined){
  795. if (k!=this.json.data.group.column){
  796. var td = new Element("td", {
  797. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  798. }).inject(tr);
  799. //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
  800. if (c.isHtml){
  801. td.set("html", d);
  802. }else{
  803. td.set("text", d);
  804. }
  805. }
  806. }
  807. }.bind(this));
  808. // Object.each(entry.data, function(d, k){
  809. // if (k!=this.json.data.group.column){
  810. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  811. // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
  812. // }
  813. // }.bind(this));
  814. subtrs.push(tr)
  815. }.bind(this));
  816. groupAreaNode.store("subtrs", subtrs);
  817. var _self = this;
  818. groupAreaNode.addEvent("click", function(){
  819. var subtrs = this.retrieve("subtrs");
  820. var iconNode = groupAreaNode.getFirst("div");
  821. if (subtrs[0]){
  822. if (subtrs[0].getStyle("display")=="none"){
  823. subtrs.each(function(subtr){ subtr.setStyle("display", "table-row"); });
  824. if( iconNode ) {
  825. iconNode.setStyle("background", "url(" + "../x_component_process_StatementDesigner/$View/default/icon/down.png) center center no-repeat");
  826. }else{
  827. this.setStyles( _self.json.data.viewStyles["groupExpandNode"] )
  828. }
  829. }else{
  830. subtrs.each(function(subtr){ subtr.setStyle("display", "none"); });
  831. if( iconNode ) {
  832. iconNode.setStyle("background", "url(" + "../x_component_process_StatementDesigner/$View/default/icon/right.png) center center no-repeat");
  833. }else{
  834. this.setStyles( _self.json.data.viewStyles["groupCollapseNode"] )
  835. }
  836. }
  837. }
  838. _self.setContentHeight();
  839. });
  840. }.bind(this));
  841. this.setContentColumnWidth();
  842. this.setContentHeight();
  843. }else if(this.json.data.noDataText){
  844. var noDataTextNodeStyle = this.css.noDataTextNode;
  845. if( this.json.data.viewStyles ){
  846. if( this.json.data.viewStyles["noDataTextNode"] ){
  847. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  848. }else{
  849. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  850. }
  851. }
  852. this.noDataTextNode = new Element( "div", {
  853. "styles": noDataTextNodeStyle,
  854. "text" : this.json.data.noDataText
  855. }).inject( this.viewContentBodyNode );
  856. }
  857. }else{
  858. if (json.data.grid.length){
  859. json.data.grid.each(function(line, idx){
  860. var tr = new Element("tr", {
  861. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  862. }).inject(this.viewContentTableNode);
  863. //this.createViewCheckboxTd( tr );
  864. Object.each(entries, function(c, k){
  865. var d = line.data[k];
  866. if (d!=undefined){
  867. var td = new Element("td", {
  868. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  869. }).inject(tr);
  870. //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  871. if (c.isHtml){
  872. td.set("html", d);
  873. }else{
  874. td.set("text", d);
  875. }
  876. //td.set("text", d);
  877. }
  878. }.bind(this));
  879. // Object.each(line.data, function(d, k){
  880. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  881. // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  882. // }.bind(this));
  883. }.bind(this));
  884. this.setContentColumnWidth();
  885. this.setContentHeight();
  886. }else if(this.json.data.noDataText){
  887. var noDataTextNodeStyle = this.css.noDataTextNode;
  888. if( this.json.data.viewStyles ){
  889. if( this.json.data.viewStyles["noDataTextNode"] ){
  890. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  891. }else{
  892. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  893. }
  894. }
  895. this.noDataTextNode = new Element( "div", {
  896. "styles": noDataTextNodeStyle,
  897. "text" : this.json.data.noDataText
  898. }).inject( this.viewContentBodyNode );
  899. }
  900. }
  901. }.bind(this));
  902. }.bind(this));
  903. }
  904. },
  905. addColumn: function(){
  906. debugger;
  907. MWF.require("MWF.widget.UUID", function(){
  908. var id = (new MWF.widget.UUID).id;
  909. var json = {
  910. "id": id,
  911. "column": id,
  912. "displayName": this.designer.lp.unnamed,
  913. "orderType": "original"
  914. };
  915. if (!this.json.data.selectList) this.json.data.selectList = [];
  916. this.json.data.selectList.push(json);
  917. var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this);
  918. this.items.push(column);
  919. column.selected();
  920. if (this.viewContentTableNode){
  921. var trs = this.viewContentTableNode.getElements("tr");
  922. trs.each(function(tr){
  923. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  924. }.bind(this));
  925. //this.setContentColumnWidth();
  926. }
  927. this.setViewWidth();
  928. this.addColumnNode.scrollIntoView(true);
  929. }.bind(this));
  930. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  931. },
  932. setContentHeight: function(){
  933. var size = this.areaNode.getSize();
  934. var titleSize = this.viewTitleNode.getSize();
  935. var actionbarSize = this.actionbarNode ? this.actionbarNode.getSize() : {x:0, y:0};
  936. var pagingSize = this.pagingNode ? this.pagingNode.getSize() : {x:0, y:0};
  937. var height = size.y-titleSize.y-actionbarSize.y-pagingSize.y-4;
  938. this.viewContentScrollNode.setStyle("height", height);
  939. var contentSize = this.viewContentBodyNode.getSize();
  940. if (height<contentSize.y) height = contentSize.y+10;
  941. this.viewContentNode.setStyle("height", height);
  942. this.contentLeftNode.setStyle("height", height);
  943. this.contentRightNode.setStyle("height", height);
  944. //this.viewContentBodyNode.setStyle("min-height", height);
  945. },
  946. loadViewColumns: function(){
  947. // for (var i=0; i<10; i++){
  948. if (this.json.data.selectList) {
  949. this.json.data.selectList.each(function (json) {
  950. this.items.push(new MWF.xApplication.query.StatementDesigner.View.Column(json, this));
  951. }.bind(this));
  952. }
  953. // }
  954. },
  955. showActionbar : function( noSetHeight ){
  956. this.actionbarNode.show();
  957. if( !this.json.data.actionbarList )this.json.data.actionbarList = [];
  958. if( !this.actionbarList || this.actionbarList.length == 0 ){
  959. if( this.json.data.actionbarList.length ){
  960. this.json.data.actionbarList.each( function(json){
  961. this.actionbarList.push( new MWF.xApplication.query.StatementDesigner.View.Actionbar( json, this.json.data.actionbarList, this) )
  962. }.bind(this));
  963. }else{
  964. this.actionbarList.push( new MWF.xApplication.query.StatementDesigner.View.Actionbar( null, this.json.data.actionbarList, this) )
  965. }
  966. }
  967. if( !noSetHeight )this.setContentHeight();
  968. },
  969. loadPaging: function( noSetHeight ){
  970. this.pagingNode = new Element("div#pagingNode", {"styles": this.css.pagingNode}).inject(this.areaNode);
  971. this.pagingList = [];
  972. if( !this.json.data.pagingList )this.json.data.pagingList = [];
  973. if( !this.pagingList || this.pagingList.length == 0 ){
  974. if( this.json.data.pagingList.length ){
  975. this.json.data.pagingList.each( function(json){
  976. this.pagingList.push( new MWF.xApplication.query.StatementDesigner.View.Paging( json, this.json.data.pagingList, this) )
  977. }.bind(this));
  978. }else{
  979. this.pagingList.push( new MWF.xApplication.query.StatementDesigner.View.Paging( null, this.json.data.pagingList, this) )
  980. }
  981. }
  982. // if( !noSetHeight )this.setContentHeight();
  983. },
  984. setViewWidth: function(){
  985. if( !this.viewAreaNode )return;
  986. this.viewAreaNode.setStyle("width", "auto");
  987. this.viewTitleNode.setStyle("width", "auto");
  988. var s1 = this.viewTitleTableNode.getSize();
  989. var s2 = this.refreshNode.getSize();
  990. var s3 = this.addColumnNode.getSize();
  991. var width = s1.x+s2.x+s2.x;
  992. var size = this.areaNode.getSize();
  993. if (width>size.x){
  994. this.viewTitleNode.setStyle("width", ""+(width-2)+"px");
  995. this.viewAreaNode.setStyle("width", ""+(width-2)+"px");
  996. }else{
  997. this.viewTitleNode.setStyle("width", ""+(size.x-2)+"px");
  998. this.viewAreaNode.setStyle("width", ""+(size.x-2)+"px");
  999. }
  1000. this.setContentColumnWidth();
  1001. this.setContentHeight();
  1002. },
  1003. _setEditStyle: function(name, input, oldValue){
  1004. if( name=="data.actionbarHidden" ){
  1005. if( this.json.data.actionbarHidden ){
  1006. this.hideActionbar()
  1007. }else{
  1008. this.showActionbar()
  1009. }
  1010. }
  1011. if( name=="data.selectAllEnable" ){
  1012. if( this.json.data.selectAllEnable ){
  1013. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","table-cell");
  1014. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","table-cell");
  1015. }else{
  1016. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","none");
  1017. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","none");
  1018. }
  1019. }
  1020. if (name=="data.viewStyleType"){
  1021. var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null;
  1022. var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null;
  1023. this.loadTemplateStyles( file, extendFile, function( templateStyles ){
  1024. this.templateStyles = templateStyles;
  1025. var oldFile, oldExtendFile;
  1026. if( oldValue && this.stylesList[oldValue] ){
  1027. oldFile = this.stylesList[oldValue].file;
  1028. oldExtendFile = this.stylesList[oldValue].extendFile;
  1029. }
  1030. this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){
  1031. this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null;
  1032. if (oldTemplateStyles["view"]) this.clearTemplateStyles(oldTemplateStyles["view"]);
  1033. if (this.templateStyles["view"]) this.setTemplateStyles(this.templateStyles["view"]);
  1034. this.setAllStyles();
  1035. this.actionbarList.each( function (module) {
  1036. if (oldTemplateStyles["actionbar"]){
  1037. module.clearTemplateStyles(oldTemplateStyles["actionbar"]);
  1038. }
  1039. module.setStyleTemplate();
  1040. module.setAllStyles();
  1041. })
  1042. this.pagingList.each( function (module) {
  1043. if (oldTemplateStyles["paging"]){
  1044. module.clearTemplateStyles(oldTemplateStyles["paging"]);
  1045. }
  1046. module.setStyleTemplate();
  1047. module.setAllStyles();
  1048. });
  1049. // this.moduleList.each(function(module){
  1050. // if (oldTemplateStyles[module.moduleName]){
  1051. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  1052. // }
  1053. // module.setStyleTemplate();
  1054. // module.setAllStyles();
  1055. // }.bind(this));
  1056. }.bind(this))
  1057. }.bind(this))
  1058. }
  1059. if (name=="data.viewStyles"){
  1060. this.setCustomStyles();
  1061. }
  1062. },
  1063. loadTemplateStyle : function( callback ){
  1064. this.loadStylesList(function(){
  1065. var oldStyleValue = "";
  1066. if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType="default";
  1067. this.loadTemplateStyles( this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
  1068. function( templateStyles ){
  1069. this.templateStyles = templateStyles;
  1070. if( !this.json.data.viewStyleType )this.json.data.viewStyleType = "default";
  1071. if ( this.templateStyles && this.templateStyles["view"]){
  1072. var viewStyles = Object.clone(this.templateStyles["view"]);
  1073. if( viewStyles.contentGroupTd )delete viewStyles.contentGroupTd;
  1074. if( viewStyles.groupCollapseNode )delete viewStyles.groupCollapseNode;
  1075. if( viewStyles.groupExpandNode )delete viewStyles.groupExpandNode;
  1076. if(!this.json.data.viewStyles){
  1077. this.json.data.viewStyles = viewStyles;
  1078. }else{
  1079. this.setTemplateStyles( viewStyles );
  1080. }
  1081. }
  1082. this.setCustomStyles();
  1083. if(callback)callback();
  1084. }.bind(this)
  1085. );
  1086. }.bind(this));
  1087. },
  1088. clearTemplateStyles: function(styles){
  1089. if (styles){
  1090. if (styles.container) this.removeStyles(styles.container, "container");
  1091. if (styles.table) this.removeStyles(styles.table, "table");
  1092. if (styles.titleTr) this.removeStyles(styles.titleTr, "titleTr");
  1093. if (styles.titleTd) this.removeStyles(styles.titleTd, "titleTd");
  1094. if (styles.contentTr) this.removeStyles(styles.contentTr, "contentTr");
  1095. if (styles.contentSelectedTr) this.removeStyles(styles.contentSelectedTr, "contentSelectedTr");
  1096. if (styles.contentTd) this.removeStyles(styles.contentTd, "contentTd");
  1097. // if (styles.contentGroupTd) this.removeStyles(styles.contentGroupTd, "contentGroupTd");
  1098. // if (styles.groupCollapseNode) this.removeStyles(styles.groupCollapseNode, "groupCollapseNode");
  1099. // if (styles.groupExpandNode) this.removeStyles(styles.groupExpandNode, "groupExpandNode");
  1100. if (styles.checkboxNode) this.removeStyles(styles.checkboxNode, "checkboxNode");
  1101. if (styles.checkedCheckboxNode) this.removeStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1102. if (styles.radioNode) this.removeStyles(styles.radioNode, "radioNode");
  1103. if (styles.checkedRadioNode) this.removeStyles(styles.checkedRadioNode, "checkedRadioNode");
  1104. if (styles.tableProperties) this.removeStyles(styles.tableProperties, "tableProperties");
  1105. }
  1106. },
  1107. setTemplateStyles: function(styles){
  1108. if (styles.container) this.copyStyles(styles.container, "container");
  1109. if (styles.table) this.copyStyles(styles.table, "table");
  1110. if (styles.titleTr) this.copyStyles(styles.titleTr, "titleTr");
  1111. if (styles.titleTd) this.copyStyles(styles.titleTd, "titleTd");
  1112. if (styles.contentTr) this.copyStyles(styles.contentTr, "contentTr");
  1113. if (styles.contentSelectedTr) this.copyStyles(styles.contentSelectedTr, "contentSelectedTr");
  1114. if (styles.contentTd) this.copyStyles(styles.contentTd, "contentTd");
  1115. // if (styles.contentGroupTd) this.copyStyles(styles.contentGroupTd, "contentGroupTd");
  1116. // if (styles.groupCollapseNode) this.copyStyles(styles.groupCollapseNode, "groupCollapseNode");
  1117. // if (styles.groupExpandNode) this.copyStyles(styles.groupExpandNode, "groupExpandNode");
  1118. if (styles.checkboxNode) this.copyStyles(styles.checkboxNode, "checkboxNode");
  1119. if (styles.checkedCheckboxNode) this.copyStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1120. if (styles.radioNode) this.copyStyles(styles.radioNode, "radioNode");
  1121. if (styles.checkedRadioNode) this.copyStyles(styles.checkedRadioNode, "checkedRadioNode");
  1122. if (styles.tableProperties) this.copyStyles(styles.tableProperties, "tableProperties");
  1123. },
  1124. removeStyles: function(from, to){
  1125. if (this.json.data.viewStyles[to]){
  1126. Object.each(from, function(style, key){
  1127. if (this.json.data.viewStyles[to][key] && this.json.data.viewStyles[to][key]==style){
  1128. delete this.json.data.viewStyles[to][key];
  1129. }
  1130. }.bind(this));
  1131. }
  1132. },
  1133. copyStyles: function(from, to){
  1134. if (!this.json.data.viewStyles[to]) this.json.data.viewStyles[to] = {};
  1135. Object.each(from, function(style, key){
  1136. if (!this.json.data.viewStyles[to][key]) this.json.data.viewStyles[to][key] = style;
  1137. }.bind(this));
  1138. }
  1139. // preview: function(){
  1140. // if( this.isNewView ){
  1141. // this.designer.notice( this.designer.lp.saveViewNotice, "error" );
  1142. // return;
  1143. // }
  1144. // this.saveSilence( function () {
  1145. // var url = "../x_desktop/app.html?app=query.Query&status=";
  1146. // url += JSON.stringify({
  1147. // id : this.data.application,
  1148. // viewId : this.data.id
  1149. // });
  1150. // window.open(o2.filterUrl(url),"_blank");
  1151. // }.bind(this));
  1152. // },
  1153. // saveSilence: function(callback){
  1154. // if (!this.data.name){
  1155. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1156. // return false;
  1157. // }
  1158. //
  1159. // this.designer.actions.saveView(this.data, function(json){
  1160. // this.data.id = json.data.id;
  1161. // this.isNewView = false;
  1162. // //this.page.textNode.set("text", this.data.name);
  1163. // if (this.lisNode) {
  1164. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1165. // }
  1166. // if (callback) callback();
  1167. // }.bind(this));
  1168. // },
  1169. // save: function(callback){
  1170. // //if (this.designer.tab.showPage==this.page){
  1171. // if (!this.data.name){
  1172. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1173. // return false;
  1174. // }
  1175. // //}
  1176. // this.designer.actions.saveView(this.data, function(json){
  1177. // this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1178. // this.isNewView = false;
  1179. // this.data.id = json.data.id;
  1180. // //this.page.textNode.set("text", this.data.name);
  1181. // if (this.lisNode) {
  1182. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1183. // }
  1184. // if (callback) callback();
  1185. // }.bind(this));
  1186. // },
  1187. // saveAs: function(){
  1188. // var form = new MWF.xApplication.query.StatementDesigner.View.NewNameForm(this, {
  1189. // name : this.data.name + "_" + MWF.xApplication.query.StatementDesigner.LP.copy,
  1190. // query : this.data.query || this.data.application,
  1191. // queryName : this.data.queryName || this.data.applicationName
  1192. // }, {
  1193. // onSave : function( data, callback ){
  1194. // this._saveAs( data, callback );
  1195. // }.bind(this)
  1196. // }, {
  1197. // app: this.designer
  1198. // });
  1199. // form.edit()
  1200. // },
  1201. // _saveAs : function( data , callback){
  1202. // var _self = this;
  1203. //
  1204. // var d = this.cloneObject( this.data );
  1205. //
  1206. // d.isNewView = true;
  1207. // d.id = this.designer.actions.getUUID();
  1208. // d.name = data.name;
  1209. // d.alias = "";
  1210. // d.query = data.query;
  1211. // d.queryName = data.queryName;
  1212. // d.application = data.query;
  1213. // d.applicationName = data.queryName;
  1214. // d.pid = d.id + d.id;
  1215. //
  1216. // delete d[this.data.id+"viewFilterType"];
  1217. // d[d.id+"viewFilterType"]="custom";
  1218. //
  1219. // d.data.selectList.each( function( entry ){
  1220. // entry.id = (new MWF.widget.UUID).id;
  1221. // }.bind(this));
  1222. //
  1223. // this.designer.actions.saveView(d, function(json){
  1224. // this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  1225. // if (callback) callback();
  1226. // }.bind(this));
  1227. // }
  1228. });
  1229. MWF.xApplication.query.StatementDesigner.View.Column = new Class({
  1230. Extends: MWF.xApplication.query.ViewDesigner.View.Column,
  1231. initialize: function(json, view, next){
  1232. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/column.html";
  1233. this.view = view;
  1234. this.json = json;
  1235. this.next = next;
  1236. this.css = this.view.css;
  1237. this.content = this.view.viewTitleTrNode;
  1238. this.domListNode = this.view.domListNode;
  1239. this.load();
  1240. },
  1241. selected: function(){
  1242. if (this.view.statement.currentSelectedModule){
  1243. if (this.view.statement.currentSelectedModule==this){
  1244. return true;
  1245. }else{
  1246. this.view.statement.currentSelectedModule.unSelected();
  1247. }
  1248. }
  1249. this.view.domListNode.show();
  1250. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  1251. this.listNode.setStyles(this.css.cloumnListNode_selected);
  1252. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1253. new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1254. this.view.statement.currentSelectedModule = this;
  1255. this.isSelected = true;
  1256. this._showActions();
  1257. this.showProperty();
  1258. },
  1259. unSelected: function(){
  1260. this.view.statement.currentSelectedModule = null;
  1261. //this.node.setStyles(this.css.viewTitleColumnNode);
  1262. if (this.isError){
  1263. this.node.setStyles(this.css.viewTitleColumnNode_error)
  1264. }else{
  1265. this.node.setStyles(this.css.viewTitleColumnNode)
  1266. }
  1267. this.listNode.setStyles(this.css.cloumnListNode);
  1268. this.isSelected = false;
  1269. this._hideActions();
  1270. this.hideProperty();
  1271. }
  1272. });
  1273. MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
  1274. Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
  1275. initialize: function(json, jsonList, view, options){
  1276. this.setOptions( options );
  1277. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/actionbar.html";
  1278. this.path = "../x_component_query_ViewDesigner/$View/";
  1279. this.imagePath_default = "../x_component_query_ViewDesigner/$View/";
  1280. this.imagePath_custom = "../x_component_process_FormDesigner/Module/Actionbar/";
  1281. this.cssPath = "../x_component_query_ViewDesigner/$View/"+this.options.style+"/actionbar.wcss";
  1282. this.view = view;
  1283. this.json = json;
  1284. this.jsonList = jsonList;
  1285. this.css = this.view.css;
  1286. this.container = this.view.actionbarNode;
  1287. this.moduleName = "actionbar";
  1288. this.load();
  1289. },
  1290. getJsonPath : function(){
  1291. return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
  1292. },
  1293. selected: function(){
  1294. if (this.view.statement.currentSelectedModule){
  1295. if (this.view.statement.currentSelectedModule==this){
  1296. return true;
  1297. }else{
  1298. this.view.statement.currentSelectedModule.unSelected();
  1299. }
  1300. }
  1301. this.view.domListNode.show();
  1302. this.node.setStyles(this.css.toolbarWarpNode_selected);
  1303. //this.listNode.setStyles(this.css.cloumnListNode_selected);
  1304. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1305. //new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1306. this.view.statement.currentSelectedModule = this;
  1307. this.isSelected = true;
  1308. //this._showActions();
  1309. this.showProperty();
  1310. },
  1311. unSelected: function(){
  1312. this.view.statement.currentSelectedModule = null;
  1313. this.node.setStyles(this.css.toolbarWarpNode);
  1314. //this.listNode.setStyles(this.css.cloumnListNode);
  1315. this.isSelected = false;
  1316. //this._hideActions();
  1317. this.hideProperty();
  1318. },
  1319. });
  1320. MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
  1321. Extends: MWF.xApplication.query.ViewDesigner.View.Paging,
  1322. selected: function(){
  1323. if (this.view.statement.currentSelectedModule){
  1324. if (this.view.statement.currentSelectedModule==this){
  1325. return true;
  1326. }else{
  1327. this.view.statement.currentSelectedModule.unSelected();
  1328. }
  1329. }
  1330. this.view.domListNode.show();
  1331. this.node.setStyles(this.css.pagingWarpNode_selected);
  1332. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1333. this.view.statement.currentSelectedModule = this;
  1334. this.isSelected = true;
  1335. this.showProperty();
  1336. },
  1337. unSelected: function(){
  1338. this.view.statement.currentSelectedModule = null;
  1339. this.node.setStyles(this.css.pagingWarpNode);
  1340. this.isSelected = false;
  1341. this.hideProperty();
  1342. }
  1343. });