forked from mtierltd/timetracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimelines-admin.js
More file actions
169 lines (134 loc) · 6.89 KB
/
timelines-admin.js
File metadata and controls
169 lines (134 loc) · 6.89 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
(function() {
function timeConverter(UNIX_timestamp){
var a = new Date(UNIX_timestamp * 1000);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var year = a.getFullYear();
var month = months[a.getMonth()];
var date = a.getDate();
var hour = a.getHours();
var min = a.getMinutes();
var sec = a.getSeconds();
var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
return time;
}
$( function() {
var group1 = "project";
var group2 = "user";
var group3 = "day";
var filterProjectId = "";
var filterClientId = "";
$(document).ready(function() {
$("#dialog-confirm").dialog({
autoOpen: false,
modal: true
});
function editTimeline(dialogTimelineEditForm){
target = dialogTimelineEditForm.target;
form = dialogTimelineEditForm.find( "form" );
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/edit-timeline/'+target.getData().id);
var jqxhr = $.post( baseUrl, {status:form.find("#status").val()},function() {
getTimelines();
$(dialogTimelineEditForm).dialog("close");
})
.done(function(data, status, jqXHR) {
var response = data;
if ('Error' in response){
alert(response.Error);
}
})
.fail(function() {
alert( "error" );
});
}
dialogTimelineEditForm = $( "#dialog-timeline-edit-form" ).dialog({
autoOpen: false,
height: 400,
width: 350,
modal: true,
create: function( event, ui ) {
},
buttons: {
"Edit timeline": { text:'Edit timeline',
click:function(){
editTimeline(dialogTimelineEditForm);
}, class:'primary'},
Cancel: function() {
dialogTimelineEditForm.dialog( "close" );
}
},
close: function() {
}
});
getTimelines();
function getTimelines(){
var editIcon = function(cell, formatterParams){ //plain text value
return "<i class='fa fa-edit'></i>";
};
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/timelines-admin');
var table = new Tabulator("#timelines", {
ajaxURL:baseUrl,
layout:"fitColumns",
// rowClick:function(e, row){
// e.preventDefault();
// dialogTimelineEditForm.target = row;
// debugger;
// dialogTimelineEditForm.find('#status').val(row.getData().status);
// dialogTimelineEditForm.dialog("open");
// return false;
// },
columns:[
//{title:"Id", field:"id", width:100}, //column has a fixed width of 100px;
{title:"#", field:"", formatter:"rownum"},
{title:"Id", field:"id", widthGrow:1}, //column will be allocated 1/5 of the remaining space
{title:"User", field:"userUid", widthGrow:1}, //column will be allocated 1/5 of the remaining space
{title:"Status", field:"status", widthGrow:1}, //column will be allocated 1/5 of the remaining space
//{title:"User", field:"userUid", widthGrow:1}, //column will be allocated 1/5 of the remaining space
//{title:"Project", field:"projectName", widthGrow:1}, //column will be allocated 1/5 of the remaining space
//{title:"Client", field:"clientName", widthGrow:1}, //column will be allocated 1/5 of the remaining space
{title:"When", field:"timeInterval", widthGrow:1}, //column will be allocated 1/5 of the remaining space
{title:"Total Duration", field:"totalDuration",formatter:function(cell, formatterParams, onRendered){
//cell - the cell component
//formatterParams - parameters set for the column
//onRendered - function to call when the formatter has been rendered
var duration = cell.getValue();
var s = Math.floor( (duration) % 60 );
var m = Math.floor( (duration/60) % 60 );
var h = Math.floor( (duration/(60*60)));
return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
},}, //column will be allocated 1/5 of the remaining space
{title:"created At", field:"createdAt",formatter:function(cell, formatterParams, onRendered){
//cell - the cell component
//formatterParams - parameters set for the column
//onRendered - function to call when the formatter has been rendered
var unix = cell.getValue();
return timeConverter(unix);
},}, //column will be allocated 1/5 of the remaining space
{title:"Download", field:"", formatter:"rownum",formatter:function(cell, formatterParams, onRendered){
//cell - the cell component
//formatterParams - parameters set for the column
//onRendered - function to call when the formatter has been rendered
//debugger;
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/download-timeline/'+cell.getRow().getData()["id"]);
return '<a href="'+baseUrl+'">'+"Download"+'</a>';
}},
{formatter:editIcon, width:40, align:"center", cellClick:function(e, cell){
dialogTimelineEditForm.target = cell.getRow();
//debugger;
dialogTimelineEditForm.find('#status').val(cell.getRow().getData().status);
dialogTimelineEditForm.dialog("open");
return false;
}},
],
ajaxResponse:function(url, params, response){
return response.Timelines; //return the tableData property of a response json object
},
});
}
});
} );
}());