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 EnableButtonResult implements ButtonTypeInter {
	
	public List<String> processOutResult(StringBuffer sb,ButtonAttributeVO btnAttributes){
		List <String> list=new ArrayList<String>();
		 sb.append("//启用方法 ").append(Constant.SYSMBOL_LINE);;
		 sb.append(" function enableHandler() {");
		 sb.append("    var row = UICtrl.checkSelectedRows(").append(Utils.toLowerCaseFirstOne(btnAttributes.getEntityName())).append("GridManager);");
		 sb.append("    if(row){ ");
		 sb.append("	   if(row.status==1){");
		 sb.append("		 Public.tip(\"").append(btnAttributes.getFormName()).append(Constant.ENBABLE_TIP).append("\");");
		 sb.append("		 return false;");
		 sb.append("	   }else{");
	     sb.append("		 changeStatus(row.id,1);");
		 sb.append("		 Public.successTip(\"").append(btnAttributes.getFormName()).append(Constant.ENBABLE_SUCCESS).append("\");");
		 sb.append("	   }");
		 sb.append("	}");
		 sb.append("   }");
		 sb.append(" ");
		 
			sb.append(" function changeStatus(id,status){");
			sb.append("	 $.post(web_app.name").append("+\"/").append(Utils.toLowerCaseFirstOne(btnAttributes.getEntityName()))
			.append("/change").append(Utils.toUpperCaseFirstOne(btnAttributes.getEntityName())).append("Status.ajax\",{     id:id,status:status}      ,function(data){");
			//sb.append("		reloadGrid();");
			sb.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;
	}
}
