<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>文档中心</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("content");
				$("#article_content").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 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(id, state)
	{
		if (set_article_attr((state == 1) ? "把文档设为公共文档?" : "把文档设为私有文档?", id, "public", state)){
			window.location.reload();
		  }
	}
	function lock_article(id, state)
	{
		if (set_article_attr((state == 1) ? "锁定所选文档?" : "解锁所选文档?", id, "lock", state)){
			window.location.reload();
		  }
	}
	function edit_article(id)
	{
      	var title = $('#article .title').text();
      	var tag = $('#article .author .tag a').text();
      	var html_text = $('#article .text').html();

		// edit document
		$("#edit_dialog").dialog({
			modal: true,
			resizable:false,
			width: 700,
			height: 450,
			title: "编辑文档",
			buttons:{
				"确定": function(){
					var new_title = $.trim($("#article_title").val());
					if (new_title.length > 0){
						var content = $.trim($("#edit_dialog #text_editor").val());
						if (content.length > 0){
							// check content changed
							var new_tag   = $.trim($("#article_tag").val());
							if (content != html_text){
								$.ajax({
									type: "POST",
									url: "/update_article",
									async: false,
									data: {id:id, title:new_title, tag: new_tag, content: content},
									dataType: "text",
									success: function(data, status){
										// check result
										if (data.substr(0,1) == ">"){
											// refresh
											window.location.reload();
							  			  }else{
											alert(data);
											$("#input").focus();
							  			  }
						  			},
									error: function(){
										alert("无法上传文档。");
						  			}
					  			});
							  }else{
						      	if (tag == null) tag = "";
							  	if (new_title != title || tag != new_tag){
									$.ajax({
										type: "POST",
										url: "/update_article",
										async: false,
										data: {id:id, title:new_title, tag: new_tag},
										dataType: "text",
										success: function(data, status){
											// check result
											if (data.substr(0,1) == ">"){
												// refresh
												window.location.reload();
								  			  }else{
												alert(data);
												$("#input").focus();
							  				  }
						  				},
										error: function(){
											alert("无法上传文档。");
							  			}
						  			});
							  	  }else{
									// close window
									$("#edit_dialog").dialog("destroy");
							  	  }
							  }
						  }else{
							alert("文档内容未输入。");
							$("#edit_dialog #text_editor").focus();
						  }
					  }else{
						alert("文档标题未输入。");
						$("#article_title").focus();
					  }
				  }
			},
			open: function(){
				$(this).html('<div class="ui-widget"><table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin:0 0 5px 0;"><tr><td width="60px">文档分类:</td><td width="20%"><input id="article_tag" type="text" style="width:90%"/></td><td width="60px">文档标题:</td><td width="*"><input id="article_title" type="text" style="width:405px"/></td></tr></table></div><textarea id="text_editor" name="text_editor"></textarea>');
				$("#edit_dialog #text_editor").cleditor({
					width:		660,
       				height:     320,
		          	controls:   "bold italic underline strikethrough subscript superscript | font size style | color highlight removeformat | bullets numbering | alignleft center alignright justify | rule icon image upload link unlink | source",
		          	colors:     "FFF FCC FC9 FF9 FFC 9F9 9FF CFF CCF FCF CCC F66 F96 FF6 FF3 6F9 3FF 6FF 99F F9F BBB F00 F90 FC6 FF0 3F3 6CC 3CF 66C C6C 999 C00 F60 FC3 FC0 3C0 0CC 36F 63F C3C 666 900 C60 C93 990 090 399 33F 60C 939 333 600 930 963 660 060 366 009 339 636 000 300 630 633 330 030 033 006 309 303",
       				fonts:      "宋体,楷体,黑体,幼圆,隶书,Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond,Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana",
       				sizes:      "1,2,3,4,5,6,7",
       				styles:     [["Paragraph", "<p>"], ["Header 1", "<h1>"], ["Header 2", "<h2>"], ["Header 3", "<h3>"],  ["Header 4","<h4>"],  ["Header 5","<h5>"], ["Header 6","<h6>"]],
       				useCSS:   	false, // use CSS to style HTML when possible (not supported in ie)
       				bodyStyle:  "margin:4px; font:10pt Arial,Verdana; cursor:text"
		      	});
		      	$("#edit_dialog #text_editor").val(html_text).blur();
		      	$("#edit_dialog #article_title").val(title);
		      	if (tag) $("#edit_dialog #article_tag").val(tag);
				$("#article_tag").autocomplete({source: [],minLength: 0});
		      	update_tag_selection();
			},
			close: function(){
				$("#article_tag").autocomplete("destroy");
			}
		});
		return false;
	};
	function new_comment(id)
	{
		// check title
		var content = $.trim($("#input").val());
		if (content.length > 0){
			$.ajax({
				type: "POST",
				url: "/new_comment",
				async: false,
				data: {id:id, content: content},
				dataType: "text",
				success: function(data, status){
					// check result
					if (data.substr(0,1) == ">"){
						// refresh
						window.location.reload();
					  }else{
						alert(data);
						$("#input").focus();
					  }
				  },
				error: function(){
					alert("无法发表评论。");
				  }
			  });
		  }else{
			alert("评论内容未输入。");
			$("#input").focus();
		  }
	}
	function edit_comment(record, document_id, id)
	{
      	var html_text = record.parent().parent().parent().children(".text").html();
		// edit document
		$("#edit_dialog").dialog({
			modal: true,
			resizable:false,
			width: 700,
			height: 450,
			title: "编辑评论",
			buttons:{
				"确定": function(){
					var content = $.trim($("#edit_dialog #text_editor").val());
					if (content.length > 0){
						// check content changed
						if (content != html_text){
							$.ajax({
								type: "POST",
								url: "/update_comment",
								async: false,
								data: {document_id:document_id, id:id, content: content},
								dataType: "text",
								success: function(data, status){
									// check result
									if (data.substr(0,1) == ">"){
										// refresh
										window.location.reload();
						  			  }else{
										alert(data);
										$("#input").focus();
						  			  }
					  			},
								error: function(){
									alert("无法更新评论。");
					  			}
				  			});
						  }else{
							// close window
							$("#edit_dialog").dialog("destroy");
					  	  }
					  }else{
						alert("文档内容未输入。");
						$("#edit_dialog #text_editor").focus();
					  }
				  }
			},
			open: function(){
				$(this).html('<textarea id="text_editor" name="text_editor"></textarea>');
				$("#edit_dialog #text_editor").cleditor({
					width:		660,
       				height:     345,
		          	controls:   "bold italic underline strikethrough subscript superscript | font size style | color highlight removeformat | bullets numbering | alignleft center alignright justify | rule icon image upload link unlink | source",
		          	colors:     "FFF FCC FC9 FF9 FFC 9F9 9FF CFF CCF FCF CCC F66 F96 FF6 FF3 6F9 3FF 6FF 99F F9F BBB F00 F90 FC6 FF0 3F3 6CC 3CF 66C C6C 999 C00 F60 FC3 FC0 3C0 0CC 36F 63F C3C 666 900 C60 C93 990 090 399 33F 60C 939 333 600 930 963 660 060 366 009 339 636 000 300 630 633 330 030 033 006 309 303",
       				fonts:      "宋体,楷体,黑体,幼圆,隶书,Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond,Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana",
       				sizes:      "1,2,3,4,5,6,7",
       				styles:     [["Paragraph", "<p>"], ["Header 1", "<h1>"], ["Header 2", "<h2>"], ["Header 3", "<h3>"],  ["Header 4","<h4>"],  ["Header 5","<h5>"], ["Header 6","<h6>"]],
       				useCSS:   	false, // use CSS to style HTML when possible (not supported in ie)
       				bodyStyle:  "margin:4px; font:10pt Arial,Verdana; cursor:text"
		      	});
		      	$("#edit_dialog #text_editor").val(html_text).blur();
			}
		});
		return false;
	}
	function remove_comment(document_id, id)
	{
		if (confirm("确认删除评论?")){
  			$.ajax({
  				type: "GET",
				url: "/remove_comment",
				async: false,
				data:{document_id:document_id, 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_current_page(document_id, current_page)
	{
		// get content
   		$.ajax({
			type: "GET",
			url: "/get_comment_info",
			async: false,
			data: {document_id:document_id, page:current_page},
			dataType: "text",
			success: function(data){
				$("#comment .block").html(data);
			}
		});
	}
	$(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(){
   			resizing = true;
			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();
		
		// editor
		if (isIE6()){
			document.execCommand("BackgroundImageCache",false,true);
		  }
		<!--#include init_editor-->
		
		//initalize page nav
		pageNav.pre="上一页";
		pageNav.next="下一页";
		<!--#include page_nav-->

		// 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:60% 宋体; margin: 5px 10px; padding: 5px; float:left; 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);}

	#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:3px 5px;display: inline-block;}
	.cPageNum{font-weight: bold;padding:2px 2px;}
	#pageNav{font-size:75%; margin: 5px 0;}
	#pageNav a{text-decoration:none;}
	#pageNav a:hover{background: #fff4d8;}
	
	#article{margin: 0 1em;}
	#article .title{font:150% 黑体; text-align:center;}
	#article .author{font-size:80%; color:#cccccc; text-align:center;}
	#article .author .tag{margin:0 1em;}
	#article .text{padding:8px 0;}

	#article .op a:link, #article .op a:visited{font:80% "宋体";text-decoration:none; color:#00f;}
	#article .op span{margin:0 5px 0 0;}

	#comment h1.header{margin-top: 0.5em; font-size: 1em; font-weight: normal; line-height: 1.5em; color: #4E6CA3; border-bottom: 1px solid #B0BED9; clear: both;}
	#comment .spacer{line-height: 5px; border-bottom: 1px solid #B0BED9;}
	#comment .spacer2{margin:0 auto;width:98%;line-height: 5px; border-bottom: 1px dashed #B0BED9;}
	
	.reply{margin:5px 1em;}
	.reply .info{font-size:80%;color:#cccccc;}
	.reply .op{float:right;}
	.reply .op a:link, .reply .op a:visited{font:"宋体";text-decoration:none; color:#00f;}
	.reply .op span{margin:0 5px 0 0;}
</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="article_content">
		<div id="article">
			<!--#include article-->
		</div>
		<div id="comment">
			<!--#include reply_info-->
			<!--#include reply-->
		</div>
	</div>
</div>
<div id="dialog"></div>
<div id="upload_dialog"></div>
<div id="edit_dialog"></div>
</body>
</html>
