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 ViewButtonResult 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 viewHandler() {");
		  sb.append("   var row = UICtrl.checkSelectedRows(").append(Utils.toLowerCaseFirstOne(btnAttributes.getEntityName())).append("GridManager);");
		  sb.append("   if (row) {");
		  sb.append("       viewInfo(row.id);");
		  sb.append("    }");
		  sb.append(" }");

		  sb.append(" function viewInfo(id) {");
		  sb.append("     if (!id) {");
		  sb.append("         var row = ").append(Utils.toLowerCaseFirstOne(btnAttributes.getEntityName())).append("GridManager.getSelectedRow();");
		  sb.append("         if (!row) { Public.tip('请选择数据！'); return; }");
		  sb.append("         id = row.id;");
		  sb.append("     }");
		  sb.append("     UICtrl.showAjaxDialog({");
		  sb.append("         width: 900,");
		  sb.append("        title: \"查看").append(btnAttributes.getFormName()).append("信息\",");
		  sb.append("        url: web_app.name + '/").append(Utils.toLowerCaseFirstOne(btnAttributes.getEntityName()))
		    .append("/load").append(btnAttributes.getEntityName()).append("Detail.load',");
		  sb.append("        param: {id:id},");
		  sb.append("        init:initReadOnly,");
		  sb.append("        ok: doSave").append(btnAttributes.getEntityName()).append(",");
		  sb.append("        close: onDialogCloseHandler ");
		  sb.append("    });");

		  sb.append(" 	}");
		  sb.append(" ");
		sb.append(Constant.SYSMBOL_LINE);
		  sb.append(" function initReadOnly(){");
		  sb.append("		$('input,select,textarea', $('form[name=\"").append(Utils.toLowerCaseFirstOne(btnAttributes.getEntityName())).append("Form\"]')).attr('readonly', true);");
		  sb.append("		$(\"#ok\").hide();");
		  sb.append("	}");
		  sb.append(" ");
		sb.append(Constant.SYSMBOL_LINE);
		  list.add(sb.toString());
		 // list.add(Integer.toString(fieldAttributes.getCurrCols()));
		return list;
	}
}
