<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title><!--#include article_type--></title>
<link type="text/css" href="/css/base.css" rel="stylesheet" />	
<link type="text/css" href="/css/cleditor.css" rel="stylesheet" />	
<script src="/jquery/jquery.min.js" type="text/javascript"></script>
<script src="/jquery/jquery-ui.min.js" type="text/javascript"></script>
<script src="/jquery/jquery.cleditor.min.js" type="text/javascript"></script>
<script src="/jquery/common.min.js" type="text/javascript"></script>

<script type="text/javascript">
	function isIE6()
	{
    	if ($.browser.msie){
        	if ($.browser.version == "6.0") return true;
	      }
    	return false;
	}
	function adjust_content_width()
	{
    	if ($.browser.msie){
        	if ($.browser.version != "6.0"){
				var content_parent = document.getElementById("dt_list").parentNode;
				$("#dt_list").width(content_parent.offsetHeight > content_parent.scrollHeight ? '100%' : parseInt(content_parent.clientWidth) - 20);
			  }
		  }
	}

	// upload image
	(function($) {
		$.cleditor.buttons.upload = {
			name: 'upload',
			title: 'Upload Image',
			command: 'insertimage',
			stripIndex: 32,
			buttonClick: function upload_image_click(e, data){
				var last_selection;
				if ($.browser.msie){
					last_selection = data.editor.doc.selection.createRange();
				  }
				// show dialog
				var file_url;
				$("#upload_dialog").dialog({
					modal: true,
					resizable: false,
					width: 350,
					title: "上传图片",
					buttons:{
						"确定": function(){
        					var filename = $.trim($("#filename").val());
        					if (filename.length > 0){
								var $iframe = $("#upload_dialog iframe");
								$iframe.bind('load', function(){
									if ($("#upload_dialog").dialog("isOpen")){
										try{
											file_url = $(this).get(0).contentWindow.document.getElementById('image').innerHTML;
										  }catch(e){};
										if (file_url){
							   				$("#upload_dialog").dialog("close");
										  }else{
											alert('图片上传出错!');
										  }
									  }
									$(this).unbind('load');
								});
        						$("#upload_dialog form").submit();
        					  }
						}
					},
					open: function(){
						$(this).empty();
						$(this).html('<iframe style="width:0;height:0;border:0;" name="__upload_frame__" /><form method="post" enctype="multipart/form-data" action="/upload/image/" target="__upload_frame__"><fieldset><div><label for="filename">上传图片：</label><input id="filename" name="filename" type="file" accept="image/*" /></div></fieldset></form>');
						$("#upload_dialog #filename").focus();
					},
					close: function()
					{
		   				data.editor.$frame[0].contentWindow.focus();
						if ($.browser.msie) last_selection.select();
		   				if (file_url){
							data.editor.execCommand(data.command, file_url, null, data.button);
						  }
					}
				});
				return false;
			}
		};
	})(jQuery);

	// tags
	function update_tag_selection()
	{
		var availableTags = [];
   		$.ajax({
			type: "GET",
			url: "/get_tag_list",
			async: false,
			data: {user:"current", encode:"text"},
			dataType: "json",
			success: function(data){
				var tag_name;
				$.each(data, function(row_index, row){
					tag_name = row["name"];
					if (tag_name.length > 0){
						availableTags.push(unescape(tag_name));
					  }
				});
			}
		});
		$("#article_tag").autocomplete("option", "source", availableTags);
	}
	function on_remove_tag_name()
	{
		if (confirm('确认删除分类"' + $(this).parent().next().text() + '"?') == true){
       		$(this).parent().parent().remove();
		  }
		return false;
	}
	function edit_tags()
	{
		// get selected group
		var html_text = "<div>分类名称: <input id='tag_name' type='text' style='width:250px;' /><button id='add'>增加</button></div><div class='tag_list'><ul id='sortable'>";
		// get tag list
   		$.ajax({
			type: "GET",
			url: "/get_tag_list",
			async: false,
			data: {user:"current"},
			dataType: "json",
			success: function(data){
				var tag_name;
				$.each(data, function(row_index, row){
					tag_name = row["name"];
					if (tag_name.length > 0){
						html_text += "<li class='ui-state-default'><span style='float:right'><a href='#'>删除</a></span><span>";
						html_text += tag_name;
						html_text += "</span></li>";
					  }
				});
			}
		});
		html_text += "</ul></div>";

		// show dialog
		$("#dialog").dialog({
			modal: true,
			resizable:true,
			minHeight: 200,
			minWidth: 400,
			maxWidth: 400,
			title: "分类设置",
			buttons:{
				"确定": function(){
					var result = new Array;
					$(".tag_list ul li span:last-child").filter(function(){ result.push($(this).text()); return true;});
        			$.ajax({
	    				type: "GET",
						url: "/set_tag_list",
   						async: false,
						data: {user:"current", tag_name:result},
						dataType: "text",
						success: function(data, status){
							// check result
							if (data.substr(0,1) == ">"){
								// refresh
								$("#navigator").load("/navigator?id=3", function(){ $("#article_tags").click(edit_tags);});
								update_tag_selection();
								// close window
								$("#dialog").dialog("destroy");
							  }else{
								alert(data);
							  }
						  },
						error: function(){
							alert("无法更改分类信息。");
						}
					});
				}
			},
			open: function(){
				$(this).html(html_text);
				$("#sortable").sortable({revert: true, axis: "y"});
				$("#add").click(function(){
					var tag_name = $.trim($("#dialog #tag_name").val());
					if (tag_name.length > 0){
						// check exist
						if ($(".tag_list ul li span:last-child").filter(function(){ return $(this).text() == tag_name;}).length > 0){
							alert('分类"' + tag_name + '"已定义。');
						  	$("#dialog #tag_name").focus();
						  }else{
							$(".tag_list ul").append("<li class='ui-state-default'><span style='float:right'><a href='#'>删除</a></span><span></span></li>");
							$(".tag_list ul :last-child span:last-child").text(tag_name);
							$(".tag_list ul :last-child a").click(on_remove_tag_name);
						  }
					  }else{
					  	alert("分类名称未输入。");
					  	$("#dialog #tag_name").focus();
					  }
				});
				$(".tag_list li a").click(on_remove_tag_name);
			}
		});
		return false;
	}

	function remove_article(record, id)
	{
		if (confirm("确认删除'" + record.parent().parent().children().eq(1).text() +"'?")){
  			$.ajax({
  				type: "GET",
				url: "/remove_article",
				async: false,
				data:{id:id},
				dataType: "text",
				success: function(data, status){
					// check result
					if (data.substr(0,1) == ">"){
						// refrrsh
						window.location.reload();
					  }else{
						alert(data);
					  }
				  },
				error: function(){
					alert("无法删除文档。");
				}
			});
		  }
		return false;
	}
	function set_article_attr(message, id, attr, val)
	{
		var result = false;
		if (confirm(message)){
  			$.ajax({
  				type: "GET",
				url: "/set_article_attr",
				async: false,
				data:{id:id, attr:attr, val:val},
				dataType: "text",
				success: function(data, status){
					// check result
					if (data.substr(0,1) == ">"){
						result = true;
					  }else{
						alert(data);
					  }
				  },
				error: function(){
					alert("无法修改文档属性。");
				}
			});
		  }
	  	return result;
	}
	function set_public(record, id)
	{
		if (record.children().hasClass('ui-icon-mail-closed')){
			if (set_article_attr("把文档设为公共文档?", id, "public", 1)){
				record.children().removeClass('ui-icon-mail-closed').addClass('ui-icon-mail-open');
				record.attr('title','公共文档');
			  }
		  }else{
			if (set_article_attr("把文档设为私有文档?", id, "public", 0)){
				record.children().removeClass('ui-icon-mail-open').addClass('ui-icon-mail-closed');
				record.attr('title','私有文档');
			  }
		  }
	}
	function lock_article(record, id)
	{
		if (record.children().hasClass('ui-icon-locked')){
			if (set_article_attr("解锁所选文档?", id, "lock", 0)){
				record.children().removeClass('ui-icon-locked').addClass('ui-icon-unlocked');
				record.attr('title','文档解锁');
			  }
		  }else{
			if (set_article_attr("锁定所选文档?", id, "lock", 1)){
				record.children().removeClass('ui-icon-unlocked').addClass('ui-icon-locked');
				record.attr('title','文档锁定');
			  }
		  }
	}

	$(function(){
		// note: 1em = 16px, 100%, 12pt
		var work_height = $(window).height()-32-28-8;
		$("#navigator").height(work_height + "px");
		$("#content").height(work_height + "px");

		// disable cache
		$.ajaxSetup({cache: false});

		// function to resize content areas when window is resized
		$(window).resize(function(){
			var work_height = $(window).height()-32-28-8;
			$("#navigator").height(work_height + "px");
			$("#content").height(work_height + "px");
			adjust_content_width();
	    });

		// load navigator
		$("#navigator").load("/navigator?id=3", function(){ $("#article_tags").click(edit_tags);});
		$("#user").load("/user_panel", function(){$("#login").click(function(){login();});$("#logout").click(function(){logout();});});

		var editor;
		$("#collapse").click(function(){
			var $nav = $("#navigator");
			var $link = $("#collapse a");
			if ($nav.is(":visible")){
				$nav.hide();
				$link.html("&gt;&gt;&gt;").attr("title","展开导航窗口");
			  }else{
				$nav.show();
				$link.html("&lt;&lt;&lt;").attr("title","折叠导航窗口");
			  }
			$(window).resize();
			return false;
		});

		// buttons
		$("button", ".button_panel").button();
		
		// width
		if (isIE6()){
			document.execCommand("BackgroundImageCache",false,true);
		  }
		<!--#include init_editor-->
		
		// initialize selection
		$("#article_tag").autocomplete({
			source: [],
			minLength: 0
		  });
		update_tag_selection();
		
		// new article
		$("#new_article").click(function(){
			// check title
			var article_title = $.trim($("#article_title").val());
			var article_tag   = $.trim($("#article_tag").val());
			if (article_title.length > 0){
				var content = $.trim($("#input").val());
				if (content.length > 0){
					$.ajax({
						type: "POST",
						url: "/new_article",
						async: false,
						data: {title:article_title, tag: article_tag, content: content},
						dataType: "text",
						success: function(data, status){
							// check result
							if (data.substr(0,1) == ">"){
								// refresh
								location.href="/articles/" + data.substr(1);
							  }else{
								alert(data);
								$("#input").focus();
							  }
						  },
						error: function(){
							alert("无法上传文档。");
						  }
					  });
				  }else{
					alert("文档内容未输入。");
					$("#input").focus();
				  }
			  }else{
				alert("文档标题未输入。");
				$("#article_title").focus();
			  }
		});

		//initalize page nav
		pageNav.pre="上一页";
		pageNav.next="下一页";
		<!--#include page_nav-->

		<!--#include init_default_tag-->

		// adjust content width
		adjust_content_width();
	});
