1+ ( function ( ) {
2+
3+
4+ function timeConverter ( UNIX_timestamp ) {
5+ var a = new Date ( UNIX_timestamp * 1000 ) ;
6+ var months = [ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' ] ;
7+ var year = a . getFullYear ( ) ;
8+ var month = months [ a . getMonth ( ) ] ;
9+ var date = a . getDate ( ) ;
10+ var hour = a . getHours ( ) ;
11+ var min = a . getMinutes ( ) ;
12+ var sec = a . getSeconds ( ) ;
13+ var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
14+ return time ;
15+ }
16+
17+ $ ( function ( ) {
18+
19+ var group1 = "project" ;
20+ var group2 = "user" ;
21+ var group3 = "day" ;
22+ var filterProjectId = "" ;
23+ var filterClientId = "" ;
24+
25+
26+ $ ( document ) . ready ( function ( ) {
27+ $ ( "#dialog-confirm" ) . dialog ( {
28+ autoOpen : false ,
29+ modal : true
30+ } ) ;
31+
32+
33+
34+ function editTimeline ( dialogTimelineEditForm ) {
35+ target = dialogTimelineEditForm . target ;
36+ form = dialogTimelineEditForm . find ( "form" ) ;
37+ var baseUrl = OC . generateUrl ( '/apps/timetracker/ajax/edit-timeline/' + target . getData ( ) . id ) ;
38+ var jqxhr = $ . post ( baseUrl , { status :form . find ( "#status" ) . val ( ) } , function ( ) {
39+ getTimelines ( ) ;
40+ $ ( dialogTimelineEditForm ) . dialog ( "close" ) ;
41+ } )
42+ . done ( function ( data , status , jqXHR ) {
43+ var response = data ;
44+ if ( 'Error' in response ) {
45+ alert ( response . Error ) ;
46+ }
47+ } )
48+ . fail ( function ( ) {
49+ alert ( "error" ) ;
50+ } ) ;
51+
52+ }
53+
54+ dialogTimelineEditForm = $ ( "#dialog-timeline-edit-form" ) . dialog ( {
55+ autoOpen : false ,
56+ height : 400 ,
57+ width : 350 ,
58+ modal : true ,
59+ create : function ( event , ui ) {
60+
61+ } ,
62+ buttons : {
63+ "Edit timeline" : { text :'Edit timeline' ,
64+ click :function ( ) {
65+ editTimeline ( dialogTimelineEditForm ) ;
66+ } , class :'primary' } ,
67+ Cancel : function ( ) {
68+ dialogTimelineEditForm . dialog ( "close" ) ;
69+ }
70+ } ,
71+ close : function ( ) {
72+
73+
74+ }
75+ } ) ;
76+
77+
78+
79+ getTimelines ( ) ;
80+
81+ function getTimelines ( ) {
82+
83+ var editIcon = function ( cell , formatterParams ) { //plain text value
84+ return "<i class='fa fa-edit'></i>" ;
85+ } ;
86+ function pad ( n , width , z ) {
87+ z = z || '0' ;
88+ n = n + '' ;
89+ return n . length >= width ? n : new Array ( width - n . length + 1 ) . join ( z ) + n ;
90+ }
91+
92+ var baseUrl = OC . generateUrl ( '/apps/timetracker/ajax/timelines-admin' ) ;
93+ var table = new Tabulator ( "#timelines" , {
94+ ajaxURL :baseUrl ,
95+ layout :"fitColumns" ,
96+ // rowClick:function(e, row){
97+ // e.preventDefault();
98+ // dialogTimelineEditForm.target = row;
99+ // debugger;
100+ // dialogTimelineEditForm.find('#status').val(row.getData().status);
101+ // dialogTimelineEditForm.dialog("open");
102+ // return false;
103+ // },
104+ columns :[
105+ //{title:"Id", field:"id", width:100}, //column has a fixed width of 100px;
106+ { title :"#" , field :"" , formatter :"rownum" } ,
107+ { title :"Id" , field :"id" , widthGrow :1 } , //column will be allocated 1/5 of the remaining space
108+ { title :"User" , field :"userUid" , widthGrow :1 } , //column will be allocated 1/5 of the remaining space
109+ { title :"Status" , field :"status" , widthGrow :1 } , //column will be allocated 1/5 of the remaining space
110+
111+ //{title:"User", field:"userUid", widthGrow:1}, //column will be allocated 1/5 of the remaining space
112+ //{title:"Project", field:"projectName", widthGrow:1}, //column will be allocated 1/5 of the remaining space
113+ //{title:"Client", field:"clientName", widthGrow:1}, //column will be allocated 1/5 of the remaining space
114+ { title :"When" , field :"timeInterval" , widthGrow :1 } , //column will be allocated 1/5 of the remaining space
115+ { title :"Total Duration" , field :"totalDuration" , formatter :function ( cell , formatterParams , onRendered ) {
116+ //cell - the cell component
117+ //formatterParams - parameters set for the column
118+ //onRendered - function to call when the formatter has been rendered
119+ var duration = cell . getValue ( ) ;
120+ var s = Math . floor ( ( duration ) % 60 ) ;
121+ var m = Math . floor ( ( duration / 60 ) % 60 ) ;
122+ var h = Math . floor ( ( duration / ( 60 * 60 ) ) ) ;
123+
124+ return pad ( h , 2 ) + ':' + pad ( m , 2 ) + ':' + pad ( s , 2 ) ;
125+
126+ } , } , //column will be allocated 1/5 of the remaining space
127+ { title :"created At" , field :"createdAt" , formatter :function ( cell , formatterParams , onRendered ) {
128+ //cell - the cell component
129+ //formatterParams - parameters set for the column
130+ //onRendered - function to call when the formatter has been rendered
131+ var unix = cell . getValue ( ) ;
132+
133+ return timeConverter ( unix ) ;
134+
135+ } , } , //column will be allocated 1/5 of the remaining space
136+ { title :"Download" , field :"" , formatter :"rownum" , formatter :function ( cell , formatterParams , onRendered ) {
137+ //cell - the cell component
138+ //formatterParams - parameters set for the column
139+ //onRendered - function to call when the formatter has been rendered
140+ //debugger;
141+ var baseUrl = OC . generateUrl ( '/apps/timetracker/ajax/download-timeline/' + cell . getRow ( ) . getData ( ) [ "id" ] ) ;
142+
143+ return '<a href="' + baseUrl + '">' + "Download" + '</a>' ;
144+
145+ } } ,
146+
147+ { formatter :editIcon , width :40 , align :"center" , cellClick :function ( e , cell ) {
148+
149+ dialogTimelineEditForm . target = cell . getRow ( ) ;
150+ //debugger;
151+ dialogTimelineEditForm . find ( '#status' ) . val ( cell . getRow ( ) . getData ( ) . status ) ;
152+ dialogTimelineEditForm . dialog ( "open" ) ;
153+ return false ;
154+
155+ } } ,
156+
157+ ] ,
158+ ajaxResponse :function ( url , params , response ) {
159+
160+ return response . Timelines ; //return the tableData property of a response json object
161+ } ,
162+ } ) ;
163+
164+ }
165+ } ) ;
166+
167+
168+ } ) ;
169+ } ( ) ) ;
0 commit comments