worklog.ejs
8.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<!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>