Extjs管理系统的 增加和修改使用同一个win

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();//代表根目录
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title>系统开发基础平台V3.5</title>
<link rel="stylesheet" type="text/css" href="<%=path %>/content/extjs/resources/css/ext-all.css">


<style type="text/css">
 html, body {
        font:normal 12px verdana;
        margin:0;
        padding:0;
        border:0 none;
        overflow:hidden;
        height:100%;
 }
 
 .dialogIcon{
	background-image: url("<%=path %>/content/images/modifyPass.png");
}
</style>
	<script type="text/javascript" src="<%=path %>/content/extjs/ext-base.js"></script>
	<script type="text/javascript" src="<%=path %>/content/extjs/ext-all.js"></script>
	<script type='text/javascript' src='/spring/dwr/engine.js'></script>
    <script type='text/javascript' src='/spring/dwr/util.js'></script>
   <script type='text/javascript' src='/spring/dwr/interface/applyService.js'></script>
   </head>
   <script type="text/javascript">
   var grid;
   var selectId;
   var registWin;
   var submit_url;
   function buildWin(id,name){
   var date;
   submit_url = name;
   	if(id== null){
   	       Ext.getCmp("id").setValue(id);
		   Ext.getCmp("name").setValue("");
		   Ext.getCmp("msg").setValue("");
		   Ext.getCmp("win").setTitle("添加新的功能菜单");
   		win.show();
   	}else{
   	 	dwr.engine.setAsync(false); 
		applyService.getEntity("Menu",id,function(data){
    	date= data;
    	});
    	dwr.engine.setAsync(true);
    	   Ext.getCmp("id").setValue(id);
		   Ext.getCmp("name").setValue(date.menuName);
		   Ext.getCmp("msg").setValue(date.bewrite);
		   Ext.getCmp("win").setTitle("修改已有的功能菜单");
   	}
   	win.show();
   }
  function login(name){
  if(Ext.getCmp('name').getValue()==""){
    	Ext.Msg.alert("错误","功能名称不能为空");
    	return null;
    }
  if(Ext.getCmp('msg').getValue()==""){
    	Ext.Msg.alert("错误","描述信息不能为空");
    	return null;
    }
    
    form.form.submit({
		url					:name,
		method			:"post",
		success 			:function(form,action){
				if(action.result.msg=="OK"){
						win.hide();
						store_power.reload();
				}else{
						Ext.Msg.alert('错误提示',action.result.msg);
				}
				},
			//提交失败的回调函数  
			failure : function(form, action) {
				switch (action.failureType) {
				case Ext.form.Action.CLIENT_INVALID:

					Ext.Msg.alert('错误提示', '表单数据非法请核实后重新输入!');
					break;
				case Ext.form.Action.CONNECT_FAILURE:
					Ext.Msg.alert('错误提示', '网络连接异常!');
					break;
				case Ext.form.Action.SERVER_INVALID:
					Ext.Msg.alert('错误提示', "您的输入用户信息有误,请核实后重新输入!"
							+ action.result.msg + "--");
					//form.form.reset();
				}
			}

		});
  }
   function buildForm(){
   form = new Ext.form.FormPanel({
            baseCls 				: 'x-plain',
			labelWidth 			: 55,
			width					:300,
			defaultType 		: 'textfield',
			buttonAlign 		: 'center',
			items : [ {
				id : "id",
				fieldLabel : '功能名称',
				name : 'menu.id',
				hidden :true,
				anchor : '100%' // anchor width by percentage
			},{
				id : "name",
				fieldLabel : '功能名称',
				name : 'menu.menuName',
				anchor : '100%' // anchor width by percentage
			}, {
				id : "msg",
				fieldLabel : '描述信息',
				name : 'menu.bewrite',
				anchor : '100%' // anchor width by percentage
			}],
			buttons : [ {
				text : '添加',
				type : 'submit',
				id : "login",
				handler : function(){login(submit_url);}
			}, {
				text : '取消',
				handler : function() {
					win.hide();
				}

			} ]
             });
             win = new Ext.Window({
            	 id:'win',
             	title:'添加新的功能',
             	closable : false,
             	closeactin: 'hide',
             	items:form
             });
   }
  Ext.onReady(function () {
  buildForm();
/*      	dwr.engine.setAsync(false); 
	applyService.getEntity("Menu",1,function(data){
    	date= data;
    	alert(data);
    	});
    		applyService.getEntity2Nodeinfo(1,function(data){
    	date= data;
    	alert(data);
    	});
   dwr.engine.setAsync(true);   */
             //数据源
             	store_power = new Ext.data.JsonStore({//对应类别store   
                                url:"ask_findMuneInfo.do",   
                                root:'root', 
                                idProperty: 'id',
                                fields:[{   
                                    name:'power_id',   
                                    mapping:'id'  
                                },{   
                                    name:'name',   
                                    mapping:'menuName'  
                                },{
                                	name:'miaoshu',
                                	mapping:'bewrite'
                                },{
                                	name:'times',
                                	mapping:'time'
                                }]
                            });

	store_power.load();
             //复选框列
             var sm = new Ext.grid.CheckboxSelectionModel();
              //定义列
              var column = new Ext.grid.ColumnModel({
                  columns: [
                  		sm,
    					{ header: '编号', dataIndex: 'power_id', sortable: true },
                       { header: '功能名称', dataIndex: 'name' },
                       { header: '描述', dataIndex: 'miaoshu' }
                  ]
              });
              //添加按钮
             var tbtn = new Ext.Toolbar.Button({
                  text: '添加新的功能菜单',
                  icon:'<%=path%>/content/images/add.gif',
                 listeners: {'click': function () {
                 		form.form.reset();
						buildWin(null,"apply_newMenu.do");
                          }
                  }
             });
             var tbar = new Ext.Toolbar.Button({
                  text: '修改功能菜单',
                  icon:'<%=path%>/content/images/upload.gif',
                 listeners: {'click': function () {
                 		var row = grid.getSelectionModel().getSelections();
                 		//for (var i = 0; i < row.length; i++) {
                 			if(row.length>1){
                 				Ext.Msg.alert("错误","每次只能修改一条");
                 				return null;
                 			}
							if(row.length==0){
                 			Ext.Msg.alert("错误","没有选择要修改的记录");
                 				return null;
                 			}
                 			selectId = row[0].get('power_id');
                 			buildWin(selectId,"apply_upMenu.do");
                          }
                  }
             });
                 var tbarr = new Ext.Toolbar.Button({
                  text: '删除功能菜单',
                  icon:'<%=path%>/content/images/delete.gif',
                 listeners: {'click': function () {
                 		var row = grid.getSelectionModel().getSelections();
                 		//for (var i = 0; i < row.length; i++) {
                 			if(row.length>1){
                 				Ext.Msg.alert("错误","每次只能删除一条");
                 				return null;
                 			}
							if(row.length==0){
                 			Ext.Msg.alert("错误","没有选择要删除的记录");
                 				return null;
                 			}
                 			    Ext.Msg.confirm("提示","确定删除该记录?",function(name){
                 				if(name=="yes"){
                 				
                 			   	dwr.engine.setAsync(false); 
								applyService.delectEntity("menu",row[0].get('power_id'),function(data){
							    	date= data;
							    	});
							    dwr.engine.setAsync(true); 
							    if(date == "success"){
							    store_power.reload();
							    }
							    
							    }
                 			});
                          }
                  }
             });
 
             
             //分页控件
             var pager = new Ext.PagingToolbar({                 
             pageSize: 2,                
             store: store_power,                 
             
             listeners: {"beforechange": function (bbar, params) {
                         var grid = bbar.ownerCt ;                     
                          var store = grid.getStore();
                         var start = params.start;
                          var limit = params.limit;
                         alert(store.getCount());
                       return false;
                      }
                 }
             });
             //列表
             grid = new Ext.grid.GridPanel({
                  sm: sm,
                 store: store_power,
                 tbar: [tbtn,tbar,tbarr],
                 bbar: pager,
                 colModel: column
             });
             new Ext.Viewport({
             layout:'fit',
             	items:[grid]
             });
         });
   </script>
<body>

</body>
</html>

 

你可能感兴趣的:(ExtJs)