Statement.js 68 KB

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