Ext 는 표 로 데 이 터 를 증가, 삭제, 수정 하 는 전체 인 스 턴 스 를 표시 합 니 다.

1. 페이지 js
/**
 *     
 */
var menuMgr = function() {

	var menuForm;//     
	var window;//   
	var gridPanel;//   
	var dataStore;//    
	return {

		init : function() {
			var Menu = new Ext.data.Record.create([ {
				name : 'idno'
			}, {
				name : 'name'
			}, {
				name : 'img'
			}, {
				name : 'url'
			}, {
				name : 'parentid'
			}, {
				name : 'sort'
			}, {
				name : 'oper'
			}]);
			// var fields = ['idno', 'name', 'img', 'url', 'parentid',
			// 'sort','oper'];

			//      
			var topBar = new Ext.Toolbar([ {
				text : '    ',
				iconCls : 'add',
				handler : menuMgr.showAddMenuWindow
			//          ()
					}, {
						text : '    ',
						iconCls : 'edit',
						handler : menuMgr.showEditMenuWindow
					}, {
						text : '    ',
						iconCls : 'delete',
						handler : menuMgr.delMenu
					}

			]);

			var sm = new Ext.grid.CheckboxSelectionModel();//          
			var columnModel = new Ext.grid.ColumnModel([sm, {
				header : "idno",
				dataIndex : "idno",
				sortable : true
			}, {
				header : "    ",
				dataIndex : "name",
				sortable : true
			}, {
				header : "  ",
				dataIndex : "img",
				width : 40,
				align : 'center',
				//   
					renderer : function(imgUrl) {
						return "<img src='../../images/" + imgUrl + "'/>"
					}
				}, {
					header : "url",
					dataIndex : "url",
					width : 150,
					sortable : false
				}, {
					header : "    ",
					dataIndex : "parentid",
					sortable : true
				}, {
					header : "  ",
					dataIndex : "sort",
					sortable : true
				}, {
					header : "  ",
					dataIndex : "oper"
				}]);

			var storeCfg = {};//        
			storeCfg['url'] = 'server.jsp';
			storeCfg['recordName'] = "Menu";
			storeCfg['record'] = Menu;

			dataStore = Ext.dream.createStore(storeCfg);

			var gridCfg = {};//       
			// cfg['fields'] = fields;
			gridCfg['dataStore'] = dataStore;
			gridCfg['tbar'] = topBar;
			gridCfg['columnModel'] = columnModel;
			gridCfg['pageSize'] = 4;
			gridCfg['sm'] = sm;
			gridPanel = Ext.dream.createGridPanel(gridCfg);
			Ext.main.createViewPort(gridPanel);
		},

		/**
		 *     、      
		 */
		createMenuWindow : function() {

			var cfg = {};//      
			cfg['fieldLabel'] = '   ';
			cfg['url'] = 'comboServer.jsp';
			cfg['recordType'] = 'Menu', cfg['fields'] = ['name', 'idno'];
			cfg['name'] = 'parentid';
			var parentMenu = Ext.combo.createComboBox(cfg);
			window = new Ext.Window( {

				title : '<div align="left">    </div>',
				x : 150,
				y : 100,
				frame : true,
				modal : true,
				closable : true,
				animCollapse : true,//    
				//          
				collapsible : false,
				resizable : false,
				//       
				items : [menuForm = new Ext.form.FormPanel( {
					id : 'menuForm',
					width : 400,
					frame : true,
					border : false,
					labelAlign : 'right',
					items : [new Ext.form.TextField( {
						name : 'idno',
						value : '0',
						inputType : 'hidden'

					}),

					new Ext.form.TextField( {
						fieldLabel : '    ',
						id : 'name',
						name : 'name',
						allowBlank : false,
						blankText : '        ',
						width : 200,
						msgTarget : 'side'

					}), new Ext.form.TextField( {
						fieldLabel : '    ',
						id : 'img',
						name : 'img',
						allowBlank : false,
						blankText : '        ',
						width : 200,
						msgTarget : 'side'

					}), new Ext.form.TextField( {
						fieldLabel : '    ',
						id : 'url',
						name : 'url',
						allowBlank : false,
						blankText : '        ',
						width : 200,
						msgTarget : 'side'

					}), parentMenu, new Ext.form.TextField( {
						fieldLabel : '  ',
						id : 'sort',
						name : 'sort',
						allowBlank : true,
						width : 200,
						msgTarget : 'side'

					}), new Ext.form.TextField( {
						fieldLabel : '  ',
						id : 'oper',
						name : 'oper',
						allowBlank : true,
						width : 200,
						msgTarget : 'side'

					})]

				})]
				,//       

			});// window  
		},

		/**
		 *         
		 */
		showAddMenuWindow : function() {
			menuMgr.createMenuWindow();
			window.addButton(new Ext.Button( {
				text : '  ',
				//          
					handler : menuMgr.addMenu
				}));
			window.show();
		},

		/**
		 *           
		 */
		showEditMenuWindow : function() {
			menuMgr.createMenuWindow();
			window.addButton(new Ext.Button( {
				text : '  ',
				//            
					handler : menuMgr.updateMenu
				}));
			if (Ext.validate.noSelected(gridPanel)) {//        
				return;
			} else {
				if (Ext.validate.selectedMore(gridPanel)) {//     
					return;
				} else {
					var idno = "";
					idno = Ext.validate.getSelected(gridPanel, 'idno');
					var cfg = {};
					cfg['form'] = menuForm;
					cfg['url'] = 'loadForm.jsp?idno=' + idno;
					Ext.dao.loadFormData(cfg);
					window.show();
				}
			}
		},

		/**
		 *         
		 */
		addMenu : function() {
			var Menu = {};
			Menu = Ext.dao.getObjFromForm(menuForm);
			MenuManager.addMenu(Menu, function(success) {
				window.close();
				if (success) {
					//       
					dataStore.reload(dataStore);
					Ext.MessageBox.alert("  ", "      ");
					// Msg.suggest("  ","      ");
				} else {
					Ext.MessageBox.alert("  ", "      ");
				}
			});
		},

		/**
		 *     
		 */
		updateMenu : function() {
			var Menu = {};
			Menu = Ext.dao.getObjFromForm(menuForm);
			MenuManager.updateMenu(Menu, function(success) {
				window.close();
				if (success) {
					//           
					dataStore.removeAll();
					dataStore.reload();
					Ext.MessageBox.alert("  ", "      ");
				} else {
					Ext.MessageBox.alert("  ", "      ");
				}
			});
		},

		/**
		 *     
		 */
		delMenu : function() {
			if (Ext.validate.noSelected(gridPanel)) {//        
				return;
			} else {
				Ext.Msg.confirm('<font color="red">  </font>', '            ?',
						menuMgr.deleteOrNot);
			};
		},

		/**
		 *     
		 */
		deleteOrNot : function(id) {
			if (id == "yes") {
				var idnos = "";
				idnos = Ext.validate.getSelected(gridPanel, 'idno');
				MenuManager.batchDelMenuByPKs(idnos, function(success) {
					if (success) {
						//        ,       
						//                 
						var records = gridPanel.getSelectionModel()
								.getSelections();
						for (i = 0;i < records.length; i++) {
							dataStore.remove(records[i]);
						}
						Ext.MessageBox.alert("  ", "      ");
					} else {
						Ext.MessageBox.alert("  ", "      ");
					}
				})
			} else {
				return;
			}
		}

	}
}();
Ext.onReady(menuMgr.init, menuMgr, true);

