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 EnableButtonRowResult implements ButtonTypeInter {
	
	public List<String> processOutResult(StringBuffer sb,ButtonAttributeVO btnAttr){
		List <String> list=new ArrayList<String>();
		 sb.append("//启用方法 ").append(Constant.SYSMBOL_LINE);;
		 sb.append(" function enableRow").append(Utils.toUpperCaseFirstOne(btnAttr.getEntityName())).append("() {");
		 sb.append("    var row = UICtrl.checkSelectedRows(").append(Utils.toLowerCaseFirstOne(btnAttr.getEntityName())).append("GridManager);");
		 sb.append("    if(row){ ");
		 sb.append("	   if(row.status==1){");
		 sb.append("		 Public.tip(\"").append(btnAttr.getFormName()).append(Constant.ENBABLE_TIP).append("\");");
		 sb.append("		 return false;");
		 sb.append("	   }else{");
	     sb.append("		 changeRowStatus(row.id,1);");
		 sb.append("		 Public.successTip(\"").append(btnAttr.getFormName()).append(Constant.ENBABLE_SUCCESS).append("\");");
		 sb.append("	   }");
		 sb.append("	}");
		 sb.append("   }");
		 sb.append(" ");
		 
		sb.append(" function changeRowStatus(id,status){");
		if (btnAttr.getIsForm()==1){  //表单生成器 
			sb.append("	 $.post(web_app.name").append("+\"/dataManage")
			  .append("/changeDataRecordDetailStatus.ajax\",{id:id,status:status");
		} else { 
		sb.append("	 $.post(web_app.name").append("+\"/").append(btnAttr.getParentEntityName())
		  .append("/changeDataRecordDetailStatus.ajax\",{id:id,status:status");
		}
		 sb.append(",subTab:'").append(btnAttr.getEntityName()).append("'")
		  .append("}   ,function(data){");
				
		/*sb.append("   var url = '/").append(btnAttr.getParentEntityName()).append("/saveRow")
		   .append(Utils.toUpperCaseFirstOne(btnAttr.getParentEntityName())).append("Detail.ajax")
		   .append("?maiTab=").append(btnAttr.getParentEntityName())
		   .append("&subTab=").append(btnAttr.getEntityName())
		   .append("&modelId='+"+"$(\"#modelId\").val()")
		   .append("+'&id='+"+"$(\"#id\").val()");
		   sb.append(";");
		   */
		sb.append("        reload").append(Utils.toUpperCaseFirstOne(btnAttr.getEntityName())).append("Grid();");
		sb.append("	 });");
		sb.append("	}");
		sb.append(Constant.SYSMBOL_LINE);

		  list.add(sb.toString());
		 // list.add(Integer.toString(fieldAttributes.getCurrCols()));
		return list;
	}
}
