easyuiの拡張機能

50559 ワード

1.combo拡張clearBtn属性表示クリアボタン

(function ($) {
    var cache = $.fn.combo,
        cacheProperty = $.extend(true, {}, $.fn.combo);

    function hideIcon() {
        cache.apply(this, ['getIcon', 0]).css('visibility',
            'hidden')
    }

    function showIcon() {
        cache.apply(this, ['getIcon', 0]).css('visibility',
            'visible')
    }

    $.fn.combo = function (options, param) {
        if(typeof options === "string"){
            return cache.apply(this, [options, param]);
        }
        options = options || {};
        return $.each(this,function(){
            var result, me = $(this);
            result = cache.apply(me, [options, param]);
                $.each(me,function(){
                    var temp = $.data(this, "combo"),
                        isCreate = false;
                    if (temp&&temp.options&&temp.options.clearBtn) {
                        cache.call($(this),{
                            icons: [{
                                iconCls: 'icon-clear',
                                handler: function () {
                                    cache.call(me, "clear");
                                    if(options.afterClear) {
                                        options.afterClear.call($(this));
                                    }
                                }
                            }],
                            onChange: function (n,o) {
                                if (cache.call($(this), "getValue") !== "") {
                                    showIcon.call($(this));
                                } else {
                                    hideIcon.call($(this));
                                }
                                if(temp.options.onChangeSelf){
                                	temp.options.onChangeSelf(n,o);
                                }
                                
                            }
                        });
                        isCreate = true;
                    }
                    isCreate && (hideIcon.call($(this)),isCreate=false);
                });
            return result;
        });
    }
    $.extend($.fn.combo, cacheProperty);
    $.extend($.fn.combo.defaults, {clearBtn: false});
    //$.extend($.fn.combo.defaults, {onChangeSelf: function(){}});
})(jQuery);

2.easyui拡張チェックルール

$.extend($.fn.validatebox.defaults.rules, {
    num : {
        validator : function(value) {
            return /^[1-9]\d*(\.\d+)?$/.test(value);
        },
        message : '      !'
    },
    notNull:{
        validator:function(value){
            return $.trim(value) !="";
        },
        message:"        "
    },
    maxLength:{
        validator:function(value,params){
            var temp = value.replace(/[^\x00-\xff]/g,"");
             return temp.length + (value.length-temp.length)*3 <= params[0];
            /*return value.length<=params[0];*/
        },
        message:"          {0} !"
     /*   message:"          {0} !"*/
    },
    numRange:{
		validator:function(value,params){
			var result = false;
			if(params.length==3){
				if(params[2]===0){
					if(value.indexOf(".")!=-1){
						params[2]="    " + params[0] + "-" + params[1] + "     !";
						return false;
					}
				}
				params.pop();
			}
			if(params.length==2){
				result = value-0 >=params[0] && value-0<=params[1];
				params.push("         " + params[0] + "-" + params[1] + "  !");
			}else if(params.length == 1) {
				result = value-0 <= params[0];
				params.push("");
				params.push("        "+ params[0] +"!");
			}else{
				params.push("");
				params.push("");
				params.push("");
				params[2]="      !";
			}
			return result;
		},
		message:"{2}"
	},
    invalidChar:{
        validator:function(value) {
            //[`~!#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]
            var pattern = new RegExp("[`~!#$%^&*()=|{}':;',\\[\\]<>/?~!#¥……&*()—|{}【】‘;:”“'。,、?]");
            return !pattern.test(value);
        },
        message:"    ~!#$%¥^&*()=|     !"
    },
	phone: {    
        validator: function(value,param){
        	if(/^1\d{10}$/.test(value)){
	            return true;
        	}else{
        		return false;
        	}
        },    
        message: '   11     '
    },
    minLength: {    
        validator: function(value,param){
        	return value.length == param[0];
        },    
        message: '   {0}   '
    }
});

3.easyui拡張動的追加datagridエディタの削除

//  datagrid:      editor
$.extend($.fn.datagrid.methods, {
	addEditor: function (jq, param) {
		if (param instanceof Array) {
			$.each(param, function (index, item) {
				var e = $(jq).datagrid('getColumnOption', item.field);
				e.editor = item.editor;
			});
		} else {
			var e = $(jq).datagrid('getColumnOption', param.field);
			e.editor = param.editor;
		}
	},
	removeEditor: function (jq, param) {
		if (param instanceof Array) {
			$.each(param, function (index, item) {
				var e = $(jq).datagrid('getColumnOption', item);
				e.editor = {};
			});
		} else {
			var e = $(jq).datagrid('getColumnOption', param);
			e.editor = {};
		}
	}
});
  :
dg.datagrid('addEditor', [ {
				field : 'controlNo',
				editor : {
					type : 'textbox',
					options : {
						validType : 'maxLength[30]'
					}
				}
} ]);

4.easyui combobox検索機能の追加

//    
		impexpPortCodeCombox=$("#impexpPortCode").combobox({
			url:ctx+'/businessDictionaryController.do?action=getComboBoxList&type=IMPEXP_PORT',
			valueField:'id',textField:'text',editable:true,required:true,width:240,clearBtn:true,panelHeight: 200,hasDownArrow:false,
			filter: function(q, row){
                var opts = $(this).combobox('options');
                return row[opts.valueField].indexOf(q) >= 0;
            },
			onSelect:function(value){
				$("#impexpPort").val(value.text);
			},
			onLoadSuccess:function(){
				if(master && master.impexpPortCode){
					impexpPortCodeCombox.combobox('select',master.impexpPortCode);
				}
			},
			
			onHidePanel:function onComboboxHidePanel() {
		        var el = $(this);
		        el.combobox('textbox').focus();
		        //            
		        var opts = el.combobox("options");
		        var data = el.combobox("getData");
		        var value = el.combobox("getValue");
		        //        ,       
		        var panel = el.combobox("panel");
		        var items = panel.find(".combobox-item-selected");
		        if (items.length > 0) {
		            var values = el.combobox("getValues");
		            el.combobox("setValues", values);
		            var text =  el.combobox("getText");
		            $("#fm_equipmentName").val(text);
		            return;
		        }
		        var allowInput = opts.allowInput;
		        if (allowInput) {
		            var idx = data.length;

		            data[idx] = [];
		            data[idx][opts.textField] = value;
		            data[idx][opts.valueField] = value;
		            el.combobox("loadData", data);
		        } else {
		            //         ,   
		            el.combobox("clear");
		        }
		    }
		});