<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.util.*" %>
<%@ page import="com.gx.webpage.framework.util.inoutformat.DataBean" %>
<%@ page import="com.gx.webpage.engine.pagedesigndbengine.factory.PageDesignDbEngineFactory"%>
<%@ page import="com.gx.webpage.engine.pagedesigndbengine.valueobject.*"%>
<%@ page import="com.gx.webpage.framework.util.page.*"%>
<%
    String table = "";
    boolean isError = false;
    String infStr = "";
    String formUuid = DataBean.getStr(request,"uuid");
    try{
        if(request.getMethod().equalsIgnoreCase("POST")){
            int addtype = DataBean.getInt(request,"addType");
            if(addtype == 1)
            {
                FormsUiModel fm = new FormsUiModel();
                fm.setFormUuid(formUuid);
                fm.setUiName("基本视图");
                fm.setType(FormsUiModel.TYPE_DESIGN);
                fm = PageDesignDbEngineFactory.getInstance().getPageDbEngineApi().createFormsUi(fm,request);
            }else if(addtype == 2){
                FormsUiModel fm = new FormsUiModel();
                fm.setFormUuid(formUuid);
                fm.setUiName("基本子视图");
								fm.setType(FormsUiModel.TYPE_CHILD);
                fm = PageDesignDbEngineFactory.getInstance().getPageDbEngineApi().createFormsUi(fm,request);
            }else if(addtype == 9){
                FormsUiModel fm = new FormsUiModel();
                fm.setFormUuid(formUuid);
                fm.setUiName("空视图");
								fm.setType(FormsUiModel.TYPE_EMPTY);
                fm = PageDesignDbEngineFactory.getInstance().getPageDbEngineApi().createFormsUi(fm,request);
            }
        }
        Collection col = PageDesignDbEngineFactory.getInstance().getPageDbEngineApi().findAllFormsUi(formUuid,request);
        Iterator it = col.iterator();
        while(it.hasNext()){
            FormsUiModel fm = (FormsUiModel)it.next();
            table += "<tr onclick='itemClick(this)' style='cursor : hand'>\r\n";
            table += "<td><input type=radio name=uuid value='" + fm.getUuid() + "'></td>\r\n";
            table += "<td>" + DataBean.getStr(fm.getUuid()) + "&nbsp;</td>\r\n";
            table += "<td>" + DataBean.getStr(fm.getUiName()) + "&nbsp;</td>\r\n";
            table += "<td>" + fm.getType() + "&nbsp;</td>\r\n";
            table += "</tr>";
        }
    }catch(Exception err){
        isError = true;
        infStr = DataBean.getErrStr(err);
				//err.printStackTrace();
    }