</script>
<style type="text/css">
	html,body{margin:0; padding:0;}
	html{overflow:visible;}
	body{font-size:11pt; min-width:500px;overflow-y:hidden !important; overflow-x:auto !important;}
	
	#banner #logo{font:200% 黑体; float:left; padding:3px 5px 0}
	#banner #user{font:80% 宋体; float:right; padding:5px 8px}

	#user a{text-decoration:none;}
	#user span{margin:2px 0 0 5px;}

	#menubar{background-color:#555; clear:both; height:28px}
	#menubar #collapse{padding:3px 0 0 0; float:left; color:#fff;}
	#menubar a:link, #menubar a:visited{color:white; text-decoration:none; vertical-align:middle;}
	#menubar a:hover{color:red;}
	#menubar #collapse a{font-weight:bold;}
	#menubar ul{padding:3px 10px 3px 5px; margin:0; text-align: right}
	#menubar li{padding:0 5px; font:90% "黑体"; color:#fff; display:inline}
	
	#navigator{font:宋体; width:160px; float:left; margin:5px; padding:5px; display:block;}
	#navigator a{display:block; width:125px; word-break:keep-all; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin:2.5px;}
	#navigator a:link, #navigator a:visited{font:80% "宋体";padding:0;}
	
	#content{padding:0 5px; margin:0; overflow:auto; display:block;}
	
	.button_panel{font:80% 宋体; margin: 5px 10px; padding: 5px; clear: both;}
	.button_panel .ui-button {position: static;}

	.ui-dialog-title{font-size:80%;padding:0;}
	.ui-dialog fieldset { padding:0; border:0; margin-top:10px; }
	.ui-dialog form div { margin:5px 0;}
	.ui-dialog .ui-dialog-buttonpane{margin:0.2em 0 0; padding:0.2em 1em 0.1em 0.4em;}
	.ui-dialog .ui-dialog-buttonpane button{margin:0.2em 0.4em 0.1em 0; padding:0;}
	.ui-widget .ui-widget{ font-size: 0.7em;}

	.ui-autocomplete{font-size:80%;}

	.ui-icon-red{ width: 16px; height: 16px; background-image: url(/css/images/ui-icons_cc0000_256x240.png);}
	.ui-icon-blue{ width: 16px; height: 16px; background-image: url(/css/images/ui-icons_004276_256x240.png);}

	#dt_list{font:85% "宋体", Verdana, Arial, Helvetica, sans-serif;margin: 0;padding: 0;color: #333;background-color: #fff;}
	#dt_list h1{margin-top: 0.5em;font-size: 1.3em;font-weight: normal;line-height: 1.6em;color: #4E6CA3;border-bottom: 1px solid #B0BED9;clear: both;}
	#dt_list .spacer{height: 10px;clear: both;}

	table#article_list{border-top: 1px solid #aaa;clear:both;}
	#article_list thead th{font-weight:normal;line-height:1.6em;border-bottom: 1px solid #aaa;background-color:#eee; padding-top:2px;}
	#article_list td{border-bottom:1px dotted #aaa;padding-top: 3px;padding-bottom: 3px;}
	#article_list tbody tr:hover{background-color:#f8f8f8;}
	#article_list tbody a{text-decoration:none;color:#000;}
	#article_list tbody .op a{color:#00c;}
	#article_list tbody span{vertical-align:middle;}

	#dialog{font-size:70%;margin:0}
	#dialog label{ float:left; width:7em; text-align:right;}
	#dialog input, select{ padding:1px 1px; border:1px solid #ccc; width:65%;}

	#upload_dialog{font-size:70%;margin:0}
	#upload_dialog label{ float:left; width:7em; text-align:right;}
	#upload_dialog input{ padding:1px 1px; border:1px solid #ccc; width:65%;}

	.tag_list ul{list-style-type: none; margin: 0; padding: 0; margin-bottom: 10px; }
	.tag_list li{margin: 5px; padding: 5px; }
	.tag_list li a:link, .tag_list li a:visited{font:90% "宋体";padding:0;color:#c00}

	#page{float:right;}

	.pageNum{border: 1px solid #999;padding:2px 5px;display: inline-block;}
	.cPageNum{font-weight: bold;padding:2px 5px;}
	#pageNav{font-size:90%; margin: 5px 0;}
	#pageNav a:hover{text-decoration:none;background: #fff4d8; }
</style>
</head>
<body id="home">
<div id="banner">
	<div id="logo">雪人CAT网络协同翻译平台</div>
	<div id="user">
	</div>
</div>
<div id="menubar">
	<ul>
		<li id="collapse"><a href="#" title="折叠导航窗口">&lt;&lt;&lt;</a></li>
		<li><a href="/index.htm" id="homepage">首页</a></li>
		<li><a href="/project.htm" id="project">项目</a></li>
		<li><a href="/articles/all/list" id="document">文档</a></li>
		<li><a href="/forum.htm" id="discuss">论坛</a></li>
		<li><a href="/message.htm" id="message">通讯</a></li>
		<li><a href="/help.htm" id="help">帮助</a></li>
	</ul>
</div>
<div class="ui-widget ui-state-default ui-corner-all" id="navigator"></div>
<div id="content">
	<div id="dt_list">
		<table cellpadding="0" cellspacing="0" border="0" class="display" id="article_list" width="100%">
			<thead>
				<tr>
					<th width="10%">类别</th>
					<th width="*">标题</th>
					<th width="8%">作者</th>
					<th width="20%">更新时间</th>
					<th width="80px">操作</th>
				</tr>
			</thead>
			<tbody>
				<!--#include article_list-->
			</tbody>
		</table>
		<div id="page">
			<div id="pageNav"></div>
		</div>
		<div id="spacer"></div>
		<!--#include editor-->
	</div>
</div>
<div id="dialog"></div>
<div id="upload_dialog"></div>
</body>
</html>
