All Downloads are FREE. Search and download functionalities are using the official Maven repository.

public.component.assets.custom.loy.js Maven / Gradle / Ivy

There is a newer version: 3.0.1.11
Show newest version
/*
 * Copyright   Loy Fu. 付厚俊
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
(function($){
	var Dictionary = {
			i18nValue : function(dictionaryId,group){
				if(this[group]){
					for(var i=0;i0){
			for (var i=0;i0){
			groups = newGroupArr.join(',');
			var url = "dicts";
			if(context){
				url = context+"/dicts";
			}
			$.ajax({ url: url,data:{"groups":groups,"lang":lang}, 
	        	success: function(data){
		            if(data.success){
		            	$.extend(Dictionary, data.data);
		            }
	        	},
				error: function(msg) { 
					$.loy.alert('Fetch dictionary data is error ','error');
				},
                complete: function(msg) { callback(); }
	        });
		}else{
			callback(); 
		}	
	}
		
	$.loy.dictList = function(group){
		return Dictionary[group];
	}
	
	$.loy.buildSelectOptions= function(selectId,group,placeholder_text,$container){
		var list = Dictionary[group];
		var temp = [];
		if(list){
			$('#'+selectId,$container).html('');
			temp.push('');
			for(var i=0;i'+l+'');
			}
		}
		$('#'+selectId,$container).html(temp.join(' '));
		$('#'+selectId,$container).chosen({allow_single_deselect:true,
			placeholder_text_single:placeholder_text});          
	}
	
	$.loy.showSysMsg = function(msg){  
		$('#systemMsgDiv').show();
		$('#systemMsgSpan').html(msg);
		var winHeight = $(window).height();
        var scroH = $(window).scrollTop();
        var topH = winHeight + scroH -150;
        $("#systemMsgDiv").css("top", topH + "px").css("position", "absolute").css("right", "5px");
		setTimeout(function(){
			$('#systemMsgDiv').hide();
		} , 1500)
	};
	$.loy.alert = function(msg,type){  
		bootbox.dialog({
		    title: $.i18n.prop('info'),
			message: msg,
			//className: "alert_modal",
			buttons:{
				ok:{
					"label" : $.i18n.prop('close'),
					"className" : "btn-sm btn-danger"
				}			
			}
		});
	};
	$.loy.confirm = function(msg,fun){  
		  bootbox.confirm({  
		        buttons: {   
		            cancel: {  
		               // label: '取消',  
		                className: 'btn-default'  
		            } ,
		            confirm: {  
		                //label: '确认',  
		                className: "btn  btn-success" 
		            },  
		        },  
		        message: msg,  
		        callback: function(result) {  
		            if(result) {  
		            	if(fun){
		            		fun(result);
		            	}
		            } else {  
		            }  
		        },  
		        title: $.i18n.prop('confirm_info')
		 });
	};
	$.loy.i18n = function($targetScope){
		var $scope;
		if($targetScope){
			$scope = $targetScope;
		}else{
			$scope = $(document);
		}
		$("*[i18n]",$scope).each(function(){
    		 var $this = $(this);
    		 var key =$this.attr('i18n');
    		 var value = $.i18n.prop(key);
    		 $this.html(value);
    	});
	}
})(jQuery);




(function($){
	$.loy = $.extend({}, $.loy);
	$.loy.i18n = function(names,lang,$container,settings){
		settings = $.extend({}, settings);
		//settings.language = lang;
		//settings.container = $container;
		var defaults = { 
		    name:names,// 资源文件名称
		    path:'',// 资源文件所在目录路径
		    mode:'both',// 模式:变量或 Map 
		    language:lang,// 对应的语言
		    cache:false, 
		    encoding: 'UTF-8', 
		    callback: function() {// 回调方法
		    	$("*[i18n]",$container).each(function(){
		    		 var $this = $(this);
		    		 var key =$this.attr('i18n');
		    		 var value = $.i18n.prop(key);
		    		 if($this.attr('placeholder')){
		    			 $this.attr('placeholder',value);
		    		 }else{
		    			 $this.html(value);
		    		 }
		    	});
		    	if(settings.custCallback){
	    			 settings.custCallback();
	    		}
		    } 
		 };
		settings = $.extend(defaults, settings);
		jQuery.i18n.properties(settings); 
	}
})(jQuery);

(function($){
	var ajaxParam={
		async:true,
		cache:false,
		dataType:'json',
		timeout:60000,
		type:'POST',
		//contentType:"application/json; charset=utf-8",
		url:'',
		shade:true,
		showErrorMsg:true,
		showSuccess:false,
		beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("ajax", true);
        }
	};
	
	$.loy = $.extend({}, $.loy);
	$.loy.statusErrorShow = function(status){
		if(status == 401){
			top.location.href ="login";
			return;
		}
		if(status == 403){
			$.loy.alert($.i18n.prop('no_permission'),'error');
			return;
		}
		$.loy.alert($.i18n.prop('system_error'),'error');
		return;
	};
	$.loy.ajax = function(options){
		options = $.extend({}, ajaxParam,options);
		if(!options.url || options.url.length==0){
			$.loy.alert("url can't null ",'error');
			return;
		}
		
		if(options.dataType=='json'){
			var error = options.error;
			var success = options.success;
			options.error = function(XMLHttpRequest, textStatus, errorThrown){
				if(error){
					error.call();
				}
				if(textStatus == 'timeout'){
					$.loy.alert($.i18n.prop('request_timeout'));
					return;
				}
				$.loy.statusErrorShow(XMLHttpRequest.status);
				
			};
			options.success = function(data, textStatus, XMLHttpRequest){
				if(options.dataType=='json'){
					if(XMLHttpRequest && XMLHttpRequest.statusText == ""){
						if(options.showErrorMsg){
							$.loy.alert($.i18n.prop('check_network'),'error');
							return;
						}  
				    }
					if(!data){
						if(error){
							error.call(this,data);
							if(options.showErrorMsg){
								$.loy.alert($.i18n.prop('data_format_error'),'error');
							}  
						}
				    }
					
					if(data == undefined ){
						if(options.shade){
						   //关闭遮罩
							closeMaskDiv();
					    }
						$.loy.alert($.i18n.prop('data_format_error'),'error');
						return;
					}
					if(!data.success){
						if(data.errorCode && data.errorCode == 'not_login'){
							top.location.href =data.loginUrl;
							return;
						}
					}
					
					if(!data.success){//业务上失败
						if(error){
							error.call(this,data);
						}
						if(data.msg && data.msg.length>0){
							if(options.showErrorMsg){
								$.loy.alert(data.msg,'error');	
							} 
						}else{
							if(options.showErrorMsg){
								$.loy.alert($.i18n.prop("system_error"),'error');	
							} 
						}
					}else{
						if(options.showSuccess){
							$.loy.showSysMsg($.i18n.prop("operate_success"));
						}
						if(success){
					       success.call(this,data);
				        }
					}
				}	
			};
			$.ajax(options);
		}	
	}
})(jQuery);





© 2015 - 2025 Weber Informatics LLC | Privacy Policy