Table.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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", "ViewBase", 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.ViewBase,
  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. tableClear: function(e){
  443. var _self = this;
  444. if (!e) e = this.node;
  445. this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableClearTitle, MWF.APPDTBD.LP.tableClearInfo, 480, 120, function(){
  446. _self.designer.actions.deleteAllRow(_self.data.id,function(json){
  447. this.designer.notice(this.designer.lp.tableClear_success, "success", this.node, {"x": "left", "y": "bottom"});
  448. }.bind(_self));
  449. this.close();
  450. }, function(){
  451. this.close();
  452. }, null);
  453. },
  454. tableImplode: function(e){
  455. var _self = this;
  456. if (!e) e = this.node;
  457. this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableImplodeTitle, MWF.APPDTBD.LP.tableImplodeInfo, 480, 120, function(){
  458. _self.implodeLocal();
  459. this.close();
  460. }, function(){
  461. this.close();
  462. }, null);
  463. },
  464. implodeLocal: function(){
  465. if (!this.uploadFileAreaNode){
  466. this.uploadFileAreaNode = new Element("div");
  467. var html = "<input name=\"file\" type=\"file\" accept=\".json\"/>";
  468. this.uploadFileAreaNode.set("html", html);
  469. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  470. this.fileUploadNode.addEvent("change", this.implodeLocalFile.bind(this));
  471. }else{
  472. if (this.fileUploadNode) this.fileUploadNode.destroy();
  473. this.uploadFileAreaNode.empty();
  474. var html = "<input name=\"file\" type=\"file\" accept=\".json\"/>";
  475. this.uploadFileAreaNode.set("html", html);
  476. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  477. this.fileUploadNode.addEvent("change", this.implodeLocalFile.bind(this));
  478. }
  479. this.fileUploadNode.click();
  480. },
  481. implodeLocalFile: function(){
  482. var files = this.fileUploadNode.files;
  483. if (files.length){
  484. var file = files[0];
  485. var reader = new FileReader();
  486. reader.readAsText(file);
  487. var _self = this;
  488. reader.onload = function(){
  489. var data = JSON.parse(this.result);
  490. _self.designer.actions.rowSave(_self.data.id,data,function(json){
  491. this.designer.notice(this.designer.lp.tableImplode_success, "success", this.node, {"x": "left", "y": "bottom"});
  492. }.bind(_self));
  493. };
  494. }
  495. },
  496. tableExplode: function(e){
  497. var _self = this;
  498. if (!e) e = this.node;
  499. this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableExplodeTitle, MWF.APPDTBD.LP.tableExplodeInfo, 480, 120, function(){
  500. var url = _self.designer.actions.action.address + _self.designer.actions.action.actions.exportRow.uri
  501. url = url.replace("{tableFlag}",_self.data.id);
  502. url = url.replace("{count}",1000);
  503. window.open(o2.filterUrl(url))
  504. this.close();
  505. }, function(){
  506. this.close();
  507. }, null);
  508. },
  509. setContentHeight: function(){
  510. var size = this.areaNode.getSize();
  511. var titleSize = this.viewTitleNode.getSize()
  512. debugger;
  513. var height = size.y-titleSize.y-2;
  514. // if (this.jpqlAreaNode){
  515. // var jpqlSize = this.jpqlAreaNode.getComputedSize();
  516. // height = height - jpqlSize.totalHeight;
  517. // }
  518. this.viewContentScrollNode.setStyle("height", height);
  519. var contentSize = this.viewContentBodyNode.getSize();
  520. if (height<contentSize.y) height = contentSize.y+10;
  521. this.viewContentNode.setStyle("height", height);
  522. this.contentLeftNode.setStyle("height", height);
  523. this.contentRightNode.setStyle("height", height);
  524. //this.viewContentBodyNode.setStyle("min-height", height);
  525. },
  526. createJpqlAreaNode: function(callback){
  527. if (!this.jpqlAreaNode){
  528. this.viewTitleNode.setStyles(this.css.viewTitleNode_run);
  529. this.refreshNode.setStyles(this.css.tableRunNode_run);
  530. this.addColumnNode.setStyles(this.css.addColumnNode_run);
  531. this.jpqlAreaNode = new Element("div", {
  532. "styles": this.css.jpqlAreaNode
  533. }).inject(this.viewTitleContentNode, "top");
  534. this.jpqlEditor = new MWF.xApplication.query.TableDesigner.Table.JPQLRunner(this.jpqlAreaNode, this.refreshNode, this);
  535. this.jpqlEditor.load(function(){
  536. this.jpqlEditor.setJpql("slect", "select o from "+this.data.name+" o", 0, 50);
  537. if (callback) callback();
  538. }.bind(this));
  539. this.setContentHeight();
  540. }else{
  541. if (callback) callback();
  542. }
  543. },
  544. runJpql: function(jpql){
  545. this.designer.actions.executeJpql(this.data.id, jpql, function(json){
  546. this.loadViewMask.hide();
  547. if (jpql.type!="select"){
  548. this.designer.notice(this.designer.lp.jpqlRunSuccess, "success");
  549. if (this.lastSelectJPQL) this.runJpql(this.lastSelectJPQL);
  550. }else{
  551. this.lastSelectJPQL = jpql;
  552. this.viewContentBodyNode.empty();
  553. this.viewContentTableNode = new Element("table", {
  554. "styles": this.css.viewContentTableNode,
  555. "border": "0px",
  556. "cellPadding": "0",
  557. "cellSpacing": "0"
  558. }).inject(this.viewContentBodyNode);
  559. if (json.data.length){
  560. json.data.each(function(line, idx){
  561. new MWF.xApplication.query.TableDesigner.Table.DataLine(line, this);
  562. }.bind(this));
  563. this.setContentColumnWidth();
  564. this.setContentHeight();
  565. }
  566. }
  567. }.bind(this), function(xhr, text, error){
  568. this.loadViewMask.hide();
  569. if (xhr.status!=0){
  570. var errorText = error;
  571. if (xhr){
  572. var json = JSON.decode(xhr.responseText);
  573. if (json){
  574. errorText = json.message.trim() || "request json error";
  575. }else{
  576. errorText = "request json error: "+xhr.responseText;
  577. }
  578. }
  579. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  580. }
  581. }.bind(this));
  582. },
  583. loadViewData: function(){
  584. if (this.data.buildSuccess){
  585. if (this.data.id){
  586. o2.require("o2.widget.Mask", null, false);
  587. this.loadViewMask = new o2.widget.Mask();
  588. this.loadViewMask.loadNode(this.viewAreaNode);
  589. this.createJpqlAreaNode(function(){
  590. var jpql = this.jpqlEditor.getJpql();
  591. this.runJpql(jpql);
  592. }.bind(this));
  593. }
  594. }
  595. }
  596. });
  597. MWF.xApplication.query.TableDesigner.Table.Column = new Class({
  598. Extends:MWF.xApplication.query.ViewDesigner.ViewBase.Column,
  599. initialize: function(json, view, next){
  600. this.propertyPath = "../x_component_query_TableDesigner/$Table/column.html";
  601. this.view = view;
  602. this.json = json;
  603. this.next = next;
  604. this.css = this.view.css;
  605. this.content = this.view.viewTitleTrNode;
  606. this.domListNode = this.view.domListNode;
  607. this.load();
  608. },
  609. createDomListItem: function(){
  610. //this.view.columnListEditTr;
  611. var idx = this.view.columnListTable.rows.length;
  612. this.listNode = this.view.columnListTable.insertRow(idx-1).setStyles(this.css.cloumnListNode);
  613. this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.name);
  614. this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.description);
  615. this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.type);
  616. this.resetTextNode();
  617. },
  618. selected: function(){
  619. debugger;
  620. if (this.view.currentSelectedModule){
  621. if (this.view.currentSelectedModule==this){
  622. return true;
  623. }else{
  624. if (!this.view.currentSelectedModule.unSelected()) return true;
  625. }
  626. }
  627. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  628. this.listNode.setStyles(this.css.cloumnListNode_selected);
  629. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  630. new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  631. this.view.currentSelectedModule = this;
  632. this.isSelected = true;
  633. this._showActions();
  634. this.showProperty();
  635. },
  636. unSelected: function(){
  637. if (this.checkColumn()){
  638. this.resetTextNode();
  639. this.view.currentSelectedModule = null;
  640. //this.node.setStyles(this.css.viewTitleColumnNode);
  641. if (this.isError){
  642. this.node.setStyles(this.css.viewTitleColumnNode_error)
  643. }else{
  644. this.node.setStyles(this.css.viewTitleColumnNode)
  645. }
  646. this.listNode.setStyles(this.css.cloumnListNode);
  647. this.isSelected = false;
  648. this._hideActions();
  649. this.hideProperty();
  650. return true;
  651. }
  652. return false;
  653. },
  654. checkColumn: function(){
  655. debugger;
  656. var tds = this.listNode.getElements("td");
  657. var nameInput = tds[0].getFirst();
  658. var descriptionInput = tds[1].getFirst();
  659. var select = tds[2].getFirst();
  660. if (nameInput && nameInput.tagName.toString().toLowerCase()=="input"){
  661. var name = tds[0].getFirst().get("value");
  662. var description = tds[1].getFirst().get("value");
  663. var type = tds[2].getFirst().options[tds[2].getFirst().selectedIndex].value;
  664. if (name && name!==this.json.name && this.view.checkColumnName(name)){
  665. if (!this.view.json.draftData.fieldList) this.view.json.draftData.fieldList = [];
  666. var columnNames = this.view.json.draftData.fieldList.map(function(item){ return item.name; });
  667. if ((columnNames.indexOf(name)!=-1)){
  668. this.view.designer.notice(this.view.designer.lp.duplicateName, "error");
  669. tds[0].getFirst().focus();
  670. return false;
  671. }else{
  672. this.json.name = name;
  673. this.json.description = description;
  674. this.json.type = type;
  675. return true;
  676. }
  677. }else if (name==this.json.name){
  678. this.json.name = name;
  679. this.json.description = description;
  680. this.json.type = type;
  681. return true;
  682. }else{
  683. this.view.designer.notice(this.view.designer.lp.inputName, "error");
  684. tds[0].getFirst().focus();
  685. return false;
  686. }
  687. }
  688. return true;
  689. },
  690. showProperty: function(){
  691. var tds = this.listNode.getElements("td");
  692. tds[0].empty();
  693. tds[1].empty();
  694. tds[2].empty();
  695. var nameInput = new Element("input", {"styles": this.css.columnListEditModifyInput, "value": this.json.name}).inject(tds[0]);
  696. var descriptionInput = new Element("input", {"styles": this.css.columnListEditModifyInput, "value": this.json.description}).inject(tds[1]);
  697. var select = new Element("select", {"styles": this.css.columnListEditModifySelect}).inject(tds[2]);
  698. //var options = '<option value=""></option>';
  699. var options = '<option '+((this.json.type=='string') ? 'selected' : '')+' value="string">string</option>';
  700. options += '<option '+((this.json.type=='integer') ? 'selected' : '')+' value="integer">integer</option>';
  701. options += '<option '+((this.json.type=='long') ? 'selected' : '')+' value="long">long</option>';
  702. options += '<option '+((this.json.type=='double') ? 'selected' : '')+' value="double">double</option>';
  703. options += '<option '+((this.json.type=='boolean') ? 'selected' : '')+' value="boolean">boolean</option>';
  704. options += '<option '+((this.json.type=='date') ? 'selected' : '')+' value="date">date</option>';
  705. options += '<option '+((this.json.type=='time') ? 'selected' : '')+' value="time">time</option>';
  706. options += '<option '+((this.json.type=='dateTime') ? 'selected' : '')+' value="dateTime">dateTime</option>';
  707. options += '<option '+((this.json.type=='stringList') ? 'selected' : '')+' value="stringList">stringList</option>';
  708. options += '<option '+((this.json.type=='integerList') ? 'selected' : '')+' value="integerList">integerList</option>';
  709. options += '<option '+((this.json.type=='longList') ? 'selected' : '')+' value="longList">longList</option>';
  710. options += '<option '+((this.json.type=='doubleList') ? 'selected' : '')+' value="doubleList">doubleList</option>';
  711. options += '<option '+((this.json.type=='booleanList') ? 'selected' : '')+' value="booleanList">booleanList</option>';
  712. options += '<option '+((this.json.type=='stringLob') ? 'selected' : '')+' value="stringLob">stringLob</option>';
  713. options += '<option '+((this.json.type=='stringMap') ? 'selected' : '')+' value="stringMap">stringMap</option>';
  714. select.set("html", options);
  715. nameInput.focus();
  716. select.addEvents({
  717. "change": function(e){
  718. if (this.checkColumn()) this.resetColumnTextNode();
  719. }.bind(this),
  720. "click": function(e){e.stopPropagation()}
  721. });
  722. nameInput.addEvents({
  723. "keydown": function(e){ if (e.code==13) if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  724. "change": function(e){ if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  725. "click": function(e){e.stopPropagation()}
  726. });
  727. descriptionInput.addEvents({
  728. "keydown": function(e){ if (e.code==13) if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  729. "change": function(e){ if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  730. "click": function(e){e.stopPropagation()}
  731. });
  732. },
  733. hideProperty: function(){
  734. var tds = this.listNode.getElements("td");
  735. tds[0].empty().set("text", this.json.name);
  736. tds[1].empty().set("text", this.json.description);
  737. tds[2].empty().set("text", this.json.type);
  738. },
  739. resetColumnTextNode: function(){
  740. var text = (this.json.description) ? this.json.name+"("+this.json.description+")" : this.json.name;
  741. this.textNode.set("text", text);
  742. },
  743. resetTextNode: function(){
  744. var text = (this.json.description) ? this.json.name+"("+this.json.description+")" : this.json.name;
  745. this.textNode.set("text", text);
  746. this.listNode.getFirst().set("text", this.json.name);
  747. this.listNode.getFirst().getNext().set("text", this.json.description);
  748. this.listNode.getLast().set("text", this.json.type);
  749. },
  750. "delete": function(e){
  751. var _self = this;
  752. if (!e) e = this.node;
  753. this.view.designer.confirm("warn", e, MWF.APPDTBD.LP.deleteColumnTitle, MWF.APPDTBD.LP.deleteColumn, 300, 120, function(){
  754. _self.destroy();
  755. this.close();
  756. }, function(){
  757. this.close();
  758. }, null);
  759. },
  760. destroy: function(){
  761. if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  762. if (this.actionArea) this.actionArea.destroy();
  763. if (this.listNode) this.listNode.destroy();
  764. if (this.property) this.property.propertyContent.destroy();
  765. var idx = this.view.items.indexOf(this);
  766. if (this.view.viewContentTableNode){
  767. var trs = this.view.viewContentTableNode.getElements("tr");
  768. trs.each(function(tr){
  769. tr.deleteCell(idx);
  770. }.bind(this));
  771. }
  772. if (this.view.json.draftData.fieldList) this.view.json.draftData.fieldList.erase(this.json);
  773. this.view.items.erase(this);
  774. this.areaNode.destroy();
  775. this.view.selected();
  776. this.view.setViewWidth();
  777. MWF.release(this);
  778. delete this;
  779. },
  780. addColumn: function(e, data){
  781. var json;
  782. if (!data){
  783. if (!this.view.json.draftData.fieldList) this.view.json.draftData.fieldList = [];
  784. var columnNames = this.view.json.draftData.fieldList.map(function(item){ return item.name; });
  785. var name = "column";
  786. var i=1;
  787. while(columnNames.indexOf(name)!=-1){
  788. name = "column"+i;
  789. i++;
  790. }
  791. json = {
  792. "name": name,
  793. "type":"string",
  794. "description": this.view.designer.lp.newColumn
  795. };
  796. }else{
  797. json = data;
  798. }
  799. this.view.json.draftData.fieldList.push(json);
  800. var column = new MWF.xApplication.query.TableDesigner.Table.Column(json, this.view, this);
  801. this.view.items.push(column);
  802. column.selected();
  803. if (this.view.viewContentTableNode){
  804. var trs = this.view.viewContentTableNode.getElements("tr");
  805. trs.each(function(tr){
  806. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  807. }.bind(this));
  808. //this.setContentColumnWidth();
  809. }
  810. this.view.setViewWidth();
  811. this.view.addColumnNode.scrollIntoView(true);
  812. },
  813. _createIconAction: function(){
  814. if (!this.actionArea){
  815. this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
  816. this._createAction({
  817. "name": "add",
  818. "icon": "add.png",
  819. "event": "click",
  820. "action": "addColumn",
  821. "title": MWF.APPDVD.LP.action.add
  822. });
  823. this._createAction({
  824. "name": "delete",
  825. "icon": "delete1.png",
  826. "event": "click",
  827. "action": "delete",
  828. "title": MWF.APPDVD.LP.action["delete"]
  829. });
  830. }
  831. }
  832. });
  833. MWF.xApplication.query.TableDesigner.Table.DataLine = new Class({
  834. initialize: function(data, table){
  835. this.table = table;
  836. this.lineData = data;
  837. this.tableData = this.table.data;
  838. this.tableContentTableNode = this.table.viewContentTableNode;
  839. this.css = this.table.css;
  840. this.load();
  841. },
  842. load: function(){
  843. this.tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.tableContentTableNode);
  844. this.tableData.draftData.fieldList.each(function(c, i){
  845. var d = this.lineData[c.name];
  846. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.tr);
  847. td.store("field", c);
  848. if (d!=undefined){
  849. var t = o2.typeOf(d);
  850. switch (t){
  851. case "array":
  852. td.store("data", d);
  853. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>[...]</div>");
  854. break;
  855. case "object":
  856. td.store("data", d);
  857. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>{...}</div>");
  858. break;
  859. default:
  860. td.set("text", d);
  861. }
  862. }else{
  863. switch (c.type){
  864. case "stringList":
  865. case "integerList":
  866. case "longList":
  867. case "doubleList":
  868. case "booleanList":
  869. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>[...]</div>");
  870. break;
  871. case "stringLob":
  872. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>...</div>");
  873. break;
  874. case "stringMap":
  875. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>{...}</div>");
  876. break;
  877. default:
  878. td.set("text", "");
  879. }
  880. }
  881. if (td.getFirst()){
  882. td.getFirst().addEvent("click", function(e){
  883. this.getFieldValue(e.target.getParent());
  884. }.bind(this));
  885. }
  886. }.bind(this));
  887. },
  888. createObjectValueDlg: function(target){
  889. var div = new Element("div", {"styles": {"margin": "10px 10px 0px 10px", "padding": "5px", "overflow": "hidden"}});
  890. //var node = new Element("div", {"styles": {"margin": "10px 10px 0px 10px", "padding": "5px", "overflow": "hidden"}}).inject(div);
  891. var p = target.getPosition(this.table.designer.content);
  892. var s = target.getSize();
  893. var size = this.table.designer.content.getSize();
  894. var top = p.y;
  895. var left = (p.x+s.x/2)-180;
  896. if (top+400+10>size.y) top = size.y-400-10;
  897. if (left+360+10>size.x) left = size.x-360-10;
  898. if (top<10) top = 10;
  899. if (left<10) left = 10;
  900. var fromTop = p.y+s.y/2;
  901. var fromLeft = p.x+s.x/2;
  902. var options ={
  903. "content": div,
  904. "isTitle": false,
  905. "container": this.table.designer.content,
  906. "width": 360,
  907. "height": 400,
  908. "top": top,
  909. "left": left,
  910. "fromTop": fromTop,
  911. "fromLeft": fromLeft,
  912. "buttonList": [
  913. {
  914. "text": this.table.designer.lp.close,
  915. "action": function(){dlg.close();}.bind(this)
  916. }
  917. ]
  918. }
  919. var dlg = o2.DL.open(options);
  920. return dlg;
  921. },
  922. getFieldValue: function(node){
  923. var field = node.retrieve("field")
  924. this.loadFieldValue(field.name, function(){
  925. var value = this.lineData[field.name];
  926. var dlg = this.createObjectValueDlg(node);
  927. var listNode = dlg.content.getFirst();
  928. switch (field.type){
  929. case "stringList":
  930. case "integerList":
  931. case "longList":
  932. case "doubleList":
  933. case "booleanList":
  934. o2.require("o2.widget.Arraylist", function(){
  935. var list = new o2.widget.Arraylist(listNode, {
  936. "style": "table",
  937. "title": field.name,
  938. "isAdd": false,
  939. "isDelete": false,
  940. "isModify": false
  941. });
  942. list.load(value);
  943. }.bind(this));
  944. break;
  945. case "stringLob":
  946. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>...</div>");
  947. break;
  948. case "stringMap":
  949. o2.require("o2.widget.Maplist", function(){
  950. var list = new o2.widget.Maplist(listNode, {
  951. "style": "table",
  952. "title": field.name,
  953. "isAdd": false,
  954. "isDelete": false,
  955. "isModify": false
  956. });
  957. list.load(value);
  958. }.bind(this));
  959. break;
  960. }
  961. }.bind(this));
  962. },
  963. loadFieldValue: function(name, callback){
  964. if (name){
  965. if (this.lineData[name]){
  966. if (callback) callback();
  967. }else{
  968. this.table.designer.actions.getRow(this.tableData.id, this.lineData.id, function(json){
  969. this.lineData = json.data;
  970. if (callback) callback();
  971. }.bind(this));
  972. }
  973. }
  974. }
  975. });
  976. MWF.xApplication.query.TableDesigner.Table.JPQLRunner = new Class({
  977. initialize: function(node, runNode, table){
  978. this.table = table;
  979. this.node = node;
  980. this.runNode = runNode;
  981. this.css = this.table.css;
  982. this.lp = this.table.designer.lp;
  983. //this.select = select;
  984. },
  985. load: function(callback){
  986. this.optionArea = new Element("div", {"styles": this.css.jpqlOptionArea}).inject(this.node);
  987. //this.contentArea = new Element("div", {"styles": this.css.jpqlContentArea}).inject(this.node);
  988. this.contentWhereArea = new Element("div", {"styles": this.css.jpqlContentWhereArea}).inject(this.node);
  989. this.loadOptions();
  990. //this.loadSelectEditor(callback);
  991. this.loadEditor(callback);
  992. },
  993. loadOptions: function(){
  994. var html = "<table cellpadding='0' cellspacing='0' style='height:30px'><tr>";
  995. html += "<td style='padding: 0 5px'>"+this.lp.jpqlType+"</td>";
  996. html += "<td style='padding: 0 5px'><select><option value='select'>select</option><option value='update'>update</option><option value='delete'>delete</option></select></td>";
  997. html += "<td style='padding: 0 5px'>"+this.lp.jpqlFromResult+"</td>";
  998. html += "<td style='padding: 0 5px'><input type='number' value='1'/></td>";
  999. html += "<td style='padding: 0 5px'>"+this.lp.jpqlMaxResult+"</td>";
  1000. html += "<td style='padding: 0 5px'><input type='number' value='50'/></td>";
  1001. // html += "<td style='padding: 0 5px'>"+this.lp.jpqlSelectTitle+"</td>";
  1002. // html += "<td style='padding: 0 5px'><input readonly type='text' value='"+this.select+"'/></td>";
  1003. // html += "<td style='padding: 0 5px'>"+this.lp.inputWhere+"</td>";
  1004. html += "</tr></table>";
  1005. this.optionArea.set("html", html);
  1006. this.jpqlTypeSelect = this.optionArea.getElement("select");
  1007. var inputs = this.optionArea.getElements("input");
  1008. this.fromResultInput = inputs[0];
  1009. this.maxResultsInput = inputs[1];
  1010. this.jpqlTypeSelect.setStyles(this.css.jpqlTypeSelect);
  1011. this.fromResultInput.setStyles(this.css.jpqlOptionInput);
  1012. this.maxResultsInput.setStyles(this.css.jpqlOptionInput);
  1013. this.jpqlTypeSelect.addEvent("change", function(){
  1014. var type = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value;
  1015. this.changeType(type, true);
  1016. }.bind(this));
  1017. // inputs[2].setStyles(this.css.jpqlOptionInput);
  1018. // inputs[2].setStyle("width", "200px")
  1019. },
  1020. // loadSelectEditor: function(){
  1021. // this.contentArea.set("text", this.select);
  1022. // o2.require("o2.widget.ace", function(){
  1023. // o2.widget.ace.load(function(){
  1024. // o2.load("../o2_lib/ace/src-min-noconflict/ext-static_highlight.js", function(){
  1025. // var highlight = ace.require("ace/ext/static_highlight");
  1026. // highlight(this.contentArea, {mode: "ace/mode/jql", theme: "ace/theme/tomorrow", "fontSize": 16});
  1027. // }.bind(this));
  1028. // }.bind(this));
  1029. // }.bind(this));
  1030. // },
  1031. loadEditor: function(callback){
  1032. o2.require("o2.widget.JavascriptEditor", function(){
  1033. this.editor = new o2.widget.JavascriptEditor(this.contentWhereArea, {"title": "JPQL", "option": {"mode": "sql"}});
  1034. this.editor.load(function(){
  1035. this.editor.addEditorEvent("change", function(){
  1036. this.checkJpqlType();
  1037. }.bind(this));
  1038. // this.editor.editor.on("change", function(){
  1039. // this.checkJpqlType();
  1040. // }.bind(this));
  1041. if (callback) callback();
  1042. }.bind(this));
  1043. }.bind(this), false);
  1044. },
  1045. checkJpqlType: function(){
  1046. var str = this.editor.editor.getValue();
  1047. var jpql_select = /^select/i;
  1048. var jpql_update = /^update/i;
  1049. var jpql_delete = /^delete/i;
  1050. if (jpql_select.test(str)) return this.changeType("select");
  1051. if (jpql_update.test(str)) return this.changeType("update");
  1052. if (jpql_delete.test(str)) return this.changeType("delete");
  1053. },
  1054. changeType: function(type, force){
  1055. if (type != this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value || force){
  1056. for (var i=0; i<this.jpqlTypeSelect.options.length; i++){
  1057. if (this.jpqlTypeSelect.options[i].value==type){
  1058. this.jpqlTypeSelect.options[i].set("selected", true);
  1059. break;
  1060. }
  1061. }
  1062. if (type!="select"){
  1063. var tds = this.optionArea.getElements("td");
  1064. tds[2].hide();
  1065. tds[3].hide();
  1066. tds[4].hide();
  1067. tds[5].hide();
  1068. }else{
  1069. var tds = this.optionArea.getElements("td");
  1070. tds[2].show();
  1071. tds[3].show();
  1072. tds[4].show();
  1073. tds[5].show();
  1074. }
  1075. }
  1076. },
  1077. setJpql: function(type, jpql, firstResult, maxResults){
  1078. if (this.editor){
  1079. if (this.editor.editor) this.editor.editor.setValue(jpql);
  1080. }
  1081. if (this.jpqlTypeSelect){
  1082. for (var i=0; i<this.jpqlTypeSelect.options.length; i++){
  1083. if (this.jpqlTypeSelect.options[i].value==type.toString().toLowerCase()){
  1084. this.jpqlTypeSelect.options[i].set("selected", true);
  1085. break;
  1086. }
  1087. }
  1088. }
  1089. if (this.fromResultInput) this.fromResultInput.set("value", firstResult);
  1090. if (this.maxResultsInput) this.maxResultsInput.set("value", maxResults);
  1091. },
  1092. getJpql: function(){
  1093. var jpql = this.editor.editor.getValue();
  1094. var type = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].get("value");
  1095. var fromResult = this.fromResultInput.get("value");
  1096. var maxResults = this.maxResultsInput.get("value");
  1097. return {
  1098. "data": jpql,
  1099. "type": type,
  1100. "firstResult": fromResult.toInt(),
  1101. "maxResults": maxResults.toInt()
  1102. }
  1103. }
  1104. });