2, 배경 처리 MenuMgr. java

package com.dreamoa.dwrservice.menuMgr;

import org.apache.log4j.Logger;

import com.dreamoa.domain.Menu;
import com.dreamoa.sys.BaseDAO;
import com.dreamoa.util.RandomUtil;
import com.dreamoa.util.StringUtil;

/**
 *       、 、   
 * @author     
 */
public class MenuMgr extends BaseDAO<Menu>{
	
	Logger log = Logger.getLogger(MenuMgr.class);
	
	/**
	 *     
	 * @param menu
	 */
	public boolean addMenu(Menu menu){
		try {
			menu.setIdno(RandomUtil.GenPrimaryKey());
			beginTransaction();
			save(menu);
			commit();
			return true;
		} catch (RuntimeException e) {
			log.error("MenuMgr.java:addMenu(),      ");
			e.printStackTrace();
			return false;
		}
	}
	
	/**
	 *     
	 * @param menu
	 */
	public boolean updateMenu(Menu menu){
		try {
			beginTransaction();
			update(menu);
			commit();
			return true;
		} catch (RuntimeException e) {
			log.error("MenuMgr.java:updateMenu(),      ");
			e.printStackTrace();
			return false;
		}
	}
	
	/**
	 *         
	 * @param idno
	 * @return
	 */
	public boolean delMenuByPK(String idno){
		try {
			beginTransaction();
			deleteById("idno", idno);
			commit();
			return true;
		} catch (RuntimeException e) {
			log.error("MenuMgr.java:delMenuByPK(),      ");
			e.printStackTrace();
			return false;
		}
	}
	
	/**
	 *       
	 * @param idnos
	 * @return
	 */
	public boolean batchDelMenuByPKs(String idnos){
		beginTransaction();
		try {
			String[] idnoArr = StringUtil.split(idnos, ",");
			for (int i = 0; i < idnoArr.length; i++) {
				String idno = idnoArr[i];
				deleteById("idno", idno);
			}
		} catch (RuntimeException e) {
			log.error("MenuMgr.java:batchDelMenuByPKs(),        ");
			rollback();
			e.printStackTrace();
			return false;
		}
		commit();
		return true;
	}
}

좋은 웹페이지 즐겨찾기