Statement.js 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552
  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. var json = this.jsonEditor.editor.getValue();
  521. var o = JSON.parse(json);
  522. o2.Actions.get("x_query_assemble_designer").executeStatement(this.json.id, 1, 50 , o, function(json){
  523. o2.require("o2.widget.JsonParse", function(){
  524. this.runResultNode.empty();
  525. var jsonResult = new o2.widget.JsonParse(json.data, this.runResultNode);
  526. jsonResult.load();
  527. }.bind(this));
  528. this.runMask.hide();
  529. }.bind(this), function(xhr, text, error){
  530. debugger;
  531. if (this.runMask) this.runMask.hide();
  532. var errorText = error;
  533. if (xhr){
  534. var json = JSON.decode(xhr.responseText);
  535. if (json){
  536. errorText = json.message.trim() || "request json error";
  537. }else{
  538. errorText = "request json error: "+xhr.responseText;
  539. }
  540. }
  541. errorText = errorText.replace(/\</g, "&lt;");
  542. errorText = errorText.replace(/\</g, "&gt;");
  543. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  544. }.bind(this))
  545. }.bind(this));
  546. },
  547. save: function(callback){
  548. debugger;
  549. if (!this.data.name){
  550. this.designer.notice(this.designer.lp.inputStatementName, "error");
  551. return false;
  552. }
  553. if( typeOf(this.viewJson) === "object" ){
  554. this.data.view = JSON.stringify(this.viewJson);
  555. }
  556. //if( !this.data.tableType ){
  557. // this.data.tableType = "dynamic";
  558. //}
  559. if (this.editor) this.data.data = this.editor.editor.getValue();
  560. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  561. this.designer.actions.saveStatement(this.data, function(json){
  562. this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  563. this.data.id = json.data.id;
  564. if (this.lisNode) {
  565. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  566. }
  567. if (callback) callback();
  568. }.bind(this));
  569. },
  570. _setEditStyle: function(){},
  571. saveSilence: function(callback){
  572. if (!this.data.name){
  573. this.designer.notice(this.designer.lp.inputStatementName, "error");
  574. return false;
  575. }
  576. if( typeOf(this.viewJson) === "object" ){
  577. this.data.view = JSON.stringify(this.viewJson);
  578. }
  579. if (this.editor) this.data.data = this.editor.editor.getValue();
  580. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  581. this.designer.actions.saveStatement(this.data, function(json){
  582. //this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  583. this.data.id = json.data.id;
  584. if (this.lisNode) {
  585. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  586. }
  587. if (callback) callback();
  588. }.bind(this));
  589. },
  590. loadView : function( callback ){
  591. this.setViewSize();
  592. this.designer.addEvent("resize", this.setViewSize.bind(this));
  593. if( !this.data.view ){
  594. this.viewJson = {};
  595. }else{
  596. this.viewJson = JSON.parse(this.data.view)
  597. }
  598. this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.viewJson, {});
  599. this.view.load( function () {
  600. this.view.setContentHeight();
  601. }.bind(this));
  602. },
  603. setViewSize: function(){
  604. debugger;
  605. var size = this.areaNode.getSize();
  606. var designerSize = this.designerArea.getComputedSize();
  607. var y = size.y-designerSize.totalHeight;
  608. var mTop = this.viewArea.getStyle("margin-top").toInt();
  609. var mBottom = this.viewArea.getStyle("margin-bottom").toInt();
  610. var pTop = this.viewArea.getStyle("padding-top").toInt();
  611. var pBottom = this.viewArea.getStyle("padding-bottom").toInt();
  612. y = y-mTop-mBottom-pTop-pBottom-1;
  613. var tabSize = this.tabNode.getComputedSize();
  614. y = y - tabSize.totalHeight;
  615. this.viewArea.setStyle("height", ""+y+"px");
  616. // var titleSize = this.runTitleNode.getComputedSize();
  617. // y = y - titleSize.totalHeight;
  618. // this.runContentNode.setStyle("height", ""+y+"px");
  619. },
  620. preview: function(){
  621. if( this.isNewStatement ){
  622. this.designer.notice( this.designer.lp.saveStatementNotice, "error" );
  623. return;
  624. }
  625. if( this.data.type !== "select" ){
  626. this.designer.notice( this.designer.lp.previewNotSelectStatementNotice, "error" );
  627. return;
  628. }
  629. if( !this.data.view ){
  630. this.designer.notice( this.designer.lp.noViewNotice, "error" );
  631. }
  632. this.saveSilence( function () {
  633. var url = "../x_desktop/app.html?app=query.Query&status=";
  634. url += JSON.stringify({
  635. id : this.data.application,
  636. statementId : this.data.id
  637. });
  638. window.open(o2.filterUrl(url),"_blank");
  639. }.bind(this));
  640. }
  641. });
  642. MWF.xApplication.query.StatementDesigner.View = new Class({
  643. Extends: MWF.xApplication.query.ViewDesigner.View,
  644. Implements: [Options, Events],
  645. options: {
  646. "style": "default",
  647. "isView": false,
  648. "showTab": true,
  649. "propertyPath": "../x_component_query_StatementDesigner/$Statement/view.html"
  650. },
  651. initialize: function(designer, statement, data, options){
  652. this.setOptions(options);
  653. this.path = "../x_component_query_ViewDesigner/$View/";
  654. this.cssPath = "../x_component_query_ViewDesigner/$View/"+this.options.style+"/css.wcss";
  655. this._loadCss();
  656. this.statement = statement;
  657. this.designer = designer;
  658. this.data = data;
  659. // if (!this.data.data) this.data.data = {};
  660. this.parseData();
  661. this.node = this.statement.viewArea;
  662. //this.tab = this.designer.tab;
  663. this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto" }});
  664. this.areaNode.setStyles(this.css.areaNode);
  665. //MWF.require("MWF.widget.ScrollBar", function(){
  666. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  667. //}.bind(this));
  668. // this.propertyListNode = this.designer.propertyDomArea;
  669. //this.propertyNode = this.designer.propertyContentArea;
  670. // if(this.designer.application) this.data.applicationName = this.designer.application.name;
  671. // if(this.designer.application) this.data.application = this.designer.application.id;
  672. // this.isNewView = (this.data.name) ? false : true;
  673. this.items = [];
  674. this.view = this;
  675. // this.autoSave();
  676. // this.designer.addEvent("queryClose", function(){
  677. // if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  678. // }.bind(this));
  679. },
  680. load : function( callback ){
  681. this.setAreaNodeSize();
  682. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  683. this.areaNode.inject(this.node);
  684. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  685. this.loadTemplateStyle( function () {
  686. this.loadActionbar();
  687. this.loadView();
  688. this.loadPaging();
  689. // this.selected();
  690. this.setEvent();
  691. //if (this.options.showTab) this.page.showTabIm();
  692. this.setViewWidth();
  693. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  694. if(callback)callback();
  695. }.bind(this))
  696. },
  697. parseData: function(){
  698. this.json = this.data;
  699. if( !this.json.id ){
  700. this.json.id = (new o2.widget.UUID).id;
  701. }
  702. if( !this.json.data || !this.json.data.events ){
  703. var url = "../x_component_query_StatementDesigner/$Statement/view.json";
  704. MWF.getJSON(url, {
  705. "onSuccess": function(obj){
  706. if(!this.json.data)this.json.data = obj.data;
  707. if(!this.json.data.events)this.json.data.events = obj.data.events;
  708. }.bind(this),
  709. "onerror": function(text){
  710. this.notice(text, "error");
  711. }.bind(this),
  712. "onRequestFailure": function(xhr){
  713. this.notice(xhr.responseText, "error");
  714. }.bind(this)
  715. },false);
  716. }
  717. },
  718. setEvent: function(){
  719. this.areaNode.addEvents({
  720. "click": function(e){ this.selected(); e.stopPropagation(); }.bind(this),
  721. "mouseover": function(){ if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode_over)}.bind(this),
  722. "mouseout": function(){if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode)}.bind(this)
  723. });
  724. this.refreshNode.addEvent("click", function(e){
  725. this.loadViewData();
  726. e.stopPropagation();
  727. }.bind(this));
  728. this.addColumnNode.addEvent("click", function(e){
  729. this.addColumn();
  730. e.stopPropagation();
  731. }.bind(this));
  732. },
  733. selected: function(){
  734. debugger;
  735. if (this.statement.currentSelectedModule){
  736. if (this.statement.currentSelectedModule==this){
  737. return true;
  738. }else{
  739. this.statement.currentSelectedModule.unSelected();
  740. }
  741. }
  742. this.areaNode.setStyles(this.css.areaNode_selected);
  743. this.statement.currentSelectedModule = this;
  744. this.domListNode.show();
  745. this.isSelected = true;
  746. this.showProperty();
  747. },
  748. unSelected: function(){
  749. this.statement.currentSelectedModule = null;
  750. this.isSelected = false;
  751. this.areaNode.setStyles(this.css.areaNode);
  752. this.hideProperty();
  753. },
  754. showProperty: function(){
  755. if (!this.property){
  756. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  757. "path": this.options.propertyPath,
  758. "onPostLoad": function(){
  759. this.property.show();
  760. }.bind(this)
  761. });
  762. this.property.load();
  763. }else{
  764. this.property.show();
  765. }
  766. },
  767. hideProperty: function(){
  768. if (this.property) this.property.hide();
  769. },
  770. loadViewData: function(){
  771. if (this.data.id){
  772. this.saveSilence(function(){
  773. this.viewContentBodyNode.empty();
  774. this.viewContentTableNode = new Element("table", {
  775. "styles": this.css.viewContentTableNode,
  776. "border": "0px",
  777. "cellPadding": "0",
  778. "cellSpacing": "0"
  779. }).inject(this.viewContentBodyNode);
  780. this.designer.actions.loadView(this.data.id, null,function(json){
  781. var entries = {};
  782. json.data.selectList.each(function(entry){entries[entry.column] = entry;}.bind(this));
  783. if (this.json.data.group.column){
  784. if (json.data.groupGrid.length){
  785. var groupColumn = null;
  786. for (var c = 0; c<json.data.selectList.length; c++){
  787. if (json.data.selectList[c].column === json.data.group.column){
  788. groupColumn = json.data.selectList[c];
  789. break;
  790. }
  791. }
  792. json.data.groupGrid.each(function(line, idx){
  793. var groupTr = new Element("tr", {
  794. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode,
  795. "data-is-group" : "yes"
  796. }).inject(this.viewContentTableNode);
  797. var colSpan = this.items.length ;
  798. var td = new Element("td", {
  799. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentGroupTd"] : this.css.viewContentGroupTdNode,
  800. "colSpan": colSpan
  801. }).inject(groupTr);
  802. var groupAreaNode;
  803. if( this.json.data.viewStyles ){
  804. groupAreaNode = new Element("div", {"styles": this.json.data.viewStyles["groupCollapseNode"]}).inject(td);
  805. groupAreaNode.set("text", line.group);
  806. }else{
  807. groupAreaNode = new Element("div", {"styles": this.css.viewContentTdGroupNode}).inject(td);
  808. var groupIconNode = new Element("div", {"styles": this.css.viewContentTdGroupIconNode}).inject(groupAreaNode);
  809. var groupTextNode = new Element("div", {"styles": this.css.viewContentTdGroupTextNode}).inject(groupAreaNode);
  810. if (groupColumn){
  811. //groupTextNode.set("text", (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": line.group, "gridData": json.data.groupGrid, "data": json.data, "entry": line}) : line.group);
  812. groupTextNode.set("text", line.group);
  813. }else{
  814. groupTextNode.set("text", line.group);
  815. }
  816. }
  817. var subtrs = [];
  818. line.list.each(function(entry){
  819. var tr = new Element("tr", {
  820. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  821. }).inject(this.viewContentTableNode);
  822. tr.setStyle("display", "none");
  823. //this.createViewCheckboxTd( tr );
  824. var td = new Element("td", {
  825. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  826. }).inject(tr);
  827. Object.each(entries, function(c, k){
  828. var d = entry.data[k];
  829. if (d!=undefined){
  830. if (k!=this.json.data.group.column){
  831. var td = new Element("td", {
  832. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  833. }).inject(tr);
  834. //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
  835. if (c.isHtml){
  836. td.set("html", d);
  837. }else{
  838. td.set("text", d);
  839. }
  840. }
  841. }
  842. }.bind(this));
  843. // Object.each(entry.data, function(d, k){
  844. // if (k!=this.json.data.group.column){
  845. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  846. // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
  847. // }
  848. // }.bind(this));
  849. subtrs.push(tr)
  850. }.bind(this));
  851. groupAreaNode.store("subtrs", subtrs);
  852. var _self = this;
  853. groupAreaNode.addEvent("click", function(){
  854. var subtrs = this.retrieve("subtrs");
  855. var iconNode = groupAreaNode.getFirst("div");
  856. if (subtrs[0]){
  857. if (subtrs[0].getStyle("display")=="none"){
  858. subtrs.each(function(subtr){ subtr.setStyle("display", "table-row"); });
  859. if( iconNode ) {
  860. iconNode.setStyle("background", "url(" + "../x_component_process_StatementDesigner/$View/default/icon/down.png) center center no-repeat");
  861. }else{
  862. this.setStyles( _self.json.data.viewStyles["groupExpandNode"] )
  863. }
  864. }else{
  865. subtrs.each(function(subtr){ subtr.setStyle("display", "none"); });
  866. if( iconNode ) {
  867. iconNode.setStyle("background", "url(" + "../x_component_process_StatementDesigner/$View/default/icon/right.png) center center no-repeat");
  868. }else{
  869. this.setStyles( _self.json.data.viewStyles["groupCollapseNode"] )
  870. }
  871. }
  872. }
  873. _self.setContentHeight();
  874. });
  875. }.bind(this));
  876. this.setContentColumnWidth();
  877. this.setContentHeight();
  878. }else if(this.json.data.noDataText){
  879. var noDataTextNodeStyle = this.css.noDataTextNode;
  880. if( this.json.data.viewStyles ){
  881. if( this.json.data.viewStyles["noDataTextNode"] ){
  882. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  883. }else{
  884. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  885. }
  886. }
  887. this.noDataTextNode = new Element( "div", {
  888. "styles": noDataTextNodeStyle,
  889. "text" : this.json.data.noDataText
  890. }).inject( this.viewContentBodyNode );
  891. }
  892. }else{
  893. if (json.data.grid.length){
  894. json.data.grid.each(function(line, idx){
  895. var tr = new Element("tr", {
  896. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  897. }).inject(this.viewContentTableNode);
  898. //this.createViewCheckboxTd( tr );
  899. Object.each(entries, function(c, k){
  900. var d = line.data[k];
  901. if (d!=undefined){
  902. var td = new Element("td", {
  903. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  904. }).inject(tr);
  905. //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  906. if (c.isHtml){
  907. td.set("html", d);
  908. }else{
  909. td.set("text", d);
  910. }
  911. //td.set("text", d);
  912. }
  913. }.bind(this));
  914. // Object.each(line.data, function(d, k){
  915. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  916. // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  917. // }.bind(this));
  918. }.bind(this));
  919. this.setContentColumnWidth();
  920. this.setContentHeight();
  921. }else if(this.json.data.noDataText){
  922. var noDataTextNodeStyle = this.css.noDataTextNode;
  923. if( this.json.data.viewStyles ){
  924. if( this.json.data.viewStyles["noDataTextNode"] ){
  925. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  926. }else{
  927. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  928. }
  929. }
  930. this.noDataTextNode = new Element( "div", {
  931. "styles": noDataTextNodeStyle,
  932. "text" : this.json.data.noDataText
  933. }).inject( this.viewContentBodyNode );
  934. }
  935. }
  936. }.bind(this));
  937. }.bind(this));
  938. }
  939. },
  940. addColumn: function(){
  941. debugger;
  942. MWF.require("MWF.widget.UUID", function(){
  943. var id = (new MWF.widget.UUID).id;
  944. var json = {
  945. "id": id,
  946. "column": id,
  947. "displayName": this.designer.lp.unnamed,
  948. "orderType": "original"
  949. };
  950. if (!this.json.data.selectList) this.json.data.selectList = [];
  951. this.json.data.selectList.push(json);
  952. var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this);
  953. this.items.push(column);
  954. column.selected();
  955. if (this.viewContentTableNode){
  956. var trs = this.viewContentTableNode.getElements("tr");
  957. trs.each(function(tr){
  958. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  959. }.bind(this));
  960. //this.setContentColumnWidth();
  961. }
  962. this.setViewWidth();
  963. this.addColumnNode.scrollIntoView(true);
  964. }.bind(this));
  965. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  966. },
  967. setContentHeight: function(){
  968. var size = this.areaNode.getSize();
  969. var titleSize = this.viewTitleNode.getSize();
  970. var actionbarSize = this.actionbarNode ? this.actionbarNode.getSize() : {x:0, y:0};
  971. var pagingSize = this.pagingNode ? this.pagingNode.getSize() : {x:0, y:0};
  972. var height = size.y-titleSize.y-actionbarSize.y-pagingSize.y-4;
  973. this.viewContentScrollNode.setStyle("height", height);
  974. var contentSize = this.viewContentBodyNode.getSize();
  975. if (height<contentSize.y) height = contentSize.y+10;
  976. this.viewContentNode.setStyle("height", height);
  977. this.contentLeftNode.setStyle("height", height);
  978. this.contentRightNode.setStyle("height", height);
  979. //this.viewContentBodyNode.setStyle("min-height", height);
  980. },
  981. loadViewColumns: function(){
  982. // for (var i=0; i<10; i++){
  983. if (this.json.data.selectList) {
  984. this.json.data.selectList.each(function (json) {
  985. this.items.push(new MWF.xApplication.query.StatementDesigner.View.Column(json, this));
  986. }.bind(this));
  987. }
  988. // }
  989. },
  990. showActionbar : function( noSetHeight ){
  991. this.actionbarNode.show();
  992. if( !this.json.data.actionbarList )this.json.data.actionbarList = [];
  993. if( !this.actionbarList || this.actionbarList.length == 0 ){
  994. if( this.json.data.actionbarList.length ){
  995. this.json.data.actionbarList.each( function(json){
  996. this.actionbarList.push( new MWF.xApplication.query.StatementDesigner.View.Actionbar( json, this.json.data.actionbarList, this) )
  997. }.bind(this));
  998. }else{
  999. this.actionbarList.push( new MWF.xApplication.query.StatementDesigner.View.Actionbar( null, this.json.data.actionbarList, this) )
  1000. }
  1001. }
  1002. if( !noSetHeight )this.setContentHeight();
  1003. },
  1004. loadPaging: function( noSetHeight ){
  1005. this.pagingNode = new Element("div#pagingNode", {"styles": this.css.pagingNode}).inject(this.areaNode);
  1006. this.pagingList = [];
  1007. if( !this.json.data.pagingList )this.json.data.pagingList = [];
  1008. if( !this.pagingList || this.pagingList.length == 0 ){
  1009. if( this.json.data.pagingList.length ){
  1010. this.json.data.pagingList.each( function(json){
  1011. this.pagingList.push( new MWF.xApplication.query.StatementDesigner.View.Paging( json, this.json.data.pagingList, this) )
  1012. }.bind(this));
  1013. }else{
  1014. this.pagingList.push( new MWF.xApplication.query.StatementDesigner.View.Paging( null, this.json.data.pagingList, this) )
  1015. }
  1016. }
  1017. // if( !noSetHeight )this.setContentHeight();
  1018. },
  1019. setViewWidth: function(){
  1020. if( !this.viewAreaNode )return;
  1021. this.viewAreaNode.setStyle("width", "auto");
  1022. this.viewTitleNode.setStyle("width", "auto");
  1023. var s1 = this.viewTitleTableNode.getSize();
  1024. var s2 = this.refreshNode.getSize();
  1025. var s3 = this.addColumnNode.getSize();
  1026. var width = s1.x+s2.x+s2.x;
  1027. var size = this.areaNode.getSize();
  1028. if (width>size.x){
  1029. this.viewTitleNode.setStyle("width", ""+(width-2)+"px");
  1030. this.viewAreaNode.setStyle("width", ""+(width-2)+"px");
  1031. }else{
  1032. this.viewTitleNode.setStyle("width", ""+(size.x-2)+"px");
  1033. this.viewAreaNode.setStyle("width", ""+(size.x-2)+"px");
  1034. }
  1035. this.setContentColumnWidth();
  1036. this.setContentHeight();
  1037. },
  1038. _setEditStyle: function(name, input, oldValue){
  1039. if( name=="data.actionbarHidden" ){
  1040. if( this.json.data.actionbarHidden ){
  1041. this.hideActionbar()
  1042. }else{
  1043. this.showActionbar()
  1044. }
  1045. }
  1046. if( name=="data.selectAllEnable" ){
  1047. if( this.json.data.selectAllEnable ){
  1048. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","table-cell");
  1049. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","table-cell");
  1050. }else{
  1051. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","none");
  1052. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","none");
  1053. }
  1054. }
  1055. if (name=="data.viewStyleType"){
  1056. var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null;
  1057. var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null;
  1058. this.loadTemplateStyles( file, extendFile, function( templateStyles ){
  1059. this.templateStyles = templateStyles;
  1060. var oldFile, oldExtendFile;
  1061. if( oldValue && this.stylesList[oldValue] ){
  1062. oldFile = this.stylesList[oldValue].file;
  1063. oldExtendFile = this.stylesList[oldValue].extendFile;
  1064. }
  1065. this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){
  1066. this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null;
  1067. if (oldTemplateStyles["view"]) this.clearTemplateStyles(oldTemplateStyles["view"]);
  1068. if (this.templateStyles["view"]) this.setTemplateStyles(this.templateStyles["view"]);
  1069. this.setAllStyles();
  1070. this.actionbarList.each( function (module) {
  1071. if (oldTemplateStyles["actionbar"]){
  1072. module.clearTemplateStyles(oldTemplateStyles["actionbar"]);
  1073. }
  1074. module.setStyleTemplate();
  1075. module.setAllStyles();
  1076. })
  1077. this.pagingList.each( function (module) {
  1078. if (oldTemplateStyles["paging"]){
  1079. module.clearTemplateStyles(oldTemplateStyles["paging"]);
  1080. }
  1081. module.setStyleTemplate();
  1082. module.setAllStyles();
  1083. });
  1084. // this.moduleList.each(function(module){
  1085. // if (oldTemplateStyles[module.moduleName]){
  1086. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  1087. // }
  1088. // module.setStyleTemplate();
  1089. // module.setAllStyles();
  1090. // }.bind(this));
  1091. }.bind(this))
  1092. }.bind(this))
  1093. }
  1094. if (name=="data.viewStyles"){
  1095. this.setCustomStyles();
  1096. }
  1097. },
  1098. loadTemplateStyle : function( callback ){
  1099. this.loadStylesList(function(){
  1100. var oldStyleValue = "";
  1101. if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType="default";
  1102. this.loadTemplateStyles( this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
  1103. function( templateStyles ){
  1104. this.templateStyles = templateStyles;
  1105. if( !this.json.data.viewStyleType )this.json.data.viewStyleType = "default";
  1106. if ( this.templateStyles && this.templateStyles["view"]){
  1107. var viewStyles = Object.clone(this.templateStyles["view"]);
  1108. if( viewStyles.contentGroupTd )delete viewStyles.contentGroupTd;
  1109. if( viewStyles.groupCollapseNode )delete viewStyles.groupCollapseNode;
  1110. if( viewStyles.groupExpandNode )delete viewStyles.groupExpandNode;
  1111. if(!this.json.data.viewStyles){
  1112. this.json.data.viewStyles = viewStyles;
  1113. }else{
  1114. this.setTemplateStyles( viewStyles );
  1115. }
  1116. }
  1117. this.setCustomStyles();
  1118. if(callback)callback();
  1119. }.bind(this)
  1120. );
  1121. }.bind(this));
  1122. },
  1123. clearTemplateStyles: function(styles){
  1124. if (styles){
  1125. if (styles.container) this.removeStyles(styles.container, "container");
  1126. if (styles.table) this.removeStyles(styles.table, "table");
  1127. if (styles.titleTr) this.removeStyles(styles.titleTr, "titleTr");
  1128. if (styles.titleTd) this.removeStyles(styles.titleTd, "titleTd");
  1129. if (styles.contentTr) this.removeStyles(styles.contentTr, "contentTr");
  1130. if (styles.contentSelectedTr) this.removeStyles(styles.contentSelectedTr, "contentSelectedTr");
  1131. if (styles.contentTd) this.removeStyles(styles.contentTd, "contentTd");
  1132. // if (styles.contentGroupTd) this.removeStyles(styles.contentGroupTd, "contentGroupTd");
  1133. // if (styles.groupCollapseNode) this.removeStyles(styles.groupCollapseNode, "groupCollapseNode");
  1134. // if (styles.groupExpandNode) this.removeStyles(styles.groupExpandNode, "groupExpandNode");
  1135. if (styles.checkboxNode) this.removeStyles(styles.checkboxNode, "checkboxNode");
  1136. if (styles.checkedCheckboxNode) this.removeStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1137. if (styles.radioNode) this.removeStyles(styles.radioNode, "radioNode");
  1138. if (styles.checkedRadioNode) this.removeStyles(styles.checkedRadioNode, "checkedRadioNode");
  1139. if (styles.tableProperties) this.removeStyles(styles.tableProperties, "tableProperties");
  1140. }
  1141. },
  1142. setTemplateStyles: function(styles){
  1143. if (styles.container) this.copyStyles(styles.container, "container");
  1144. if (styles.table) this.copyStyles(styles.table, "table");
  1145. if (styles.titleTr) this.copyStyles(styles.titleTr, "titleTr");
  1146. if (styles.titleTd) this.copyStyles(styles.titleTd, "titleTd");
  1147. if (styles.contentTr) this.copyStyles(styles.contentTr, "contentTr");
  1148. if (styles.contentSelectedTr) this.copyStyles(styles.contentSelectedTr, "contentSelectedTr");
  1149. if (styles.contentTd) this.copyStyles(styles.contentTd, "contentTd");
  1150. // if (styles.contentGroupTd) this.copyStyles(styles.contentGroupTd, "contentGroupTd");
  1151. // if (styles.groupCollapseNode) this.copyStyles(styles.groupCollapseNode, "groupCollapseNode");
  1152. // if (styles.groupExpandNode) this.copyStyles(styles.groupExpandNode, "groupExpandNode");
  1153. if (styles.checkboxNode) this.copyStyles(styles.checkboxNode, "checkboxNode");
  1154. if (styles.checkedCheckboxNode) this.copyStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1155. if (styles.radioNode) this.copyStyles(styles.radioNode, "radioNode");
  1156. if (styles.checkedRadioNode) this.copyStyles(styles.checkedRadioNode, "checkedRadioNode");
  1157. if (styles.tableProperties) this.copyStyles(styles.tableProperties, "tableProperties");
  1158. },
  1159. removeStyles: function(from, to){
  1160. if (this.json.data.viewStyles[to]){
  1161. Object.each(from, function(style, key){
  1162. if (this.json.data.viewStyles[to][key] && this.json.data.viewStyles[to][key]==style){
  1163. delete this.json.data.viewStyles[to][key];
  1164. }
  1165. }.bind(this));
  1166. }
  1167. },
  1168. copyStyles: function(from, to){
  1169. if (!this.json.data.viewStyles[to]) this.json.data.viewStyles[to] = {};
  1170. Object.each(from, function(style, key){
  1171. if (!this.json.data.viewStyles[to][key]) this.json.data.viewStyles[to][key] = style;
  1172. }.bind(this));
  1173. }
  1174. // preview: function(){
  1175. // if( this.isNewView ){
  1176. // this.designer.notice( this.designer.lp.saveViewNotice, "error" );
  1177. // return;
  1178. // }
  1179. // this.saveSilence( function () {
  1180. // var url = "../x_desktop/app.html?app=query.Query&status=";
  1181. // url += JSON.stringify({
  1182. // id : this.data.application,
  1183. // viewId : this.data.id
  1184. // });
  1185. // window.open(o2.filterUrl(url),"_blank");
  1186. // }.bind(this));
  1187. // },
  1188. // saveSilence: function(callback){
  1189. // if (!this.data.name){
  1190. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1191. // return false;
  1192. // }
  1193. //
  1194. // this.designer.actions.saveView(this.data, function(json){
  1195. // this.data.id = json.data.id;
  1196. // this.isNewView = false;
  1197. // //this.page.textNode.set("text", this.data.name);
  1198. // if (this.lisNode) {
  1199. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1200. // }
  1201. // if (callback) callback();
  1202. // }.bind(this));
  1203. // },
  1204. // save: function(callback){
  1205. // //if (this.designer.tab.showPage==this.page){
  1206. // if (!this.data.name){
  1207. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1208. // return false;
  1209. // }
  1210. // //}
  1211. // this.designer.actions.saveView(this.data, function(json){
  1212. // this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1213. // this.isNewView = false;
  1214. // this.data.id = json.data.id;
  1215. // //this.page.textNode.set("text", this.data.name);
  1216. // if (this.lisNode) {
  1217. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1218. // }
  1219. // if (callback) callback();
  1220. // }.bind(this));
  1221. // },
  1222. // saveAs: function(){
  1223. // var form = new MWF.xApplication.query.StatementDesigner.View.NewNameForm(this, {
  1224. // name : this.data.name + "_" + MWF.xApplication.query.StatementDesigner.LP.copy,
  1225. // query : this.data.query || this.data.application,
  1226. // queryName : this.data.queryName || this.data.applicationName
  1227. // }, {
  1228. // onSave : function( data, callback ){
  1229. // this._saveAs( data, callback );
  1230. // }.bind(this)
  1231. // }, {
  1232. // app: this.designer
  1233. // });
  1234. // form.edit()
  1235. // },
  1236. // _saveAs : function( data , callback){
  1237. // var _self = this;
  1238. //
  1239. // var d = this.cloneObject( this.data );
  1240. //
  1241. // d.isNewView = true;
  1242. // d.id = this.designer.actions.getUUID();
  1243. // d.name = data.name;
  1244. // d.alias = "";
  1245. // d.query = data.query;
  1246. // d.queryName = data.queryName;
  1247. // d.application = data.query;
  1248. // d.applicationName = data.queryName;
  1249. // d.pid = d.id + d.id;
  1250. //
  1251. // delete d[this.data.id+"viewFilterType"];
  1252. // d[d.id+"viewFilterType"]="custom";
  1253. //
  1254. // d.data.selectList.each( function( entry ){
  1255. // entry.id = (new MWF.widget.UUID).id;
  1256. // }.bind(this));
  1257. //
  1258. // this.designer.actions.saveView(d, function(json){
  1259. // this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  1260. // if (callback) callback();
  1261. // }.bind(this));
  1262. // }
  1263. });
  1264. MWF.xApplication.query.StatementDesigner.View.Column = new Class({
  1265. Extends: MWF.xApplication.query.ViewDesigner.View.Column,
  1266. initialize: function(json, view, next){
  1267. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/column.html";
  1268. this.view = view;
  1269. this.json = json;
  1270. this.next = next;
  1271. this.css = this.view.css;
  1272. this.content = this.view.viewTitleTrNode;
  1273. this.domListNode = this.view.domListNode;
  1274. this.load();
  1275. },
  1276. selected: function(){
  1277. if (this.view.statement.currentSelectedModule){
  1278. if (this.view.statement.currentSelectedModule==this){
  1279. return true;
  1280. }else{
  1281. this.view.statement.currentSelectedModule.unSelected();
  1282. }
  1283. }
  1284. this.view.domListNode.show();
  1285. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  1286. this.listNode.setStyles(this.css.cloumnListNode_selected);
  1287. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1288. new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1289. this.view.statement.currentSelectedModule = this;
  1290. this.isSelected = true;
  1291. this._showActions();
  1292. this.showProperty();
  1293. },
  1294. unSelected: function(){
  1295. this.view.statement.currentSelectedModule = null;
  1296. //this.node.setStyles(this.css.viewTitleColumnNode);
  1297. if (this.isError){
  1298. this.node.setStyles(this.css.viewTitleColumnNode_error)
  1299. }else{
  1300. this.node.setStyles(this.css.viewTitleColumnNode)
  1301. }
  1302. this.listNode.setStyles(this.css.cloumnListNode);
  1303. this.isSelected = false;
  1304. this._hideActions();
  1305. this.hideProperty();
  1306. }
  1307. });
  1308. MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
  1309. Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
  1310. initialize: function(json, jsonList, view, options){
  1311. this.setOptions( options );
  1312. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/actionbar.html";
  1313. this.path = "../x_component_query_ViewDesigner/$View/";
  1314. this.imagePath_default = "../x_component_query_ViewDesigner/$View/";
  1315. this.imagePath_custom = "../x_component_process_FormDesigner/Module/Actionbar/";
  1316. this.cssPath = "../x_component_query_ViewDesigner/$View/"+this.options.style+"/actionbar.wcss";
  1317. this.view = view;
  1318. this.json = json;
  1319. this.jsonList = jsonList;
  1320. this.css = this.view.css;
  1321. this.container = this.view.actionbarNode;
  1322. this.moduleName = "actionbar";
  1323. this.load();
  1324. },
  1325. getJsonPath : function(){
  1326. return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
  1327. },
  1328. selected: function(){
  1329. if (this.view.statement.currentSelectedModule){
  1330. if (this.view.statement.currentSelectedModule==this){
  1331. return true;
  1332. }else{
  1333. this.view.statement.currentSelectedModule.unSelected();
  1334. }
  1335. }
  1336. this.view.domListNode.show();
  1337. this.node.setStyles(this.css.toolbarWarpNode_selected);
  1338. //this.listNode.setStyles(this.css.cloumnListNode_selected);
  1339. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1340. //new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1341. this.view.statement.currentSelectedModule = this;
  1342. this.isSelected = true;
  1343. //this._showActions();
  1344. this.showProperty();
  1345. },
  1346. unSelected: function(){
  1347. this.view.statement.currentSelectedModule = null;
  1348. this.node.setStyles(this.css.toolbarWarpNode);
  1349. //this.listNode.setStyles(this.css.cloumnListNode);
  1350. this.isSelected = false;
  1351. //this._hideActions();
  1352. this.hideProperty();
  1353. },
  1354. });
  1355. MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
  1356. Extends: MWF.xApplication.query.ViewDesigner.View.Paging,
  1357. selected: function(){
  1358. if (this.view.statement.currentSelectedModule){
  1359. if (this.view.statement.currentSelectedModule==this){
  1360. return true;
  1361. }else{
  1362. this.view.statement.currentSelectedModule.unSelected();
  1363. }
  1364. }
  1365. this.view.domListNode.show();
  1366. this.node.setStyles(this.css.pagingWarpNode_selected);
  1367. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1368. this.view.statement.currentSelectedModule = this;
  1369. this.isSelected = true;
  1370. this.showProperty();
  1371. },
  1372. unSelected: function(){
  1373. this.view.statement.currentSelectedModule = null;
  1374. this.node.setStyles(this.css.pagingWarpNode);
  1375. this.isSelected = false;
  1376. this.hideProperty();
  1377. }
  1378. });