<script language="javascript" src="<?=BASEURL?>public/admin/js/dialog.js" ></script>
<script language="javascript" src="<?=BASEURL?>public/admin/js/jquery.form.js" ></script>

<dl class="adminoption">
  <dt></dt>
  <dd class="active">更新分类</dd>
</dl>
<div id="tab1" class="tab">
  <table cellspacing="0" class="adminform">
    <tr>
      <th>选择分类</th>
    </tr>
    <tr>
      <td><input type="button" name="sbtpl" value="选择需要更新的分类" class="Dialog" rel="{type:'div',size:{w:600,h:400},url:'<?=BASEURI?>model_html/allcat',off:'hidden'}" /></td>
    </tr>
    <tr>
      <th>是否更新子分类</th>
    </tr>
    <tr>
      <td><input type="radio" name="html[upnext]" value="1" checked>
        是&nbsp;&nbsp;
        <input type="radio" name="html[upnext]" value="0">
        否</td>
    </tr>
    <tr>
      <th>每次最大创建页数：</th>
    </tr>
    <tr>
      <td><input type="text" name="html[max_numbers]" value="10"></td>
    </tr>
    <tfoot>
      <tr>
        <td><input type="button" name="sb" value="开始更新" id="updatehtml"/></td>
      </tr>
    </tfoot>
  </table>
</div>
<div class="adminform_bottom"> </div>
<div class="progress">
<table class="admintable"  cellspacing="0" align="center">
  <tr>
    <td width="10%" height="25" class="key">生成HTML数量</td>
    <td id="publish_html_numbers">0</td>
  </tr>
  <tr>
    <td height="25" class="key">发布状态</td>
    <td id="publish_status">准备中...</td>
  </tr>
  <tr>
    <td height="25" class="key">发布进度</td>
    <td><div class="progress_td">
    	<div id="progress_bar" class="progress_bar"> 0% </div>
        </div>
    </td>
  </tr>
</table>
</div>
<script language="javascript">
	$(document).ready(
		function(){
			$("#updatehtml").click(
				function(){
					publish_category();
					$(this).attr("disabled",true);
				}
			);
		}
	);
	function publish_category(){
		$('#progress_bar').css("width","0%");
		strhtml	=	"0%";
		$('#progress_bar').html(strhtml);
		$("#publish_status").html("正在更新...");
		$(".progress").slideDown() 
		$.ajax({
		  type: "post",
		  data:$("#adminform").formSerialize(),
		  url: "<?=BASEURI?>model_html/category",
		  dataType: "json",
		  success: function(msg){
			  $("#publish_status").html("暂停");
			  eval(msg.js);
		  }
		}); 
		$("body").ajaxError(function(event,request,settings){
			 $("#adminform").action=settings.url;
			 $("#adminform").submit();
		}); 
	}
	function publish_category_ajax(current_html_number,html_sum_file,max_html_number){
		$('#publish_html_numbers').html(html_sum_file);
		$('#progress').html("display","block");
		$("publish_status").html("执行");
		$.ajax({
		  type: "post",
		  data:$("#adminform").formSerialize(),
		  url: "<?=BASEURI?>model_html/category/"+current_html_number+"/"+html_sum_file+"/"+max_html_number,
		  dataType: "json",
		  success: function(msg){
			  $("#publish_status").html("暂停");
			  eval(msg.js);
			 }
		  }); 
		$("body").ajaxError(function(event,request,settings){
			 $("#adminform").action=settings.url;
			 $("#adminform").submit();
			 exit();
		}); 

		var intpx	=	$('#progress_bar').css("width");
		intpx	=	intpx.replace("px","");
		intpx	=	intpx.replace("%","");
		$('#progress_bar').css("width",parseInt(current_html_number/html_sum_file*100)+"%");
		strhtml	=	parseInt(current_html_number/html_sum_file*100)+"%";
		$('#progress_bar').html(strhtml);		
	}
	
	function publish_category_complete(current_html_number,html_sum_file,max_html_number){
		$('#publish_status').html("完成");
		$('#progress_bar').html("100%");
		$('#publish_html_numbers').html(html_sum_file);
		var intpx	=	$('#progress_bar').css("width");
		intpx	=	intpx.replace("px","");
		intpx	=	intpx.replace("%","");
		$('#progress_bar').css("width",parseInt(current_html_number/html_sum_file*100)+"%");
		strhtml	=	parseInt(current_html_number/html_sum_file*100)+"%";
		$('#progress_bar').html(strhtml);
		$('#publish_html_numbers').html(0);
		$('#progress_bar').css("width","100%");
		$('#progress_bar').html("100%");
		$('#publish_status').html("stop");
		alert("完成");
		$("#progress").slideUp(); 
		$("#updatehtml").attr("disabled",false);
	}

</script>
