<%@include file="/WEB-INF/common/layouts/common.jsp" %>
<%@ page language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>城市列表</title>
</head>
<body>
<%-- <div class="row${fluid}">
    <div class="span6">
        <h2 class="page-title">KlfCity列表</h2>
    </div>
    <div class="span6 header_buttons">
        <a href="${ctx}/klfcity?action=create" class="btn blue pull-right"><i class="icon-plus"></i></a>
    </div>
</div> --%>

<!-- 面包屑 begin -->
<div class="row-fluid">
	<div class="span12">
		<ul class="breadcrumb">
			<!-- <li><a href="/house365-hmc-web/">首页</a> <span class="divider"></span></li> -->
			<li class="active" ><span class="divider" style="color:#26a0da;font-weight:bold;">/</span>城市列表</li>
		</ul>
	</div>
</div>
<!-- 面包屑 begin -->

<div class="page-container">
    <div class="row${fluid}">
        <div class="span12">
            <form id="filterForm" class="form-inline filterForm" action="${ctx}/klfcity" method="get">
				<input type="text" name="search_LIKE_id" value="${param['search_LIKE_id']}" 
					class="m-wrap small" placeholder="城市编号" title="城市编号">
				<input type="text" name="search_LIKE_name" value="${param['search_LIKE_name']}" 
					class="m-wrap small" placeholder="城市名称" title="城市名称">
				<select name="search_LIKE_used" id="isUsedSelected">
					<option value="">全部</option>
					<option value="0">未使用</option>
					<option value="1">已使用</option>
				</select>
				<%-- <input type="text" name="search_LIKE_used" value="${param['search_LIKE_used']}" 
					class="m-wrap small" placeholder="是否使用-0:未使用，1:已使用"> --%>
				<%-- <div class="buttons pull-right" style="margin-left:15px;">
                    <a href="${ctx}/klfcity?action=create" class="btn blue pull-right" title="新增城市"><i class="icon-plus"></i></a>
                </div> --%>
                <!-- <div class="buttons pull-right">
                    <a href="javascript:void(0);" onclick="deleteById('')" class="btn blue pull-right" title="删除城市"><i class="icon-minus"></i></a>
                </div> -->
                <div class="buttons pull-right" style="margin:3px 30px 0 0;">
                    <i class="icon-search icon-2x pointer" onclick="$('#filterForm').submit();"  title="搜索"></i>
                </div>
	         </form>
        </div>
    </div>
    <table class="table table-striped table-advance table-hover">
        <thead>
        	<tr>
        		<th width="100" style="text-align:center"><input id="cityCheckAll" type="checkbox" onclick="checkAll(this)" /></th>
				<th width="100">城市id</th>
				<th width="100">城市名称</th>
				<th width="100">城市代号</th>
				<th width="100">是否使用</th>
				<th width="150">操作</th>
			</tr>
        </thead>
        <c:forEach items="${klfCitys}" var="klfCity">
            <tr>
            	<td nowrap="nowrap" style="text-align:center">
				    <input type="checkbox" name="cityCheck" value="${klfCity.id}" onclick="checkMember(this)"/>
				</td>
				<td nowrap="nowrap">
				    <a href="${ctx}/klfcity/${klfCity.id}">						
				    	<c:if test="${null ne klfCity.id && '' ne klfCity.id}">
							<c:out value="${klfCity.id}" />
						</c:if>
						<c:if test="${null eq klfCity.id || '' eq klfCity.id}">
							&nbsp;
						</c:if>
				</td>
				<td nowrap="nowrap">
						<c:if test="${null ne klfCity.name && '' ne klfCity.name}">
							<c:out value="${klfCity.name}" />
						</c:if>
						<c:if test="${null eq klfCity.name || '' eq klfCity.name}">
							&nbsp;
						</c:if>
				</td>
				<td nowrap="nowrap">
						<c:if test="${null ne klfCity.code && '' ne klfCity.code}">
							<c:out value="${klfCity.code}" />
						</c:if>
						<c:if test="${null eq klfCity.code || '' eq klfCity.code}">
							&nbsp;
						</c:if>
				</td>
				<td nowrap="nowrap">
				<c:choose>
						<c:when test="${null ne klfCity.used && '' ne klfCity.used && 1 eq klfCity.used}">
							<span style="color:green;">已使用</span>
						</c:when>
						<c:otherwise>
							未使用
						</c:otherwise>
				</c:choose>
				</td>
				<td nowrap="nowrap">
                    <i class="icon-edit pointer icon-large" title="编辑"
						onclick="window.location='${ctx}/klfcity/${klfCity.id}?action=edit'"></i>
						&nbsp;&nbsp; <i
						title="删除"
						class="icon-minus pointer icon-large"
						onclick="deleteById('${klfCity.id}')"> </i>
					</td>
			</tr>
        </c:forEach>
    </table>
    <div class="row${fluid}">
        <house365:pagination page="${page}"/>
    </div>
</div>
<script type="text/javascript">

//全选
function checkAll(btn)       
{       
	if(btn.checked)
	{
		for(i=0;i<document.all("cityCheck").length;i++)       
		{       
			document.all("cityCheck")[i].checked = "checked";
		}     
	}
	else
	{
		for(i=0;i<document.all("cityCheck").length;i++)       
		{       
			document.all("cityCheck")[i].checked = "";
		}     
	}
}       

//单选
function checkMember(btn)
{
	if(btn.checked)
	{
		var checkAll = true;
		for(i=0;i<document.all("cityCheck").length;i++)       
		{       
			if(document.all("cityCheck")[i].checked == false)
			{
				checkAll = false;
			}
		}     
		
		if(checkAll)
		{
			document.getElementById("cityCheckAll").checked = true;   
		}
	}
	else
	{
		document.getElementById("cityCheckAll").checked = false;   
	}
}

    var deleteById = function (klfcityId) {
    	
    	var isNoneChecked=true;
    	for(i=0;i<document.getElementsByName('cityCheck').length;i++)       
		{       
			if(document.getElementsByName('cityCheck')[i].checked)
			{
				isNoneChecked = false;
				break;
			}
		} 
    	
    	if(isNoneChecked){
    		House365Util.createModal("删除账号", "请至少选择一个账号!", function () {
    			return;
    		});
    		return;
    	}
    	
    	
    	
    	House365Util.createModal("删除城市", "确定要删除该城市？", function () {
    		
    		if(klfcityId == "")
    		{
    			for(i=0;i<document.getElementsByName('cityCheck').length;i++)       
        		{       
        			if(document.getElementsByName('cityCheck')[i].checked)
        			{
        				klfcityId += document.getElementsByName('cityCheck')[i].value + ",";
        			}
        		}     
        		
        		var str = "";
        		if(klfcityId != "")
        		{
        			str = klfcityId.split(",");
        			
        			if(str[str.length-1] == "")
        			{
        				klfcityId = klfcityId.substring(0,klfcityId.length-1);
        			}
        		}
    		}
    		
            $.ajax({
                url: '${ctx}/klfcity/' + klfcityId,
                type: "DELETE",
                success: function () {
                    window.location.reload();
                }
            });
        });
    };
    
	$(function(){
		<c:if test="${null ne param['search_LIKE_used'] && '' ne param['search_LIKE_used']}">
			$("#isUsedSelected").val("${param['search_LIKE_used']}");
			if("${param['search_LIKE_used']}"=="1"){
				$(".chosen-single span").text("已使用");
			
			}else{
				$(".chosen-single span").text("未使用");
			}
		</c:if>
	});
	
</script>
</body>
</html>
