FormImpl.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. package com.extUi.form;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import com.sysmodel.XFormFactory;
  5. import com.sysmodel.collectmodel.xmlmodel.impl.ActionImpl;
  6. import com.sysmodel.collectmodel.xmlmodel.impl.ContainerImpl;
  7. import com.sysmodel.collectmodel.xmlmodel.impl.FormCollectionImpl;
  8. import com.sysmodel.collectmodel.xmlmodel.impl.HiddenFieldImpl;
  9. import com.sysmodel.collectmodel.xmlmodel.impl.ReportFieldImpl;
  10. import com.sysmodel.collectmodel.xmlmodel.impl.TabItemImpl;
  11. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  12. import com.sysmodel.datamodel.xmlmodel.able.MdpConstant;
  13. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  14. import com.sysmodel.xformmodel.able.Validate;
  15. import com.sysmodel.xformmodel.importcontrol.CheckBoxControl;
  16. import com.sysmodel.xformmodel.importcontrol.RadioControl;
  17. import com.sysmodel.xformmodel.importcontrol.SelectControl;
  18. import com.sysmodel.xformmodel.importcontrol.TextAreaControl;
  19. import com.sysmodel.xformmodel.importcontrol.TreeControl;
  20. public class FormImpl implements Formable{
  21. FormCollectionImpl formCollection = null;
  22. @SuppressWarnings("unused")
  23. private SysModel sysModel = ModelFactory.getSysmodel();
  24. /**
  25. * 生成表单按钮
  26. */
  27. public StringBuffer getFormButtonJs(String pageid) {
  28. StringBuffer sb = new StringBuffer();
  29. ArrayList<ActionImpl> buttons = formCollection.getPageRoot().getAllActions();
  30. sb.append(" buttons: [\n");
  31. for (int i = 0; i < buttons.size(); i++) {
  32. ActionImpl button = buttons.get(i);
  33. if (button.getType().equals("save")) {
  34. sb.append(" {\n");
  35. sb.append(" text: '保存',\n");
  36. sb.append(" handler:function(){\n");
  37. sb.append(" fsf.getForm().submit({\n");
  38. sb.append(" failure:function(retForm,retAction){\n");
  39. sb.append(" if(retAction.result&&retAction.result=='1'){\n");
  40. sb.append(" Ext.MessageBox.alert('提示', '保存数据成功!');\n");
  41. sb.append(" Win.hide();\n");
  42. sb.append(" document.location.reload();\n");
  43. sb.append(" }else if(retAction.result&&retAction.result=='error'){ \n");
  44. sb.append(" Ext.MessageBox.alert('提示', '保存数据失败!');\n");
  45. sb.append(" }else {\n");
  46. sb.append(" Ext.MessageBox.alert('提示', '保存数据出错!');\n");
  47. sb.append(" }\n");
  48. sb.append(" },\n");
  49. sb.append(" waitMsg:'保存中...'\n");
  50. sb.append(" });\n");
  51. sb.append(" }\n");
  52. sb.append(" },\n");
  53. } else if (button.getType().equals("reset")) {
  54. sb.append(" {\n");
  55. sb.append(" text: '重置',\n");
  56. sb.append(" handler: function(){\n");
  57. sb.append(" document.forms[0].reset();\n");
  58. sb.append(" }\n");
  59. sb.append(" },\n");
  60. } else if (button.getType().equals("close")) {
  61. sb.append(" {\n");
  62. sb.append(" text: '关闭',\n");
  63. sb.append(" handler: function(){\n");
  64. sb.append(" Win.hide();\n");
  65. sb.append(" }\n");
  66. sb.append(" },\n");
  67. }
  68. }
  69. sb.reverse();
  70. sb.deleteCharAt(1);
  71. sb.reverse();
  72. sb.append(" ]\n");
  73. return sb;
  74. }
  75. /**
  76. * 生成form表单
  77. */
  78. @SuppressWarnings({ "rawtypes", "unused" })
  79. public StringBuffer getFormJs(String pageid) {
  80. StringBuffer sb = new StringBuffer();
  81. formCollection = (FormCollectionImpl) XFormFactory.getXFormModel()
  82. .getFormCollection(pageid);
  83. ArrayList containers = formCollection.getPageBody().getAlContainers();
  84. ArrayList hiddens = formCollection.getPageBody().getAlHiddenFields();
  85. sb.append("// 私有方法\n");
  86. sb.append("\n");
  87. sb.append("/**\n");
  88. sb.append(" * 生成新增和编辑表单,\n");
  89. sb.append(" */\n");
  90. sb.append("var getEditFrom = function() {\n");
  91. sb.append("// if (_this.editFrom == null) {\n");
  92. sb.append("_this.editFrom = new Ext.form.FormPanel({\n");
  93. sb.append("labelWidth : 100,\n");
  94. sb.append("frame : true,\n");
  95. sb.append("autoScroll : true,\n");
  96. sb.append("autoHeight : true,\n");
  97. sb.append("bodyStyle : 'padding:5px 5px 0',\n");
  98. sb.append("defaultType : 'textfield',\n");
  99. sb.append("items : [{\n");
  100. sb.append("xtype : 'hidden',\n");
  101. sb.append("name : 'classid',\n");
  102. sb.append("value : '");
  103. sb.append(formCollection.getClassid());
  104. sb.append("'// 表的classid\n");
  105. sb.append("}, {\n");
  106. sb.append("xtype : 'hidden',\n");
  107. sb.append("name : 'FD_OBJECTID");
  108. sb.append(formCollection.getClassid());
  109. sb.append("'// 注意添加表的classid\n");
  110. sb.append("},\n");
  111. // 生成字段
  112. sb.append(this.getContaineJs(containers));
  113. sb.append("],\n");
  114. sb.append("\n");
  115. sb.append("buttons : [{\n");
  116. sb.append("text : '保存',\n");
  117. sb.append("handler : function() {\n");
  118. sb.append("\n");
  119. sb.append("if(_this.editFrom.getForm().isValid()){\n");
  120. sb.append("var values = _this.editFrom.getForm().getValues();\n");
  121. sb.append("if (values['FD_OBJECTID' + values['classid']] != '') {\n");
  122. sb.append("_this.edit(values);\n");
  123. sb.append("} else {\n");
  124. sb.append("_this.add(values);\n");
  125. sb.append("}\n");
  126. sb.append("}\n");
  127. sb.append("\n");
  128. sb.append("}\n");
  129. sb.append("}, {\n");
  130. sb.append("text : '重置',\n");
  131. sb.append("handler : function() {\n");
  132. sb.append("\n");
  133. sb.append("var values = _this.editFrom.getForm().getValues();\n");
  134. sb.append("if (values['FD_OBJECTID' + values['classid']] != '') {\n");
  135. sb.append("var id = values['FD_OBJECTID'\n");
  136. sb.append("+ values['classid']];\n");
  137. sb.append("_this.editFrom.getForm().reset();\n");
  138. sb.append("_this.editFrom.getForm().loadRecord(record);\n");
  139. sb.append("} else {\n");
  140. sb.append("_this.editFrom.getForm().reset();\n");
  141. sb.append("}\n");
  142. sb.append("}\n");
  143. sb.append("}]\n");
  144. sb.append("});\n");
  145. sb.append("// }\n");
  146. sb.append("\n");
  147. sb.append("}\n");
  148. return sb;
  149. }
  150. /**
  151. * 生成表单内的容器
  152. *
  153. * @param containers
  154. * @return
  155. */
  156. @SuppressWarnings("rawtypes")
  157. public StringBuffer getContaineJs(ArrayList containers) {
  158. StringBuffer sb = new StringBuffer();
  159. for (int i = 0; i < containers.size(); i++) {
  160. ContainerImpl container = (ContainerImpl) containers.get(i);
  161. if (container.getXtype().equals("fieldset")) {
  162. sb.append(getCollapsibleJs(container));
  163. } else if (container.getXtype().equals("fieldsetcheck")) {
  164. sb.append(getCheckboxToggleJs(container));
  165. } else if (container.getXtype().equals("tabpanel")) {
  166. sb.append(getTabpanelJs(container));
  167. } else if (container.getXtype().equals("no")) {
  168. sb.append(getCommonJs(container));
  169. }
  170. }
  171. sb.reverse();
  172. sb.deleteCharAt(1);
  173. sb.reverse();
  174. return sb;
  175. }
  176. /**
  177. * 生成 带checkbox 的fieldset
  178. *
  179. * @param container
  180. * @return
  181. */
  182. @SuppressWarnings("rawtypes")
  183. public StringBuffer getCheckboxToggleJs(ContainerImpl container) {
  184. StringBuffer sb = new StringBuffer();
  185. ArrayList fields = container.getObjElements();
  186. sb.append(" {\n");
  187. sb.append(" checkboxToggle:true,\n");
  188. sb.append(" title: '" + container.getTitle() + "',\n");
  189. sb.append(" autoHeight:" + container.isAutoHeight() + ",\n");
  190. sb.append(" collapsed: " + container.isCollapsed() + ",\n");
  191. sb.append(" xtype:'fieldset',\n");
  192. sb.append(" layout:'column',\n");
  193. sb.append(" width: 700,\n");
  194. sb.append(" border:false,\n");
  195. sb.append(" labelSeparator:':',\n");
  196. sb.append(" items:[\n");
  197. sb.append(getFieldJs(fields));
  198. sb.append(" ]\n");
  199. sb.append(" },\n");
  200. return sb;
  201. }
  202. /**
  203. * 生成tabPanel
  204. *
  205. * @param container
  206. * @return
  207. */
  208. public StringBuffer getTabpanelJs(ContainerImpl container) {
  209. StringBuffer sb = new StringBuffer();
  210. sb.append(" {\n");
  211. sb.append(" xtype:'tabpanel',\n");
  212. sb.append(" activeTab: 0,\n");
  213. sb.append(" deferredRender:false,//设为false,提交的时候才会提交所有tab里的field \n");
  214. sb.append(" defaults:" + container.getDefaults() + ", \n");
  215. sb.append(" items:[\n");
  216. sb.append(getTabJs(container));
  217. sb.append(" ]\n");
  218. sb.append(" },\n");
  219. return sb;
  220. }
  221. /**
  222. * 生成tabpanel 中的 tab
  223. *
  224. * @param container
  225. * @return
  226. */
  227. @SuppressWarnings("rawtypes")
  228. public StringBuffer getTabJs(ContainerImpl container) {
  229. StringBuffer sb = new StringBuffer();
  230. ArrayList tabitens = container.getObjElements();
  231. for (int i = 0; i < tabitens.size(); i++) {
  232. TabItemImpl tab = (TabItemImpl) tabitens.get(i);
  233. ArrayList fields = tab.getObjElements();
  234. sb.append(" {\n");
  235. sb.append(" title:'" + tab.getTitle() + "',\n");
  236. sb.append(" layout:'column',\n");
  237. sb.append(" border:false, \n");
  238. sb.append(" labelSeparator:':', \n");
  239. sb.append(" width: 700, \n");
  240. sb.append(" items:[\n");
  241. sb.append(getFieldJs(fields));
  242. sb.append(" ]\n");
  243. sb.append(" },\n");
  244. }
  245. if (sb.indexOf(",") > -1) {
  246. sb.reverse();
  247. sb.deleteCharAt(1);
  248. sb.reverse();
  249. }
  250. return sb;
  251. }
  252. /**
  253. * 生成普通panel
  254. *
  255. * @param container
  256. * @return
  257. */
  258. public StringBuffer getCommonJs(ContainerImpl container) {
  259. StringBuffer sb = new StringBuffer();
  260. ArrayList<?> fields = container.getObjElements();
  261. sb.append(" {\n");
  262. sb.append(" layout:'column',\n");
  263. sb.append(" xtype : 'panel',\n");
  264. sb.append(" items:[\n");
  265. sb.append(getFieldJs(fields));
  266. sb.append(" ]\n");
  267. sb.append(" },\n");
  268. return sb;
  269. }
  270. /**
  271. * 生成可收缩的fieldset
  272. *
  273. * @param container
  274. * @return
  275. */
  276. @SuppressWarnings("rawtypes")
  277. public StringBuffer getCollapsibleJs(ContainerImpl container) {
  278. StringBuffer sb = new StringBuffer();
  279. ArrayList fields = container.getObjElements();
  280. sb.append(" {\n");
  281. sb.append(" title: '" + container.getTitle() + "',\n");
  282. sb.append(" autoHeight:" + container.isAutoHeight() + ",\n");
  283. sb.append(" collapsed: " + container.isCollapsed() + ",\n");
  284. sb.append(" collapsible: true,\n");
  285. sb.append(" xtype:'fieldset',\n");
  286. sb.append(" width: 700,\n");
  287. sb.append(" layout:'column',\n");
  288. sb.append(" border:false,\n");
  289. sb.append(" labelSeparator:':',\n");
  290. sb.append(" items:[\n");
  291. sb.append(getFieldJs(fields));
  292. sb.append(" ]\n");
  293. sb.append(" },\n");
  294. return sb;
  295. }
  296. /**
  297. * 生成 hiddens
  298. *
  299. * @param hiddens
  300. * @return
  301. */
  302. @SuppressWarnings("rawtypes")
  303. public StringBuffer getHiddenJs(ArrayList hiddens) {
  304. StringBuffer sb = new StringBuffer();
  305. String classids = formCollection.getClassid();
  306. String[] classidStr = classids.split(",");
  307. for (int i = 0; i < classidStr.length; i++) {
  308. String classid = classidStr[i];
  309. sb.append(" {\n");
  310. sb.append(" xtype:'hidden',\n");
  311. sb.append(" id:'FD_OBJECTID" + classid + "',\n");
  312. sb.append(" name: 'FD_OBJECTID" + classid + "'\n");
  313. sb.append(" },\n");
  314. }
  315. for (int i = 0; i < hiddens.size(); i++) {
  316. HiddenFieldImpl hiddenField = (HiddenFieldImpl) hiddens.get(i);
  317. sb.append(" {\n");
  318. sb.append(" xtype:'hidden',\n");
  319. sb.append(" id:'" + hiddenField.getName() + "_" + hiddenField.getClassid() + "',\n");
  320. sb.append(" name: '" + hiddenField.getName().toUpperCase() + "_"
  321. + hiddenField.getClassid() + "',\n");
  322. sb.append(" value: '" + hiddenField.getValue() + "'\n");
  323. sb.append(" },\n");
  324. }
  325. return sb;
  326. }
  327. /**
  328. * 生成具体字段的js代码,
  329. *
  330. * @param fields
  331. * @return
  332. */
  333. @SuppressWarnings("rawtypes")
  334. public StringBuffer getFieldJs(ArrayList fields) {
  335. StringBuffer sb = new StringBuffer();
  336. for (int i = 0; i < fields.size(); i++) {
  337. ReportFieldImpl field = (ReportFieldImpl) fields.get(i);
  338. if (field.getControlType().equals("text")) {// 文本框-text
  339. sb.append(getTextJs(field));
  340. } else if (field.getControlType().equals("select")) {// 下拉框-commbo
  341. sb.append(getSelectJs(field));
  342. } else if (field.getControlType().equals("checkbox")) {// 复选框-checkbox
  343. sb.append(getCheckboxJs(field));
  344. } else if (field.getControlType().equals("radio")) {// 单选框-radio
  345. sb.append(getRadioJs(field));
  346. } else if (field.getControlType().equals("date")) {// 日期-date
  347. sb.append(getDateJs(field));
  348. } else if (field.getControlType().equals("textarea")) {// 文本域-textarea
  349. sb.append(getTextareaJs(field));
  350. } else if (field.getControlType().equals("tree")) {// 树形下拉框-commbotree
  351. sb.append(getTreeJs(field));
  352. } else if (field.getControlType().equals("datetime")) {// 日期时间-datetime
  353. sb.append(getDateTimeJs(field));
  354. } else if (field.getControlType().equals("upload")) {// 上传组件-upload
  355. // sb.append(getTreeJs(field));
  356. } else if (field.getControlType().equals("hidden")) {// 隐藏字段-hidden
  357. // sb.append(getTreeJs(field));
  358. } else if (field.getControlType().equals("number")) {// 数字框-number
  359. // sb.append(getTreeJs(field));
  360. }
  361. }
  362. sb.reverse();
  363. sb.deleteCharAt(1);
  364. sb.reverse();
  365. return sb;
  366. }
  367. /**
  368. * 生成文本框
  369. *
  370. * @param field
  371. * @return
  372. */
  373. public StringBuffer getTextJs(ReportFieldImpl field) {
  374. StringBuffer sb = new StringBuffer();
  375. Validate validate = field.getValidate();
  376. sb.append(" {\n");
  377. sb.append(" columnWidth:" + field.getColumnWidth() + ",\n");
  378. sb.append(" layout: 'form',\n");
  379. sb.append(" labelWidth:80,\n");
  380. sb.append(" border:false,\n");
  381. sb.append(" items: [{\n");
  382. sb.append(" xtype:'textfield',\n");
  383. sb.append(" fieldLabel: '" + field.getLabel() + "',\n");
  384. if (validate != null) {
  385. if (validate.isNeed()) {
  386. sb.append(" allowBlank:false,\n");
  387. } else {
  388. sb.append(" allowBlank:true,\n");
  389. }
  390. if (!validate.getMaxLength().equals("")) {
  391. sb.append(" maxLength:" + validate.getMaxLength() + ",\n");
  392. sb.append(" maxLengthText:'最大长度" + validate.getMaxLength() + "',\n");
  393. }
  394. // ext中的vtype
  395. if (validate.getvType() != "") {
  396. sb.append(" vtype :'" + validate.getvType() + "',\n");
  397. }
  398. }
  399. sb.append(" name: '" + field.getName().toUpperCase() + "_" + field.getClassid()
  400. + "',\n");
  401. sb.append(" anchor:'95%'\n");
  402. sb.append(" }]\n");
  403. sb.append(" },\n");
  404. return sb;
  405. }
  406. /**
  407. * 生成日期控件js
  408. *
  409. * @param field
  410. * @return
  411. */
  412. public StringBuffer getDateJs(ReportFieldImpl field) {
  413. StringBuffer sb = new StringBuffer();
  414. Validate validate = field.getValidate();
  415. sb.append(" {\n");
  416. sb.append(" columnWidth:" + field.getColumnWidth() + ",\n");
  417. sb.append(" layout: 'form',\n");
  418. sb.append(" labelWidth:80,\n");
  419. sb.append(" items: [\n");
  420. sb.append(" {\n");
  421. sb.append(" fieldLabel: '" + field.getLabel() + "',\n");
  422. sb.append(" xtype:'datefield',\n");
  423. sb.append(" editable:false,\n");// 不能手工编辑输入日期值
  424. sb.append(" name: '" + field.getName().toUpperCase() + "_" + field.getClassid()
  425. + "', \n");
  426. sb.append(" anchor:'95%',\n");
  427. sb.append(" altFormats: 'Y-m-d',\n");
  428. sb.append(" format:'Y-m-d',\n");
  429. if (validate != null) {
  430. if (validate.isNeed()) {
  431. sb.append(" allowBlank:false,\n");
  432. } else {
  433. sb.append(" allowBlank:true,\n");
  434. }
  435. }
  436. sb.append(" border:false\n");
  437. sb.append(" }\n");
  438. sb.append(" ]\n");
  439. sb.append(" },\n");
  440. return sb;
  441. }
  442. /**
  443. * 生成下拉选择框js
  444. *
  445. * @param field
  446. * @return
  447. */
  448. public StringBuffer getSelectJs(ReportFieldImpl field) {
  449. StringBuffer sb = new StringBuffer();
  450. sb.append(" {\n");
  451. sb.append(" columnWidth:" + field.getColumnWidth() + ",\n");
  452. sb.append(" layout: 'form',\n");
  453. sb.append(" labelWidth:80,\n");
  454. sb.append(" border:false,\n");
  455. sb.append(" items: [\n");
  456. sb.append(" {\n");
  457. sb.append(" fieldLabel: '" + field.getLabel() + "',\n");
  458. sb.append(" anchor:'95%',\n");
  459. sb.append("xtype: 'combo' , \n");
  460. sb.append(" hiddenName:'" + field.getName().toUpperCase() + "_" + field.getClassid()
  461. + "',\n");
  462. sb.append(" store: {\n");
  463. sb.append("url : '../ws/sys/constantService/getConstantByName',\n");
  464. sb.append("autoLoad : true,\n");
  465. sb.append("baseParams : {name:'");
  466. SelectControl selectControl = (SelectControl) field.getControl();
  467. sb.append(selectControl.getConstantName());
  468. sb.append("'},\n");
  469. sb.append("xtype: 'jsonstore' , \n");
  470. sb.append("root : 'constants',\n");
  471. sb.append("fields : ['name', 'value']\n");
  472. sb.append("},\n");
  473. sb.append(" valueField:'name',\n");
  474. sb.append(" displayField:'value',\n");
  475. sb.append(" typeAhead: true,\n");
  476. sb.append(" triggerAction: 'all',\n");
  477. sb.append("listeners : {\n");
  478. sb.append(" afterrender : function(obj) {\n");
  479. sb.append(" obj.getStore().on('load', function() {\n");
  480. sb.append(" obj.setValue(obj.getValue());\n");
  481. sb.append(" });\n");
  482. sb.append(" }\n");
  483. sb.append("},\n");
  484. sb.append(" selectOnFocus:true\n");
  485. sb.append(" }\n");
  486. sb.append(" ]\n");
  487. sb.append(" },\n");
  488. return sb;
  489. }
  490. /**
  491. * 生成日期时间选择控件js
  492. *
  493. * @param field
  494. * @return
  495. */
  496. public StringBuffer getDateTimeJs(ReportFieldImpl field) {
  497. StringBuffer sb = new StringBuffer();
  498. Validate validate = field.getValidate();
  499. sb.append(" {\n");
  500. sb.append(" columnWidth:" + field.getColumnWidth() + ",\n");
  501. sb.append(" layout: 'form',\n");
  502. sb.append(" labelWidth:80,\n");
  503. sb.append(" items: [\n");
  504. sb.append(" {\n");
  505. sb.append(" fieldLabel: '" + field.getLabel() + "',\n");
  506. sb.append(" xtype:'datetimefield',\n");
  507. sb.append(" editable:false,\n");// 不能手工编辑输入日期值
  508. sb.append(" name: '" + field.getName().toUpperCase() + "_" + field.getClassid()
  509. + "', \n");
  510. sb.append(" anchor:'95%',\n");
  511. // sb.append(" altFormats: 'Y-m-d',\n");
  512. // sb.append(" format:'Y-m-d',\n");
  513. if (validate != null) {
  514. if (validate.isNeed()) {
  515. sb.append(" allowBlank:false,\n");
  516. } else {
  517. sb.append(" allowBlank:true,\n");
  518. }
  519. }
  520. sb.append(" border:false\n");
  521. sb.append(" })\n");
  522. sb.append(" ]\n");
  523. sb.append(" },\n");
  524. return sb;
  525. }
  526. public StringBuffer getRadioGroupJs(ReportFieldImpl field) {
  527. StringBuffer sb = new StringBuffer();
  528. Validate validate = field.getValidate();
  529. sb.append(" {\n");
  530. sb.append(" columnWidth:" + field.getColumnWidth() + ",\n");
  531. sb.append(" layout: 'form',\n");
  532. sb.append(" labelWidth:80,\n");
  533. sb.append(" items: [\n");
  534. sb.append(" {\n");
  535. sb.append(" fieldLabel: '" + field.getLabel() + "',\n");
  536. sb.append(" xtype:'radiogroup',\n");
  537. // sb.append(" editable:false,\n");//不能手工编辑输入日期值
  538. // sb.append(" name: '" + field.getName() + "_" +
  539. // field.getClassid()
  540. // + "', \n");
  541. sb.append(" anchor:'95%',\n");
  542. // sb.append(" altFormats: 'Y-m-d',\n");
  543. // sb.append(" format:'Y-m-d',\n");
  544. if (validate != null) {
  545. if (validate.isNeed()) {
  546. sb.append(" allowBlank:false,\n");
  547. } else {
  548. sb.append(" allowBlank:true,\n");
  549. }
  550. }
  551. sb.append(" items: [\n");
  552. sb.append(this.getRadioJs(field));
  553. sb.append(" ]\n");
  554. sb.append(" border:false\n");
  555. sb.append(" })\n");
  556. sb.append(" ]\n");
  557. sb.append(" },\n");
  558. return sb;
  559. }
  560. public StringBuffer getRadioJs(ReportFieldImpl field) {
  561. RadioControl radioControl = (RadioControl) field.getControl();
  562. String constantName = radioControl.getConstantName();
  563. StringBuffer sb = new StringBuffer();
  564. SysModel sysmodel = ModelFactory.getSysmodel();
  565. // 二维常量
  566. MdpConstant twoConstan = sysmodel.getMdpConstantByName(constantName);
  567. List<String[]> lis = twoConstan.getAllNode();
  568. for (int i = 0; i < lis.size(); i++) {
  569. String[] temp = lis.get(i);
  570. sb.append(" {boxLabel: '" + temp[0] + "', name: '" + field.getName().toUpperCase()
  571. + "',inputValue: '" + temp[1] + "'},\n");
  572. }
  573. sb.deleteCharAt(sb.lastIndexOf(","));
  574. return sb;
  575. }
  576. public StringBuffer getCheckboxGroupJs(ReportFieldImpl field) {
  577. StringBuffer sb = new StringBuffer();
  578. Validate validate = field.getValidate();
  579. sb.append(" {\n");
  580. sb.append(" columnWidth:" + field.getColumnWidth() + ",\n");
  581. sb.append(" layout: 'form',\n");
  582. sb.append(" labelWidth:80,\n");
  583. sb.append(" items: [\n");
  584. sb.append(" {\n");
  585. sb.append(" fieldLabel: '" + field.getLabel() + "',\n");
  586. sb.append(" xtype:'checkboxgroup',\n");
  587. // sb.append(" editable:false,\n");//不能手工编辑输入日期值
  588. // sb.append(" name: '" + field.getName() + "_" +
  589. // field.getClassid()
  590. // + "', \n");
  591. sb.append(" anchor:'95%',\n");
  592. // sb.append(" altFormats: 'Y-m-d',\n");
  593. // sb.append(" format:'Y-m-d',\n");
  594. if (validate != null) {
  595. if (validate.isNeed()) {
  596. sb.append(" allowBlank:false,\n");
  597. } else {
  598. sb.append(" allowBlank:true,\n");
  599. }
  600. }
  601. sb.append(" items: [\n");
  602. sb.append(this.getCheckboxJs(field));
  603. sb.append(" ]\n");
  604. sb.append(" border:false\n");
  605. sb.append(" })\n");
  606. sb.append(" ]\n");
  607. sb.append(" },\n");
  608. return sb;
  609. }
  610. public StringBuffer getCheckboxJs(ReportFieldImpl field) {
  611. CheckBoxControl checkBoxControl = (CheckBoxControl) field.getControl();
  612. String constantName = checkBoxControl.getConstantName();
  613. StringBuffer sb = new StringBuffer();
  614. SysModel sysmodel = ModelFactory.getSysmodel();
  615. // 二维常量
  616. MdpConstant twoConstan = sysmodel.getMdpConstantByName(constantName);
  617. List<String[]> lis = twoConstan.getAllNode();
  618. for (int i = 0; i < lis.size(); i++) {
  619. String[] temp = lis.get(i);
  620. sb.append(" {boxLabel: '" + temp[0] + "', name: '" + field.getName().toUpperCase()
  621. + "',inputValue: '" + temp[1] + "'},\n");
  622. }
  623. sb.deleteCharAt(sb.lastIndexOf(","));
  624. return sb;
  625. }
  626. public StringBuffer getTreeJs(ReportFieldImpl field) {
  627. StringBuffer sb = new StringBuffer();
  628. sb.append("{\n");
  629. sb.append(" columnWidth:" + field.getColumnWidth() + ",\n");
  630. sb.append(" layout : 'form',\n");
  631. sb.append(" labelWidth : 80,\n");
  632. sb.append(" border : false,\n");
  633. sb.append(" items : [new Ext.form.ComboBoxTree({\n");
  634. sb.append(" hiddenName : '" + field.getName().toLowerCase() + "',\n");
  635. sb.append(" //allowUnLeafClick : true,//非叶子节点是否可选,默认为falase 不可选\n");
  636. sb.append(" fieldLabel : '" + field.getLabel() + "',\n");
  637. sb.append(" tree : new Ext.tree.TreePanel({\n");
  638. sb.append(" root : new Ext.tree.AsyncTreeNode({\n");
  639. sb.append(" text : '--选择--',\n");
  640. sb.append(" id : '1'\n");
  641. sb.append(" }),\n");
  642. sb.append(" rootVisible : false,\n");
  643. sb.append(" border : false,\n");
  644. sb.append(" loader : new Ext.tree.TreeLoader({\n");
  645. sb.append(" baseParams : {\n");
  646. sb.append(" name : '");
  647. TreeControl selectControl = (TreeControl) field.getControl();
  648. sb.append(selectControl.getReferenceTable());
  649. sb.append("'\n");
  650. sb.append(" },\n");
  651. sb.append(" dataUrl : '../ws/sys/constantService/getTreeConstantByName',\n");
  652. sb.append(" requestMethod : 'POST'\n");
  653. sb.append(" })\n");
  654. sb.append(" })\n");
  655. sb.append(" })]\n");
  656. sb.append("}, \n");
  657. return sb;
  658. }
  659. public StringBuffer getTextareaJs(ReportFieldImpl field) {
  660. StringBuffer sb = new StringBuffer();
  661. TextAreaControl textarea = new TextAreaControl();
  662. if (field.getControl() != null) {
  663. textarea = (TextAreaControl) field.getControl();
  664. }
  665. sb.append(" {\n");
  666. sb.append(" columnWidth:.99,\n");
  667. sb.append(" layout: 'form',\n");
  668. sb.append(" labelWidth:80,\n");
  669. sb.append(" border:false,\n");
  670. sb.append(" items :[\n");
  671. sb.append(" new Ext.form.TextArea({\n");
  672. sb.append(" fieldLabel: '" + field.getLabel() + "',\n");
  673. sb.append(" width:" + textarea.getWidth() + ",\n");
  674. sb.append(" height:" + textarea.getHeight() + ",\n");
  675. sb.append(" anchor:'95%',\n");
  676. sb.append(" allowBlank:true,\n");
  677. sb.append(" hideLabel:false,\n");
  678. sb.append(" name:'" + field.getName().toUpperCase() + "_" + field.getClassid()
  679. + "'\n");
  680. sb.append(" })\n");
  681. sb.append(" ]\n");
  682. sb.append(" },\n");
  683. return sb;
  684. }
  685. }