worklog.ejs 8.6 KB
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>WorkLog</title>
	<% include utils.ejs %>
	<style>
		.menu{
			width: 220px;
			background-color: #323A45;
			height: 100%;
		}
		.center{
			position: fixed;
			top: 0;
			left: 220px;
			right: 0;
			bottom: 0;
			background-color: #fff;
		}
		.tab-head{
			margin: 10px 0 0;
			height: 90px;
			width: 100%;
			background-color: rgba(200,200,200,0.1);
		}
		.tab-head-menu{ 
		    display: block;
		    font-size: 30px;
		    padding: 30px;
		    position: relative;
		    text-align: left;
		}
		.tab-head-menu li{
			display: inline-block;
		}
		.tab-head-menu li a{
			color: #ccc;
		}
		.tab-head-menu li a.activat{
			color: #000;
			border-bottom: 3px solid #ff5252;
		}
		.date{
			min-height: 420px;
		}
		#datepicker{
			width: 230px;
			display: inline-block;
    		float: left;
		}
		.log-items{
			width: 420px;
			min-height: 100px;
			display: inline-block;
    		float: left;
    		background-color: #F6F6F6;
		}
		.log-content{
			bottom: 0;
		    left: 650px;
		    min-height: 500px;
		    position: absolute;
		    right: 0;
		    top: 120px;
		    background-color: #f6f6f6;
		}
		.log-items > ul >li{
			text-align: left;
			margin: 1px;
			background-color: #fff;
			padding: 8px 15px;
		}
		.add-worklog-item{
			cursor: pointer;
		}
		.comment-tiem,.log-item,.add-worklog-item{
			height: 40px;
			width: 100%;
		}
		.log-item{
			cursor: pointer;
		}
		.log-items > ul >li.log-item{
			background-color: #F8EBB5;
		}
		.comment-tiem>i{
			color: #f50057;
		}
		.item-content{
			width: 100%;
			height: 70%;
		}
		.item-experience{
			width: 100%;
			height: 30%;
		}
	</style>
	<link rel='stylesheet' href='/css/formEditor.css' /> 
