老手网

给DWZ(JUI)的lookupGroup增加回调函数

分类:javascript 作者:oldhand 来源: 发布:2013-05-14 09:42:12
DWZ 是一个很好的富客户端框架
lookupGroup也是一个必用到的东东,但没有回调函数,后期处理相当的不便。
修改其dwz.database.js
增加几行,就能实行一个很好的回调。

使用就方便了,
如:
<input type="hidden" value="H2" name="roleid" id="roleid">
<input type="hidden" value="H2" name="roleid.id" id="roleid_id">
<input type="text" name="roleid.Name" readonly="" class="input input-large required textInput readonly" value="CEO">	
<a width="400" lookupgroup="roleid" warn="请选择部门" href="index.php?........." callback="roleid_callback" class="btnLook">选择部门</a>	
<script language="javascript">
function roleid_callback()
{
	jQuery("#roleid").val(jQuery("#roleid_id").val());
}
</script>

修改的代码如下:


/**
 * @author 
 */
(function($){
	var _lookup = {currentGroup:"", suffix:"", $target:null, pk:"id",callback:null}; /*  这里增加   ,callback:null   */
	var _util = {
		_lookupPrefix: function(key){
			var strDot = _lookup.currentGroup ? "." : "";
			return _lookup.currentGroup + strDot + key + _lookup.suffix;
		},
		lookupPk: function(key){
			return this._lookupPrefix(key);
		},
		lookupField: function(key){
			return this.lookupPk(key);
		}
	};
	
	$.extend({
		bringBackSuggest: function(args){
			var $box = _lookup['$target'].parents(".unitBox:first");
			$box.find(":input").each(function(){
				var $input = $(this), inputName = $input.attr("name");
				
				for (var key in args) {
					var name = (_lookup.pk == key) ? _util.lookupPk(key) : _util.lookupField(key);

					if (name == inputName) {
						$input.val(args[key]);
						break;
					}
				}
			});
			var callback = _lookup['callback'];      /*  这6行是增加的 处理回调 */
			try
			{
				eval(callback+"();");
			}
			catch (e){}
		},
		bringBack: function(args){
			$.bringBackSuggest(args);
			$.pdialog.closeCurrent();
		}
	});
	
	$.fn.extend({
		lookup: function(){
			return this.each(function(){
				var $this = $(this), options = {mask:true, 
					width:$this.attr('width')||820, height:$this.attr('height')||400,
					maxable:eval($this.attr("maxable") || "true"),
					resizable:eval($this.attr("resizable") || "true")
				};
				$this.click(function(event){
					_lookup = $.extend(_lookup, {
						currentGroup: $this.attr("lookupGroup") || "",
						callback: $this.attr("callback"),  /*  这一行是增加的  */
						suffix: $this.attr("suffix") || "",
						$target: $this,
						pk: $this.attr("lookupPk") || "id"
					});
					
					var url = unescape($this.attr("href")).replaceTmById($(event.target).parents(".unitBox:first"));
					if (!url.isFinishedTm()) {
						alertMsg.error($this.attr("warn") || DWZ.msg("alertSelectMsg"));
						return false;
					}
					
					$.pdialog.open(url, "_blank", $this.attr("title") || $this.text(), options);
					return false;
				});
			});
		},
	/*以下代码省略*/
})(jQuery);


-
分享到:

Copyright © 2012 - 2014 oldhand.cn All Rights Reserved. 粤ICP备13025864号