6262 function editClient ( dialogClientEditForm ) {
6363 target = dialogClientEditForm . target ;
6464 form = dialogClientEditForm . find ( "form" ) ;
65- var baseUrl = OC . generateUrl ( '/apps/timetracker/ajax/edit-client/' + target . id ) ;
65+ var baseUrl = OC . generateUrl ( '/apps/timetracker/ajax/edit-client/' + target ) ;
6666 var jqxhr = $ . post ( baseUrl , { name :form . find ( "#name" ) . val ( ) } , function ( ) {
6767 getClients ( ) ;
6868 $ ( dialogClientEditForm ) . dialog ( "close" ) ;
8181 } ) ;
8282
8383 }
84+
8485 function getClients ( ) {
85- var baseUrl = OC . generateUrl ( '/apps/timetracker/ajax/clients' ) ;
86- $ . getJSON ( baseUrl , function ( data ) {
87-
88- var clients = [ ] ;
89- $ . each ( data . Clients , function ( id , clientMap ) {
90-
91- clients . push ( "<div class='client-button'>" +
92- "<div class='client-name' id='client-name-" + clientMap [ 'id' ] + "'>" +
93- clientMap [ 'name' ] +
94- "</div>" +
95- "<div class='controls'>" +
96- "<span class='fas fa-edit clickable client-edit' id='" + clientMap [ 'id' ] + "' data-name='" + clientMap [ 'name' ] + "'></span>" +
97- "<span class='fas fa-times clickable client-delete' id='" + clientMap [ 'id' ] + "'></span>" +
98- "</div>" +
99- "</div>" ) ;
100- } ) ;
101- $ ( "#clients" ) . html ( $ ( "<div/>" , {
102- "class" : "clients-list" ,
103- html : clients . join ( "" )
104- } ) )
105- $ ( '.client-edit' ) . click ( function ( e ) {
106- e . preventDefault ( ) ;
107- dialogClientEditForm . target = e . target ;
108-
109- form = dialogClientEditForm . find ( "form" )
110- form . find ( "#name" ) . val ( $ ( e . target ) . data ( "name" ) ) ;
111- dialogClientEditForm . dialog ( "open" ) ;
112- return false ;
113-
86+ var baseUrl = OC . generateUrl ( '/apps/timetracker/ajax/clients' ) ;
11487
115- } )
116- $ ( '.client-delete' ) . click ( function ( e ) {
117- $ ( "#dialog-confirm" ) . dialog ( {
118- buttons : {
119- "Confirm" : { click :function ( ) {
120- var baseUrl = OC . generateUrl ( '/apps/timetracker/ajax/delete-client/' + e . target . id ) ;
121- var jqxhr = $ . post ( baseUrl , function ( ) {
122- getClients ( ) ;
123- $ ( "#dialog-confirm" ) . dialog ( "close" ) ;
124- } )
125- . done ( function ( data , status , jqXHR ) {
126- var response = data ;
127- if ( 'Error' in response ) {
128- alert ( response . Error ) ;
129- }
130- } )
131- . fail ( function ( ) {
132- alert ( "error" ) ;
133- } )
134- . always ( function ( ) {
135-
136- } ) ;
88+ var editIcon = function ( cell , formatterParams ) { //plain text value
89+ return "<i class='fa fa-edit'></i>" ;
90+ } ;
91+
92+
93+ var columns = [
94+ { title :"#" , field :"" , formatter :"rownum" , width : 40 , align : "center" } ,
95+ { title :"Name" , field :"name" , widthGrow :1 } , //column will be allocated 1/5 of the remaining space
96+ { formatter :"buttonCross" , width :40 , align :"center" , cellClick :function ( e , cell ) {
97+ $ ( "#dialog-confirm" ) . dialog ( {
98+ buttons : {
99+ "Confirm" : { click : function ( ) {
100+ var baseUrl = OC . generateUrl ( '/apps/timetracker/ajax/delete-client/' + cell . getRow ( ) . getData ( ) . id ) ;
101+ var jqxhr = $ . post ( baseUrl , function ( ) {
102+ getClients ( ) ;
103+ $ ( "#dialog-confirm" ) . dialog ( "close" ) ;
104+ } )
105+ . done ( function ( data , status , jqXHR ) {
106+ var response = data ;
107+ if ( 'Error' in response ) {
108+ alert ( response . Error ) ;
109+ }
110+ } )
111+ . fail ( function ( ) {
112+ alert ( "error" ) ;
113+ } )
137114 return false ;
138- } ,
139- text : 'Confirm' ,
140- class : 'primary'
141- } ,
142- "Cancel" : function ( ) {
143- $ ( this ) . dialog ( "close" ) ;
144- return false ;
145- }
146- }
147- } ) ;
148- $ ( "#dialog-confirm" ) . dialog ( "open" ) ;
149- return false ;
150- } )
115+ } ,
116+ text : 'Confirm' ,
117+ class :'primary'
118+ } ,
119+ "Cancel" : function ( ) {
120+ $ ( this ) . dialog ( "close" ) ;
121+ }
122+ }
151123 } ) ;
152- }
124+ $ ( "#dialog-confirm" ) . dialog ( 'open' ) ;
153125
126+ //cell.getRow().delete();
127+ } } ,
128+ { formatter :editIcon , width :40 , align :"center" , cellClick :function ( e , cell ) {
154129
130+ dialogClientEditForm . target = cell . getRow ( ) . getData ( ) . id ;
131+
132+ form = dialogClientEditForm . find ( "form" )
133+ form . find ( "#name" ) . val ( cell . getRow ( ) . getData ( ) . name ) ;
134+ dialogClientEditForm . dialog ( "open" ) ;
135+
136+ } } ,
137+ ] ;
138+
139+ var table = new Tabulator ( "#clients" , {
140+ ajaxURL :baseUrl ,
141+ layout :"fitColumns" ,
142+ columns :columns ,
143+ rowClick :function ( e , row ) {
144+ return false ;
145+ } ,
146+ ajaxResponse :function ( url , params , response ) {
147+
148+ return response . Clients ; //return the tableData property of a response json object
149+ } ,
150+ } ) ;
151+ }
155152 } ) ;
156153} ( ) ) ;
0 commit comments