GridImpl.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. package com.extUi.grid;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import com.sysmodel.XFormFactory;
  5. import com.sysmodel.listmodel.xmlmodel.impl.ActionButtonImpl;
  6. import com.sysmodel.listmodel.xmlmodel.impl.FormListImpl;
  7. import com.sysmodel.listmodel.xmlmodel.impl.ListFieldImpl;
  8. import com.sysmodel.listmodel.xmlmodel.impl.QueryFieldImpl;
  9. import com.sysmodel.xformmodel.importcontrol.DateControl;
  10. import com.sysmodel.xformmodel.importcontrol.SelectControl;
  11. public class GridImpl implements Gridable{
  12. public StringBuffer getGridButtonJs(String listid) {
  13. StringBuffer sb = new StringBuffer();
  14. FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
  15. ArrayList<ActionButtonImpl> listActions = formList.getListAction();
  16. ArrayList<QueryFieldImpl> queryFields = formList.getQueryFields();
  17. if (listActions.size() > 0 || queryFields.size() > 0) {
  18. sb.append(" tbar:[").append("\n");
  19. if (queryFields.size() > 0) {
  20. sb.append(" {text:'查询',").append("\n");
  21. sb.append(" tooltip:'查询过滤',").append("\n");
  22. sb.append(" iconCls:'add',").append("\n");
  23. sb.append(" onClick:function(){\n");
  24. sb.append(" qryWin.show(this);\n");
  25. sb.append(" qryForm.getForm().reset(); \n");
  26. sb.append(" }\n");
  27. sb.append(" },'-', \n");
  28. }
  29. if (listActions.size() > 0) {
  30. for (int i = 0; i < listActions.size(); i++) {
  31. ActionButtonImpl action = (ActionButtonImpl) listActions.get(i);
  32. if (action.getButtonName().equals("add")) {
  33. sb.append(" {text:'新增',").append("\n");
  34. sb.append(" tooltip:'添加一条纪录',").append("\n");
  35. sb.append(" iconCls:'add',").append("\n");
  36. sb.append(" onClick:function(){").append("\n");
  37. sb.append(" editWin.show(this);\n");
  38. sb.append(" editform.getForm().reset();\n");
  39. sb.append(" }").append("\n");
  40. sb.append(" },'-', \n");
  41. } else if (action.getButtonName().equals("edit")) {
  42. sb.append(" {text:'修改',").append("\n");
  43. sb.append(" tooltip:'修改一条纪录',").append("\n");
  44. sb.append(" iconCls:'option',").append("\n");
  45. sb.append(" onClick:function(){").append("\n");
  46. sb.append(" if(sm" + listid + ".getCount()==1){").append("\n");
  47. sb.append(" editWin.show(this);\n");
  48. sb.append(" editform.getForm().reset();\n");
  49. sb.append(" editform.getForm().loadRecord(sm" + listid
  50. + ".getSelected());\n");
  51. sb.append(" }else{ ").append("\n");
  52. sb.append(" Ext.MessageBox.alert('提示', '请选择一条记录!');").append("\n");
  53. sb.append(" }").append("\n");
  54. sb.append(" }").append("\n");
  55. sb.append(" },'-', \n");
  56. } else if (action.getButtonName().equals("delete")) {
  57. sb.append(" {text:'删除',").append("\n");
  58. sb.append(" tooltip:'删除选择的纪录',").append("\n");
  59. sb.append(" iconCls:'remove',").append("\n");
  60. sb.append(" handler: function(){").append("\n");
  61. sb.append(" Ext.MessageBox.confirm('Confirm', '你确定要删除吗?', doDelete);")
  62. .append("\n");
  63. sb.append(" }").append("\n");
  64. sb.append(" },'-', \n");
  65. }
  66. }
  67. }
  68. sb = new StringBuffer(sb.substring(0, sb.lastIndexOf(",'-',")));
  69. sb.append(" ],\n");
  70. }
  71. return sb;
  72. }
  73. public StringBuffer getGridJs(String listid) {
  74. StringBuffer sb = new StringBuffer();
  75. FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
  76. ArrayList<ListFieldImpl> listFields = formList.getQueryList().getlistFields();
  77. @SuppressWarnings("unused")
  78. ArrayList<ActionButtonImpl> listActions = formList.getListAction();
  79. @SuppressWarnings("unused")
  80. ArrayList<QueryFieldImpl> queryFields = formList.getQueryFields();
  81. sb.append("/**\n");
  82. sb.append(" * 显示数据列表和查询表单\n");
  83. sb.append(" */\n");
  84. sb.append("_this.showListGrid = function(obj) {\n");
  85. sb.append(this.getQureyFormJs(listid));
  86. sb.append("// 构造列表\n");
  87. sb.append("\n");
  88. sb.append("/**\n");
  89. sb.append(" * gird加载数据失败回调函数\n");
  90. sb.append(" */\n");
  91. sb.append("function feafailFn(response, options) {\n");
  92. sb.append("// alert(response.responseText)\n");
  93. sb.append("Ext.MessageBox.alert('提示', '数据加载失败!');\n");
  94. sb.append("}\n");
  95. sb.append("function feasucFn(response, options) {\n");
  96. sb.append("// alert(response.responseText)\n");
  97. sb.append("// Ext.MessageBox.alert('提示', '查询失败!');\n");
  98. sb.append("}\n");
  99. sb.append("// 构造数据源\n");
  100. sb.append("var ds = new Ext.data.Store({// 这是数据源\n");
  101. sb.append("baseParams : {\n");
  102. sb.append("listId : '");
  103. sb.append(formList.getListid());
  104. sb.append("'// listid\n");
  105. sb.append("},\n");
  106. sb.append("proxy : new Ext.data.HttpProxy({\n");
  107. sb.append("url : '../ws/crud/CRUDService/query/',\n");
  108. sb.append("method : 'POST',\n");
  109. sb.append("timeout : 15000,\n");
  110. sb.append("success : feasucFn,\n");
  111. sb.append("failure : feafailFn\n");
  112. sb.append("}),\n");
  113. sb.append("reader : new Ext.data.JsonReader({\n");
  114. sb.append("totalProperty : 'total',\n");
  115. sb.append("root : 'rows'\n");
  116. sb.append("}, [\n");
  117. this.getDataStore(formList.getQueryTables(), listFields, formList.getQueryList()
  118. .isHaveOrder(), sb);
  119. sb.append("])\n");
  120. sb.append("});\n");
  121. sb.append("\n");
  122. sb.append("// 构造列\n");
  123. sb.append("\n");
  124. sb.append("var sm = new Ext.grid.CheckboxSelectionModel();\n");
  125. sb.append("var colModel = new Ext.grid.ColumnModel([sm,\n");
  126. this.getColumnModel(listFields, formList.getQueryList().isHaveOrder(), sb);
  127. sb.append("]);\n");
  128. sb.append("\n");
  129. sb.append("// 构造Grid\n");
  130. sb.append("_this.listGrid = new Ext.grid.GridPanel({\n");
  131. sb.append("frame : true,\n");
  132. sb.append("sm : sm,\n");
  133. sb.append("title : '用户信息表',//grid标题,需要根据配置文件生成\n");
  134. sb.append("cm : colModel,\n");
  135. sb.append("tbar : [{\n");
  136. sb.append("text : '详细信息',\n");
  137. sb.append("id : 'info_880',\n");
  138. sb.append("tooltip : '显示详细信息',\n");
  139. sb.append("iconCls : 'info',\n");
  140. sb.append("onClick : function() {\n");
  141. sb.append("_this.showInfo();\n");
  142. sb.append("}\n");
  143. sb.append("}, '-', {\n");
  144. sb.append("text : '修改',\n");
  145. sb.append("id : 'edit_");
  146. sb.append(formList.getListid());
  147. sb.append("',//注意classid\n");
  148. sb.append("tooltip : '查询过滤',\n");
  149. sb.append("iconCls : 'add',\n");
  150. sb.append("onClick : function() {\n");
  151. sb.append("_this.showEditPanel();\n");
  152. sb.append("}\n");
  153. sb.append("}, '-', {\n");
  154. sb.append("text : '新增',\n");
  155. sb.append("id : 'add_");
  156. sb.append(formList.getListid());
  157. sb.append("',//注意classid\n");
  158. sb.append("tooltip : '添加一条纪录',\n");
  159. sb.append("iconCls : 'add',\n");
  160. sb.append("handler : function() {\n");
  161. sb.append("_this.showAddPanel();\n");
  162. sb.append("}\n");
  163. sb.append("}, '-', {\n");
  164. sb.append("text : '删除',\n");
  165. sb.append("tooltip : '删除选择的纪录',\n");
  166. sb.append("id : 'del_");
  167. sb.append(formList.getListid());
  168. sb.append("',//注意classid\n");
  169. sb.append("iconCls : 'remove',\n");
  170. sb.append("handler : function() {\n");
  171. sb.append("_this.showDelcon();\n");
  172. sb.append("}\n");
  173. sb.append("}],\n");
  174. if (formList.getQueryList().getPageSize() > 0) {
  175. sb.append("bbar : new Ext.PagingToolbar({\n");
  176. sb.append("beforePageText : '第',\n");
  177. sb.append("afterPageText : '页 ,共{0}页',\n");
  178. sb.append("pageSize : ");
  179. sb.append(formList.getQueryList().getPageSize());
  180. sb.append(",//根据配置文件读取页面大小\n");
  181. sb.append("store : ds,\n");
  182. sb.append("displayInfo : true,\n");
  183. sb.append("displayMsg : '当前记录 {0} - {1} ,共 {2}条',\n");
  184. sb.append("emptyMsg : '当前没有显示的纪录',\n");
  185. sb.append("prependButtons : true\n");
  186. sb.append("\n");
  187. sb.append("}),\n");
  188. }
  189. sb.append("autoWidth : true,\n");
  190. sb.append("autoScroll : true,\n");
  191. sb.append("bodyStyle : 'width:100%',\n");
  192. sb.append("height : 300,\n");
  193. sb.append("store : ds,\n");
  194. sb.append("viewConfig : {\n");
  195. sb.append("forceFit : true\n");
  196. sb.append("}\n");
  197. sb.append("});\n");
  198. sb.append("\n");
  199. sb.append("ds.load({\n");
  200. sb.append("params : {\n");
  201. sb.append("start : 0,\n");
  202. sb.append("limit : ");
  203. sb.append(formList.getQueryList().getPageSize());
  204. sb.append("\n");
  205. sb.append("}\n");
  206. sb.append("});\n");
  207. sb.append("\n");
  208. sb.append("// 构造容器-将此容器加入到框架中\n");
  209. sb.append("var panel = new Ext.Panel();\n");
  210. sb.append("panel.add(_this.queryFrom);\n");
  211. sb.append("panel.add(_this.listGrid);\n");
  212. sb.append("\n");
  213. sb.append("com.sinosoft.common.frameWork.FrameWork.changeCenter(panel);\n");
  214. sb.append("\n");
  215. // sb.append("com.sinosoft.system.right.Right.showUserButtns('m113');\n");
  216. sb.append("\n");
  217. sb.append("};\n");
  218. return sb;
  219. }
  220. public StringBuffer getGridRightMenuJs(String listid) {
  221. // TODO Auto-generated method stub
  222. return null;
  223. }
  224. public StringBuffer getQureyFormJs(String listid) {
  225. StringBuffer sb = new StringBuffer();
  226. FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
  227. ArrayList<QueryFieldImpl> queryFields = formList.getQueryFields();
  228. sb.append("// 构造查询表单\n");
  229. sb.append("_this.queryFrom = new Ext.form.FormPanel({\n");
  230. sb.append("labelWidth : 100,\n");
  231. sb.append("frame : true,\n");
  232. sb.append("autoScroll : true,\n");
  233. sb.append("autoHeight : true,\n");
  234. sb.append("bodyStyle : 'padding:5px 5px 0',\n");
  235. // sb.append("defaultType : 'textfield',\n");
  236. sb.append("items : [\n");
  237. sb.append("//根据配置循环生成查询表单字段\n");
  238. for (int i = 0; i < queryFields.size(); i++) {
  239. QueryFieldImpl queryField = (QueryFieldImpl) queryFields.get(i);
  240. if (queryField.getControlType().equals("text")) {
  241. sb.append(" {\n");
  242. sb.append(" xtype:'textfield',\n");
  243. sb.append(" fieldLabel: '" + queryField.getLabel() + "',\n");
  244. sb.append(" name: '" + queryField.getDataName().toUpperCase() + "_"
  245. + listid + "',\n");
  246. if (queryField.getValidate().isNeed()) {
  247. sb.append(" allowBlank:false\n");
  248. } else {
  249. sb.append(" allowBlank:true\n");
  250. }
  251. sb.append(" },\n");
  252. } else if (queryField.getControlType().equals("select")) {
  253. sb.append(" {\n");
  254. sb.append("xtype: 'combo' , \n");
  255. sb.append(" fieldLabel: '" + queryField.getLabel() + "', \n");
  256. sb.append(" hiddenName:'"
  257. + queryField.getDataName().toUpperCase() + "',\n");
  258. sb.append(" store: {\n");
  259. sb.append("url : '../ws/sys/constantService/getConstantByName',\n");
  260. sb.append("autoLoad : true,\n");
  261. sb.append("baseParams : {name:'");
  262. SelectControl selectControl = (SelectControl) queryField.getControl();
  263. sb.append(selectControl.getConstantName());
  264. sb.append("'},\n");
  265. sb.append("xtype: 'jsonstore' , \n");
  266. sb.append("root : 'constants',\n");
  267. sb.append("fields : ['name', 'value']\n");
  268. sb.append("},\n");
  269. sb.append(" valueField:'value',\n");
  270. sb.append(" displayField:'name',\n");
  271. sb.append(" typeAhead: true,\n");
  272. sb.append(" triggerAction: 'all',\n");
  273. sb.append(" selectOnFocus:true,\n");
  274. sb.append(" editable:false\n");
  275. sb.append(" } ,\n");
  276. } else if (queryField.getControlType().equals("date")) {
  277. sb.append(" {\n");
  278. sb.append(" fieldLabel: '" + queryField.getLabel() + "',\n");
  279. sb.append(" name: '" + queryField.getDataName().toUpperCase() + "_"
  280. + queryField.getClassid() + "', \n");
  281. sb.append(" anchor:'90%',\n");
  282. sb.append(" xtype:'datefield',\n");
  283. sb.append(" editable:false,\n");// 不能手工编辑输入日期值
  284. DateControl date = (DateControl) queryField.getControl();
  285. if (date.getFormat().equals("yyyy-MM-dd")) {
  286. sb.append(" altFormats: 'Y-m-d',\n");
  287. sb.append(" format:'Y-m-d',\n");
  288. } else if (date.getFormat().equals("yyyy-MM-dd HH")) {
  289. sb.append(" altFormats: 'Y-m-d H',\n");
  290. sb.append(" format:'Y-m-d H',\n");
  291. } else if (date.getFormat().equals("yyyy-MM-dd HH:mm")) {
  292. sb.append(" altFormats: 'Y-m-d H:i',\n");
  293. sb.append(" format:'Y-m-d H:i',\n");
  294. } else if (date.getFormat().equals("yyyy-MM-dd HH:mm:ss")) {
  295. sb.append(" altFormats: 'Y-m-d H:i:s',\n");
  296. sb.append(" format:'Y-m-d H:i:s',\n");
  297. }
  298. sb.append(" allowBlank:true\n");
  299. sb.append(" },\n");
  300. }
  301. }
  302. sb.reverse();
  303. sb.deleteCharAt(1);
  304. sb.reverse();
  305. sb.append("],\n");
  306. sb.append("\n");
  307. sb.append("buttons : [{\n");
  308. sb.append("text : '查询',\n");
  309. sb.append("handler : function() {\n");
  310. sb.append("_this.query();\n");
  311. sb.append("}\n");
  312. sb.append("}, {\n");
  313. sb.append("text : '重置',\n");
  314. sb.append("handler : function() {\n");
  315. sb.append("_this.queryFrom.getForm().reset();\n");
  316. sb.append("}\n");
  317. sb.append("}]\n");
  318. sb.append("});\n");
  319. return sb;
  320. }
  321. private void addItems(QueryFieldImpl queryField, StringBuffer sb, String listid) {
  322. if (queryField.getControlType().equals("text")) {
  323. sb.append(" {\n");
  324. sb.append(" xtype:'textfield',\n");
  325. sb.append(" fieldLabel: '" + queryField.getLabel() + "',\n");
  326. sb.append(" name: '" + queryField.getDataName().toUpperCase() + "_"
  327. + listid + "',\n");
  328. sb.append("anchor : '90%',\n");
  329. if (queryField.getValidate().isNeed()) {
  330. sb.append(" allowBlank:false\n");
  331. } else {
  332. sb.append(" allowBlank:true\n");
  333. }
  334. sb.append(" }\n");
  335. } else if (queryField.getControlType().equals("select")) {
  336. sb.append(" {\n");
  337. sb.append("xtype: 'combo' , \n");
  338. sb.append(" fieldLabel: '" + queryField.getLabel() + "', \n");
  339. sb.append(" hiddenName:'" + queryField.getDataName().toUpperCase()
  340. + "',\n");
  341. sb.append(" store: {\n");
  342. sb.append("url : '../ws/sys/constantService/getConstantByName',\n");
  343. sb.append("autoLoad : true,\n");
  344. sb.append("baseParams : {name:'");
  345. SelectControl selectControl = (SelectControl) queryField.getControl();
  346. sb.append(selectControl.getConstantName());
  347. sb.append("'},\n");
  348. sb.append("xtype: 'jsonstore' , \n");
  349. sb.append("root : 'constants',\n");
  350. sb.append("fields : ['name', 'value']\n");
  351. sb.append("},\n");
  352. sb.append(" valueField:'value',\n");
  353. sb.append(" displayField:'name',\n");
  354. sb.append(" typeAhead: true,\n");
  355. sb.append(" triggerAction: 'all',\n");
  356. sb.append(" selectOnFocus:true,\n");
  357. sb.append(" anchor : '90%',\n");
  358. sb.append(" editable:false\n");
  359. sb.append(" }\n");
  360. } else if (queryField.getControlType().equals("date")) {
  361. sb.append(" {\n");
  362. sb.append(" fieldLabel: '" + queryField.getLabel() + "',\n");
  363. sb.append(" name: '" + queryField.getDataName().toUpperCase() + "_"
  364. + queryField.getClassid() + "', \n");
  365. sb.append(" anchor:'90%',\n");
  366. sb.append(" xtype:'datefield',\n");
  367. sb.append(" editable:false,\n");// 不能手工编辑输入日期值
  368. DateControl date = (DateControl) queryField.getControl();
  369. if (date.getFormat().equals("yyyy-MM-dd")) {
  370. sb.append(" altFormats: 'Y-m-d',\n");
  371. sb.append(" format:'Y-m-d',\n");
  372. } else if (date.getFormat().equals("yyyy-MM-dd HH")) {
  373. sb.append(" altFormats: 'Y-m-d H',\n");
  374. sb.append(" format:'Y-m-d H',\n");
  375. } else if (date.getFormat().equals("yyyy-MM-dd HH:mm")) {
  376. sb.append(" altFormats: 'Y-m-d H:i',\n");
  377. sb.append(" format:'Y-m-d H:i',\n");
  378. } else if (date.getFormat().equals("yyyy-MM-dd HH:mm:ss")) {
  379. sb.append(" altFormats: 'Y-m-d H:i:s',\n");
  380. sb.append(" format:'Y-m-d H:i:s',\n");
  381. }
  382. sb.append(" allowBlank:true\n");
  383. sb.append(" }\n");
  384. }
  385. }
  386. /**
  387. * 构造查询FORM(2列)
  388. *
  389. * @param queryFields
  390. * @param sb
  391. */
  392. private void getFormItems(List<QueryFieldImpl> queryFields, StringBuffer sb, String listid) {
  393. if (null == queryFields || 0 == queryFields.size()) {
  394. return;
  395. } else if (1 == queryFields.size()) {
  396. this.addItems(queryFields.get(0), sb, listid);
  397. return;
  398. }
  399. for (int i = 0; i < queryFields.size(); i++) {
  400. if (0 == i % 2) {
  401. sb.append("{\n");
  402. sb.append("layout:'column',\n");
  403. sb.append("items:[\n");
  404. sb.append(" {\n");
  405. sb.append(" columnWidth:.5,\n");
  406. sb.append(" layout:'form',\n");
  407. sb.append(" labelAlign:'left',\n");
  408. sb.append(" items:[\n");
  409. this.addItems(queryFields.get(i), sb, listid);
  410. if (queryFields.size() == i + 1) {
  411. sb.append("]\n");
  412. sb.append("}\n");
  413. sb.append("]\n");
  414. sb.append("},\n");
  415. }
  416. } else {
  417. sb.append("]\n");
  418. sb.append("},\n");
  419. sb.append(" {\n");
  420. sb.append(" columnWidth:.5,\n");
  421. sb.append(" layout:'form',\n");
  422. sb.append(" labelAlign:'left',\n");
  423. sb.append(" items:[\n");
  424. this.addItems(queryFields.get(i), sb, listid);
  425. sb.append("]\n");
  426. sb.append("}\n");
  427. sb.append("]\n");
  428. sb.append("},\n");
  429. }
  430. }
  431. }
  432. private List<QueryFieldImpl> queryFieldFilter(List<QueryFieldImpl> queryFields) {
  433. List<QueryFieldImpl> list = new ArrayList<QueryFieldImpl>();
  434. for (QueryFieldImpl f : queryFields) {
  435. if ("is_del".equalsIgnoreCase(f.getDataName())
  436. || "updatedate".equalsIgnoreCase(f.getDataName())
  437. || "is_upload".equalsIgnoreCase(f.getDataName())) {
  438. continue;
  439. }
  440. list.add(f);
  441. }
  442. return list;
  443. }
  444. public StringBuffer getQureyForm2Col(String listid) {
  445. StringBuffer sb = new StringBuffer();
  446. FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
  447. List<QueryFieldImpl> queryFields = formList.getQueryFields();
  448. queryFields = this.queryFieldFilter(queryFields);
  449. sb.append("// 构造查询表单\n");
  450. sb.append("_this.queryFrom = new Ext.form.FormPanel({\n");
  451. sb.append("labelWidth : 100,\n");
  452. sb.append("frame : true,\n");
  453. sb.append("autoScroll : true,\n");
  454. sb.append("autoHeight : true,\n");
  455. sb.append("bodyStyle : 'padding:5px 5px 0',\n");
  456. sb.append("items : [\n");
  457. sb.append("//根据配置循环生成查询表单字段\n");
  458. this.getFormItems(queryFields, sb, listid);
  459. // sb = sb.replace(sb.length()-1, sb.length(), "");
  460. sb.reverse();
  461. sb.deleteCharAt(1);
  462. sb.reverse();
  463. sb.append("],\n");
  464. sb.append("\n");
  465. sb.append("buttons : [{\n");
  466. sb.append("text : '查询',\n");
  467. sb.append("handler : function() {\n");
  468. sb.append("_this.query();\n");
  469. sb.append("}\n");
  470. sb.append("}, {\n");
  471. sb.append("text : '重置',\n");
  472. sb.append("handler : function() {\n");
  473. sb.append("_this.queryFrom.getForm().reset();\n");
  474. sb.append("}\n");
  475. sb.append("}]\n");
  476. sb.append("});\n");
  477. return sb;
  478. }
  479. public StringBuffer getTpl(String listid) {
  480. StringBuffer sb = new StringBuffer();
  481. FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
  482. ArrayList<ListFieldImpl> listFields = formList.getQueryList().getlistFields();
  483. sb.append("var tpl = new Ext.XTemplate(\"");
  484. sb.append("<table class='info_table'>\",\n");
  485. for (int i = 0; i < listFields.size(); i += 2) {
  486. ListFieldImpl listFieldImpl = (ListFieldImpl) listFields.get(i);
  487. sb.append("\"<tr>\",\n");
  488. sb.append("\"<td>");
  489. sb.append(listFieldImpl.getLabel());
  490. sb.append("</td>\",\n");
  491. sb.append("\"<td>");
  492. sb.append("{");
  493. sb.append(listFieldImpl.getDataName().toUpperCase());
  494. sb.append("_");
  495. sb.append(listFieldImpl.getClassid());
  496. sb.append("}</td>\",\n");
  497. if (i + 1 < listFields.size()) {
  498. ListFieldImpl listFieldImpl2 = (ListFieldImpl) listFields.get(i + 1);
  499. sb.append("\"<td>");
  500. sb.append(listFieldImpl2.getLabel());
  501. sb.append("</td>\",\n");
  502. sb.append("\"<td>");
  503. sb.append("{");
  504. sb.append(listFieldImpl2.getDataName().toUpperCase());
  505. sb.append("_");
  506. sb.append(listFieldImpl2.getClassid());
  507. sb.append("}</td>\",\n");
  508. } else {
  509. sb.append("\"<td colspan=\'2\'>&nbsp;</td>\",\n");
  510. }
  511. sb.append("\"</tr>\",\n");
  512. }
  513. sb.append("\"</table>\"");
  514. sb.append(")");
  515. return sb;
  516. }
  517. private void getDataStore(List<String> tables, List<ListFieldImpl> listFields, boolean sort,
  518. StringBuffer sb) {
  519. // if(sort){
  520. // sb.append(" {name:").append("'ROWNUM_'},").append("\n");
  521. // }
  522. for (int i = 0; i < tables.size(); i++) {
  523. String classid = (String) tables.get(i);
  524. sb.append(" {name:").append("'FD_OBJECTID" + classid + "'},").append("\n");
  525. }
  526. for (int i = 0; i < listFields.size(); i++) {
  527. ListFieldImpl listFieldImpl = (ListFieldImpl) listFields.get(i);
  528. sb.append(" {name:")
  529. .append("'" + listFieldImpl.getDataName().toUpperCase() + "_"
  530. + listFieldImpl.getClassid() + "'},").append("\n");
  531. }
  532. sb.deleteCharAt(sb.lastIndexOf(","));
  533. }
  534. private void getColumnModel(List<ListFieldImpl> listFields, boolean sort, StringBuffer sb) {
  535. // if(sort){
  536. // sb.append(" {header:").append("'编号'").append(", dataIndex: 'ROWNUM_',width:35,sortable: true,type:'int'").append("},").append("\n");
  537. // }
  538. for (int i = 0; i < listFields.size(); i++) {
  539. ListFieldImpl listFieldImpl = (ListFieldImpl) listFields.get(i);
  540. sb.append(" {header:")
  541. .append("'" + listFieldImpl.getLabel() + "'")
  542. .append(", dataIndex: ")
  543. .append("'" + listFieldImpl.getDataName().toUpperCase() + "_"
  544. + listFieldImpl.getClassid() + "'").append(", sortable:")
  545. .append(" true},").append("\n");
  546. }
  547. sb.deleteCharAt(sb.lastIndexOf(","));
  548. }
  549. private List<ListFieldImpl> formListFilter(List<ListFieldImpl> listFields) {
  550. List<ListFieldImpl> list = new ArrayList<ListFieldImpl>();
  551. for (ListFieldImpl f : listFields) {
  552. if ("is_del".equalsIgnoreCase(f.getDataName())
  553. || "updatedate".equalsIgnoreCase(f.getDataName())
  554. || "is_upload".equalsIgnoreCase(f.getDataName())) {
  555. continue;
  556. }
  557. list.add(f);
  558. }
  559. return list;
  560. }
  561. public StringBuffer getGridJsForQuery(String listid) {
  562. StringBuffer sb = new StringBuffer();
  563. FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
  564. List<ListFieldImpl> listFields = formList.getQueryList().getlistFields();
  565. listFields = this.formListFilter(listFields);
  566. sb.append("/**\n");
  567. sb.append(" * 显示数据列表和查询表单\n");
  568. sb.append(" */\n");
  569. sb.append("_this.showListGrid = function(obj) {\n");
  570. sb.append(this.getQureyForm2Col(listid));
  571. sb.append("// 构造列表\n");
  572. sb.append("\n");
  573. sb.append("/**\n");
  574. sb.append(" * gird加载数据失败回调函数\n");
  575. sb.append(" */\n");
  576. sb.append("function feafailFn(response, options) {\n");
  577. sb.append("// alert(response.responseText)\n");
  578. sb.append("Ext.MessageBox.alert('提示', '数据加载失败!');\n");
  579. sb.append("}\n");
  580. sb.append("function feasucFn(response, options) {\n");
  581. sb.append("// alert(response.responseText)\n");
  582. sb.append("// Ext.MessageBox.alert('提示', '查询失败!');\n");
  583. sb.append("}\n");
  584. sb.append("// 构造数据源\n");
  585. sb.append("var ds = new Ext.data.Store({// 这是数据源\n");
  586. sb.append("baseParams : {\n");
  587. sb.append("listId : '");
  588. sb.append(formList.getListid());
  589. sb.append("'// listid\n");
  590. sb.append("},\n");
  591. sb.append("proxy : new Ext.data.HttpProxy({\n");
  592. sb.append("url : '../ws/crud/CRUDService/query/',\n");
  593. sb.append("method : 'POST',\n");
  594. sb.append("timeout : 15000,\n");
  595. sb.append("success : feasucFn,\n");
  596. sb.append("failure : feafailFn\n");
  597. sb.append("}),\n");
  598. sb.append("reader : new Ext.data.JsonReader({\n");
  599. sb.append("totalProperty : 'total',\n");
  600. sb.append("root : 'rows'\n");
  601. sb.append("}, [\n");
  602. this.getDataStore(formList.getQueryTables(), listFields, formList.getQueryList()
  603. .isHaveOrder(), sb);
  604. sb.append("])\n");
  605. sb.append("});\n");
  606. sb.append("\n");
  607. sb.append("// 构造列\n");
  608. sb.append("\n");
  609. sb.append("var sm = new Ext.grid.CheckboxSelectionModel();\n");
  610. sb.append("var colModel = new Ext.grid.ColumnModel([sm,\n");
  611. this.getColumnModel(listFields, formList.getQueryList().isHaveOrder(), sb);
  612. sb.append("]);\n");
  613. sb.append("\n");
  614. sb.append("// 构造Grid\n");
  615. sb.append("_this.listGrid = new Ext.grid.GridPanel({\n");
  616. sb.append("frame : true,\n");
  617. sb.append("sm : sm,\n");
  618. sb.append("title : '用户信息表',//grid标题,需要根据配置文件生成\n");
  619. sb.append("cm : colModel,\n");
  620. sb.append("tbar : [{\n");
  621. sb.append("text : '详细信息',\n");
  622. sb.append("id : 'info_880',\n");
  623. sb.append("tooltip : '显示详细信息',\n");
  624. sb.append("iconCls : 'info',\n");
  625. sb.append("onClick : function() {\n");
  626. sb.append("_this.showInfo();\n");
  627. sb.append("}\n");
  628. sb.append("}, '-', {\n");
  629. sb.append("text : '导出EXCEL',\n");
  630. sb.append("tooltip : '导出EXCEL',\n");
  631. sb.append("id : 'excel_");
  632. sb.append(formList.getListid());
  633. sb.append("',//注意classid\n");
  634. sb.append("iconCls : 'remove',\n");
  635. sb.append("handler : function() {\n");
  636. sb.append("_this.exportExcel(_this.listGrid);\n");
  637. sb.append("}\n");
  638. sb.append("}],\n");
  639. if (formList.getQueryList().getPageSize() > 0) {
  640. sb.append("bbar : new Ext.PagingToolbar({\n");
  641. sb.append("beforePageText : '第',\n");
  642. sb.append("afterPageText : '页 ,共{0}页',\n");
  643. sb.append("pageSize : ");
  644. sb.append(formList.getQueryList().getPageSize());
  645. sb.append(",//根据配置文件读取页面大小\n");
  646. sb.append("store : ds,\n");
  647. sb.append("displayInfo : true,\n");
  648. sb.append("displayMsg : '当前记录 {0} - {1} ,共 {2}条',\n");
  649. sb.append("emptyMsg : '当前没有显示的纪录',\n");
  650. sb.append("prependButtons : true\n");
  651. sb.append("\n");
  652. sb.append("}),\n");
  653. }
  654. sb.append("autoWidth : true,\n");
  655. sb.append("autoScroll : true,\n");
  656. sb.append("bodyStyle : 'width:100%',\n");
  657. sb.append("height : 300,\n");
  658. sb.append("store : ds,\n");
  659. sb.append("viewConfig : {\n");
  660. sb.append("forceFit : true\n");
  661. sb.append("}\n");
  662. sb.append("});\n");
  663. sb.append("\n");
  664. sb.append("ds.load({\n");
  665. sb.append("params : {\n");
  666. sb.append("start : 0,\n");
  667. sb.append("limit : ");
  668. sb.append(formList.getQueryList().getPageSize());
  669. sb.append("\n");
  670. sb.append("}\n");
  671. sb.append("});\n");
  672. sb.append("\n");
  673. sb.append("// 构造容器-将此容器加入到框架中\n");
  674. sb.append("var panel = new Ext.Panel();\n");
  675. sb.append("panel.add(_this.queryFrom);\n");
  676. sb.append("panel.add(_this.listGrid);\n");
  677. sb.append("\n");
  678. sb.append("com.sinosoft.common.frameWork.FrameWork.changeCenter(panel);\n");
  679. sb.append("\n");
  680. // sb.append("com.sinosoft.system.right.Right.showUserButtns('m113');\n");
  681. sb.append("\n");
  682. sb.append("};\n");
  683. return sb;
  684. }
  685. }