<%layout("/eova/layout/default.html",{'title' : 'Dialog' }){%>

<form id="myForm" method="post" class="form">
    <table class="table" style="width: 100%;">
        <tr>
            <th>数据源</th>
             <td><#combo id="ds" name="ds" value="main" /></td>
        </tr>
        <tr>
            <th>元类型</th>
            <td><#combo id="type" name="type" value="table" /></td>
        </tr>
        <tr>
            <th>元数据表</th>
            <td><#find id="table" name="table" url="/meta/find/mian-table" /></td>
        </tr>
        <tr id="tr_pk" style="display: none;">
            <th>视图主键</th>
            <td><#text id="pk" name="pk" value="" />(仅纯查询视图可不填主键)</td>
        </tr>
        <tr>
            <th>元对象名称</th>
            <td><#text id="name" name="name" /></td>
        </tr>
        <tr>
            <th>元对象编码</th>
            <td><#text id="code" name="code" /></td>
        </tr>
    </table>
</form>
<script type="text/javascript">

$(function(){
    var $type = $('#ds').eovacombo({
		json : [
			<%for(ds in dataSources){%>
	        {id:'${ds}', cn : '${ds}'},
			<%}%>
		],
		onChange: function (oldValue, newValue) {
			valueChange();
	    }
	}).reload();
    
    var $type = $('#type').eovacombo({
		json : [
		        {id:'table', cn : 'Table'},
		        {id:'view', cn : 'View'}
		],
		onChange: function (oldValue, newValue) {
			valueChange();
	    }
	}).reload();

  	//init
    valueChange();
});

// 元类型变更时级联变更元数据表查找框URL
var valueChange = function(){
    var type = $('#type').eovacombo().getValue();
    var url = '/meta/find/' + $('#ds').eovacombo().getValue() + '-' + type;
    $('#table').eovafind({url: url});

    if(type == 'view'){
        $('#tr_pk').show();
    } else {
        $('#tr_pk').hide();

    }
}

var fm = $('#myForm');
var submitNow = function($dialog, $widget, $pjq) {
    var url = "/meta/doImports";
    $.post(url, $.getFormParasObj(fm), function(result) {
        if (result.success) {
            //$pjq.messager.alert('提示', result.msg, 'info');
            $.slideMsg("导入元数据成功！", $pjq);
            $.widgetReLoad($widget);
            $dialog.dialog('destroy');
        } else {
            $pjq.messager.alert('提示', result.msg, 'error');
        }
    }, 'json');
};
var btnSaveCallback = function($dialog, $widget, $pjq) {
    submitNow($dialog, $widget, $pjq);
};
</script>


<%}%>
