MyForm.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Ext.define('erp.view.ma.MyForm',{
  2. extend: 'Ext.form.Panel',
  3. alias: 'widget.myform',
  4. id: 'form',
  5. frame : true,
  6. autoScroll : true,
  7. defaultType : 'textfield',
  8. labelSeparator : ':',
  9. layout : 'column',
  10. fieldDefaults : {
  11. margin : '2 2 2 2',
  12. fieldStyle : "background:#FFFAFA;color:#515151;",
  13. labelAlign : "right",
  14. msgTarget: 'side',
  15. blankText : $I18N.common.form.blankText
  16. },
  17. initComponent : function(){
  18. this.callParent(arguments);
  19. formCondition = getUrlParam('formCondition');//从url解析参数
  20. formCondition = (formCondition == null) ? "" : formCondition.replace(/IS/g,"=");
  21. var type=getUrlParam('type');
  22. if(type){
  23. var cond=getUrlParam('cond');
  24. cond=(cond==null)?'':cond.replace(/IS/g,"=");
  25. if(type=='crm'){//市场调研
  26. this.getItemsAndButtons({caller: 'Reporttemplate', condition: cond});
  27. }else if(type=='ProductTrain'){//产品培训
  28. this.getItemsAndButtons({caller: 'PXReporttemplate', condition: cond});
  29. }
  30. }else{
  31. this.getItemsAndButtons({caller: this.caller||'Form', condition: formCondition});
  32. }
  33. },
  34. getItemsAndButtons: function(param){
  35. var me = this, main = parent.Ext.getCmp("content-panel");
  36. if(main) {
  37. main.getActiveTab().setLoading(true);
  38. }
  39. Ext.Ajax.request({//拿到form的items
  40. url : basePath + "common/singleFormItems.action",
  41. params: param,
  42. method : 'post',
  43. callback : function(options,success,response){
  44. if(main) {
  45. main.getActiveTab().setLoading(false);
  46. }
  47. var res = new Ext.decode(response.responseText);
  48. if(res.items) {
  49. Ext.each(res.items, function(item){
  50. if(screen.width >= 1280){//根据屏幕宽度,调整列显示宽度
  51. if(item.columnWidth > 0 && item.columnWidth <= 0.34){
  52. item.columnWidth = 0.25;
  53. } else if(item.columnWidth > 0.34 && item.columnWidth <= 0.67){
  54. item.columnWidth = 0.5;
  55. }
  56. }
  57. });
  58. me.add(res.items);
  59. }
  60. if(res.data){
  61. me.getForm().setValues(Ext.decode(res.data));
  62. me.getForm().getFields().each(function (item, index, length){
  63. item.originalValue = item.value;
  64. });
  65. }
  66. }
  67. });
  68. }
  69. });