123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787 |
- package com.extUi.grid;
- import java.util.ArrayList;
- import java.util.List;
- import com.sysmodel.XFormFactory;
- import com.sysmodel.listmodel.xmlmodel.impl.ActionButtonImpl;
- import com.sysmodel.listmodel.xmlmodel.impl.FormListImpl;
- import com.sysmodel.listmodel.xmlmodel.impl.ListFieldImpl;
- import com.sysmodel.listmodel.xmlmodel.impl.QueryFieldImpl;
- import com.sysmodel.xformmodel.importcontrol.DateControl;
- import com.sysmodel.xformmodel.importcontrol.SelectControl;
- public class GridImpl implements Gridable{
- public StringBuffer getGridButtonJs(String listid) {
- StringBuffer sb = new StringBuffer();
- FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
- ArrayList<ActionButtonImpl> listActions = formList.getListAction();
- ArrayList<QueryFieldImpl> queryFields = formList.getQueryFields();
- if (listActions.size() > 0 || queryFields.size() > 0) {
- sb.append(" tbar:[").append("\n");
- if (queryFields.size() > 0) {
- sb.append(" {text:'查询',").append("\n");
- sb.append(" tooltip:'查询过滤',").append("\n");
- sb.append(" iconCls:'add',").append("\n");
- sb.append(" onClick:function(){\n");
- sb.append(" qryWin.show(this);\n");
- sb.append(" qryForm.getForm().reset(); \n");
- sb.append(" }\n");
- sb.append(" },'-', \n");
- }
- if (listActions.size() > 0) {
- for (int i = 0; i < listActions.size(); i++) {
- ActionButtonImpl action = (ActionButtonImpl) listActions.get(i);
- if (action.getButtonName().equals("add")) {
- sb.append(" {text:'新增',").append("\n");
- sb.append(" tooltip:'添加一条纪录',").append("\n");
- sb.append(" iconCls:'add',").append("\n");
- sb.append(" onClick:function(){").append("\n");
- sb.append(" editWin.show(this);\n");
- sb.append(" editform.getForm().reset();\n");
- sb.append(" }").append("\n");
- sb.append(" },'-', \n");
- } else if (action.getButtonName().equals("edit")) {
- sb.append(" {text:'修改',").append("\n");
- sb.append(" tooltip:'修改一条纪录',").append("\n");
- sb.append(" iconCls:'option',").append("\n");
- sb.append(" onClick:function(){").append("\n");
- sb.append(" if(sm" + listid + ".getCount()==1){").append("\n");
- sb.append(" editWin.show(this);\n");
- sb.append(" editform.getForm().reset();\n");
- sb.append(" editform.getForm().loadRecord(sm" + listid
- + ".getSelected());\n");
- sb.append(" }else{ ").append("\n");
- sb.append(" Ext.MessageBox.alert('提示', '请选择一条记录!');").append("\n");
- sb.append(" }").append("\n");
- sb.append(" }").append("\n");
- sb.append(" },'-', \n");
- } else if (action.getButtonName().equals("delete")) {
- sb.append(" {text:'删除',").append("\n");
- sb.append(" tooltip:'删除选择的纪录',").append("\n");
- sb.append(" iconCls:'remove',").append("\n");
- sb.append(" handler: function(){").append("\n");
- sb.append(" Ext.MessageBox.confirm('Confirm', '你确定要删除吗?', doDelete);")
- .append("\n");
- sb.append(" }").append("\n");
- sb.append(" },'-', \n");
- }
- }
- }
- sb = new StringBuffer(sb.substring(0, sb.lastIndexOf(",'-',")));
- sb.append(" ],\n");
- }
- return sb;
- }
- public StringBuffer getGridJs(String listid) {
- StringBuffer sb = new StringBuffer();
- FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
- ArrayList<ListFieldImpl> listFields = formList.getQueryList().getlistFields();
- @SuppressWarnings("unused")
- ArrayList<ActionButtonImpl> listActions = formList.getListAction();
- @SuppressWarnings("unused")
- ArrayList<QueryFieldImpl> queryFields = formList.getQueryFields();
- sb.append("/**\n");
- sb.append(" * 显示数据列表和查询表单\n");
- sb.append(" */\n");
- sb.append("_this.showListGrid = function(obj) {\n");
- sb.append(this.getQureyFormJs(listid));
- sb.append("// 构造列表\n");
- sb.append("\n");
- sb.append("/**\n");
- sb.append(" * gird加载数据失败回调函数\n");
- sb.append(" */\n");
- sb.append("function feafailFn(response, options) {\n");
- sb.append("// alert(response.responseText)\n");
- sb.append("Ext.MessageBox.alert('提示', '数据加载失败!');\n");
- sb.append("}\n");
- sb.append("function feasucFn(response, options) {\n");
- sb.append("// alert(response.responseText)\n");
- sb.append("// Ext.MessageBox.alert('提示', '查询失败!');\n");
- sb.append("}\n");
- sb.append("// 构造数据源\n");
- sb.append("var ds = new Ext.data.Store({// 这是数据源\n");
- sb.append("baseParams : {\n");
- sb.append("listId : '");
- sb.append(formList.getListid());
- sb.append("'// listid\n");
- sb.append("},\n");
- sb.append("proxy : new Ext.data.HttpProxy({\n");
- sb.append("url : '../ws/crud/CRUDService/query/',\n");
- sb.append("method : 'POST',\n");
- sb.append("timeout : 15000,\n");
- sb.append("success : feasucFn,\n");
- sb.append("failure : feafailFn\n");
- sb.append("}),\n");
- sb.append("reader : new Ext.data.JsonReader({\n");
- sb.append("totalProperty : 'total',\n");
- sb.append("root : 'rows'\n");
- sb.append("}, [\n");
- this.getDataStore(formList.getQueryTables(), listFields, formList.getQueryList()
- .isHaveOrder(), sb);
- sb.append("])\n");
- sb.append("});\n");
- sb.append("\n");
- sb.append("// 构造列\n");
- sb.append("\n");
- sb.append("var sm = new Ext.grid.CheckboxSelectionModel();\n");
- sb.append("var colModel = new Ext.grid.ColumnModel([sm,\n");
- this.getColumnModel(listFields, formList.getQueryList().isHaveOrder(), sb);
- sb.append("]);\n");
- sb.append("\n");
- sb.append("// 构造Grid\n");
- sb.append("_this.listGrid = new Ext.grid.GridPanel({\n");
- sb.append("frame : true,\n");
- sb.append("sm : sm,\n");
- sb.append("title : '用户信息表',//grid标题,需要根据配置文件生成\n");
- sb.append("cm : colModel,\n");
- sb.append("tbar : [{\n");
- sb.append("text : '详细信息',\n");
- sb.append("id : 'info_880',\n");
- sb.append("tooltip : '显示详细信息',\n");
- sb.append("iconCls : 'info',\n");
- sb.append("onClick : function() {\n");
- sb.append("_this.showInfo();\n");
- sb.append("}\n");
- sb.append("}, '-', {\n");
- sb.append("text : '修改',\n");
- sb.append("id : 'edit_");
- sb.append(formList.getListid());
- sb.append("',//注意classid\n");
- sb.append("tooltip : '查询过滤',\n");
- sb.append("iconCls : 'add',\n");
- sb.append("onClick : function() {\n");
- sb.append("_this.showEditPanel();\n");
- sb.append("}\n");
- sb.append("}, '-', {\n");
- sb.append("text : '新增',\n");
- sb.append("id : 'add_");
- sb.append(formList.getListid());
- sb.append("',//注意classid\n");
- sb.append("tooltip : '添加一条纪录',\n");
- sb.append("iconCls : 'add',\n");
- sb.append("handler : function() {\n");
- sb.append("_this.showAddPanel();\n");
- sb.append("}\n");
- sb.append("}, '-', {\n");
- sb.append("text : '删除',\n");
- sb.append("tooltip : '删除选择的纪录',\n");
- sb.append("id : 'del_");
- sb.append(formList.getListid());
- sb.append("',//注意classid\n");
- sb.append("iconCls : 'remove',\n");
- sb.append("handler : function() {\n");
- sb.append("_this.showDelcon();\n");
- sb.append("}\n");
- sb.append("}],\n");
- if (formList.getQueryList().getPageSize() > 0) {
- sb.append("bbar : new Ext.PagingToolbar({\n");
- sb.append("beforePageText : '第',\n");
- sb.append("afterPageText : '页 ,共{0}页',\n");
- sb.append("pageSize : ");
- sb.append(formList.getQueryList().getPageSize());
- sb.append(",//根据配置文件读取页面大小\n");
- sb.append("store : ds,\n");
- sb.append("displayInfo : true,\n");
- sb.append("displayMsg : '当前记录 {0} - {1} ,共 {2}条',\n");
- sb.append("emptyMsg : '当前没有显示的纪录',\n");
- sb.append("prependButtons : true\n");
- sb.append("\n");
- sb.append("}),\n");
- }
- sb.append("autoWidth : true,\n");
- sb.append("autoScroll : true,\n");
- sb.append("bodyStyle : 'width:100%',\n");
- sb.append("height : 300,\n");
- sb.append("store : ds,\n");
- sb.append("viewConfig : {\n");
- sb.append("forceFit : true\n");
- sb.append("}\n");
- sb.append("});\n");
- sb.append("\n");
- sb.append("ds.load({\n");
- sb.append("params : {\n");
- sb.append("start : 0,\n");
- sb.append("limit : ");
- sb.append(formList.getQueryList().getPageSize());
- sb.append("\n");
- sb.append("}\n");
- sb.append("});\n");
- sb.append("\n");
- sb.append("// 构造容器-将此容器加入到框架中\n");
- sb.append("var panel = new Ext.Panel();\n");
- sb.append("panel.add(_this.queryFrom);\n");
- sb.append("panel.add(_this.listGrid);\n");
- sb.append("\n");
- sb.append("com.sinosoft.common.frameWork.FrameWork.changeCenter(panel);\n");
- sb.append("\n");
- // sb.append("com.sinosoft.system.right.Right.showUserButtns('m113');\n");
- sb.append("\n");
- sb.append("};\n");
- return sb;
- }
- public StringBuffer getGridRightMenuJs(String listid) {
- // TODO Auto-generated method stub
- return null;
- }
- public StringBuffer getQureyFormJs(String listid) {
- StringBuffer sb = new StringBuffer();
- FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
- ArrayList<QueryFieldImpl> queryFields = formList.getQueryFields();
- sb.append("// 构造查询表单\n");
- sb.append("_this.queryFrom = new Ext.form.FormPanel({\n");
- sb.append("labelWidth : 100,\n");
- sb.append("frame : true,\n");
- sb.append("autoScroll : true,\n");
- sb.append("autoHeight : true,\n");
- sb.append("bodyStyle : 'padding:5px 5px 0',\n");
- // sb.append("defaultType : 'textfield',\n");
- sb.append("items : [\n");
- sb.append("//根据配置循环生成查询表单字段\n");
- for (int i = 0; i < queryFields.size(); i++) {
- QueryFieldImpl queryField = (QueryFieldImpl) queryFields.get(i);
- if (queryField.getControlType().equals("text")) {
- sb.append(" {\n");
- sb.append(" xtype:'textfield',\n");
- sb.append(" fieldLabel: '" + queryField.getLabel() + "',\n");
- sb.append(" name: '" + queryField.getDataName().toUpperCase() + "_"
- + listid + "',\n");
- if (queryField.getValidate().isNeed()) {
- sb.append(" allowBlank:false\n");
- } else {
- sb.append(" allowBlank:true\n");
- }
- sb.append(" },\n");
- } else if (queryField.getControlType().equals("select")) {
- sb.append(" {\n");
- sb.append("xtype: 'combo' , \n");
- sb.append(" fieldLabel: '" + queryField.getLabel() + "', \n");
- sb.append(" hiddenName:'"
- + queryField.getDataName().toUpperCase() + "',\n");
- sb.append(" store: {\n");
- sb.append("url : '../ws/sys/constantService/getConstantByName',\n");
- sb.append("autoLoad : true,\n");
- sb.append("baseParams : {name:'");
- SelectControl selectControl = (SelectControl) queryField.getControl();
- sb.append(selectControl.getConstantName());
- sb.append("'},\n");
- sb.append("xtype: 'jsonstore' , \n");
- sb.append("root : 'constants',\n");
- sb.append("fields : ['name', 'value']\n");
- sb.append("},\n");
- sb.append(" valueField:'value',\n");
- sb.append(" displayField:'name',\n");
- sb.append(" typeAhead: true,\n");
- sb.append(" triggerAction: 'all',\n");
- sb.append(" selectOnFocus:true,\n");
- sb.append(" editable:false\n");
- sb.append(" } ,\n");
- } else if (queryField.getControlType().equals("date")) {
- sb.append(" {\n");
- sb.append(" fieldLabel: '" + queryField.getLabel() + "',\n");
- sb.append(" name: '" + queryField.getDataName().toUpperCase() + "_"
- + queryField.getClassid() + "', \n");
- sb.append(" anchor:'90%',\n");
- sb.append(" xtype:'datefield',\n");
- sb.append(" editable:false,\n");// 不能手工编辑输入日期值
- DateControl date = (DateControl) queryField.getControl();
- if (date.getFormat().equals("yyyy-MM-dd")) {
- sb.append(" altFormats: 'Y-m-d',\n");
- sb.append(" format:'Y-m-d',\n");
- } else if (date.getFormat().equals("yyyy-MM-dd HH")) {
- sb.append(" altFormats: 'Y-m-d H',\n");
- sb.append(" format:'Y-m-d H',\n");
- } else if (date.getFormat().equals("yyyy-MM-dd HH:mm")) {
- sb.append(" altFormats: 'Y-m-d H:i',\n");
- sb.append(" format:'Y-m-d H:i',\n");
- } else if (date.getFormat().equals("yyyy-MM-dd HH:mm:ss")) {
- sb.append(" altFormats: 'Y-m-d H:i:s',\n");
- sb.append(" format:'Y-m-d H:i:s',\n");
- }
- sb.append(" allowBlank:true\n");
- sb.append(" },\n");
- }
- }
- sb.reverse();
- sb.deleteCharAt(1);
- sb.reverse();
- sb.append("],\n");
- sb.append("\n");
- sb.append("buttons : [{\n");
- sb.append("text : '查询',\n");
- sb.append("handler : function() {\n");
- sb.append("_this.query();\n");
- sb.append("}\n");
- sb.append("}, {\n");
- sb.append("text : '重置',\n");
- sb.append("handler : function() {\n");
- sb.append("_this.queryFrom.getForm().reset();\n");
- sb.append("}\n");
- sb.append("}]\n");
- sb.append("});\n");
- return sb;
- }
- private void addItems(QueryFieldImpl queryField, StringBuffer sb, String listid) {
- if (queryField.getControlType().equals("text")) {
- sb.append(" {\n");
- sb.append(" xtype:'textfield',\n");
- sb.append(" fieldLabel: '" + queryField.getLabel() + "',\n");
- sb.append(" name: '" + queryField.getDataName().toUpperCase() + "_"
- + listid + "',\n");
- sb.append("anchor : '90%',\n");
- if (queryField.getValidate().isNeed()) {
- sb.append(" allowBlank:false\n");
- } else {
- sb.append(" allowBlank:true\n");
- }
- sb.append(" }\n");
- } else if (queryField.getControlType().equals("select")) {
- sb.append(" {\n");
- sb.append("xtype: 'combo' , \n");
- sb.append(" fieldLabel: '" + queryField.getLabel() + "', \n");
- sb.append(" hiddenName:'" + queryField.getDataName().toUpperCase()
- + "',\n");
- sb.append(" store: {\n");
- sb.append("url : '../ws/sys/constantService/getConstantByName',\n");
- sb.append("autoLoad : true,\n");
- sb.append("baseParams : {name:'");
- SelectControl selectControl = (SelectControl) queryField.getControl();
- sb.append(selectControl.getConstantName());
- sb.append("'},\n");
- sb.append("xtype: 'jsonstore' , \n");
- sb.append("root : 'constants',\n");
- sb.append("fields : ['name', 'value']\n");
- sb.append("},\n");
- sb.append(" valueField:'value',\n");
- sb.append(" displayField:'name',\n");
- sb.append(" typeAhead: true,\n");
- sb.append(" triggerAction: 'all',\n");
- sb.append(" selectOnFocus:true,\n");
- sb.append(" anchor : '90%',\n");
- sb.append(" editable:false\n");
- sb.append(" }\n");
- } else if (queryField.getControlType().equals("date")) {
- sb.append(" {\n");
- sb.append(" fieldLabel: '" + queryField.getLabel() + "',\n");
- sb.append(" name: '" + queryField.getDataName().toUpperCase() + "_"
- + queryField.getClassid() + "', \n");
- sb.append(" anchor:'90%',\n");
- sb.append(" xtype:'datefield',\n");
- sb.append(" editable:false,\n");// 不能手工编辑输入日期值
- DateControl date = (DateControl) queryField.getControl();
- if (date.getFormat().equals("yyyy-MM-dd")) {
- sb.append(" altFormats: 'Y-m-d',\n");
- sb.append(" format:'Y-m-d',\n");
- } else if (date.getFormat().equals("yyyy-MM-dd HH")) {
- sb.append(" altFormats: 'Y-m-d H',\n");
- sb.append(" format:'Y-m-d H',\n");
- } else if (date.getFormat().equals("yyyy-MM-dd HH:mm")) {
- sb.append(" altFormats: 'Y-m-d H:i',\n");
- sb.append(" format:'Y-m-d H:i',\n");
- } else if (date.getFormat().equals("yyyy-MM-dd HH:mm:ss")) {
- sb.append(" altFormats: 'Y-m-d H:i:s',\n");
- sb.append(" format:'Y-m-d H:i:s',\n");
- }
- sb.append(" allowBlank:true\n");
- sb.append(" }\n");
- }
- }
- /**
- * 构造查询FORM(2列)
- *
- * @param queryFields
- * @param sb
- */
- private void getFormItems(List<QueryFieldImpl> queryFields, StringBuffer sb, String listid) {
- if (null == queryFields || 0 == queryFields.size()) {
- return;
- } else if (1 == queryFields.size()) {
- this.addItems(queryFields.get(0), sb, listid);
- return;
- }
- for (int i = 0; i < queryFields.size(); i++) {
- if (0 == i % 2) {
- sb.append("{\n");
- sb.append("layout:'column',\n");
- sb.append("items:[\n");
- sb.append(" {\n");
- sb.append(" columnWidth:.5,\n");
- sb.append(" layout:'form',\n");
- sb.append(" labelAlign:'left',\n");
- sb.append(" items:[\n");
- this.addItems(queryFields.get(i), sb, listid);
- if (queryFields.size() == i + 1) {
- sb.append("]\n");
- sb.append("}\n");
- sb.append("]\n");
- sb.append("},\n");
- }
- } else {
- sb.append("]\n");
- sb.append("},\n");
- sb.append(" {\n");
- sb.append(" columnWidth:.5,\n");
- sb.append(" layout:'form',\n");
- sb.append(" labelAlign:'left',\n");
- sb.append(" items:[\n");
- this.addItems(queryFields.get(i), sb, listid);
- sb.append("]\n");
- sb.append("}\n");
- sb.append("]\n");
- sb.append("},\n");
- }
- }
- }
- private List<QueryFieldImpl> queryFieldFilter(List<QueryFieldImpl> queryFields) {
- List<QueryFieldImpl> list = new ArrayList<QueryFieldImpl>();
- for (QueryFieldImpl f : queryFields) {
- if ("is_del".equalsIgnoreCase(f.getDataName())
- || "updatedate".equalsIgnoreCase(f.getDataName())
- || "is_upload".equalsIgnoreCase(f.getDataName())) {
- continue;
- }
- list.add(f);
- }
- return list;
- }
- public StringBuffer getQureyForm2Col(String listid) {
- StringBuffer sb = new StringBuffer();
- FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
- List<QueryFieldImpl> queryFields = formList.getQueryFields();
- queryFields = this.queryFieldFilter(queryFields);
- sb.append("// 构造查询表单\n");
- sb.append("_this.queryFrom = new Ext.form.FormPanel({\n");
- sb.append("labelWidth : 100,\n");
- sb.append("frame : true,\n");
- sb.append("autoScroll : true,\n");
- sb.append("autoHeight : true,\n");
- sb.append("bodyStyle : 'padding:5px 5px 0',\n");
- sb.append("items : [\n");
- sb.append("//根据配置循环生成查询表单字段\n");
- this.getFormItems(queryFields, sb, listid);
- // sb = sb.replace(sb.length()-1, sb.length(), "");
- sb.reverse();
- sb.deleteCharAt(1);
- sb.reverse();
- sb.append("],\n");
- sb.append("\n");
- sb.append("buttons : [{\n");
- sb.append("text : '查询',\n");
- sb.append("handler : function() {\n");
- sb.append("_this.query();\n");
- sb.append("}\n");
- sb.append("}, {\n");
- sb.append("text : '重置',\n");
- sb.append("handler : function() {\n");
- sb.append("_this.queryFrom.getForm().reset();\n");
- sb.append("}\n");
- sb.append("}]\n");
- sb.append("});\n");
- return sb;
- }
- public StringBuffer getTpl(String listid) {
- StringBuffer sb = new StringBuffer();
- FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
- ArrayList<ListFieldImpl> listFields = formList.getQueryList().getlistFields();
- sb.append("var tpl = new Ext.XTemplate(\"");
- sb.append("<table class='info_table'>\",\n");
- for (int i = 0; i < listFields.size(); i += 2) {
- ListFieldImpl listFieldImpl = (ListFieldImpl) listFields.get(i);
- sb.append("\"<tr>\",\n");
- sb.append("\"<td>");
- sb.append(listFieldImpl.getLabel());
- sb.append("</td>\",\n");
- sb.append("\"<td>");
- sb.append("{");
- sb.append(listFieldImpl.getDataName().toUpperCase());
- sb.append("_");
- sb.append(listFieldImpl.getClassid());
- sb.append("}</td>\",\n");
- if (i + 1 < listFields.size()) {
- ListFieldImpl listFieldImpl2 = (ListFieldImpl) listFields.get(i + 1);
- sb.append("\"<td>");
- sb.append(listFieldImpl2.getLabel());
- sb.append("</td>\",\n");
- sb.append("\"<td>");
- sb.append("{");
- sb.append(listFieldImpl2.getDataName().toUpperCase());
- sb.append("_");
- sb.append(listFieldImpl2.getClassid());
- sb.append("}</td>\",\n");
- } else {
- sb.append("\"<td colspan=\'2\'> </td>\",\n");
- }
- sb.append("\"</tr>\",\n");
- }
- sb.append("\"</table>\"");
- sb.append(")");
- return sb;
- }
- private void getDataStore(List<String> tables, List<ListFieldImpl> listFields, boolean sort,
- StringBuffer sb) {
- // if(sort){
- // sb.append(" {name:").append("'ROWNUM_'},").append("\n");
- // }
- for (int i = 0; i < tables.size(); i++) {
- String classid = (String) tables.get(i);
- sb.append(" {name:").append("'FD_OBJECTID" + classid + "'},").append("\n");
- }
- for (int i = 0; i < listFields.size(); i++) {
- ListFieldImpl listFieldImpl = (ListFieldImpl) listFields.get(i);
- sb.append(" {name:")
- .append("'" + listFieldImpl.getDataName().toUpperCase() + "_"
- + listFieldImpl.getClassid() + "'},").append("\n");
- }
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- private void getColumnModel(List<ListFieldImpl> listFields, boolean sort, StringBuffer sb) {
- // if(sort){
- // sb.append(" {header:").append("'编号'").append(", dataIndex: 'ROWNUM_',width:35,sortable: true,type:'int'").append("},").append("\n");
- // }
- for (int i = 0; i < listFields.size(); i++) {
- ListFieldImpl listFieldImpl = (ListFieldImpl) listFields.get(i);
- sb.append(" {header:")
- .append("'" + listFieldImpl.getLabel() + "'")
- .append(", dataIndex: ")
- .append("'" + listFieldImpl.getDataName().toUpperCase() + "_"
- + listFieldImpl.getClassid() + "'").append(", sortable:")
- .append(" true},").append("\n");
- }
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- private List<ListFieldImpl> formListFilter(List<ListFieldImpl> listFields) {
- List<ListFieldImpl> list = new ArrayList<ListFieldImpl>();
- for (ListFieldImpl f : listFields) {
- if ("is_del".equalsIgnoreCase(f.getDataName())
- || "updatedate".equalsIgnoreCase(f.getDataName())
- || "is_upload".equalsIgnoreCase(f.getDataName())) {
- continue;
- }
- list.add(f);
- }
- return list;
- }
- public StringBuffer getGridJsForQuery(String listid) {
- StringBuffer sb = new StringBuffer();
- FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid);
- List<ListFieldImpl> listFields = formList.getQueryList().getlistFields();
- listFields = this.formListFilter(listFields);
- sb.append("/**\n");
- sb.append(" * 显示数据列表和查询表单\n");
- sb.append(" */\n");
- sb.append("_this.showListGrid = function(obj) {\n");
- sb.append(this.getQureyForm2Col(listid));
- sb.append("// 构造列表\n");
- sb.append("\n");
- sb.append("/**\n");
- sb.append(" * gird加载数据失败回调函数\n");
- sb.append(" */\n");
- sb.append("function feafailFn(response, options) {\n");
- sb.append("// alert(response.responseText)\n");
- sb.append("Ext.MessageBox.alert('提示', '数据加载失败!');\n");
- sb.append("}\n");
- sb.append("function feasucFn(response, options) {\n");
- sb.append("// alert(response.responseText)\n");
- sb.append("// Ext.MessageBox.alert('提示', '查询失败!');\n");
- sb.append("}\n");
- sb.append("// 构造数据源\n");
- sb.append("var ds = new Ext.data.Store({// 这是数据源\n");
- sb.append("baseParams : {\n");
- sb.append("listId : '");
- sb.append(formList.getListid());
- sb.append("'// listid\n");
- sb.append("},\n");
- sb.append("proxy : new Ext.data.HttpProxy({\n");
- sb.append("url : '../ws/crud/CRUDService/query/',\n");
- sb.append("method : 'POST',\n");
- sb.append("timeout : 15000,\n");
- sb.append("success : feasucFn,\n");
- sb.append("failure : feafailFn\n");
- sb.append("}),\n");
- sb.append("reader : new Ext.data.JsonReader({\n");
- sb.append("totalProperty : 'total',\n");
- sb.append("root : 'rows'\n");
- sb.append("}, [\n");
- this.getDataStore(formList.getQueryTables(), listFields, formList.getQueryList()
- .isHaveOrder(), sb);
- sb.append("])\n");
- sb.append("});\n");
- sb.append("\n");
- sb.append("// 构造列\n");
- sb.append("\n");
- sb.append("var sm = new Ext.grid.CheckboxSelectionModel();\n");
- sb.append("var colModel = new Ext.grid.ColumnModel([sm,\n");
- this.getColumnModel(listFields, formList.getQueryList().isHaveOrder(), sb);
- sb.append("]);\n");
- sb.append("\n");
- sb.append("// 构造Grid\n");
- sb.append("_this.listGrid = new Ext.grid.GridPanel({\n");
- sb.append("frame : true,\n");
- sb.append("sm : sm,\n");
- sb.append("title : '用户信息表',//grid标题,需要根据配置文件生成\n");
- sb.append("cm : colModel,\n");
- sb.append("tbar : [{\n");
- sb.append("text : '详细信息',\n");
- sb.append("id : 'info_880',\n");
- sb.append("tooltip : '显示详细信息',\n");
- sb.append("iconCls : 'info',\n");
- sb.append("onClick : function() {\n");
- sb.append("_this.showInfo();\n");
- sb.append("}\n");
- sb.append("}, '-', {\n");
- sb.append("text : '导出EXCEL',\n");
- sb.append("tooltip : '导出EXCEL',\n");
- sb.append("id : 'excel_");
- sb.append(formList.getListid());
- sb.append("',//注意classid\n");
- sb.append("iconCls : 'remove',\n");
- sb.append("handler : function() {\n");
- sb.append("_this.exportExcel(_this.listGrid);\n");
- sb.append("}\n");
- sb.append("}],\n");
- if (formList.getQueryList().getPageSize() > 0) {
- sb.append("bbar : new Ext.PagingToolbar({\n");
- sb.append("beforePageText : '第',\n");
- sb.append("afterPageText : '页 ,共{0}页',\n");
- sb.append("pageSize : ");
- sb.append(formList.getQueryList().getPageSize());
- sb.append(",//根据配置文件读取页面大小\n");
- sb.append("store : ds,\n");
- sb.append("displayInfo : true,\n");
- sb.append("displayMsg : '当前记录 {0} - {1} ,共 {2}条',\n");
- sb.append("emptyMsg : '当前没有显示的纪录',\n");
- sb.append("prependButtons : true\n");
- sb.append("\n");
- sb.append("}),\n");
- }
- sb.append("autoWidth : true,\n");
- sb.append("autoScroll : true,\n");
- sb.append("bodyStyle : 'width:100%',\n");
- sb.append("height : 300,\n");
- sb.append("store : ds,\n");
- sb.append("viewConfig : {\n");
- sb.append("forceFit : true\n");
- sb.append("}\n");
- sb.append("});\n");
- sb.append("\n");
- sb.append("ds.load({\n");
- sb.append("params : {\n");
- sb.append("start : 0,\n");
- sb.append("limit : ");
- sb.append(formList.getQueryList().getPageSize());
- sb.append("\n");
- sb.append("}\n");
- sb.append("});\n");
- sb.append("\n");
- sb.append("// 构造容器-将此容器加入到框架中\n");
- sb.append("var panel = new Ext.Panel();\n");
- sb.append("panel.add(_this.queryFrom);\n");
- sb.append("panel.add(_this.listGrid);\n");
- sb.append("\n");
- sb.append("com.sinosoft.common.frameWork.FrameWork.changeCenter(panel);\n");
- sb.append("\n");
- // sb.append("com.sinosoft.system.right.Right.showUserButtns('m113');\n");
- sb.append("\n");
- sb.append("};\n");
- return sb;
- }
- }
|