Table.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.query = MWF.xApplication.query || {};
  3. MWF.xApplication.query.TableDesigner = MWF.xApplication.query.TableDesigner || {};
  4. MWF.APPDTBD = MWF.xApplication.query.TableDesigner;
  5. MWF.xDesktop.requireApp("query.TableDesigner", "lp."+MWF.language, null, false);
  6. MWF.xDesktop.requireApp("query.ViewDesigner", "View", null, false);
  7. MWF.xDesktop.requireApp("query.TableDesigner", "Property", null, false);
  8. MWF.xApplication.query.TableDesigner.Table = new Class({
  9. Extends: MWF.xApplication.query.ViewDesigner.View,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "isView": false,
  14. "showTab": true,
  15. "propertyPath": "/x_component_query_TableDesigner/$Table/table.html"
  16. },
  17. initialize: function(designer, data, options){
  18. this.setOptions(options);
  19. this.path = "/x_component_query_TableDesigner/$Table/";
  20. this.cssPath = "/x_component_query_TableDesigner/$Table/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.designer = designer;
  23. this.data = data;
  24. if (!this.data.draftData) this.data.draftData = {};
  25. this.parseData();
  26. this.node = this.designer.designNode;
  27. this.areaNode = new Element("div", {"styles": {"height": "100%", "overflow": "auto"}});
  28. this.propertyListNode = this.designer.propertyDomArea;
  29. if(this.designer.application) this.data.applicationName = this.designer.application.name;
  30. if(this.designer.application) this.data.application = this.designer.application.id;
  31. this.isNewTable = (this.data.id) ? false : true;
  32. this.items = [];
  33. this.view = this;
  34. this.queryView = null;
  35. this.autoSave();
  36. this.designer.addEvent("queryClose", function(){
  37. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  38. }.bind(this));
  39. },
  40. parseData: function(){
  41. this.json = this.data;
  42. },
  43. load : function(){
  44. this.setAreaNodeSize();
  45. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  46. this.areaNode.inject(this.node);
  47. this.designer.viewListAreaNode.getChildren().each(function(node){
  48. var table = node.retrieve("table");
  49. if (table.id==this.data.id){
  50. if (this.designer.currentListViewItem){
  51. this.designer.currentListViewItem.setStyles(this.designer.css.listViewItem);
  52. }
  53. node.setStyles(this.designer.css.listViewItem_current);
  54. this.designer.currentListViewItem = node;
  55. this.lisNode = node;
  56. }
  57. }.bind(this));
  58. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  59. this.designer.propertyTitleNode.set("text", this.designer.lp.clumn);
  60. this.designer.propertyDomPercent = 0.5;
  61. this.designer.loadPropertyContentResize();
  62. this.createColumnEditTable();
  63. this.loadView();
  64. this.refreshNode.setStyles(this.css.tableRunNode);
  65. if (!this.data.buildSuccess){
  66. this.refreshNode.hide();
  67. this.addColumnNode.hide();
  68. }
  69. this.selected();
  70. this.setEvent();
  71. this.setViewWidth();
  72. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  73. this.checkToolbars();
  74. },
  75. setEvent: function(){
  76. this.areaNode.addEvent("click", this.selected.bind(this));
  77. this.refreshNode.addEvent("click", function(e){
  78. this.loadViewData();
  79. e.stopPropagation();
  80. }.bind(this));
  81. this.addColumnNode.addEvent("click", function(e){
  82. debugger;
  83. this.addLine();
  84. e.stopPropagation();
  85. }.bind(this));
  86. },
  87. addLine: function(){
  88. var data = this.getNewData();
  89. this.createNewLineDlg(data);
  90. },
  91. createNewLineDlg: function(data){
  92. var div = new Element("div", {"styles": {"margin": "10px 10px 0px 10px", "padding": "5px", "height": "400px", "width": "440px", "overflow": "hidden"}});
  93. var options ={
  94. "content": div,
  95. "title": this.designer.lp.addLine,
  96. "container": this.designer.content,
  97. "width": 500,
  98. "mask": false,
  99. "height": 530,
  100. "buttonList": [
  101. {
  102. "text": this.designer.lp.ok,
  103. "action": function(){
  104. this.saveNewLine(dlg);
  105. }.bind(this)
  106. },
  107. {
  108. "text": this.designer.lp.cancel,
  109. "action": function(){dlg.close();}.bind(this),
  110. "styles": {
  111. "border": "1px solid #999",
  112. "background-color": "#f3f3f3",
  113. "color": "#666666",
  114. "height": "30px",
  115. "border-radius": "5px",
  116. "min-width": "80px",
  117. "margin": "10px 5px"
  118. }
  119. }
  120. ],
  121. "onResize": function(){
  122. var size = dlg.content.getSize();
  123. var width = size.x-60;
  124. var height = size.y - 30;
  125. div.setStyles({
  126. "width": ""+width+"px",
  127. "height": ""+height+"px",
  128. });
  129. }
  130. }
  131. var dlg = o2.DL.open(options);
  132. o2.require("o2.widget.JavascriptEditor", function(){
  133. dlg.editor = new o2.widget.JavascriptEditor(div, {"option": {"mode": "json"}});
  134. dlg.editor.load(function(){
  135. debugger;
  136. dlg.editor.editor.setValue(JSON.stringify(data, null, "\t"));
  137. }.bind(this));
  138. }.bind(this), false);
  139. return dlg;
  140. },
  141. saveNewLine: function(dlg){
  142. var str = dlg.editor.editor.getValue();
  143. try{
  144. var data = JSON.parse(str);
  145. this.designer.actions.insertRow(this.data.id, data, function(){
  146. if (this.lastSelectJPQL) this.runJpql(this.lastSelectJPQL);
  147. this.designer.notice(this.designer.lp.newLineSuccess, "success");
  148. dlg.close();
  149. }.bind(this));
  150. }catch(e){
  151. this.designer.notice(this.designer.lp.newLineSuccess, "error");
  152. }
  153. },
  154. getNewData: function(){
  155. var data = JSON.parse(this.data.data);
  156. var newLineData = {};
  157. data.fieldList.each(function(field){
  158. switch (field.type) {
  159. case "string":
  160. newLineData[field.name] = "";
  161. break;
  162. case "integer":
  163. case "long":
  164. case "double":
  165. newLineData[field.name] = 0;
  166. break;
  167. case "date":
  168. var str = new Date().format("%Y-%m-%d");
  169. newLineData[field.name] = str;
  170. break;
  171. case "time":
  172. var str = new Date().format("%H:%M:%S");
  173. newLineData[field.name] = str;
  174. break;
  175. case "dateTime":
  176. var str = new Date().format("db");
  177. newLineData[field.name] = str;
  178. break;
  179. case "boolean":
  180. newLineData[field.name] = true;
  181. break;
  182. case "stringList":
  183. case "integerList":
  184. case "longList":
  185. case "doubleList":
  186. newLineData[field.name] = [];
  187. break;
  188. case "stringLob":
  189. newLineData[field.name] = "";
  190. break;
  191. case "stringMap":
  192. newLineData[field.name] = {};
  193. break;
  194. }
  195. }.bind(this));
  196. return newLineData;
  197. },
  198. checkToolbars: function(){
  199. if (this.designer.toolbar){
  200. var buildBtn = this.designer.toolbar.childrenButton[1];
  201. var draftBtn = this.designer.toolbar.childrenButton[2];
  202. buildBtn.setDisable(true);
  203. draftBtn.setDisable(true);
  204. if (!this.data.isNewTable) buildBtn.setDisable(false);
  205. if (this.data.status=="build") draftBtn.setDisable(false);
  206. }
  207. },
  208. createColumnEditTable: function(){
  209. this.columnListTable = new Element("table", {"styles": this.css.columnListTable}).inject(this.domListNode);
  210. this.columnListHeaderTr = this.columnListTable.insertRow(-1).setStyles(this.css.columnListTr);
  211. this.columnListHeaderTr.insertCell().setStyles(this.css.columnListHeaderTd).set("text", this.designer.lp.name);
  212. this.columnListHeaderTr.insertCell().setStyles(this.css.columnListHeaderTd).set("text", this.designer.lp.description);
  213. this.columnListHeaderTr.insertCell().setStyles(this.css.columnListHeaderTd).set("text", this.designer.lp.type);
  214. this.columnListEditTr = this.columnListTable.insertRow(-1).setStyles(this.css.columnListEditTr);
  215. var td = this.columnListEditTr.insertCell().setStyles(this.css.columnListTd);
  216. this.columnListEditNameInput = new Element("input", {"styles": this.css.columnListEditInput}).inject(td);
  217. td = this.columnListEditTr.insertCell().setStyles(this.css.columnListTd);
  218. this.columnListEditDescriptionInput = new Element("input", {"styles": this.css.columnListEditInput}).inject(td);
  219. td = this.columnListEditTr.insertCell().setStyles(this.css.columnListTd);
  220. this.columnListEditTypeSelect = new Element("select", {"styles": this.css.columnListEditSelect}).inject(td);
  221. //var options = '<option value=""></option>';
  222. var options = '<option value="string">string</option>';
  223. options += '<option value="integer">integer</option>';
  224. options += '<option value="long">long</option>';
  225. options += '<option value="double">double</option>';
  226. options += '<option value="boolean">boolean</option>';
  227. options += '<option value="date">date</option>';
  228. options += '<option value="time">time</option>';
  229. options += '<option value="dateTime">dateTime</option>';
  230. options += '<option value="stringList">stringList</option>';
  231. options += '<option value="integerList">integerList</option>';
  232. options += '<option value="longList">longList</option>';
  233. options += '<option value="doubleList">doubleList</option>';
  234. options += '<option value="booleanList">booleanList</option>';
  235. options += '<option value="stringLob">stringLob</option>';
  236. options += '<option value="stringMap">stringMap</option>';
  237. this.columnListEditTypeSelect.set("html", options);
  238. this.columnListEditTypeSelect.addEvents({
  239. "change": function(e){
  240. this.checkAddColumn();
  241. }.bind(this)
  242. });
  243. this.columnListEditNameInput.addEvents({
  244. "keydown": function(e){
  245. if (e.code==13) this.checkAddColumn();
  246. }.bind(this)
  247. });
  248. this.columnListEditDescriptionInput.addEvents({
  249. "keydown": function(e){
  250. if (e.code==13) this.checkAddColumn();
  251. }.bind(this)
  252. });
  253. },
  254. checkColumnName: function(name){
  255. var rex = /^\d+|\.|\#|\s|\@|\&|\*|\(|\)|\=|\+|\!|\^|\$|\%|\;|\"|\{|\}|\[|\]|\||\\|\,|\.|\?|\/|\:|\;|\'|\"|\<|\>/g;
  256. if (rex.test(name)){
  257. this.designer.notice(this.designer.lp.errorName, "error");
  258. return false;
  259. }
  260. return true;
  261. },
  262. checkAddColumn: function(){
  263. var name = this.columnListEditNameInput.get("value");
  264. var description = this.columnListEditDescriptionInput.get("value");
  265. var type = this.columnListEditTypeSelect.options[this.columnListEditTypeSelect.selectedIndex].value;
  266. if (name && this.checkColumnName(name)){
  267. if (!this.json.draftData.fieldList) this.json.draftData.fieldList = [];
  268. var columnNames = this.json.draftData.fieldList.map(function(item){ return item.name; });
  269. if ((columnNames.indexOf(name)!=-1)){
  270. this.designer.notice(this.designer.lp.duplicateName, "error");
  271. this.columnListEditNameInput.focus();
  272. }else{
  273. var o = {
  274. "name": name,
  275. "description": description,
  276. "type": type
  277. }
  278. this.addColumn(o);
  279. this.columnListEditNameInput.set("value", "");
  280. this.columnListEditDescriptionInput.set("value", "");
  281. this.columnListEditNameInput.focus();
  282. }
  283. }
  284. },
  285. showProperty: function(){
  286. if (!this.property){
  287. this.property = new MWF.xApplication.query.TableDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  288. "path": this.options.propertyPath,
  289. "onPostLoad": function(){
  290. this.property.show();
  291. }.bind(this)
  292. });
  293. this.property.load();
  294. }else{
  295. this.property.show();
  296. }
  297. },
  298. addColumn: function(data){
  299. var json;
  300. if (!data){
  301. if (!this.json.draftData.fieldList) this.json.draftData.fieldList = [];
  302. var columnNames = this.json.draftData.fieldList.map(function(item){ return item.name; });
  303. var name = "column";
  304. var i=1;
  305. while(columnNames.indexOf(name)!=-1){
  306. name = "column"+i;
  307. i++;
  308. }
  309. json = {
  310. "name": name,
  311. "type":"string",
  312. "description": this.designer.lp.newColumn
  313. };
  314. }else{
  315. json = data;
  316. }
  317. this.json.draftData.fieldList.push(json);
  318. var column = new MWF.xApplication.query.TableDesigner.Table.Column(json, this);
  319. this.items.push(column);
  320. column.selected();
  321. if (this.viewContentTableNode){
  322. var trs = this.viewContentTableNode.getElements("tr");
  323. trs.each(function(tr){
  324. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  325. }.bind(this));
  326. //this.setContentColumnWidth();
  327. }
  328. this.setViewWidth();
  329. this.addColumnNode.scrollIntoView(true);
  330. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  331. },
  332. loadViewColumns: function(){
  333. if (this.json.draftData.fieldList) {
  334. this.json.draftData.fieldList.each(function (json) {
  335. this.items.push(new MWF.xApplication.query.TableDesigner.Table.Column(json, this));
  336. }.bind(this));
  337. }
  338. },
  339. saveSilence: function(callback){
  340. if (!this.data.name){
  341. this.designer.notice(this.designer.lp.inputTableName, "error");
  342. return false;
  343. }
  344. if (!this.json.draftData.fieldList.length){
  345. this.designer.notice(this.designer.lp.errorFieldList, "error");
  346. return false;
  347. }
  348. this.designer.actions.saveTable(this.data, function(json){
  349. this.data.id = json.data.id;
  350. if (this.lisNode) {
  351. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  352. }
  353. this.checkToolbars();
  354. if (callback) callback();
  355. }.bind(this));
  356. },
  357. save: function(callback){
  358. if (!this.data.name){
  359. this.designer.notice(this.designer.lp.inputTableName, "error");
  360. return false;
  361. }
  362. if (!this.json.draftData.fieldList.length){
  363. this.designer.notice(this.designer.lp.errorFieldList, "error");
  364. return false;
  365. }
  366. this.designer.actions.saveTable(this.data, function(json){
  367. this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  368. this.data.id = json.data.id;
  369. if (this.lisNode) {
  370. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  371. }
  372. this.checkToolbars();
  373. if (callback) callback();
  374. }.bind(this));
  375. },
  376. unSelected: function(){
  377. this.currentSelectedModule = null;
  378. return true;
  379. },
  380. statusBuild: function(e){
  381. var _self = this;
  382. if (!e) e = this.node;
  383. this.designer.confirm("warn", e, MWF.APPDTBD.LP.statusBuildTitle, MWF.APPDTBD.LP.statusBuildInfor, 420, 120, function(){
  384. _self.designer.actions.statusBuild(_self.data.id, function(json){
  385. debugger;
  386. this.designer.notice(this.designer.lp.statusBuild_success, "success", this.node, {"x": "left", "y": "bottom"});
  387. this.designer.actions.getTable(json.data.id, function(tjson){
  388. this.data.status = tjson.data.status;
  389. this.checkToolbars();
  390. }.bind(this));
  391. }.bind(_self));
  392. this.close();
  393. }, function(){
  394. this.close();
  395. }, null);
  396. },
  397. statusDraft: function(e){
  398. var _self = this;
  399. if (!e) e = this.node;
  400. this.designer.confirm("warn", e, MWF.APPDTBD.LP.statusDraftTitle, {"html": MWF.APPDTBD.LP.statusDraftInfor}, 450, 120, function(){
  401. this.close();
  402. _self.designer.confirm("warn", e, MWF.APPDTBD.LP.statusDraftTitle, {"html": MWF.APPDTBD.LP.statusDraftInforAgain}, 480, 120, function(){
  403. _self.designer.actions.statusDraft(_self.data.id, function(json){
  404. this.designer.notice(this.designer.lp.statusDraft_success, "success", this.node, {"x": "left", "y": "bottom"});
  405. this.designer.actions.getTable(json.data.id, function(tjson){
  406. this.data.status = tjson.data.status;
  407. this.checkToolbars();
  408. }.bind(this));
  409. }.bind(_self));
  410. this.close();
  411. }, function(){
  412. this.close();
  413. }, null);
  414. }, function(){
  415. this.close();
  416. }, null);
  417. },
  418. buildAllView: function(e){
  419. var _self = this;
  420. if (!e) e = this.node;
  421. this.designer.confirm("warn", e, MWF.APPDTBD.LP.buildAllViewTitle, MWF.APPDTBD.LP.buildAllViewInfor, 480, 120, function(){
  422. _self.designer.actions.buildAllTable(function(json){
  423. this.designer.notice(this.designer.lp.buildAllView_success, "success", this.node, {"x": "left", "y": "bottom"});
  424. }.bind(_self));
  425. this.close();
  426. }, function(){
  427. this.close();
  428. }, null);
  429. },
  430. buildAllView: function(e){
  431. var _self = this;
  432. if (!e) e = this.node;
  433. this.designer.confirm("warn", e, MWF.APPDTBD.LP.buildAllViewTitle, MWF.APPDTBD.LP.buildAllViewInfor, 480, 120, function(){
  434. _self.designer.actions.buildAllTable(function(json){
  435. this.designer.notice(this.designer.lp.buildAllView_success, "success", this.node, {"x": "left", "y": "bottom"});
  436. }.bind(_self));
  437. this.close();
  438. }, function(){
  439. this.close();
  440. }, null);
  441. },
  442. tableImplode: function(e){
  443. var _self = this;
  444. if (!e) e = this.node;
  445. this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableImplodeTitle, MWF.APPDTBD.LP.tableImplodeInfo, 480, 120, function(){
  446. _self.implodeLocal();
  447. this.close();
  448. }, function(){
  449. this.close();
  450. }, null);
  451. },
  452. implodeLocal: function(){
  453. if (!this.uploadFileAreaNode){
  454. this.uploadFileAreaNode = new Element("div");
  455. var html = "<input name=\"file\" type=\"file\" accept=\".json\"/>";
  456. this.uploadFileAreaNode.set("html", html);
  457. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  458. this.fileUploadNode.addEvent("change", this.implodeLocalFile.bind(this));
  459. }else{
  460. if (this.fileUploadNode) this.fileUploadNode.destroy();
  461. this.uploadFileAreaNode.empty();
  462. var html = "<input name=\"file\" type=\"file\" accept=\".json\"/>";
  463. this.uploadFileAreaNode.set("html", html);
  464. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  465. this.fileUploadNode.addEvent("change", this.implodeLocalFile.bind(this));
  466. }
  467. this.fileUploadNode.click();
  468. },
  469. implodeLocalFile: function(){
  470. var files = this.fileUploadNode.files;
  471. if (files.length){
  472. var file = files[0];
  473. var reader = new FileReader();
  474. reader.readAsText(file);
  475. var _self = this;
  476. reader.onload = function(){
  477. var data = JSON.parse(this.result);
  478. _self.designer.actions.rowSave(_self.data.id,data,function(json){
  479. this.designer.notice(this.designer.lp.tableImplode_success, "success", this.node, {"x": "left", "y": "bottom"});
  480. }.bind(_self));
  481. };
  482. }
  483. },
  484. tableExplode: function(e){
  485. var _self = this;
  486. if (!e) e = this.node;
  487. this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableExplodeTitle, MWF.APPDTBD.LP.tableExplodeInfo, 480, 120, function(){
  488. var url = _self.designer.actions.action.address + _self.designer.actions.action.actions.exportRow.uri
  489. url = url.replace("{tableFlag}",_self.data.id);
  490. url = url.replace("{count}",1000);
  491. window.open(url)
  492. this.close();
  493. }, function(){
  494. this.close();
  495. }, null);
  496. },
  497. setContentHeight: function(){
  498. var size = this.areaNode.getSize();
  499. var titleSize = this.viewTitleNode.getSize()
  500. debugger;
  501. var height = size.y-titleSize.y-2;
  502. // if (this.jpqlAreaNode){
  503. // var jpqlSize = this.jpqlAreaNode.getComputedSize();
  504. // height = height - jpqlSize.totalHeight;
  505. // }
  506. this.viewContentScrollNode.setStyle("height", height);
  507. var contentSize = this.viewContentBodyNode.getSize();
  508. if (height<contentSize.y) height = contentSize.y+10;
  509. this.viewContentNode.setStyle("height", height);
  510. this.contentLeftNode.setStyle("height", height);
  511. this.contentRightNode.setStyle("height", height);
  512. //this.viewContentBodyNode.setStyle("min-height", height);
  513. },
  514. createJpqlAreaNode: function(callback){
  515. if (!this.jpqlAreaNode){
  516. this.viewTitleNode.setStyles(this.css.viewTitleNode_run);
  517. this.refreshNode.setStyles(this.css.tableRunNode_run);
  518. this.addColumnNode.setStyles(this.css.addColumnNode_run);
  519. this.jpqlAreaNode = new Element("div", {
  520. "styles": this.css.jpqlAreaNode
  521. }).inject(this.viewTitleContentNode, "top");
  522. this.jpqlEditor = new MWF.xApplication.query.TableDesigner.Table.JPQLRunner(this.jpqlAreaNode, this.refreshNode, this);
  523. this.jpqlEditor.load(function(){
  524. this.jpqlEditor.setJpql("slect", "select o from "+this.data.name+" o", 0, 50);
  525. if (callback) callback();
  526. }.bind(this));
  527. this.setContentHeight();
  528. }else{
  529. if (callback) callback();
  530. }
  531. },
  532. runJpql: function(jpql){
  533. this.designer.actions.executeJpql(this.data.id, jpql, function(json){
  534. this.loadViewMask.hide();
  535. if (jpql.type!="select"){
  536. this.designer.notice(this.designer.lp.jpqlRunSuccess, "success");
  537. if (this.lastSelectJPQL) this.runJpql(this.lastSelectJPQL);
  538. }else{
  539. this.lastSelectJPQL = jpql;
  540. this.viewContentBodyNode.empty();
  541. this.viewContentTableNode = new Element("table", {
  542. "styles": this.css.viewContentTableNode,
  543. "border": "0px",
  544. "cellPadding": "0",
  545. "cellSpacing": "0"
  546. }).inject(this.viewContentBodyNode);
  547. if (json.data.length){
  548. json.data.each(function(line, idx){
  549. new MWF.xApplication.query.TableDesigner.Table.DataLine(line, this);
  550. }.bind(this));
  551. this.setContentColumnWidth();
  552. this.setContentHeight();
  553. }
  554. }
  555. }.bind(this), function(xhr, text, error){
  556. this.loadViewMask.hide();
  557. if (xhr.status!=0){
  558. var errorText = error;
  559. if (xhr){
  560. var json = JSON.decode(xhr.responseText);
  561. if (json){
  562. errorText = json.message.trim() || "request json error";
  563. }else{
  564. errorText = "request json error: "+xhr.responseText;
  565. }
  566. }
  567. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  568. }
  569. }.bind(this));
  570. },
  571. loadViewData: function(){
  572. if (this.data.buildSuccess){
  573. if (this.data.id){
  574. o2.require("o2.widget.Mask", null, false);
  575. this.loadViewMask = new o2.widget.Mask();
  576. this.loadViewMask.loadNode(this.viewAreaNode);
  577. this.createJpqlAreaNode(function(){
  578. var jpql = this.jpqlEditor.getJpql();
  579. this.runJpql(jpql);
  580. }.bind(this));
  581. }
  582. }
  583. }
  584. });
  585. MWF.xApplication.query.TableDesigner.Table.Column = new Class({
  586. Extends:MWF.xApplication.query.ViewDesigner.View.Column,
  587. initialize: function(json, view, next){
  588. this.propertyPath = "/x_component_query_TableDesigner/$Table/column.html";
  589. this.view = view;
  590. this.json = json;
  591. this.next = next;
  592. this.css = this.view.css;
  593. this.content = this.view.viewTitleTrNode;
  594. this.domListNode = this.view.domListNode;
  595. this.load();
  596. },
  597. createDomListItem: function(){
  598. //this.view.columnListEditTr;
  599. var idx = this.view.columnListTable.rows.length;
  600. this.listNode = this.view.columnListTable.insertRow(idx-1).setStyles(this.css.cloumnListNode);
  601. this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.name);
  602. this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.description);
  603. this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.type);
  604. this.resetTextNode();
  605. },
  606. selected: function(){
  607. debugger;
  608. if (this.view.currentSelectedModule){
  609. if (this.view.currentSelectedModule==this){
  610. return true;
  611. }else{
  612. if (!this.view.currentSelectedModule.unSelected()) return true;
  613. }
  614. }
  615. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  616. this.listNode.setStyles(this.css.cloumnListNode_selected);
  617. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  618. new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  619. this.view.currentSelectedModule = this;
  620. this.isSelected = true;
  621. this._showActions();
  622. this.showProperty();
  623. },
  624. unSelected: function(){
  625. if (this.checkColumn()){
  626. this.resetTextNode();
  627. this.view.currentSelectedModule = null;
  628. //this.node.setStyles(this.css.viewTitleColumnNode);
  629. if (this.isError){
  630. this.node.setStyles(this.css.viewTitleColumnNode_error)
  631. }else{
  632. this.node.setStyles(this.css.viewTitleColumnNode)
  633. }
  634. this.listNode.setStyles(this.css.cloumnListNode);
  635. this.isSelected = false;
  636. this._hideActions();
  637. this.hideProperty();
  638. return true;
  639. }
  640. return false;
  641. },
  642. checkColumn: function(){
  643. debugger;
  644. var tds = this.listNode.getElements("td");
  645. var nameInput = tds[0].getFirst();
  646. var descriptionInput = tds[1].getFirst();
  647. var select = tds[2].getFirst();
  648. if (nameInput && nameInput.tagName.toString().toLowerCase()=="input"){
  649. var name = tds[0].getFirst().get("value");
  650. var description = tds[1].getFirst().get("value");
  651. var type = tds[2].getFirst().options[tds[2].getFirst().selectedIndex].value;
  652. if (name && name!==this.json.name && this.view.checkColumnName(name)){
  653. if (!this.view.json.draftData.fieldList) this.view.json.draftData.fieldList = [];
  654. var columnNames = this.view.json.draftData.fieldList.map(function(item){ return item.name; });
  655. if ((columnNames.indexOf(name)!=-1)){
  656. this.view.designer.notice(this.view.designer.lp.duplicateName, "error");
  657. tds[0].getFirst().focus();
  658. return false;
  659. }else{
  660. this.json.name = name;
  661. this.json.description = description;
  662. this.json.type = type;
  663. return true;
  664. }
  665. }else if (name==this.json.name){
  666. this.json.name = name;
  667. this.json.description = description;
  668. this.json.type = type;
  669. return true;
  670. }else{
  671. this.view.designer.notice(this.view.designer.lp.inputName, "error");
  672. tds[0].getFirst().focus();
  673. return false;
  674. }
  675. }
  676. return true;
  677. },
  678. showProperty: function(){
  679. var tds = this.listNode.getElements("td");
  680. tds[0].empty();
  681. tds[1].empty();
  682. tds[2].empty();
  683. var nameInput = new Element("input", {"styles": this.css.columnListEditModifyInput, "value": this.json.name}).inject(tds[0]);
  684. var descriptionInput = new Element("input", {"styles": this.css.columnListEditModifyInput, "value": this.json.description}).inject(tds[1]);
  685. var select = new Element("select", {"styles": this.css.columnListEditModifySelect}).inject(tds[2]);
  686. //var options = '<option value=""></option>';
  687. var options = '<option '+((this.json.type=='string') ? 'selected' : '')+' value="string">string</option>';
  688. options += '<option '+((this.json.type=='integer') ? 'selected' : '')+' value="integer">integer</option>';
  689. options += '<option '+((this.json.type=='long') ? 'selected' : '')+' value="long">long</option>';
  690. options += '<option '+((this.json.type=='double') ? 'selected' : '')+' value="double">double</option>';
  691. options += '<option '+((this.json.type=='boolean') ? 'selected' : '')+' value="boolean">boolean</option>';
  692. options += '<option '+((this.json.type=='date') ? 'selected' : '')+' value="date">date</option>';
  693. options += '<option '+((this.json.type=='time') ? 'selected' : '')+' value="time">time</option>';
  694. options += '<option '+((this.json.type=='dateTime') ? 'selected' : '')+' value="dateTime">dateTime</option>';
  695. options += '<option '+((this.json.type=='stringList') ? 'selected' : '')+' value="stringList">stringList</option>';
  696. options += '<option '+((this.json.type=='integerList') ? 'selected' : '')+' value="integerList">integerList</option>';
  697. options += '<option '+((this.json.type=='longList') ? 'selected' : '')+' value="longList">longList</option>';
  698. options += '<option '+((this.json.type=='doubleList') ? 'selected' : '')+' value="doubleList">doubleList</option>';
  699. options += '<option '+((this.json.type=='booleanList') ? 'selected' : '')+' value="booleanList">booleanList</option>';
  700. options += '<option '+((this.json.type=='stringLob') ? 'selected' : '')+' value="stringLob">stringLob</option>';
  701. options += '<option '+((this.json.type=='stringMap') ? 'selected' : '')+' value="stringMap">stringMap</option>';
  702. select.set("html", options);
  703. nameInput.focus();
  704. select.addEvents({
  705. "change": function(e){
  706. if (this.checkColumn()) this.resetColumnTextNode();
  707. }.bind(this),
  708. "click": function(e){e.stopPropagation()}
  709. });
  710. nameInput.addEvents({
  711. "keydown": function(e){ if (e.code==13) if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  712. "change": function(e){ if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  713. "click": function(e){e.stopPropagation()}
  714. });
  715. descriptionInput.addEvents({
  716. "keydown": function(e){ if (e.code==13) if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  717. "change": function(e){ if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  718. "click": function(e){e.stopPropagation()}
  719. });
  720. },
  721. hideProperty: function(){
  722. var tds = this.listNode.getElements("td");
  723. tds[0].empty().set("text", this.json.name);
  724. tds[1].empty().set("text", this.json.description);
  725. tds[2].empty().set("text", this.json.type);
  726. },
  727. resetColumnTextNode: function(){
  728. var text = (this.json.description) ? this.json.name+"("+this.json.description+")" : this.json.name;
  729. this.textNode.set("text", text);
  730. },
  731. resetTextNode: function(){
  732. var text = (this.json.description) ? this.json.name+"("+this.json.description+")" : this.json.name;
  733. this.textNode.set("text", text);
  734. this.listNode.getFirst().set("text", this.json.name);
  735. this.listNode.getFirst().getNext().set("text", this.json.description);
  736. this.listNode.getLast().set("text", this.json.type);
  737. },
  738. "delete": function(e){
  739. var _self = this;
  740. if (!e) e = this.node;
  741. this.view.designer.confirm("warn", e, MWF.APPDTBD.LP.deleteColumnTitle, MWF.APPDTBD.LP.deleteColumn, 300, 120, function(){
  742. _self.destroy();
  743. this.close();
  744. }, function(){
  745. this.close();
  746. }, null);
  747. },
  748. destroy: function(){
  749. if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  750. if (this.actionArea) this.actionArea.destroy();
  751. if (this.listNode) this.listNode.destroy();
  752. if (this.property) this.property.propertyContent.destroy();
  753. var idx = this.view.items.indexOf(this);
  754. if (this.view.viewContentTableNode){
  755. var trs = this.view.viewContentTableNode.getElements("tr");
  756. trs.each(function(tr){
  757. tr.deleteCell(idx);
  758. }.bind(this));
  759. }
  760. if (this.view.json.draftData.fieldList) this.view.json.draftData.fieldList.erase(this.json);
  761. this.view.items.erase(this);
  762. this.areaNode.destroy();
  763. this.view.selected();
  764. this.view.setViewWidth();
  765. MWF.release(this);
  766. delete this;
  767. },
  768. addColumn: function(e, data){
  769. var json;
  770. if (!data){
  771. if (!this.view.json.draftData.fieldList) this.view.json.draftData.fieldList = [];
  772. var columnNames = this.view.json.draftData.fieldList.map(function(item){ return item.name; });
  773. var name = "column";
  774. var i=1;
  775. while(columnNames.indexOf(name)!=-1){
  776. name = "column"+i;
  777. i++;
  778. }
  779. json = {
  780. "name": name,
  781. "type":"string",
  782. "description": this.view.designer.lp.newColumn
  783. };
  784. }else{
  785. json = data;
  786. }
  787. this.view.json.draftData.fieldList.push(json);
  788. var column = new MWF.xApplication.query.TableDesigner.Table.Column(json, this.view, this);
  789. this.view.items.push(column);
  790. column.selected();
  791. if (this.view.viewContentTableNode){
  792. var trs = this.view.viewContentTableNode.getElements("tr");
  793. trs.each(function(tr){
  794. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  795. }.bind(this));
  796. //this.setContentColumnWidth();
  797. }
  798. this.view.setViewWidth();
  799. this.view.addColumnNode.scrollIntoView(true);
  800. },
  801. _createIconAction: function(){
  802. if (!this.actionArea){
  803. this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
  804. this._createAction({
  805. "name": "add",
  806. "icon": "add.png",
  807. "event": "click",
  808. "action": "addColumn",
  809. "title": MWF.APPDVD.LP.action.add
  810. });
  811. this._createAction({
  812. "name": "delete",
  813. "icon": "delete1.png",
  814. "event": "click",
  815. "action": "delete",
  816. "title": MWF.APPDVD.LP.action["delete"]
  817. });
  818. }
  819. }
  820. });
  821. MWF.xApplication.query.TableDesigner.Table.DataLine = new Class({
  822. initialize: function(data, table){
  823. this.table = table;
  824. this.lineData = data;
  825. this.tableData = this.table.data;
  826. this.tableContentTableNode = this.table.viewContentTableNode;
  827. this.css = this.table.css;
  828. this.load();
  829. },
  830. load: function(){
  831. this.tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.tableContentTableNode);
  832. this.tableData.draftData.fieldList.each(function(c, i){
  833. var d = this.lineData[c.name];
  834. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.tr);
  835. td.store("field", c);
  836. if (d!=undefined){
  837. var t = o2.typeOf(d);
  838. switch (t){
  839. case "array":
  840. td.store("data", d);
  841. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>[...]</div>");
  842. break;
  843. case "object":
  844. td.store("data", d);
  845. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>{...}</div>");
  846. break;
  847. default:
  848. td.set("text", d);
  849. }
  850. }else{
  851. switch (c.type){
  852. case "stringList":
  853. case "integerList":
  854. case "longList":
  855. case "doubleList":
  856. case "booleanList":
  857. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>[...]</div>");
  858. break;
  859. case "stringLob":
  860. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>...</div>");
  861. break;
  862. case "stringMap":
  863. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>{...}</div>");
  864. break;
  865. default:
  866. td.set("text", "");
  867. }
  868. }
  869. if (td.getFirst()){
  870. td.getFirst().addEvent("click", function(e){
  871. this.getFieldValue(e.target.getParent());
  872. }.bind(this));
  873. }
  874. }.bind(this));
  875. },
  876. createObjectValueDlg: function(target){
  877. var div = new Element("div", {"styles": {"margin": "10px 10px 0px 10px", "padding": "5px", "overflow": "hidden"}});
  878. //var node = new Element("div", {"styles": {"margin": "10px 10px 0px 10px", "padding": "5px", "overflow": "hidden"}}).inject(div);
  879. var p = target.getPosition(this.table.designer.content);
  880. var s = target.getSize();
  881. var size = this.table.designer.content.getSize();
  882. var top = p.y;
  883. var left = (p.x+s.x/2)-180;
  884. if (top+400+10>size.y) top = size.y-400-10;
  885. if (left+360+10>size.x) left = size.x-360-10;
  886. if (top<10) top = 10;
  887. if (left<10) left = 10;
  888. var fromTop = p.y+s.y/2;
  889. var fromLeft = p.x+s.x/2;
  890. var options ={
  891. "content": div,
  892. "isTitle": false,
  893. "container": this.table.designer.content,
  894. "width": 360,
  895. "height": 400,
  896. "top": top,
  897. "left": left,
  898. "fromTop": fromTop,
  899. "fromLeft": fromLeft,
  900. "buttonList": [
  901. {
  902. "text": this.table.designer.lp.close,
  903. "action": function(){dlg.close();}.bind(this)
  904. }
  905. ]
  906. }
  907. var dlg = o2.DL.open(options);
  908. return dlg;
  909. },
  910. getFieldValue: function(node){
  911. var field = node.retrieve("field")
  912. this.loadFieldValue(field.name, function(){
  913. var value = this.lineData[field.name];
  914. var dlg = this.createObjectValueDlg(node);
  915. var listNode = dlg.content.getFirst();
  916. switch (field.type){
  917. case "stringList":
  918. case "integerList":
  919. case "longList":
  920. case "doubleList":
  921. case "booleanList":
  922. o2.require("o2.widget.Arraylist", function(){
  923. var list = new o2.widget.Arraylist(listNode, {
  924. "style": "table",
  925. "title": field.name,
  926. "isAdd": false,
  927. "isDelete": false,
  928. "isModify": false
  929. });
  930. list.load(value);
  931. }.bind(this));
  932. break;
  933. case "stringLob":
  934. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>...</div>");
  935. break;
  936. case "stringMap":
  937. o2.require("o2.widget.Maplist", function(){
  938. var list = new o2.widget.Maplist(listNode, {
  939. "style": "table",
  940. "title": field.name,
  941. "isAdd": false,
  942. "isDelete": false,
  943. "isModify": false
  944. });
  945. list.load(value);
  946. }.bind(this));
  947. break;
  948. }
  949. }.bind(this));
  950. },
  951. loadFieldValue: function(name, callback){
  952. if (name){
  953. if (this.lineData[name]){
  954. if (callback) callback();
  955. }else{
  956. this.table.designer.actions.getRow(this.tableData.id, this.lineData.id, function(json){
  957. this.lineData = json.data;
  958. if (callback) callback();
  959. }.bind(this));
  960. }
  961. }
  962. }
  963. });
  964. MWF.xApplication.query.TableDesigner.Table.JPQLRunner = new Class({
  965. initialize: function(node, runNode, table){
  966. this.table = table;
  967. this.node = node;
  968. this.runNode = runNode;
  969. this.css = this.table.css;
  970. this.lp = this.table.designer.lp;
  971. //this.select = select;
  972. },
  973. load: function(callback){
  974. this.optionArea = new Element("div", {"styles": this.css.jpqlOptionArea}).inject(this.node);
  975. //this.contentArea = new Element("div", {"styles": this.css.jpqlContentArea}).inject(this.node);
  976. this.contentWhereArea = new Element("div", {"styles": this.css.jpqlContentWhereArea}).inject(this.node);
  977. this.loadOptions();
  978. //this.loadSelectEditor(callback);
  979. this.loadEditor(callback);
  980. },
  981. loadOptions: function(){
  982. var html = "<table cellpadding='0' cellspacing='0' style='height:30px'><tr>";
  983. html += "<td style='padding: 0 5px'>"+this.lp.jpqlType+"</td>";
  984. html += "<td style='padding: 0 5px'><select><option value='select'>select</option><option value='update'>update</option><option value='delete'>delete</option></select></td>";
  985. html += "<td style='padding: 0 5px'>"+this.lp.jpqlFromResult+"</td>";
  986. html += "<td style='padding: 0 5px'><input type='number' value='1'/></td>";
  987. html += "<td style='padding: 0 5px'>"+this.lp.jpqlMaxResult+"</td>";
  988. html += "<td style='padding: 0 5px'><input type='number' value='50'/></td>";
  989. // html += "<td style='padding: 0 5px'>"+this.lp.jpqlSelectTitle+"</td>";
  990. // html += "<td style='padding: 0 5px'><input readonly type='text' value='"+this.select+"'/></td>";
  991. // html += "<td style='padding: 0 5px'>"+this.lp.inputWhere+"</td>";
  992. html += "</tr></table>";
  993. this.optionArea.set("html", html);
  994. this.jpqlTypeSelect = this.optionArea.getElement("select");
  995. var inputs = this.optionArea.getElements("input");
  996. this.fromResultInput = inputs[0];
  997. this.maxResultsInput = inputs[1];
  998. this.jpqlTypeSelect.setStyles(this.css.jpqlTypeSelect);
  999. this.fromResultInput.setStyles(this.css.jpqlOptionInput);
  1000. this.maxResultsInput.setStyles(this.css.jpqlOptionInput);
  1001. this.jpqlTypeSelect.addEvent("change", function(){
  1002. var type = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value;
  1003. this.changeType(type, true);
  1004. }.bind(this));
  1005. // inputs[2].setStyles(this.css.jpqlOptionInput);
  1006. // inputs[2].setStyle("width", "200px")
  1007. },
  1008. // loadSelectEditor: function(){
  1009. // this.contentArea.set("text", this.select);
  1010. // o2.require("o2.widget.ace", function(){
  1011. // o2.widget.ace.load(function(){
  1012. // o2.load("/o2_lib/ace/src-min-noconflict/ext-static_highlight.js", function(){
  1013. // var highlight = ace.require("ace/ext/static_highlight");
  1014. // highlight(this.contentArea, {mode: "ace/mode/jql", theme: "ace/theme/tomorrow", "fontSize": 16});
  1015. // }.bind(this));
  1016. // }.bind(this));
  1017. // }.bind(this));
  1018. // },
  1019. loadEditor: function(callback){
  1020. o2.require("o2.widget.JavascriptEditor", function(){
  1021. this.editor = new o2.widget.JavascriptEditor(this.contentWhereArea, {"title": "JPQL", "option": {"mode": "sql"}});
  1022. this.editor.load(function(){
  1023. this.editor.editor.on("change", function(){
  1024. this.checkJpqlType();
  1025. }.bind(this));
  1026. if (callback) callback();
  1027. }.bind(this));
  1028. }.bind(this), false);
  1029. },
  1030. checkJpqlType: function(){
  1031. var str = this.editor.editor.getValue();
  1032. var jpql_select = /^select/i;
  1033. var jpql_update = /^update/i;
  1034. var jpql_delete = /^delete/i;
  1035. if (jpql_select.test(str)) return this.changeType("select");
  1036. if (jpql_update.test(str)) return this.changeType("update");
  1037. if (jpql_delete.test(str)) return this.changeType("delete");
  1038. },
  1039. changeType: function(type, force){
  1040. if (type != this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value || force){
  1041. for (var i=0; i<this.jpqlTypeSelect.options.length; i++){
  1042. if (this.jpqlTypeSelect.options[i].value==type){
  1043. this.jpqlTypeSelect.options[i].set("selected", true);
  1044. break;
  1045. }
  1046. }
  1047. if (type!="select"){
  1048. var tds = this.optionArea.getElements("td");
  1049. tds[2].hide();
  1050. tds[3].hide();
  1051. tds[4].hide();
  1052. tds[5].hide();
  1053. }else{
  1054. var tds = this.optionArea.getElements("td");
  1055. tds[2].show();
  1056. tds[3].show();
  1057. tds[4].show();
  1058. tds[5].show();
  1059. }
  1060. }
  1061. },
  1062. setJpql: function(type, jpql, firstResult, maxResults){
  1063. if (this.editor){
  1064. if (this.editor.editor) this.editor.editor.setValue(jpql);
  1065. }
  1066. if (this.jpqlTypeSelect){
  1067. for (var i=0; i<this.jpqlTypeSelect.options.length; i++){
  1068. if (this.jpqlTypeSelect.options[i].value==type.toString().toLowerCase()){
  1069. this.jpqlTypeSelect.options[i].set("selected", true);
  1070. break;
  1071. }
  1072. }
  1073. }
  1074. if (this.fromResultInput) this.fromResultInput.set("value", firstResult);
  1075. if (this.maxResultsInput) this.maxResultsInput.set("value", maxResults);
  1076. },
  1077. getJpql: function(){
  1078. var jpql = this.editor.editor.getValue();
  1079. var type = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].get("value");
  1080. var fromResult = this.fromResultInput.get("value");
  1081. var maxResults = this.maxResultsInput.get("value");
  1082. return {
  1083. "data": jpql,
  1084. "type": type,
  1085. "firstResult": fromResult.toInt(),
  1086. "maxResults": maxResults.toInt()
  1087. }
  1088. }
  1089. });