Table.js 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  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.newLineJsonError, "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. //仅允许数字字母下划线
  261. if(!(/^\w+$/).test(name)){
  262. this.designer.notice(this.designer.lp.errorName, "error");
  263. return false;
  264. }
  265. if((/^[0-9]/).test(name.substr(0, 1))){
  266. this.designer.notice(this.designer.lp.errorName, "error");
  267. return false;
  268. }
  269. if((/^[A-Z]/).test(name.substr(0, 1))){
  270. this.designer.notice(this.designer.lp.errorName, "error");
  271. return false;
  272. }
  273. var keywords = ["string","int","integer","long","float","double","boolean"];
  274. if( keywords.contains((name||"").toLowerCase()) ){
  275. this.designer.notice(this.designer.lp.nameUseKeywork.replace("{key}", keywords.join(",")), "error");
  276. return false;
  277. }
  278. return true;
  279. },
  280. checkAddColumn: function(){
  281. var name = this.columnListEditNameInput.get("value");
  282. var description = this.columnListEditDescriptionInput.get("value");
  283. var type = this.columnListEditTypeSelect.options[this.columnListEditTypeSelect.selectedIndex].value;
  284. if (name && this.checkColumnName(name)){
  285. if (!this.json.draftData.fieldList) this.json.draftData.fieldList = [];
  286. var columnNames = this.json.draftData.fieldList.map(function(item){ return item.name; });
  287. if ((columnNames.indexOf(name)!=-1)){
  288. this.designer.notice(this.designer.lp.duplicateName, "error");
  289. this.columnListEditNameInput.focus();
  290. }else{
  291. var o = {
  292. "name": name,
  293. "description": description,
  294. "type": type
  295. }
  296. this.addColumn(o);
  297. this.columnListEditNameInput.set("value", "");
  298. this.columnListEditDescriptionInput.set("value", "");
  299. this.columnListEditTypeSelect.selectedIndex = 0;
  300. this.columnListEditNameInput.focus();
  301. }
  302. }
  303. },
  304. showProperty: function(){
  305. if (!this.property){
  306. this.property = new MWF.xApplication.query.TableDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  307. "path": this.options.propertyPath,
  308. "onPostLoad": function(){
  309. this.property.show();
  310. }.bind(this)
  311. });
  312. this.property.load();
  313. }else{
  314. this.property.show();
  315. }
  316. },
  317. addColumn: function(data){
  318. var json;
  319. if (!data){
  320. if (!this.json.draftData.fieldList) this.json.draftData.fieldList = [];
  321. var columnNames = this.json.draftData.fieldList.map(function(item){ return item.name; });
  322. var name = "column";
  323. var i=1;
  324. while(columnNames.indexOf(name)!=-1){
  325. name = "column"+i;
  326. i++;
  327. }
  328. json = {
  329. "name": name,
  330. "type":"string",
  331. "description": this.designer.lp.newColumn
  332. };
  333. }else{
  334. json = data;
  335. }
  336. this.json.draftData.fieldList.push(json);
  337. var column = new MWF.xApplication.query.TableDesigner.Table.Column(json, this);
  338. this.items.push(column);
  339. column.selected();
  340. if (this.viewContentTableNode){
  341. var trs = this.viewContentTableNode.getElements("tr");
  342. trs.each(function(tr){
  343. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  344. }.bind(this));
  345. //this.setContentColumnWidth();
  346. }
  347. this.setViewWidth();
  348. this.addColumnNode.scrollIntoView(false);
  349. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  350. },
  351. setViewWidth: function(){
  352. debugger;
  353. this.viewAreaNode.setStyle("width", "auto");
  354. this.viewTitleNode.setStyle("width", "auto");
  355. var s1 = this.viewTitleTableNode.getSize();
  356. var s2 = this.refreshNode.getSize();
  357. var s3 = this.addColumnNode.getSize();
  358. var width = s1.x+ (s2.x || 30) + ( s2.x || 30 );
  359. var size = this.areaNode.getSize();
  360. if (width>size.x){
  361. this.viewTitleNode.setStyle("width", ""+width+"px");
  362. this.viewAreaNode.setStyle("width", ""+width+"px");
  363. }else{
  364. this.viewTitleNode.setStyle("width", ""+size.x+"px");
  365. this.viewAreaNode.setStyle("width", ""+size.x+"px");
  366. }
  367. this.setContentColumnWidth();
  368. this.setContentHeight();
  369. },
  370. loadViewColumns: function(){
  371. if (this.json.draftData.fieldList) {
  372. this.json.draftData.fieldList.each(function (json) {
  373. this.items.push(new MWF.xApplication.query.TableDesigner.Table.Column(json, this));
  374. }.bind(this));
  375. }
  376. },
  377. saveSilence: function(callback){
  378. debugger;
  379. if (!this.data.name){
  380. this.designer.notice(this.designer.lp.inputTableName, "error");
  381. return false;
  382. }
  383. if( this.data.status !== "build" ){
  384. var reg = /^[A-Za-z]/;
  385. if( !reg.test(this.data.name) ){
  386. this.designer.notice(this.designer.lp.tableNameNotStartWithLetter, "error");
  387. return false;
  388. }
  389. var reg2 = /^[A-Za-z0-9]+$/;
  390. if( !reg2.test(this.data.name) ){
  391. this.designer.notice(this.designer.lp.tableNameNotBeLetterAndNumber, "error");
  392. return false;
  393. }
  394. }
  395. if (!this.json.draftData.fieldList.length){
  396. this.designer.notice(this.designer.lp.errorFieldList, "error");
  397. return false;
  398. }
  399. this.designer.actions.saveTable(this.data, function(json){
  400. this.data.id = json.data.id;
  401. if (this.lisNode) {
  402. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  403. }
  404. this.checkToolbars();
  405. if (callback) callback();
  406. }.bind(this));
  407. },
  408. save: function(callback){
  409. debugger;
  410. if (!this.data.name){
  411. this.designer.notice(this.designer.lp.inputTableName, "error");
  412. return false;
  413. }
  414. if( this.data.status !== "build" ){
  415. var reg = /^[A-Za-z]/;
  416. if( !reg.test(this.data.name) ){
  417. this.designer.notice(this.designer.lp.tableNameNotStartWithLetter, "error");
  418. return false;
  419. }
  420. if( this.data.alias && !reg.test(this.data.alias) ){
  421. this.designer.notice(this.designer.lp.tableAliasNotStartWithLetter, "error");
  422. return false;
  423. }
  424. var reg2 = /^[A-Za-z0-9]+$/;
  425. if( !reg2.test(this.data.name) ){
  426. this.designer.notice(this.designer.lp.tableNameNotBeLetterAndNumber, "error");
  427. return false;
  428. }
  429. if( this.data.alias && !reg2.test(this.data.alias) ){
  430. this.designer.notice(this.designer.lp.tableAliasNotBeLetterAndNumber, "error");
  431. return false;
  432. }
  433. }
  434. if (!this.json.draftData.fieldList.length){
  435. this.designer.notice(this.designer.lp.errorFieldList, "error");
  436. return false;
  437. }
  438. this.designer.actions.saveTable(this.data, function(json){
  439. this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  440. this.data.id = json.data.id;
  441. if (this.lisNode) {
  442. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  443. }
  444. this.checkToolbars();
  445. if (callback) callback();
  446. }.bind(this));
  447. },
  448. unSelected: function(){
  449. this.currentSelectedModule = null;
  450. return true;
  451. },
  452. statusBuild: function(e){
  453. var _self = this;
  454. if (!e) e = this.node;
  455. this.designer.confirm("warn", e, MWF.APPDTBD.LP.statusBuildTitle, MWF.APPDTBD.LP.statusBuildInfor, 420, 120, function(){
  456. _self.designer.actions.statusBuild(_self.data.id, function(json){
  457. debugger;
  458. this.designer.notice(this.designer.lp.statusBuild_success, "success", this.node, {"x": "left", "y": "bottom"});
  459. this.designer.actions.getTable(json.data.id, function(tjson){
  460. this.data.status = tjson.data.status;
  461. this.checkToolbars();
  462. }.bind(this));
  463. }.bind(_self));
  464. this.close();
  465. }, function(){
  466. this.close();
  467. }, null);
  468. },
  469. statusDraft: function(e){
  470. var _self = this;
  471. if (!e) e = this.node;
  472. this.designer.confirm("warn", e, MWF.APPDTBD.LP.statusDraftTitle, {"html": MWF.APPDTBD.LP.statusDraftInfor}, 450, 120, function(){
  473. this.close();
  474. _self.designer.confirm("warn", e, MWF.APPDTBD.LP.statusDraftTitle, {"html": MWF.APPDTBD.LP.statusDraftInforAgain}, 480, 120, function(){
  475. _self.designer.actions.statusDraft(_self.data.id, function(json){
  476. this.designer.notice(this.designer.lp.statusDraft_success, "success", this.node, {"x": "left", "y": "bottom"});
  477. this.designer.actions.getTable(json.data.id, function(tjson){
  478. this.data.status = tjson.data.status;
  479. this.checkToolbars();
  480. }.bind(this));
  481. }.bind(_self));
  482. this.close();
  483. }, function(){
  484. this.close();
  485. }, null);
  486. }, function(){
  487. this.close();
  488. }, null);
  489. },
  490. buildAllView: function(e){
  491. var _self = this;
  492. if (!e) e = this.node;
  493. this.designer.confirm("warn", e, MWF.APPDTBD.LP.buildAllViewTitle, {
  494. "html": MWF.APPDTBD.LP.buildAllViewInfor
  495. }, 480, 120, function(){
  496. _self.designer.actions.buildAllTable(function(json){
  497. this.designer.notice(this.designer.lp.buildAllView_success, "success", this.node, {"x": "left", "y": "bottom"});
  498. }.bind(_self));
  499. this.close();
  500. }, function(){
  501. this.close();
  502. }, null);
  503. },
  504. bulidCurrentApp: function(e){
  505. MWF.require("MWF.widget.Mask", null, false);
  506. var _self = this;
  507. if (!e) e = this.node;
  508. this.designer.actions.listTable(this.designer.application.id, function (json) {
  509. var html = "";
  510. if( json.data.length === 0 ){
  511. this.designer.notice(this.designer.lp.buildNoTableError, "info", this.node, {"x": "left", "y": "bottom"});
  512. return;
  513. }else{
  514. var bulidStr = "";
  515. var draftStr = "";
  516. debugger;
  517. json.data.each(function(table){
  518. if( table.status === "build" ){
  519. bulidStr += "<div style='line-height: 24px;padding-left: 10px;'>" + table.name + "</div>";
  520. }else{
  521. draftStr += "<div style='line-height: 24px;padding-left: 10px;'>" + table.name + "</div>";
  522. }
  523. }.bind(this));
  524. if( bulidStr ){
  525. var h1 = MWF.APPDTBD.LP.buildCurrentAppInfor;
  526. var h2 = "<div style='min-height: 70px; max-height: 150px; width: 400px; overflow:auto; font-size: 12px;'>"+bulidStr+"</div>";
  527. html += h1.replace("{buildlist}", h2);
  528. }
  529. if( draftStr ){
  530. var h3 = MWF.APPDTBD.LP.unbuildCurrentAppInfor;
  531. var h4 = "<div style='min-height: 70px; max-height: 150pxpx; width: 400px; overflow:auto; font-size: 12px;'>"+draftStr+"</div>";
  532. html += h3.replace("{draftList}", h4);
  533. }
  534. html += MWF.APPDTBD.LP.buildCurrentAppQuection;
  535. }
  536. this.designer.confirm("warn", e, MWF.APPDTBD.LP.buildCurrentAppTitle, {
  537. "html": html
  538. }, 480, 120, function(){
  539. _self.mask = new MWF.widget.Mask({"style": "desktop", "html": MWF.APPDTBD.LP.building});
  540. _self.mask.loadNode(_self.designer.content);
  541. this.close();
  542. o2.Actions.load("x_query_assemble_designer").TableAction.buildDispatch( _self.data.application , function(json){
  543. _self.designer.notice(MWF.APPDTBD.LP.buildCurrentApp_success, "success", _self.node, {"x": "left", "y": "bottom"});
  544. _self.mask.hide();
  545. _self.designer.refresh();
  546. });
  547. }, function(){
  548. this.close();
  549. }, null);
  550. }.bind(this));
  551. },
  552. tableClear: function(e){
  553. var _self = this;
  554. if (!e) e = this.node;
  555. this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableClearTitle, MWF.APPDTBD.LP.tableClearInfo, 480, 120, function(){
  556. _self.designer.actions.deleteAllRow(_self.data.id,function(json){
  557. this.designer.notice(this.designer.lp.tableClear_success, "success", this.node, {"x": "left", "y": "bottom"});
  558. }.bind(_self));
  559. this.close();
  560. }, function(){
  561. this.close();
  562. }, null);
  563. },
  564. tableImplode: function(e){
  565. var _self = this;
  566. if (!e) e = this.node;
  567. this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableImplodeTitle, MWF.APPDTBD.LP.tableImplodeInfo, 480, 120, function(){
  568. _self.implodeLocal();
  569. this.close();
  570. }, function(){
  571. this.close();
  572. }, null);
  573. },
  574. tableExcelImplode: function(e){
  575. var _self = this;
  576. if (!e) e = this.node;
  577. this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableExcelImplodeTitle, MWF.APPDTBD.LP.tableExcelImplodeInfo, 480, 120, function(){
  578. _self.implodeExcelLocal();
  579. this.close();
  580. }, function(){
  581. this.close();
  582. }, null);
  583. },
  584. implodeExcelLocal : function (){
  585. var ExcelUtils = new MWF.xApplication.query.TableDesigner.Table.ExcelUtils();
  586. var uploadFileAreaNode = new Element("div");
  587. var html = "<input name=\"file\" type=\"file\" accept=\"*\" />";
  588. uploadFileAreaNode.set("html", html);
  589. var fileUploadNode = uploadFileAreaNode.getFirst();
  590. fileUploadNode.addEvent("change", function () {
  591. var files = fileNode.files;
  592. if (files.length) {
  593. var file = files.item(0);
  594. //第三个参数是日期的列
  595. ExcelUtils.import( file, function(json){
  596. console.log(JSON.stringify(json));
  597. this.designer.actions.rowSave(this.data.id,json[0],function(json){
  598. this.designer.notice(this.designer.lp.tableImplode_success, "success", this.node, {"x": "left", "y": "bottom"});
  599. }.bind(this));
  600. }.bind(this) );
  601. }
  602. }.bind(this));
  603. var fileNode = uploadFileAreaNode.getFirst();
  604. fileNode.click();
  605. },
  606. implodeLocal: function(){
  607. if (!this.uploadFileAreaNode){
  608. this.uploadFileAreaNode = new Element("div");
  609. var html = "<input name=\"file\" type=\"file\" accept=\".json\"/>";
  610. this.uploadFileAreaNode.set("html", html);
  611. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  612. this.fileUploadNode.addEvent("change", this.implodeLocalFile.bind(this));
  613. }else{
  614. if (this.fileUploadNode) this.fileUploadNode.destroy();
  615. this.uploadFileAreaNode.empty();
  616. var html = "<input name=\"file\" type=\"file\" accept=\".json\"/>";
  617. this.uploadFileAreaNode.set("html", html);
  618. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  619. this.fileUploadNode.addEvent("change", this.implodeLocalFile.bind(this));
  620. }
  621. this.fileUploadNode.click();
  622. },
  623. implodeLocalFile: function(){
  624. var files = this.fileUploadNode.files;
  625. if (files.length){
  626. var file = files[0];
  627. var reader = new FileReader();
  628. reader.readAsText(file);
  629. var _self = this;
  630. reader.onload = function(){
  631. var data = JSON.parse(this.result);
  632. _self.designer.actions.rowSave(_self.data.id,data,function(json){
  633. this.designer.notice(this.designer.lp.tableImplode_success, "success", this.node, {"x": "left", "y": "bottom"});
  634. }.bind(_self));
  635. };
  636. }
  637. },
  638. tableExplode: function(e){
  639. var _self = this;
  640. if (!e) e = this.node;
  641. this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableExplodeTitle, MWF.APPDTBD.LP.tableExplodeInfo, 480, 120, function(){
  642. var url = _self.designer.actions.action.address + _self.designer.actions.action.actions.exportRow.uri
  643. url = url.replace("{tableFlag}",_self.data.id);
  644. url = url.replace("{count}",1000);
  645. window.open(o2.filterUrl(url))
  646. this.close();
  647. }, function(){
  648. this.close();
  649. }, null);
  650. },
  651. tableExcelExplode: function(e){
  652. var ExcelUtils = new MWF.xApplication.query.TableDesigner.Table.ExcelUtils();
  653. var _self = this;
  654. if (!e) e = this.node;
  655. this.designer.confirm("warn", e, MWF.APPDTBD.LP.tableExcelExplodeTitle, MWF.APPDTBD.LP.tableExplodeInfo, 480, 120, function(){
  656. var fieldList = JSON.parse(_self.view.data.data).fieldList;
  657. var fieldArr = [];
  658. var resultArr = [];
  659. fieldList.each(function (field){
  660. fieldArr.push(field.name);
  661. resultArr.push("o." + field.name);
  662. })
  663. var array = [fieldArr];
  664. var jpql = {
  665. "data": "select " + resultArr.join() + " from " + _self.data.name + " o",
  666. "type": "select",
  667. "firstResult": 0,
  668. "maxResults": 1000
  669. }
  670. _self.designer.actions.executeJpql(_self.data.id, jpql, function(json){
  671. json.data.each(function (d){
  672. var f = [];
  673. if(o2.typeOf(json.data[0])==="string"){
  674. f = [d];
  675. }else {
  676. d.each(function (dd){
  677. if(!dd){
  678. f.push("");
  679. }else {
  680. f.push(dd);
  681. }
  682. })
  683. }
  684. array.push(f);
  685. })
  686. ExcelUtils.export(array, MWF.APPDTBD.LP.exportExcelFileName +(new Date).format("db"));
  687. }.bind(this));
  688. this.close();
  689. }, function(){
  690. this.close();
  691. }, null);
  692. },
  693. setContentHeight: function(){
  694. var size = this.areaNode.getSize();
  695. var titleSize = this.viewTitleNode.getSize()
  696. debugger;
  697. var height = size.y-titleSize.y-2;
  698. // if (this.jpqlAreaNode){
  699. // var jpqlSize = this.jpqlAreaNode.getComputedSize();
  700. // height = height - jpqlSize.totalHeight;
  701. // }
  702. this.viewContentScrollNode.setStyle("height", height);
  703. var contentSize = this.viewContentBodyNode.getSize();
  704. if (height<contentSize.y) height = contentSize.y+10;
  705. this.viewContentNode.setStyle("height", height);
  706. this.contentLeftNode.setStyle("height", height);
  707. this.contentRightNode.setStyle("height", height);
  708. //this.viewContentBodyNode.setStyle("min-height", height);
  709. },
  710. createJpqlAreaNode: function(callback){
  711. if (!this.jpqlAreaNode){
  712. this.viewTitleNode.setStyles(this.css.viewTitleNode_run);
  713. this.refreshNode.setStyles(this.css.tableRunNode_run);
  714. this.addColumnNode.setStyles(this.css.addColumnNode_run);
  715. this.jpqlAreaNode = new Element("div", {
  716. "styles": this.css.jpqlAreaNode
  717. }).inject(this.viewTitleContentNode, "top");
  718. this.jpqlEditor = new MWF.xApplication.query.TableDesigner.Table.JPQLRunner(this.jpqlAreaNode, this.refreshNode, this);
  719. this.jpqlEditor.load(function(){
  720. this.jpqlEditor.setJpql("slect", "select o from "+this.data.name+" o", 0, 50);
  721. if (callback) callback();
  722. }.bind(this));
  723. this.setContentHeight();
  724. }else{
  725. if (callback) callback();
  726. }
  727. },
  728. runJpql: function(jpql){
  729. this.designer.actions.executeJpql(this.data.id, jpql, function(json){
  730. this.loadViewMask.hide();
  731. if (jpql.type!="select"){
  732. this.designer.notice(this.designer.lp.jpqlRunSuccess, "success");
  733. if (this.lastSelectJPQL) this.runJpql(this.lastSelectJPQL);
  734. }else{
  735. this.lastSelectJPQL = jpql;
  736. this.viewContentBodyNode.empty();
  737. this.viewContentTableNode = new Element("table", {
  738. "styles": this.css.viewContentTableNode,
  739. "border": "0px",
  740. "cellPadding": "0",
  741. "cellSpacing": "0"
  742. }).inject(this.viewContentBodyNode);
  743. if (json.data.length){
  744. json.data.each(function(line, idx){
  745. new MWF.xApplication.query.TableDesigner.Table.DataLine(line, this);
  746. }.bind(this));
  747. this.setContentColumnWidth();
  748. this.setContentHeight();
  749. }
  750. }
  751. }.bind(this), function(xhr, text, error){
  752. this.loadViewMask.hide();
  753. if (xhr.status!=0){
  754. var errorText = error;
  755. if (xhr){
  756. var json = JSON.decode(xhr.responseText);
  757. if (json){
  758. errorText = json.message.trim() || "request json error";
  759. }else{
  760. errorText = "request json error: "+xhr.responseText;
  761. }
  762. }
  763. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  764. }
  765. }.bind(this));
  766. },
  767. loadViewData: function(){
  768. if (this.data.buildSuccess){
  769. if (this.data.id){
  770. o2.require("o2.widget.Mask", null, false);
  771. this.loadViewMask = new o2.widget.Mask();
  772. this.loadViewMask.loadNode(this.viewAreaNode);
  773. this.createJpqlAreaNode(function(){
  774. var jpql = this.jpqlEditor.getJpql();
  775. this.runJpql(jpql);
  776. }.bind(this));
  777. }
  778. }
  779. }
  780. });
  781. MWF.xApplication.query.TableDesigner.Table.Column = new Class({
  782. Extends:MWF.xApplication.query.ViewDesigner.ViewBase.Column,
  783. initialize: function(json, view, next){
  784. this.propertyPath = "../x_component_query_TableDesigner/$Table/column.html";
  785. this.view = view;
  786. this.json = json;
  787. this.next = next;
  788. this.css = this.view.css;
  789. this.content = this.view.viewTitleTrNode;
  790. this.domListNode = this.view.domListNode;
  791. this.load();
  792. },
  793. createDomListItem: function(){
  794. //this.view.columnListEditTr;
  795. var idx = this.view.columnListTable.rows.length;
  796. this.listNode = this.view.columnListTable.insertRow(idx-1).setStyles(this.css.cloumnListNode);
  797. this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.name);
  798. this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.description);
  799. this.listNode.insertCell().setStyles(this.css.columnListTd).set("text", this.json.type);
  800. this.resetTextNode();
  801. },
  802. selected: function(){
  803. debugger;
  804. if (this.view.currentSelectedModule){
  805. if (this.view.currentSelectedModule==this){
  806. return true;
  807. }else{
  808. if (!this.view.currentSelectedModule.unSelected()) return true;
  809. }
  810. }
  811. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  812. this.listNode.setStyles(this.css.cloumnListNode_selected);
  813. // new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  814. // new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  815. try{
  816. this.node.scrollIntoView(false);
  817. this.listNode.scrollIntoView(false);
  818. }catch (e) {
  819. }
  820. this.view.currentSelectedModule = this;
  821. this.isSelected = true;
  822. this._showActions();
  823. this.showProperty();
  824. },
  825. unSelected: function(){
  826. if (this.checkColumn()){
  827. this.resetTextNode();
  828. this.view.currentSelectedModule = null;
  829. //this.node.setStyles(this.css.viewTitleColumnNode);
  830. if (this.isError){
  831. this.node.setStyles(this.css.viewTitleColumnNode_error)
  832. }else{
  833. this.node.setStyles(this.css.viewTitleColumnNode)
  834. }
  835. this.listNode.setStyles(this.css.cloumnListNode);
  836. this.isSelected = false;
  837. this._hideActions();
  838. this.hideProperty();
  839. return true;
  840. }
  841. return false;
  842. },
  843. checkColumn: function(){
  844. debugger;
  845. var tds = this.listNode.getElements("td");
  846. var nameInput = tds[0].getFirst();
  847. var descriptionInput = tds[1].getFirst();
  848. var select = tds[2].getFirst();
  849. if (nameInput && nameInput.tagName.toString().toLowerCase()=="input"){
  850. var name = tds[0].getFirst().get("value");
  851. var description = tds[1].getFirst().get("value");
  852. var type = tds[2].getFirst().options[tds[2].getFirst().selectedIndex].value;
  853. if (name && name!==this.json.name && this.view.checkColumnName(name)){
  854. if (!this.view.json.draftData.fieldList) this.view.json.draftData.fieldList = [];
  855. var columnNames = this.view.json.draftData.fieldList.map(function(item){ return item.name; });
  856. if ((columnNames.indexOf(name)!=-1)){
  857. this.view.designer.notice(this.view.designer.lp.duplicateName, "error");
  858. tds[0].getFirst().focus();
  859. return false;
  860. }else{
  861. this.json.name = name;
  862. this.json.description = description;
  863. this.json.type = type;
  864. return true;
  865. }
  866. }else if (name==this.json.name){
  867. this.json.name = name;
  868. this.json.description = description;
  869. this.json.type = type;
  870. return true;
  871. }else{
  872. this.view.designer.notice(this.view.designer.lp.inputName, "error");
  873. tds[0].getFirst().focus();
  874. return false;
  875. }
  876. }
  877. return true;
  878. },
  879. showProperty: function(){
  880. var tds = this.listNode.getElements("td");
  881. tds[0].empty();
  882. tds[1].empty();
  883. tds[2].empty();
  884. var nameInput = new Element("input", {"styles": this.css.columnListEditModifyInput, "value": this.json.name}).inject(tds[0]);
  885. var descriptionInput = new Element("input", {"styles": this.css.columnListEditModifyInput, "value": this.json.description}).inject(tds[1]);
  886. var select = new Element("select", {"styles": this.css.columnListEditModifySelect}).inject(tds[2]);
  887. //var options = '<option value=""></option>';
  888. var options = '<option '+((this.json.type=='string') ? 'selected' : '')+' value="string">string</option>';
  889. options += '<option '+((this.json.type=='integer') ? 'selected' : '')+' value="integer">integer</option>';
  890. options += '<option '+((this.json.type=='long') ? 'selected' : '')+' value="long">long</option>';
  891. options += '<option '+((this.json.type=='double') ? 'selected' : '')+' value="double">double</option>';
  892. options += '<option '+((this.json.type=='boolean') ? 'selected' : '')+' value="boolean">boolean</option>';
  893. options += '<option '+((this.json.type=='date') ? 'selected' : '')+' value="date">date</option>';
  894. options += '<option '+((this.json.type=='time') ? 'selected' : '')+' value="time">time</option>';
  895. options += '<option '+((this.json.type=='dateTime') ? 'selected' : '')+' value="dateTime">dateTime</option>';
  896. options += '<option '+((this.json.type=='stringList') ? 'selected' : '')+' value="stringList">stringList</option>';
  897. options += '<option '+((this.json.type=='integerList') ? 'selected' : '')+' value="integerList">integerList</option>';
  898. options += '<option '+((this.json.type=='longList') ? 'selected' : '')+' value="longList">longList</option>';
  899. options += '<option '+((this.json.type=='doubleList') ? 'selected' : '')+' value="doubleList">doubleList</option>';
  900. options += '<option '+((this.json.type=='booleanList') ? 'selected' : '')+' value="booleanList">booleanList</option>';
  901. options += '<option '+((this.json.type=='stringLob') ? 'selected' : '')+' value="stringLob">stringLob</option>';
  902. options += '<option '+((this.json.type=='stringMap') ? 'selected' : '')+' value="stringMap">stringMap</option>';
  903. select.set("html", options);
  904. nameInput.focus();
  905. select.addEvents({
  906. "change": function(e){
  907. if (this.checkColumn()) this.resetColumnTextNode();
  908. }.bind(this),
  909. "click": function(e){e.stopPropagation()}
  910. });
  911. nameInput.addEvents({
  912. "keydown": function(e){ if (e.code==13) if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  913. "change": function(e){ if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  914. "click": function(e){e.stopPropagation()}
  915. });
  916. descriptionInput.addEvents({
  917. "keydown": function(e){ if (e.code==13) if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  918. "change": function(e){ if (this.checkColumn()) this.resetColumnTextNode(); }.bind(this),
  919. "click": function(e){e.stopPropagation()}
  920. });
  921. },
  922. hideProperty: function(){
  923. var tds = this.listNode.getElements("td");
  924. tds[0].empty().set("text", this.json.name);
  925. tds[1].empty().set("text", this.json.description);
  926. tds[2].empty().set("text", this.json.type);
  927. },
  928. resetColumnTextNode: function(){
  929. var text = (this.json.description) ? this.json.name+"("+this.json.description+")" : this.json.name;
  930. this.textNode.set("text", text);
  931. },
  932. resetTextNode: function(){
  933. var text = (this.json.description) ? this.json.name+"("+this.json.description+")" : this.json.name;
  934. this.textNode.set("text", text);
  935. this.listNode.getFirst().set("text", this.json.name);
  936. this.listNode.getFirst().getNext().set("text", this.json.description);
  937. this.listNode.getLast().set("text", this.json.type);
  938. },
  939. "delete": function(e){
  940. var _self = this;
  941. if (!e) e = this.node;
  942. this.view.designer.confirm("warn", e, MWF.APPDTBD.LP.deleteColumnTitle, MWF.APPDTBD.LP.deleteColumn, 300, 120, function(){
  943. _self.destroy();
  944. this.close();
  945. }, function(){
  946. this.close();
  947. }, null);
  948. },
  949. destroy: function(){
  950. if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  951. if (this.actionArea) this.actionArea.destroy();
  952. if (this.listNode) this.listNode.destroy();
  953. if (this.property) this.property.propertyContent.destroy();
  954. var idx = this.view.items.indexOf(this);
  955. if (this.view.viewContentTableNode){
  956. var trs = this.view.viewContentTableNode.getElements("tr");
  957. trs.each(function(tr){
  958. tr.deleteCell(idx);
  959. }.bind(this));
  960. }
  961. if (this.view.json.draftData.fieldList) this.view.json.draftData.fieldList.erase(this.json);
  962. this.view.items.erase(this);
  963. this.areaNode.destroy();
  964. this.view.selected();
  965. this.view.setViewWidth();
  966. MWF.release(this);
  967. delete this;
  968. },
  969. addColumn: function(e, data){
  970. var json;
  971. if (!data){
  972. if (!this.view.json.draftData.fieldList) this.view.json.draftData.fieldList = [];
  973. var columnNames = this.view.json.draftData.fieldList.map(function(item){ return item.name; });
  974. var name = "column";
  975. var i=1;
  976. while(columnNames.indexOf(name)!=-1){
  977. name = "column"+i;
  978. i++;
  979. }
  980. json = {
  981. "name": name,
  982. "type":"string",
  983. "description": this.view.designer.lp.newColumn
  984. };
  985. }else{
  986. json = data;
  987. }
  988. this.view.json.draftData.fieldList.push(json);
  989. var column = new MWF.xApplication.query.TableDesigner.Table.Column(json, this.view, this);
  990. this.view.items.push(column);
  991. column.selected();
  992. if (this.view.viewContentTableNode){
  993. var trs = this.view.viewContentTableNode.getElements("tr");
  994. trs.each(function(tr){
  995. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  996. }.bind(this));
  997. //this.setContentColumnWidth();
  998. }
  999. this.view.setViewWidth();
  1000. this.view.addColumnNode.scrollIntoView(false);
  1001. },
  1002. _createIconAction: function(){
  1003. if (!this.actionArea){
  1004. this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
  1005. this._createAction({
  1006. "name": "add",
  1007. "icon": "add.png",
  1008. "event": "click",
  1009. "action": "addColumn",
  1010. "title": MWF.APPDVD.LP.action.add
  1011. });
  1012. this._createAction({
  1013. "name": "delete",
  1014. "icon": "delete1.png",
  1015. "event": "click",
  1016. "action": "delete",
  1017. "title": MWF.APPDVD.LP.action["delete"]
  1018. });
  1019. }
  1020. }
  1021. });
  1022. MWF.xApplication.query.TableDesigner.Table.DataLine = new Class({
  1023. initialize: function(data, table){
  1024. this.table = table;
  1025. this.lineData = data;
  1026. this.tableData = this.table.data;
  1027. this.tableContentTableNode = this.table.viewContentTableNode;
  1028. this.css = this.table.css;
  1029. this.load();
  1030. },
  1031. load: function(){
  1032. this.tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.tableContentTableNode);
  1033. this.tableData.draftData.fieldList.each(function(c, i){
  1034. var d = this.lineData[c.name];
  1035. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.tr);
  1036. td.store("field", c);
  1037. if (d!=undefined){
  1038. var t = o2.typeOf(d);
  1039. switch (t){
  1040. case "array":
  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. case "object":
  1045. td.store("data", d);
  1046. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>{...}</div>");
  1047. break;
  1048. default:
  1049. td.set("text", d);
  1050. }
  1051. }else{
  1052. switch (c.type){
  1053. case "stringList":
  1054. case "integerList":
  1055. case "longList":
  1056. case "doubleList":
  1057. case "booleanList":
  1058. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>[...]</div>");
  1059. break;
  1060. case "stringLob":
  1061. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>...</div>");
  1062. break;
  1063. case "stringMap":
  1064. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>{...}</div>");
  1065. break;
  1066. default:
  1067. td.set("text", "");
  1068. }
  1069. }
  1070. if (td.getFirst()){
  1071. td.getFirst().addEvent("click", function(e){
  1072. this.getFieldValue(e.target.getParent());
  1073. }.bind(this));
  1074. }
  1075. }.bind(this));
  1076. },
  1077. createObjectValueDlg: function(target){
  1078. var div = new Element("div", {"styles": {"margin": "10px 10px 0px 10px", "padding": "5px", "overflow": "hidden"}});
  1079. //var node = new Element("div", {"styles": {"margin": "10px 10px 0px 10px", "padding": "5px", "overflow": "hidden"}}).inject(div);
  1080. var p = target.getPosition(this.table.designer.content);
  1081. var s = target.getSize();
  1082. var size = this.table.designer.content.getSize();
  1083. var top = p.y;
  1084. var left = (p.x+s.x/2)-180;
  1085. if (top+400+10>size.y) top = size.y-400-10;
  1086. if (left+360+10>size.x) left = size.x-360-10;
  1087. if (top<10) top = 10;
  1088. if (left<10) left = 10;
  1089. var fromTop = p.y+s.y/2;
  1090. var fromLeft = p.x+s.x/2;
  1091. var options ={
  1092. "content": div,
  1093. "isTitle": false,
  1094. "container": this.table.designer.content,
  1095. "width": 360,
  1096. "height": 400,
  1097. "top": top,
  1098. "left": left,
  1099. "fromTop": fromTop,
  1100. "fromLeft": fromLeft,
  1101. "buttonList": [
  1102. {
  1103. "text": this.table.designer.lp.close,
  1104. "action": function(){dlg.close();}.bind(this)
  1105. }
  1106. ]
  1107. }
  1108. var dlg = o2.DL.open(options);
  1109. return dlg;
  1110. },
  1111. getFieldValue: function(node){
  1112. var field = node.retrieve("field")
  1113. this.loadFieldValue(field.name, function(){
  1114. var value = this.lineData[field.name];
  1115. var dlg = this.createObjectValueDlg(node);
  1116. var listNode = dlg.content.getFirst();
  1117. switch (field.type){
  1118. case "stringList":
  1119. case "integerList":
  1120. case "longList":
  1121. case "doubleList":
  1122. case "booleanList":
  1123. o2.require("o2.widget.Arraylist", function(){
  1124. var list = new o2.widget.Arraylist(listNode, {
  1125. "style": "table",
  1126. "title": field.name,
  1127. "isAdd": false,
  1128. "isDelete": false,
  1129. "isModify": false
  1130. });
  1131. list.load(value);
  1132. }.bind(this));
  1133. break;
  1134. case "stringLob":
  1135. td.set("html", "<div style='background-color:#dddddd; cursor: pointer;float: left; padding: 3px; font-size: 10px;'>...</div>");
  1136. break;
  1137. case "stringMap":
  1138. o2.require("o2.widget.Maplist", function(){
  1139. var list = new o2.widget.Maplist(listNode, {
  1140. "style": "table",
  1141. "title": field.name,
  1142. "isAdd": false,
  1143. "isDelete": false,
  1144. "isModify": false
  1145. });
  1146. list.load(value);
  1147. }.bind(this));
  1148. break;
  1149. }
  1150. }.bind(this));
  1151. },
  1152. loadFieldValue: function(name, callback){
  1153. if (name){
  1154. if (this.lineData[name]){
  1155. if (callback) callback();
  1156. }else{
  1157. this.table.designer.actions.getRow(this.tableData.id, this.lineData.id, function(json){
  1158. this.lineData = json.data;
  1159. if (callback) callback();
  1160. }.bind(this));
  1161. }
  1162. }
  1163. }
  1164. });
  1165. MWF.xApplication.query.TableDesigner.Table.JPQLRunner = new Class({
  1166. initialize: function(node, runNode, table){
  1167. this.table = table;
  1168. this.node = node;
  1169. this.runNode = runNode;
  1170. this.css = this.table.css;
  1171. this.lp = this.table.designer.lp;
  1172. //this.select = select;
  1173. },
  1174. load: function(callback){
  1175. this.optionArea = new Element("div", {"styles": this.css.jpqlOptionArea}).inject(this.node);
  1176. //this.contentArea = new Element("div", {"styles": this.css.jpqlContentArea}).inject(this.node);
  1177. this.contentWhereArea = new Element("div", {"styles": this.css.jpqlContentWhereArea}).inject(this.node);
  1178. this.loadOptions();
  1179. //this.loadSelectEditor(callback);
  1180. this.loadEditor(callback);
  1181. },
  1182. loadOptions: function(){
  1183. var html = "<table cellpadding='0' cellspacing='0' style='height:30px'><tr>";
  1184. html += "<td style='padding: 0 5px'>"+this.lp.jpqlType+"</td>";
  1185. html += "<td style='padding: 0 5px'><select><option value='select'>select</option><option value='update'>update</option><option value='delete'>delete</option></select></td>";
  1186. html += "<td style='padding: 0 5px'>"+this.lp.jpqlFromResult+"</td>";
  1187. html += "<td style='padding: 0 5px'><input type='number' value='1'/></td>";
  1188. html += "<td style='padding: 0 5px'>"+this.lp.jpqlMaxResult+"</td>";
  1189. html += "<td style='padding: 0 5px'><input type='number' value='50'/></td>";
  1190. // html += "<td style='padding: 0 5px'>"+this.lp.jpqlSelectTitle+"</td>";
  1191. // html += "<td style='padding: 0 5px'><input readonly type='text' value='"+this.select+"'/></td>";
  1192. // html += "<td style='padding: 0 5px'>"+this.lp.inputWhere+"</td>";
  1193. html += "</tr></table>";
  1194. this.optionArea.set("html", html);
  1195. this.jpqlTypeSelect = this.optionArea.getElement("select");
  1196. var inputs = this.optionArea.getElements("input");
  1197. this.fromResultInput = inputs[0];
  1198. this.maxResultsInput = inputs[1];
  1199. this.jpqlTypeSelect.setStyles(this.css.jpqlTypeSelect);
  1200. this.fromResultInput.setStyles(this.css.jpqlOptionInput);
  1201. this.maxResultsInput.setStyles(this.css.jpqlOptionInput);
  1202. this.jpqlTypeSelect.addEvent("change", function(){
  1203. var type = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value;
  1204. this.changeType(type, true);
  1205. }.bind(this));
  1206. // inputs[2].setStyles(this.css.jpqlOptionInput);
  1207. // inputs[2].setStyle("width", "200px")
  1208. },
  1209. // loadSelectEditor: function(){
  1210. // this.contentArea.set("text", this.select);
  1211. // o2.require("o2.widget.ace", function(){
  1212. // o2.widget.ace.load(function(){
  1213. // o2.load("../o2_lib/ace/src-min-noconflict/ext-static_highlight.js", function(){
  1214. // var highlight = ace.require("ace/ext/static_highlight");
  1215. // highlight(this.contentArea, {mode: "ace/mode/jql", theme: "ace/theme/tomorrow", "fontSize": 16});
  1216. // }.bind(this));
  1217. // }.bind(this));
  1218. // }.bind(this));
  1219. // },
  1220. loadEditor: function(callback){
  1221. o2.require("o2.widget.JavascriptEditor", function(){
  1222. this.editor = new o2.widget.JavascriptEditor(this.contentWhereArea, {"title": "JPQL", "option": {"mode": "sql"}});
  1223. this.editor.load(function(){
  1224. this.editor.addEditorEvent("change", function(){
  1225. this.checkJpqlType();
  1226. }.bind(this));
  1227. // this.editor.editor.on("change", function(){
  1228. // this.checkJpqlType();
  1229. // }.bind(this));
  1230. if (callback) callback();
  1231. }.bind(this));
  1232. }.bind(this), false);
  1233. },
  1234. checkJpqlType: function(){
  1235. var str = this.editor.editor.getValue();
  1236. var jpql_select = /^select/i;
  1237. var jpql_update = /^update/i;
  1238. var jpql_delete = /^delete/i;
  1239. if (jpql_select.test(str)) return this.changeType("select");
  1240. if (jpql_update.test(str)) return this.changeType("update");
  1241. if (jpql_delete.test(str)) return this.changeType("delete");
  1242. },
  1243. changeType: function(type, force){
  1244. if (type != this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value || force){
  1245. for (var i=0; i<this.jpqlTypeSelect.options.length; i++){
  1246. if (this.jpqlTypeSelect.options[i].value==type){
  1247. this.jpqlTypeSelect.options[i].set("selected", true);
  1248. break;
  1249. }
  1250. }
  1251. if (type!="select"){
  1252. var tds = this.optionArea.getElements("td");
  1253. tds[2].hide();
  1254. tds[3].hide();
  1255. tds[4].hide();
  1256. tds[5].hide();
  1257. }else{
  1258. var tds = this.optionArea.getElements("td");
  1259. tds[2].show();
  1260. tds[3].show();
  1261. tds[4].show();
  1262. tds[5].show();
  1263. }
  1264. }
  1265. },
  1266. setJpql: function(type, jpql, firstResult, maxResults){
  1267. if (this.editor){
  1268. if (this.editor.editor) this.editor.editor.setValue(jpql);
  1269. }
  1270. if (this.jpqlTypeSelect){
  1271. for (var i=0; i<this.jpqlTypeSelect.options.length; i++){
  1272. if (this.jpqlTypeSelect.options[i].value==type.toString().toLowerCase()){
  1273. this.jpqlTypeSelect.options[i].set("selected", true);
  1274. break;
  1275. }
  1276. }
  1277. }
  1278. if (this.fromResultInput) this.fromResultInput.set("value", firstResult);
  1279. if (this.maxResultsInput) this.maxResultsInput.set("value", maxResults);
  1280. },
  1281. getJpql: function(){
  1282. var jpql = this.editor.editor.getValue();
  1283. var type = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].get("value");
  1284. var fromResult = this.fromResultInput.get("value");
  1285. var maxResults = this.maxResultsInput.get("value");
  1286. return {
  1287. "data": jpql,
  1288. "type": type,
  1289. "firstResult": fromResult.toInt(),
  1290. "maxResults": maxResults.toInt()
  1291. }
  1292. }
  1293. });
  1294. MWF.xApplication.query.TableDesigner.Table.ExcelUtils = new Class({
  1295. _loadResource : function( callback ){
  1296. var uri = "/x_component_Template/framework/xlsx/xlsx.full.js";
  1297. var uri2 = "/x_component_Template/framework/xlsx/xlsxUtils.js";
  1298. COMMON.AjaxModule.load(uri, function(){
  1299. COMMON.AjaxModule.load(uri2, function(){
  1300. callback();
  1301. }.bind(this))
  1302. }.bind(this))
  1303. },
  1304. _openDownloadDialog: function(url, saveName){
  1305. /**
  1306. * 通用的打开下载对话框方法,没有测试过具体兼容性
  1307. * @param url 下载地址,也可以是一个blob对象,必选
  1308. * @param saveName 保存文件名,可选
  1309. */
  1310. if( Browser.name !== 'ie' ){
  1311. if(typeof url == 'object' && url instanceof Blob){
  1312. url = URL.createObjectURL(url); // 创建blob地址
  1313. }
  1314. var aLink = document.createElement('a');
  1315. aLink.href = url;
  1316. aLink.download = saveName || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
  1317. var event;
  1318. if(window.MouseEvent && typeOf( window.MouseEvent ) == "function" ) event = new MouseEvent('click');
  1319. else
  1320. {
  1321. event = document.createEvent('MouseEvents');
  1322. event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  1323. }
  1324. aLink.dispatchEvent(event);
  1325. }else{
  1326. window.navigator.msSaveBlob( url, saveName);
  1327. }
  1328. },
  1329. index2ColName : function( index ){
  1330. if (index < 0) {
  1331. return null;
  1332. }
  1333. var num = 65;// A的Unicode码
  1334. var colName = "";
  1335. do {
  1336. if (colName.length > 0)index--;
  1337. var remainder = index % 26;
  1338. colName = String.fromCharCode(remainder + num) + colName;
  1339. index = (index - remainder) / 26;
  1340. } while (index > 0);
  1341. return colName;
  1342. },
  1343. export : function(array, fileName){
  1344. this._loadResource( function(){
  1345. data = xlsxUtils.format2Sheet(array, 0, 0, null);//偏移3行按keyMap顺序转换
  1346. var wb = xlsxUtils.format2WB(data, "sheet1", undefined);
  1347. var wopts = { bookType: 'xlsx', bookSST: false, type: 'binary' };
  1348. var dataInfo = wb.Sheets[wb.SheetNames[0]];
  1349. var widthArray = [];
  1350. array[0].each( function( v, i ){
  1351. widthArray.push( {wpx: 100} );
  1352. // var at = String.fromCharCode(97 + i).toUpperCase();
  1353. var at = this.index2ColName(i);
  1354. var di = dataInfo[at+"1"];
  1355. // di.v = v;
  1356. // di.t = "s";
  1357. di.s = { //设置副标题样式
  1358. font: {
  1359. //name: '宋体',
  1360. sz: 12,
  1361. color: {rgb: "#FFFF0000"},
  1362. bold: true,
  1363. italic: false,
  1364. underline: false
  1365. },
  1366. alignment: {
  1367. horizontal: "center" ,
  1368. vertical: "center"
  1369. }
  1370. };
  1371. }.bind(this));
  1372. dataInfo['!cols'] = widthArray,
  1373. this._openDownloadDialog(xlsxUtils.format2Blob(wb), fileName +".xlsx");
  1374. }.bind(this))
  1375. },
  1376. import : function( file, callback, dateColArray ){
  1377. this._loadResource( function(){
  1378. var reader = new FileReader();
  1379. var workbook, data;
  1380. reader.onload = function (e) {
  1381. //var data = data.content;
  1382. if (!e) {
  1383. data = reader.content;
  1384. }else {
  1385. data = e.target.result;
  1386. }
  1387. workbook = XLSX.read(data, { type: 'binary' });
  1388. //wb.SheetNames[0]是获取Sheets中第一个Sheet的名字
  1389. //wb.Sheets[Sheet名]获取第一个Sheet的数据
  1390. var sheet = workbook.SheetNames[0];
  1391. var jsonList = [];
  1392. for (var sheet in workbook.Sheets) {
  1393. if (workbook.Sheets.hasOwnProperty(sheet)) {
  1394. fromTo = workbook.Sheets[sheet]['!ref'];
  1395. console.log(fromTo);
  1396. var json = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
  1397. console.log(JSON.stringify(json));
  1398. jsonList.push(json);
  1399. // break; // 如果只取第一张表,就取消注释这行
  1400. }
  1401. }
  1402. if(callback)callback(jsonList);
  1403. };
  1404. reader.readAsBinaryString(file);
  1405. })
  1406. }
  1407. });