%>
<html>
<head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="./../../webpage/common/css/common.css" rel="StyleSheet"  type="text/css" />
<script language="javascript" src="./../../webpage/common/engine/constant.js"></script>
<script language="JScript.Encode" src="./../../webpage/common/engine/common.js"></script>
<script language="JScript.Encode" src="./../../webpage/common/engine/TimerControl.js"></script>
<script language="javascript">
<!--
    function btn_copy(){
        Navigate("formsUiAdd.jsp");
    }
    function btn_modify(){
        Navigate("formsUiModify.jsp");
    }
    function btn_delete(){
        Navigate("formsUiDelete.jsp");
    }
    function btn_design(){
        var chk = getOnlyOneItem();
        if(oldIndex < 1) return;
        if(chk != null)
        {
            var td = listTable.rows(oldIndex).cells(3);
            var type = parseInt(td.innerText);
            if(type == 1 || type==9)
            {
                CHILDWIN.open("./../design/WebPageDesign.jsp?uuid=" + chk.value+"&designType="+type, "basdesign");
            }else{
                CHILDWIN.open("./../design/childTableDesign/ChildDesignMain.jsp?uuid=" + chk.value+"&designType="+type, "childdesign");
            }
        }
    }
    function btn_use(){
        var chk = getOnlyOneItem();
        if(chk == null)
        {
            return;
        }
        var tr = listTable.rows(oldIndex);
        var type = parseInt(tr.cells(3).innerText);
        var quary = "";
        var isAdd = window.confirm("使用新增还是修改视图?  ok---新增 no---修改");
        var url = "";
        if(type == 1 || type==2)
        {
            if(isAdd){
                url = "./../common/module/base.jsp"
            }else{
                quary = window.prompt("传递参数:","&UUID=");
                url = "./../common/module/base.jsp"
            }
        }else if(type ==3){
            alert("查询输入页面不能直接使用！");
						return;
        }
        url += "?uiUuid=" + chk.value
        if(quary != null && quary.length > 0){
            url += quary;
        }
        CHILDWIN.open(url);
    }
    function btn_toFormsList(){
        window.navigate("./formsList.jsp");
    }
    function Navigate(url)
    {
        var chk = getOnlyOneItem();
        if(chk == null)
        {
            return;
        }
        window.navigate(url + "?uuid=" + chk.value);
    }
    function getOnlyOneItem()
    {
        var col = document.getElementsByName('uuid');
        for(var i=0; i < col.length; i++)
        {
            var chk = col(i);
            if(chk.checked == true)
            {
                return chk;
            }
        }
        MSG.show('请选择一个视图');
        return null;
    }
    var oldIndex = -1;
    function itemClick(tr)
    {
        var i = tr.rowIndex - 1;
        var col = document.getElementsByName('uuid');
        col(i).click();
        switchColor(oldIndex, false);
        oldIndex = i + 1;
        switchColor(oldIndex, true);
    }
    function switchColor(index, set)
    {
        if(index < 0) return;
        var tr = listTable.rows(index);
        if(set == true)
        {
            tr.style.backgroundColor = '#cccccc';
        }
        else
        {
            tr.style.backgroundColor = '';
        }
    }
    function but_CreatEmptyUi()
    {
        document.all("addType", 0).value= "9";
        myForm.submit();
    }
		function but_CreatNormalUi()
    {
        document.all("addType", 0).value= "1";
        myForm.submit();
    }
    function but_CreatChildUi()
    {
        document.all("addType", 0).value= "2";
        myForm.submit();
    }
//-->
</script>
    <title>视图建模</title>
</head>
<body class="main">
<div align="center">
<h3 align="center">业务对象视图列表</h3>
<%if(!isError){%>
<table class="content" id="listTable">
    <tr><td width="50px">&nbsp</td>
        <td width="200px">视图标识</td>
        <td>视图名称</td>
        <td>视图类型</td>
<%= table%>
</table>
<table class="buttable1">
<tr>
<td align=center><input class="butAction" type="button" name="but_copy"       value="拷　贝" onclick="btn_copy();">
<td align=center><input class="butAction" type="button" name="but_modify"     value="修　改" onclick="btn_modify();">
<td align=center><input class="butAction" type="button" name="but_delete"     value="删　除" onclick="btn_delete();">
<td align=center><input class="butAction" type="button" name="but_useForm"    value="测  试" onclick="btn_use();">
<td align=center><input class="butAction" type="button" name="but_CreatEmptyUi" value="建立空视图" onclick="but_CreatEmptyUi();">
<td align=center><input class="butAction" type="button" name="but_CreatNormalUi" value="建立基本视图" onclick="but_CreatNormalUi();">
<td align=center><input class="butAction" type="button" name="but_CreatChildUi"    value="建立子视图" onclick="but_CreatChildUi();">
<td align=center><input class="butAction" type="button" name="but_designForm" value="设计视图" onclick="btn_design();">
<td align=center><input class="butAction" type="button" name="but_toList"     value="返回业务对象列表" onclick="btn_toFormsList();">
</table>
<div style="display : none">
<form name=myForm id=myForm method=post>
    <input name=addType value="">
</form>
</div>
<%}else{%>
<p align=center>生成列表失败．
<p align=center><%= infStr%>
<p align=center><input class="butAction" type="button" value="后退" onclick="window.history.back();">
<%}%>
</div>
</body>
</html>