</head>
<body>
	<div class="md-overlay"></div><!-- the overlay element --> 
	<div class="md-modal md-effect-16" id="modal-16"> 
	</div>
	<div class="menu"></div>
	<div class="center blur-body">
		<div class="tab-head">
			<ul class="tab-head-menu">
				<li><a>考勤管理</a></li>
				<li><a>日程管理</a></li>
				<li><a class="activat">日志管理</a></li>
			</ul>
		</div>
		<div class="">
			<div id="current-date"></div>
		</div>
		<div class=""> 
			<div id="datepicker"  ></div> 
			<div class="log-items">
				
			</div>
			<div class="log-content">
				
			</div>
		</div>
	</div>
	
	<script id="worklog-items-template" type="text/x-handlebars-template">
		 <ul>
		 	{{#each Comments.items}}
		 		<li class="comment-tiem"><i class="fa fa-commenting-o"></i>{{content}}</li>
		 	{{/each}}
		 	{{#each WorklogItems.items}}
		 		<li class="log-item" data-uuid="{{uuid}}">{{title}}</li>
		 	{{/each}}
		 	<li class="add-worklog-item"><i class="fa fa-plus"></i></li>
		 </ul>
	</script>
	<script id="create-worklog-item-tempalte" type="text/x-handlebars-template">
		<div class="md-content">
			<h3>添加工作项</h3>
			<div>
				<form id="create-worklog-item" action=""  data-template-type="#field-singleline-tempalte"> 
			      	<div class="input-field-inline row">
			          	<label class="active col s3">标题</label>    
			         	<input  type="hidden" name="work_log_id" value="{{uuid}}">
			         	<input class="col s9" type="text" name="title" value=""> 
			       	</div> 
			       	<div class="input-field-inline row">
			          	<label class="active col s3">内容</label>     
			         	<input class="col s9" type="text" name="content" value=""> 
			       	</div> 
			       	<div class="input-field-inline row">
			          	<label class="active col s3">经验</label>     
			         	<input class="col s9" type="text" name="experience" value=""> 
			       	</div> 
			    </form>
			</div>
			<div class="md-button-wrap">   
			    <a class="md-submit-btn waves-effect waves-light btn" data-form="#create-worklog-item" href="javascript:void(0);">提交</a>
			</div>
		</div>   
	</script>
	<script id="show-item-template" type="text/x-handlebars-template">
		<div class="item-content">
			<div class="">{{createTime}}</div>
			<div class="left-align">{{item.content}}</div>
		</div>
		<div class="item-experience left-align">{{item.experience}}</div>
	</script>

	<script>
		;(function($,window,document,undefined){
			var currentDate,currentWorkLog;
			window.WorkLog=function(opt){
				this.defaults={ 
					blur:true,
					eves:[{
						eveName:'touchstart click',selector:'.add-worklog-item',action:'openAddItemModal'
					},{
						eveName:'touchstart click',selector:'.log-items .log-item',action:'showItem'
					}]
				};
				this.options=$.extend({},this.defaults,opt);
				this.init();
			};
			WorkLog.prototype={
				init: function() {
					this.bindEve();
				}, 
				bindEve: function() {
					var self=this;
					self.unbindEve
					$.each(self.options.eves,function(i,eve){
						$(document).on(eve.eveName,eve.selector,
						$.proxy(self[eve.action], self));
					}); 
				},
				unbindEve:function(){
					var self=this;
					$.each(self.options.eves,function(i,eve){
					$(document).off(eve.eveName,eve.selector,
						$.proxy(self[eve.action], self));
					});
				},
				loadWorkLog:function(date){
					var self=this,currentDate=date; 
					if(!date)
						date=moment($('#datepicker').datepicker('getDate')).format("YYYYMMDD");
					async.waterfall([
					    function(callback) {
					    	$.post('/worklog/listWorkLog',{
								'workday':date
							},function(data){
								if(data&&data.total_count>0){
									currentWorkLog=data.items[0];
									callback(null,data.items[0]); 
								}else{
									self.createWorkLog();
								} 
							}); 
					    },
					    function(worklog, callback) {
					    	$.post('/worklog/listWorkLogItem',{
								'work_log_id':worklog.uuid
							},function(data){
								currentWorkLog.WorklogItems=data; 
								callback(null, worklog);
							}); 
					    },
					    function(worklog, callback) { 
					    	$.post('/worklog/listComment',{
								'target_id':1,
								'target_type':'worklog' 
							},function(data){
								currentWorkLog.Comments=data; 
								callback(null, worklog);
							}); 
					    },
					    function(worklog, callback) { 
					    	$.post('/worklog/listSupport',{
								'target_id':worklog.uuid,
								'target_type':'worklog'
							},function(data){
								currentWorkLog.Supports=data; 
								callback(null, 'done');
							});
					    }
					],function (err, result) {console.log(currentWorkLog);
					    $('.log-items').html(
							Handlebars.compile($('#worklog-items-template').html())(currentWorkLog)
						);
					});
				},
				createWorkLog:function(){ 
					currentDate=moment($('#datepicker').datepicker('getDate')).format("YYYYMMDD");
					$.post('/worklog/createWorkLog',{
						'workday':currentDate
					},function(data){
						currentWorkLog=data;
						console.log('-----create-------'); 
						console.log(data)
						$('.log-items').html(
							Handlebars.compile($('#worklog-items-template').html())(data)
						);
					}); 
				},
				openAddItemModal:function(){
					var self=this;
					$('#modal-16').ModalEffects({
						renderTemplate:'#create-worklog-item-tempalte',
						data:currentWorkLog,
						callBack:function(ev,modal){
							self.submitCreateItemForm(ev,modal);
						}
					}).openModal();
				},
				submitCreateItemForm:function(e,modal){
					var self = this;
					var _form=$($(e.target).data('form')); 
					var parmas = _form.serializeJSON();  
					$.post('/worklog/createWorkLogItem',parmas,function(data){
						console.log(data); 
						if(data&&data.uuid){
							self.loadWorkLog(currentDate);
							modal.closeModal(e);
						}
					}); 
				},
				showItem:function(e){
					var self=this;
					var item=self.getLogItemById($(e.target).data('uuid'));
					$('.log-content').html(
						Handlebars.compile($('#show-item-template').html())({
							'item':item,
							'createTime':moment(item.created_at).format("YYYY年MM月DD日 ah:mm dddd")
						})
					);
					console.log(item);
				},
				getLogItemById:function(uuid){
					var temp;
					$.each(currentWorkLog.WorklogItems.items,function(i,item){
						if(item.uuid==uuid){
							temp=item;
						}
					});
					return temp;
				}
			};   
		})(jQuery,window,document)
		var worklog=new WorkLog({});
		
		$('#datepicker').datepicker({
			'language':'zh-CN' 
		}).datepicker('setDate',moment(new Date()).format("YYYY-MM-DD"));
		$('#datepicker').on("changeDate", function() {  
		    $('#current-date').html(moment($('#datepicker').datepicker('getDate')).format("YYYY年MM月DD日 dddd"));
		    loadWorkLog(moment($('#datepicker').datepicker('getDate')).format("YYYYMMDD"));
		});
		$('#current-date').html(moment(new Date()).format("YYYY年MM月DD日 dddd"));
		loadWorkLog(moment(new Date()).format("YYYYMMDD")); 
		function loadWorkLog(date){
			console.log(date);
			worklog.loadWorkLog(date);
		}
	</script>
</body>
</html>