Statement.js 69 KB

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