Table.js 57 KB

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