<div class="projectheader">
	
	<?php
	//print_r($LEGUWORKUSER);
	?>
	<a href="./?app=board"><img src="img/wekan-logo1.png" style="height: 45px; margin-left: 10px;;" /></a>
	<h1 style="display: inline-block; font-size: 22px; font-weight: normal;vertical-align:top; margin-top: 10px; margin-left: 15px;;">
		
	</h1>

	<span style="display: inline-block; font-size: 14px; font-weight: normal;vertical-align:top; margin-top: 20px; margin-left: 15px;;" id="lastpackinfo"></span>
	
	<?if(r('app')=='list'){?>	
	<div class="proctrl" style=" position: fixed; display: inline-block;; right: 0; top: 0;;">
		<!--<span class="fa fa-address-book" onclick="" id="" style="font-size: 20px; margin: 15px 10px 0 0; cursor: pointer;" title="项目报表"></span>-->
		
		过滤：
		<div style="display: inline-block; width: 150px;;">
			<input type="text" id="filterText" style="position: absolute; z-index: 2;width: 121px; margin-top: -15px;border:1px solid #888"/>
			<select id="editable-select" onchange="$('#filterText').val(this.value);doSearch();" style=" position: absolute;z-index: 0;width: 140px;margin-top: -15px;border:1px solid #888">
			</select>
		</div>
		
		
		<span class="fa fa-bar-chart" onclick="showReport()" id="projectReport" style="font-size: 20px; margin: 15px 10px 0 15px; cursor: pointer;" title="项目报表"></span>
		<span class="fa fa-universal-access" onclick="showCardPopover()" id="projectReport1" style="font-size: 20px; margin: 15px 10px 0 15px; cursor: pointer;" title="项目集成"></span>
	</div>
	<?}?>
	
	<?if(r('app')=='usercard'){?>
	<div class="proctrl" style=" position: fixed; display: inline-block;; right: 0; top: 0;;">
		<div style="display:inline-block;margin-top:15px;margin-right:10px">
			成员 <select name="user" id="user">
				<option value="">请选择</option>
			</select> 的
			<select name="time_type" id="time_type">
				<option value="bj">标记时间</option>
				<option value="wc">完成时间</option>
				<option value="xz">新增时间</option>
			</select>
			于
			<input type="text" name="daterange" id="date" readonly style="text-align: center;width: 200px;">

			<button id="search">查询</button>
		</div>
	</div>
	<? } ?>


	<?php
		$userinfo = getUserInfo($MYID);
		if((r('app')=='events') && $userinfo && $userinfo['extData'] && $userinfo['extData']['admin']==='all'){
			$orgs = getorgs();
		?>
		<span style="    position: relative;top: -15px;">
			<select style="padding:5px;" id="selectorg">
				<option value="">切换组织</option>
				<? foreach($orgs as $orgid=>$orgname){?>
				<option value="<?=$orgid?>"><?=$orgname?></option>
				<? } ?>
			</select>
		</span>
		<?php
		}
	?>

</div>
<script>
//提取tag
function createTags(){
	if(!DATA.boardid)return;
	var cards = DATA.cards;
	var ALLTAG = {};
	for(var i in cards){
		if(cards[i].boardId != DATA.boardid)continue;
		var tags = cards[i].title.match(/【(\S*?)】/g);
		if(tags && tags.length>0){
			tags.forEach(function(v){
				ALLTAG[v] = 1;
			})
		}
	}
	var keys = Object.keys(ALLTAG);
	
	var labelsHTML=[];
	if(DATA.boards[DATA.boardid]){
		var labels = DATA.boards[DATA.boardid].labels;
		labels.forEach(function(v){
			labelsHTML.push( '<option value="label_'+ v._id +'">* 匹配标签['+ v.name +']</option>' );
		});
	}

	var qaLabelsHTML=[];

	if(DATA.boards[DATA.boardid]){
		var qaLabels = DATA.boards[DATA.boardid].qalabels;
		qaLabels.forEach(function(v){
			qaLabelsHTML.push( '<option value="qalabel_'+ v._id +'">* 匹配QA标签['+ v.name +']</option>' );
		});
	}
	
	
	// var html = ['<option value="">选择分类或输入关键词</option><option value="my">* 指派给我的(ALT+M)</option>'+ labelsHTML.join('') + qaLabelsHTML.join('')];
	var html = ['<option value="">选择分类或输入关键词</option><option value="my">* 指派给我的(ALT+M)</option>'];


	// 延期标签 UI 策  策配 美 动效 前程 后程 所有
	// 选择标签 过滤标签的人设置的完成时间是今天的
	var htmlTodayDone4DeptLabel = ['UI','策',  '策配', '美', '动效', '前程', '后程', '所有'];
	var htmlTodayDone4DeptLabel = [];
	var yanqidepartmentuserList = Object.keys(DATA.yanqidepartmentuser);
	yanqidepartmentuserList.forEach(function (k) {
		htmlTodayDone4DeptLabel.push({
			_id:k,
			name:DATA.yanqidepartmentuser[k].name
		})

	});

	htmlTodayDone4DeptLabel.forEach(function (v) {
		if(v.name){
			html.push('<option value="todaydonedeptlabel_'+ v._id +'">* 当天完成['+v.name+']</option>');
		}
	});
	html.push('<option value="hasTodayDone">* 当天完成[所有]</option>');

	html.push(labelsHTML + qaLabelsHTML);

	keys.forEach(function(v){
		html.push('<option value="'+ v.replace('【','').replace('】','') +'">'+v+'</option>');
	});




	$('#editable-select').html( html.join(''));
}
//开始筛选
function doSearch(){
	var v = $('#filterText').val();
	if(v=='my'){
		filterList.my();
	}else if(v.indexOf('qalabel_')==0) {
		var lid = v.replace('qalabel_', '');
		filterList.hasqaLabel(lid);

	}else if(v.indexOf('label_')==0){
		var lid = v.replace('label_','');
		filterList.hasLabel(lid);
	}else if(v.indexOf('todaydonedeptlabel_')==0){
		var lid = v.replace('todaydonedeptlabel_','');
		filterList.hasTodayDone4DeptLabel(lid);
	}else if(v.indexOf('hasTodayDone')==0){
		var lid = v;
		filterList.hasTodayDone(lid);
	}else if(v==''){
		filterList.null();
	}else{
		filterList.key(v);
	}
}

$(function(){
	setTimeout(function(){
		createTags();
		
		if(window.MYINFO){
			watermark({
				watermark_txt0: MYINFO.profile.fullname,
				watermark_txt1: MYINFO.orgname + " " + MYINFO.group,
				watermark_txt2: (DATA.ts?new Date(DATA.ts*1000):new Date()).Format("yyyy-MM-dd hh:mm:ss")
			});
		}

	},10);
	
	//筛选框回车
	$('#filterText').keydown(function(e){
		setTimeout(function(){
			if(e.keyCode==13){
				doSearch();
			}
		})
	});
	
	if(DATA.boardid && DATA.boards && DATA.boards[ DATA.boardid ]){
		var board = DATA.boards[ DATA.boardid ];
		$('.projectheader h1').html( board.title );
	}else{
		$('.projectheader h1').html('我的看板');
	}
	
});
</script>