打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ExtJs 动态添加表单
  1. Ext.namespace("ExtFile.ui");  
  2. // Form  
  3. ExtFile.ui.importFormPanel = function() {  
  4.   
  5. var myConfig = {};  
  6.   
  7. Ext.apply(myConfig, {  
  8.         labelAlign : 'right',  
  9.         frame : false,  
  10.         fileUpload : true,  
  11.         bodyStyle : 'padding:10px;',  
  12.         title : '基本信息导入',  
  13.         autoScroll :true,  
  14.         height:400,  
  15.         items : [{  
  16.             layout : 'form',  
  17.             border : false,  
  18.             bodyStyle : 'padding: 12px 10px 0 10px;',  
  19.             items : [{  
  20.                 items : [{  
  21.                     id : 'com00',  
  22.                     layout : 'column',  
  23.                     items : [{  
  24.                         columnWidth : .05,  
  25.                         layout : 'form',  
  26.                         border : false,  
  27.                         labelWidth : 2,  
  28.                         bodyStyle : 'padding: 10px 22px;',  
  29.                         items : [{  
  30.                             text : '',  
  31.                             iconCls : 'plus',  
  32.                             xtype : 'button',  
  33.                             handler : this.addField.createDelegate(  
  34.                                     this, [])  
  35.                         }]  
  36.                     }, {  
  37.                         columnWidth : .05,  
  38.                         layout : 'form',  
  39.                         border : false,  
  40.                         bodyStyle : 'padding: 10px 3px;',  
  41.                         labelWidth : 2,  
  42.                         items : [{  
  43.                             text : '',  
  44.                             iconCls : 'subtraction',  
  45.                             xtype : 'button',  
  46.                             handler : this.removeField.createDelegate(  
  47.                                     this, ['00'])  
  48.                         }]  
  49.                     }, {  
  50.                         columnWidth : .7,  
  51.                         layout : 'form',  
  52.                         labelWidth : 200,  
  53.                         border : false,  
  54.                         bodyStyle : 'padding: 10px 10px;',  
  55.                         items : [{  
  56.                                     xtype : "textfield",  
  57.                                     fieldLabel : '请选择文件(.xls文件) ',  
  58.                                     name : 'file',  
  59.                                     allowBlank : false,  
  60.                                     width : 400,  
  61.                                     blankText : '导入文件不能为空',  
  62.                                     inputType : 'file'  
  63.                                       
  64.                                 }, {  
  65.                                     xtype : 'hidden',  
  66.                                     name : 'ad_itemId00'  
  67.                                 }]  
  68.                     }]  
  69.                 }]  
  70.   
  71.             }]  
  72.         },{  
  73.             columnWidth : .7,  
  74.             layout : 'form',  
  75.             labelWidth : 200,  
  76.             border : false,  
  77.             bodyStyle : 'padding: 10px 10px;',  
  78.             html:'您导入的文件不能超过7条,以免出现等待很长时间,请您慎重上传,谢谢!'  
  79.         }],  
  80.         buttons : [{  
  81.                     text : '导入文件',  
  82.                     border : false,  
  83.                     bodyStyle : 'padding: 10px 10px 0 10px;',  
  84.                     handler : this.importBase.createDelegate(this, [])  
  85.                 }, {  
  86.                     text : '下载模板',  
  87.                     handler : this.onDownload.createDelegate(this, [])  
  88.                 }]  
  89.     });  
  90.   
  91. ExtFile.ui.importFormPanel.superclass.constructor.call(this, myConfig);  
  92. };  
  93.   
  94. Ext.extend(ExtFile.ui.importFormPanel, Ext.FormPanel, {  
  95.     index : 10,  
  96.     // 移除字段  
  97.     removeField : function(name) {  
  98.         this.index = this.index - 1;  
  99.         var comp = this.getComponent(0).getComponent(0);  
  100.         if (comp.items.getCount() <= 1) {  
  101.             Ext.MessageBox.alert('温馨提示''至少保留一项数据项!');  
  102.             return;  
  103.         }  
  104.         if (comp != null) {  
  105.             var removeArray = Ext.getCmp('com' + name)  
  106.                     .findByType('hidden');  
  107.   
  108.             // 点击删除按钮后,保存其ID  
  109. //                  this.getComponent(0).add({  
  110. //                              xtype : 'hidden',  
  111. //                              name : 'removeId',  
  112. //                              value : removeArray[0].value  
  113. //                          });  
  114.             comp.remove(Ext.getCmp('com' + name));  
  115.         };  
  116.         this.doLayout(true);  
  117.           
  118.     },  
  119.     addField : function(itemId, itemTitle, itemContent, itemClassId) {  
  120.         //this.index++;               
  121.         if(this.index >= 16){  
  122.             HM.MsgUtils.alert('警告''您添加的文件不能超过7条'null,  
  123.                         null'warn', 0, false, 230);  
  124.             return;  
  125.         }  
  126.         // alert(this.index+">>"+name);  
  127.         var comp = this.getComponent(0).getComponent(0);  
  128.         var panel = new Ext.Panel({  
  129.                     autoScroll :true,  
  130.                     id : 'com' + this.index,  
  131.                     layout : 'column',  
  132.                     items : [{  
  133.                         columnWidth : .05,  
  134.                         layout : 'form',  
  135.                         border : false,  
  136.                         labelWidth : 2,  
  137.                         bodyStyle : 'padding: 10px 22px;',  
  138.                         items : [{  
  139.                             text : '',  
  140.                             iconCls : 'plus',  
  141.                             xtype : 'button',  
  142.                             handler : this.addField.createDelegate(  
  143.                                     this, [])  
  144.                         }]  
  145.                     }, {  
  146.                         columnWidth : .05,  
  147.                         layout : 'form',  
  148.                         border : false,  
  149.                         labelWidth : 2,  
  150.                         bodyStyle : 'padding: 10px 3px;',  
  151.                         items : [{  
  152.                             text : '',  
  153.                             iconCls : 'subtraction',  
  154.                             xtype : 'button',  
  155.                             handler : this.removeField.createDelegate(  
  156.                                     this, [this.index++])  
  157.                         }]  
  158.                     }, {  
  159.                         columnWidth : .7,  
  160.                         layout : 'form',  
  161.                         labelWidth : 200,  
  162.                         border : false,  
  163.                         bodyStyle : 'padding: 10px 10px;',  
  164.   
  165.                         items : [{  
  166.                                     xtype : "textfield",  
  167.                                     fieldLabel : '请选择文件(.xls文件) ',  
  168.                                     name : 'file',  
  169.                                     width : 400,  
  170.                                     allowBlank : false,  
  171.                                     blankText : '导入文件不能为空',  
  172.                                     inputType : 'file'  
  173.                                 }/*, { 
  174.  
  175.                                     xtype : 'hidden', 
  176.                                     value : itemId, 
  177.                                     name : 'ad_itemId' + this.index 
  178.                                 }*/]  
  179.                     }]  
  180.                 });  
  181.         comp.add(panel);  
  182.   
  183.         this.doLayout(true);  
  184.         return panel;  
  185.     },  
  186.     importBase : function() {  
  187.         var permitted_extensions = ["xls"];// 定义文件的后缀名  
  188.         var temp;  
  189.         var panel = this.getComponent(0).getComponent(0);  
  190.         var textfields = panel.findByType('textfield');  
  191.         for (var i = 0; i < textfields.length; i++) {  
  192.             if (textfields[i].getValue() == '') {  
  193.                 HM.MsgUtils.alert('警告''您导入文件不能为空,请选择后保存!'null,  
  194.                         null'warn', 0, false, 230);  
  195.                 return;  
  196.             }  
  197.             if (permitted_extensions.length > 0) {  
  198.                 var result = null;  
  199.                 var parts = textfields[i].getValue().split(".");  
  200.                 if (parts.length > 1) {  
  201.                     result = parts.pop();  
  202.                 }  
  203.                 if ((permitted_extensions.indexOf(result) != -1) == false) {  
  204.                     HM.MsgUtils.alert('警告''您上传的格式不正确,请您上传以[.'  
  205.                                     + permitted_extensions + ']格式!',  
  206.                             nullnull'warn', 0, false, 230);  
  207.                     return;  
  208.                 }  
  209.             }  
  210.         }  
  211.         // 保存  
  212.         var url = Ext.template.root  
  213.                 + '/baseInfo/sec_importOrgInfo.action';  
  214.         this.getForm().submit({  
  215.             timeout : 120000,  
  216.             waitTitle : '请稍候',  
  217.             waitMsg : '正在保存数据,请您耐心等候...',  
  218.             url : url,  
  219.             isUpload : true,  
  220.             enctype : 'multipart/form-data',  
  221.             scope : this,  
  222.             method : 'post',  
  223.             success : function(form, action) {  
  224.                 Ext.MessageBox.hide();  
  225.                 if (action.result.id || action.result.info != "") {  
  226.                     this.getForm().reset();  
  227.                     HM.MsgUtils.alert('提示''保存成功!'nullnull,  
  228.                             'info', 0, false);  
  229.                     this.getForm().getEl().dom.reset();// 清空file文本框的值  
  230.                     if (this.index > 10) {  
  231.                         var t = this.index-10;  
  232.                         for(var i=0;i<t;i++){  
  233.                             this.removeField(this.index-1);  
  234.                         }  
  235.                     }  
  236.                 } else {  
  237.                     location = 'data.jsp';  
  238.                 }  
  239.             },  
  240.             failure : function(form, action) {  
  241.                 Ext.MessageBox.hide();  
  242.                 HM.MsgUtils.alert('错误', action.result  
  243.                                  action.result.message  
  244.                                 : '导入失败!'nullnull'error', 0,  
  245.                         false);  
  246.             }  
  247.         });  
  248.     },  
  249.     // 下载  
  250.     onDownload : function() {  
  251.         document.location.href = Ext.template.root  
  252.                 + '/baseInfo/sec_downFile.action';  
  253.         // html : "<a href='"+  
  254.         // Ext.template.root+"/main/sysFile_downFile.action?id="+fileId+"'  
  255.         // target=_self>"+fileName+"</a>"  
  256.         // alert('下载模板');  
  257.     }  
  258. });  



本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Ext学习笔记06
ExtJS之布局篇
Extjs4 表单
Ext 布局(layout)
ExtJs 页面布局1
Ext常用6大布局方式
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服