Ext 기본 작업의 패키지

8616 단어 DAOjspextprototype
Ext.namespace('Ext.ux');
Ext.QuickTips.init(); //          

/**
 *    suggest  
 */
Msg = Ext.MessageBox;
Ext.ux.suggest = function() {
	var msgCt;

	function createBox(t, s) {
		return [
				'<div class="msg">',
				'<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
				'<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3><font color=#FF0000>',
				t,
				'</font></h3>',
				s,
				'</div></div></div>',
				'<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
				'</div>'].join('');
	}
	return {
		msg : function(title, format) {
			if (!msgCt) {
				msgCt = Ext.DomHelper.insertFirst(document.body, {
					id : 'msg-div'
				}, true);
			}
			var s = String.format.apply(String, Array.prototype.slice.call(
					arguments, 1));
			var m = Ext.DomHelper.append(msgCt, {
				html : createBox(title, s)
			}, true);
			m.slideIn('t').pause(2).ghost("t", {
				remove : true
			});
		},

		init : function() {
			var lb = Ext.get('lib-bar');
			if (lb) {
				lb.show();
			}
		}
	}
}();

Ext.apply(Ext.MessageBox, {
	suggest : Ext.ux.suggest.msg
});

/**
 *     Viewport
 */
Ext.main = {
	/**
	 *     ViewPort
	 */
	createViewPort : function(items) {
		var viewport = new Ext.Viewport( {
			layout : "fit",
			border : false,
			items : [items]
		});
		return viewport;
	}
	,

};

/**
 *   GridPanel
 */
Ext.dream = {
	
	/**
	 *          
	 * cfg['url'] = 'server.jsp';
	 * cfg['recordName'] = "Menu"; 
	 * cfg['record'] = Menu; 
	 */
	createStore:function(cfg){
		//          
		var dataStore = new Ext.data.Store( {
			autoLoad : false,
			url : cfg.url,
			reader : new Ext.data.XmlReader( {
				totalRecords : "totalNum",
				record : cfg.recordName
			}, cfg.record)
		// XmlReader  
		});//          
		return dataStore;
	},
	/**
	 * url:      record:     tbar:      columnModel:       pageSize:         
	 * var cfg = {};
	 * cfg['dataStore'] GridPanel    
	 * cfg['tbar'] = topBar;
	 * cfg['columnModel'] = columnModel; 
	 * cfg['pageSize'] = 4; 
	 * cfg['sm'] = sm;       
	 */
	createGridPanel : function(cfg) {

		var pagingBar = new Ext.PagingToolbar( {
			store : cfg.dataStore,
			pageSize : cfg.pageSize,
			displayInfo : true,
			displayMsg : ' {0}   {1} ,  {2} ',
			emptyMsg : "    "
		});

		//   Grid    
		var gridPanel = new Ext.grid.GridPanel( {

			border : false,
			width : Ext.get('box').getWidth(),
			frame : true,
			tbar : cfg.tbar,
			bbar : pagingBar,
			store : cfg.dataStore,
			stripeRows : true,
			viewConfig : {
				forceFit : true
			},
			sm : cfg.sm,//      
			cm : cfg.columnModel
		});//   grid    
		cfg.dataStore.load( {
			params : {
				start : 0,
				limit : cfg.pageSize
			}
		})
		return gridPanel;
	}
};

/**
 *     
 */
Ext.validate = {
	/**
	 *            
	 * grid:    
	 */
	selectedMore:function(grid){
		//                 
		var records = grid.getSelectionModel().getSelections();
		//              
		if (records.length != 1) {
			Ext.Msg.alert('  ', '<font color="red">        </font>');
			return true;
		} else{
			return false;
		}
	},
	
	/**
	 *            
	 */
	noSelected:function(grid){
		//                 
		var records = grid.getSelectionModel().getSelections();
		//              
		if (records.length == 0) {
			Ext.Msg.alert('  ', '<font color="red">       </font>');
			return true;
		} else {
			return false;
		}
	},
	
	/**
	 *                       , ,   
	 * name:  
	 * grid:GridPanel  
	 */
	getSelected:function(grid,name){
		//                 
		var records = grid.getSelectionModel().getSelections();
		var res = "";
		for (i = 0;i < records.length; i++) {
			var one = records[i].get(name);//       
			if (i == records.length - 1) {
				res = res + one;
			} else {
				res = res + one + ",";
			}
		}
		return res;
	}
}

/**
 *   ComboBox,  var cfg = {}; cfg['fieldLabel'] = '   ';    cfg['url']
 * ='comboServer.jsp';    url cfg['recordType'] = 'Menu',      cfg['fields'] =
 * ['name','idno']; cfg['name'] = 'parentid';    
 */
Ext.combo = {
	createComboBox : function(cfg) {
		var fields = new Array();
		fields = cfg.fields;
		var record = Ext.data.Record.create([ {
			name : fields[0]
			,
		}, {
			name : fields[1]
		}]);
		var myReader = new Ext.data.XmlReader( {
			totalRecords : "totalNum",
			record : cfg.recordType
			,
		}, record);

		var comboStore = new Ext.data.Store( {
			autoLoad : true,
			url : cfg.url,
			reader : myReader
		});

		var combo = new Ext.form.ComboBox( {
			fieldLabel : cfg.fieldLabel,
			store : comboStore,
			value : '   ...',
			editable : false,//     
			name : cfg.name,
			displayField : fields[0],//      
			valueField : fields[1],//      
			triggerAction : 'all'
		});
		return combo;
	}
};

/**
 *        
 * @author     
 */
Ext.dao = {
	
	/**
	 *          ,                js  obj {} 
	 *   : 
	 * 1、     radio,        boxLabel
 	 * 2、    combo,       3、    checkbox,       boxLabel,   ","       
	 */
	getObjFromForm : function(form) {
		fields = form.getForm().items;
		var obj = {};
		var flag = true;//     
		var checkboxValue = [];//         
		var checkBoxName;//          

		for (var i = 0;i < fields.length; i++) {
			//         
			var field = fields.itemAt(i);
			var value = field.getValue();//    
			var xtype = field.getXType();//      

			if (xtype == 'radio') {//     
				if (flag) {
					if (value) {
						value = field.boxLabel;
						flag = false;
						obj[field.name] = value;
					}
				}

			} else if (xtype == 'combo') {
				var index = field.store.find(field.valueField, value);//               
				if (index != -1) {
					var selItem = field.store.getAt(index);
					value = selItem.get(field.valueField);
					obj[field.name] = value;
				}
			} else if (xtype == 'checkbox') {
				if (value) {//    
					checkBoxName = field.name;
					checkboxValue.push(field.boxLabel)
				}
			} else {//     
				obj[field.name] = value;
			}
		}
		obj[checkBoxName] = checkboxValue;

		return obj;
	},
	
	/**
	 *        
	 * cfg.form         
	 * cfg.url    
	 */
	loadFormData:function(cfg){
		var formObj = cfg.form;
		formObj.form.load( {
			waitMsg : '   ...',
			waitTitle : '  ',
			url : cfg.url,
			method : 'POST',
			failure : function(form, action) {
				Ext.Msg.alert('  ', '    ,   :' + action.failureType);
			}
		});
	}
};

좋은 웹페이지 즐겨찾기