package com.huigou.uasp.builder.jsbutton;

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

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 UpdateButtonResult implements ButtonTypeInter {
	
	public List<String> processOutResult(StringBuffer sb,ButtonAttributeVO btnAttributes){
		List <String> list=new ArrayList<String>();
		 sb.append(" function updateHandler(){");
		//如果是配置了流程  则通过Ifame打开，发起流程页面
		/*UICtrl.addTabItem({
				tabid: 'addPickApply',
				text: "新增临时任务领料申请",
				url: web_app.name+"/pickSupply/addPickApply.job?wbsNo="+wbsNo+"&useWorkshop="+useWorkshop+"&materNo="+materNo+"&materName="+materName+"&pictureNo="+pictureNo+"&taskNo="+taskNo+"&assistedBiilno="+assistedBiilno
        });
		*/

		 sb.append("  var row = UICtrl.checkSelectedRows(").append(Utils.toLowerCaseFirstOne(btnAttributes.getEntityName())).append("GridManager);");
		 sb.append("    if (row) {");
		 sb.append("       doShowUpdateDialog(row.id);");
		 sb.append("     }");
		 sb.append(" }");
		 sb.append(" ");
		sb.append(Constant.SYSMBOL_LINE);

		 sb.append(" function doShowUpdateDialog(id) {");
		//Random  random=new Random(3);
		 sb.append("  if ($('#procId').val()!=\"\") { ");
        sb.append("UICtrl.addTabItem({ ");
		sb.append("	tabid: 'edit").append(btnAttributes.getEntityName()).append("'+id,");
		sb.append("	text: \"编辑"+btnAttributes.getFormName()+"\",");
		sb.append("	url: web_app.name+'/dataManage/addDataRecord.job?procId='+$('#procId').val()");
		sb.append("+'&formNo='+$('#formNo').val()");
		sb.append("+'&id='+id ");
		sb.append(" });");
		sb.append(" } else { ");

		 sb.append("	    UICtrl.showAjaxDialog({");
		 sb.append("	        title: \"修改").append(btnAttributes.getFormName()).append("\",");
		if (btnAttributes.getIsForm()==1){  //是表单生成器 则调用统一的添加方法
			  sb.append("       url: web_app.name +'/dataManage/addDataRecord.load',");	
			  sb.append("	        param: { id: id,formNo:$(\"#formNo\").val() },");
		} else {
		 sb.append("		    url: web_app.name + '/").append(Utils.toLowerCaseFirstOne(btnAttributes.getEntityName())).append("/load")
		   .append(Utils.toUpperCaseFirstOne(btnAttributes.getEntityName())).append("Detail.load',");
		 sb.append("	        param: { id: id },");
		}
		 sb.append("	        width: 900,");
		 sb.append("            init:function(){");
		 sb.append("              initAdd").append(Utils.toUpperCaseFirstOne(btnAttributes.getEntityName())).append("();");
		 sb.append("            },");
		 sb.append("	        ok: function() {doSave").append(Utils.toUpperCaseFirstOne(btnAttributes.getEntityName())).append("(1);},");
	
		 sb.append("	        close: onDialogCloseHandler");
		 sb.append("	    });");
	     sb.append(" }");
	     sb.append(" ");
		 sb.append(" }");
		 sb.append(Constant.SYSMBOL_LINE);
		  list.add(sb.toString());
		 // list.add(Integer.toString(fieldAttributes.getCurrCols()));
		return list;
	}
}
