package com.huigou.uasp.builder.jsbutton;

import java.util.ArrayList;
import java.util.List;

import com.huigou.uasp.builder.ButtonTypeInter;
import com.huigou.uasp.builder.vo.ButtonAttributeVO;
import com.huigou.uasp.util.Utils;
import com.huigou.uasp.util.Constant;

public class DeleteButtonResult implements ButtonTypeInter {
	
	public List<String> processOutResult(StringBuffer sb,ButtonAttributeVO btnAttributes){
		List <String> list=new ArrayList<String>();
		//  sb.append("//删除数据方法;");
		  sb.append(" function deleteHandler(){");
		  sb.append("	 var row = UICtrl.checkSelectedRows(").append(Utils.toLowerCaseFirstOne(btnAttributes.getEntityName())).append("GridManager);");
		  if (btnAttributes.getIsForm()==1){  //是表单生成器
			   sb.append("	  var action = '/dataManage/deleteDataRecord.ajax?formNo='+$(\"#formNo\").val();");
		   } else {
		  sb.append("	    var action = \"/").append(Utils.toLowerCaseFirstOne(btnAttributes.getEntityName()))
		  .append("/delete").append(Utils.toUpperCaseFirstOne(btnAttributes.getEntityName())).append("s.ajax\";");
		   }
		  sb.append("	    DataUtil.delSelectedRows({");
		  sb.append("	        action: action,");
		  sb.append("	        idFieldName: 'id',");
	      sb.append("           gridManager : ").append(Utils.toLowerCaseFirstOne(btnAttributes.getEntityName())).append("GridManager,");
		  sb.append("	        onSuccess: ").append("reload").append(Utils.toUpperCaseFirstOne(btnAttributes.getEntityName())).append("Grid");
		  sb.append("	    });");
		  sb.append(" }");
		  sb.append(Constant.SYSMBOL_LINE);
		  list.add(sb.toString());
		 // list.add(Integer.toString(fieldAttributes.getCurrCols()));
		return list;
	}
}
