<!--
/*--------------------------------------------------------------------------
 *  WQ.CURD
 *
 *  Author: 	xqiang
 *  Version: 	2.0
 *	Date:		2009-06-17
 *--------------------------------------------------------------------------*/
WQ.CURD = {
	debug: false,
	VAR_ACTION : "?action",
	BASE_URL : "?action=",
	params : null
};


WQ.CURD.init = function (url,varAction) {
	if (varAction) this.VAR_ACTION = varAction;
	this.BASE_URL = (url ? (url + "?"): "")+this.VAR_ACTION+"=";
};
WQ.CURD.doComplete = function () {
	return false;		
};
WQ.CURD.getCheckboxValues = function (checkboxName) {
	return WQ.form.getCheckboxValues(checkboxName,',');
};
/**
 * 通用操作
 * @param string action 操作方法名；　如: del
 * @param string varId 变量ID名称; 如：id|projectId|...; 默认为"id"
 * @param string checkboxName 默认为"key"
 * @param string id 需要删除的id 格式：1|2|1,2,3|; 如果此值为空则从checkName中取值
 * @param boolean isAjax 是否是AJAX方式 true/false 默认为false
 * @param function processResponse 回调函数 默认为 doComplete
 * @param string target 目标ID
 * @param string alertMessage 提示信息
 * @param string fileURL 网页路径
 */
WQ.CURD.action = function (action,varId,checkboxName,id,isAjax,processResponse,target,alertMessage,fileURL,params) {
	if (!varId) varId = "id";
	if (!checkboxName) checkboxName = 'key';
	//if (!id) id = '';
	if (isAjax == undefined || isAjax == "") isAjax = false;
	if (processResponse == undefined || !WQ.type.isFunction(processResponse)) processResponse = this.doComplete;
	if (target == undefined) target = "";
	//if (!alertMessage) alertMessage = '确实要删除选择项吗?';
	if (fileURL) 
		fileURL = fileURL+"?"+this.VAR_ACTION+"="+action;
	else
		fileURL = this.BASE_URL+action;	
	if (params) fileURL += "&"+params;
	if (this.params) fileURL += "&"+this.params;
	
	if (this.debug) {
		alert("varId = [" + varId + "]\n" 
			+ "checkboxName = [" + checkboxName + "]\n"
			+ "id = [" + id + "]\n"
			+ "isAjax = [" + isAjax + "]\n"
			+ "processResponse = [" + processResponse + "]\n"
			+ "target = [" + target + "]\n"
			);
	}		
	if (!id) id = this.getCheckboxValues(checkboxName);
	if (this.debug) alert("id = ["+id+"]");
	if (!id) {
		alert('请选择操作项!');
		return false;
	}
	if (alertMessage) {
		if (!confirm(alertMessage)) {
			return false;	
		}
	}
	if (isAjax) {
		SysAjax.send(fileURL,'ajax=1&'+varId+'='+id,processResponse,target);
	} else {
		window.location.href = fileURL+"&"+varId+"="+id;
	}	
};
/**
 * 添加操作	
 */
WQ.CURD.add = function (params) {
	var url = this.BASE_URL+"add";
	if (params) url += "&"+params;
	if (this.params) url += "&"+this.params;
	if (this.debug) alert("url = ["+url+"]");
	window.location.href  = url;
};

/**
 * 查看页面
 * @param string varId 变量ID名称; 如：id/projectId/...; 默认为"id"
 * @param string checkboxName 默认为"key"
 * @param int id 需要删除的id 格式：1/2/3; 如果此值为空则从checkName中取值
 */
WQ.CURD.read = function (varId,checkboxName,id) {
	if (!id) {		
		id = this.getCheckboxValues(checkboxName);
	}
	if (!id) {
		alert('请选择查看项!');
		return false;
	}
	window.location.href =  this.BASE_URL+"read&"+varId+"="+id;
};

/**
 * 编辑页面	
 * @param string varId 变量ID名称; 如：id/projectId/...; 默认为"id"
 * @param string checkboxName 默认为"key"
 * @param int id 需要删除的id 格式：1/2/3; 如果此值为空则从checkName中取值
 */
WQ.CURD.edit = function (varId,checkboxName,id) {
	if (!id) {		
		id = this.getCheckboxValues(checkboxName);
	}
	if (this.debug) alert("id = ["+keyValue+"]");
	if (!id) {
		alert('请选择编辑项!');
		return false;
	}
	window.location.href =  this.BASE_URL+"edit&"+varId+"="+id;
};

/**
 * 普通的删除操作
 * @param string varId 变量ID名称; 如：id/projectId/...; 默认为"id"
 * @param string checkboxName 默认为"key"
 * @param string id 需要删除的id 格式：1/2/1,2,3/; 如果此值为空则从checkName中取值
 * @param boolean isAjax 是否是AJAX方式 true/false 默认为false
 * @param function processResponse 回调函数 默认为 doComplete
 * @param string target 目标ID
 * @param string alertMessage 提示信息
 * @param string fileURL 网页路径
 */
WQ.CURD.del = function (varId,checkboxName,id,isAjax,processResponse,target,alertMessage,fileURL) {
	
	if (!alertMessage) alertMessage = '确实要删除选择项吗?';
	this.action("delete",varId,checkboxName,id,isAjax,processResponse,target,alertMessage,fileURL);	
};

/**
 * 彻底删除操作
 * @param string varId 变量ID名称; 如：id/projectId/...; 默认为"id"
 * @param string checkboxName 默认为"key"
 * @param string id 需要删除的id 格式：1/2/1,2,3/; 如果此值为空则从checkName中取值
 * @param boolean isAjax 是否是AJAX方式 true/false 默认为false
 * @param function processResponse 回调函数 默认为 doComplete
 * @param string target 目标ID
 * @param string alertMessage 提示信息
 */
WQ.CURD.delDownright = function (varId,checkboxName,id,isAjax,processResponse,target,alertMessage,fileURL) {
	
	if (!alertMessage) alertMessage = '删除将不可恢复.\n\n确定要彻底删除选择项吗?';
	this.action("delDownright",varId,checkboxName,id,isAjax,processResponse,target,alertMessage,fileURL);	
};

/**
 * 彻底删除操作
 * @param string varId 变量ID名称; 如：id/projectId/...; 默认为"id"
 * @param string checkboxName 默认为"key"
 * @param string id 需要删除的id 格式：1/2/1,2,3/; 如果此值为空则从checkName中取值
 * @param boolean isAjax 是否是AJAX方式 true/false 默认为false
 * @param function processResponse 回调函数 默认为 doComplete
 * @param string target 目标ID
 */
WQ.CURD.restore = function (varId,checkboxName,id,isAjax,processResponse,target,alertMessage,fileURL) {
	
	if (!alertMessage) alertMessage = '确定还原选择项吗?';
	this.action("restore",varId,checkboxName,id,isAjax,processResponse,target,alertMessage,fileURL);	
};

var CURD = WQ.CURD;
//-->