Skip to content

Commit 1e1a62d

Browse files
committed
show tags and lients in table
1 parent ad92372 commit 1e1a62d

File tree

5 files changed

+136
-131
lines changed

5 files changed

+136
-131
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>Time Tracker</name>
66
<summary>Time Tracker App</summary>
77
<description><![CDATA[Time Tracker App]]></description>
8-
<version>0.0.24</version>
8+
<version>0.0.25</version>
99
<licence>agpl</licence>
1010
<author mail="[email protected]" >MTier Ltd.</author>
1111
<namespace>TimeTracker</namespace>

css/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,10 @@ td.ε_row {
376376
margin-left: -8px;
377377
width: 16px;
378378
height: 16px;
379+
}
380+
#tags {
381+
margin-top: 30px;
382+
}
383+
#clients {
384+
margin-top: 30px;
379385
}

js/clients.js

Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
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");
@@ -81,76 +81,73 @@
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
}());

js/tags.js

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
modal: true
1111
});
1212
});
13+
1314
$("#new-tag-submit").click(function () {
1415
if ($("#new-tag-input").val().trim() == '')
1516
return false;
@@ -61,7 +62,7 @@
6162
function editTag(dialogTagEditForm){
6263
target = dialogTagEditForm.target;
6364
form = dialogTagEditForm.find( "form" );
64-
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/edit-tag/'+target.id);
65+
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/edit-tag/'+target);
6566
var jqxhr = $.post( baseUrl, {name:form.find("#name").val()},function() {
6667
getTags();
6768
$(dialogTagEditForm).dialog("close");
@@ -78,72 +79,71 @@
7879

7980
}
8081
function getTags(){
81-
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/tags');
82-
$.getJSON( baseUrl, function( data ) {
83-
84-
var tags = [];
85-
$.each( data.Tags, function( id, tagMap ) {
86-
87-
tags.push( "<div class='tag-button'>" +
88-
"<div class='tag-name' id='tag-name-"+tagMap['id']+"'>" +
89-
tagMap['name'] +
90-
"</div>"+
91-
"<div class='controls'>"+
92-
"<span class='fas fa-edit clickable tag-edit' id='"+tagMap['id']+"' data-name='"+tagMap['name']+"'></span>"+
93-
"<span class='fas fa-times clickable tag-delete' id='"+tagMap['id']+"'></span>"+
94-
"</div>" +
95-
"</div>" );
96-
});
82+
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/tags');
9783

98-
$("#tags").html($( "<div/>", {
99-
"class": "tags-list",
100-
html: tags.join( "" )
101-
}))
102-
$('.tag-edit').click(function(e) {
103-
e.preventDefault();
104-
dialogTagEditForm.target = e.target;
105-
106-
form = dialogTagEditForm.find( "form" )
107-
form.find("#name").val($(e.target).data("name"));
108-
dialogTagEditForm.dialog("open");
109-
110-
111-
return false;
112-
})
113-
$('.tag-delete').click(function(e) {
114-
$("#dialog-confirm").dialog({
115-
buttons : {
116-
"Confirm" : {click: function() {
117-
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/delete-tag/'+e.target.id);
118-
var jqxhr = $.post( baseUrl, function() {
119-
getTags();
120-
$("#dialog-confirm").dialog("close");
121-
})
122-
.done(function(data, status, jqXHR) {
123-
var response = data;
124-
if ('Error' in response){
125-
alert(response.Error);
126-
}
127-
})
128-
.fail(function() {
129-
alert( "error" );
130-
})
131-
return false;
132-
},
133-
text: 'Confirm',
134-
class:'primary'
135-
},
136-
"Cancel" : function() {
137-
$(this).dialog("close");
138-
}
139-
}
140-
});
141-
$("#dialog-confirm").dialog("open");
142-
return false;
143-
})
84+
var editIcon = function(cell, formatterParams){ //plain text value
85+
return "<i class='fa fa-edit'></i>";
86+
};
87+
88+
89+
var columns = [
90+
{title:"#", field:"", formatter:"rownum", width: 40, align: "center"},
91+
{title:"Name", field:"name", widthGrow:1}, //column will be allocated 1/5 of the remaining space
92+
{formatter:"buttonCross", width:40, align:"center", cellClick:function(e, cell){
93+
$("#dialog-confirm").dialog({
94+
buttons : {
95+
"Confirm" : {click: function() {
96+
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/delete-tag/'+cell.getRow().getData().id);
97+
var jqxhr = $.post( baseUrl, function() {
98+
getTags();
99+
$("#dialog-confirm").dialog("close");
100+
})
101+
.done(function(data, status, jqXHR) {
102+
var response = data;
103+
if ('Error' in response){
104+
alert(response.Error);
105+
}
106+
})
107+
.fail(function() {
108+
alert( "error" );
109+
})
110+
return false;
111+
},
112+
text: 'Confirm',
113+
class:'primary'
114+
},
115+
"Cancel" : function() {
116+
$(this).dialog("close");
117+
}
118+
}
144119
});
145-
}
120+
$("#dialog-confirm").dialog('open');
121+
122+
//cell.getRow().delete();
123+
}},
124+
{formatter:editIcon, width:40, align:"center", cellClick:function(e, cell){
146125

126+
dialogTagEditForm.target = cell.getRow().getData().id;
127+
128+
form = dialogTagEditForm.find( "form" )
129+
form.find("#name").val(cell.getRow().getData().name);
130+
dialogTagEditForm.dialog("open");
147131

132+
}},
133+
];
134+
135+
var table = new Tabulator("#tags", {
136+
ajaxURL:baseUrl,
137+
layout:"fitColumns",
138+
columns:columns,
139+
rowClick:function(e, row){
140+
return false;
141+
},
142+
ajaxResponse:function(url, params, response){
143+
144+
return response.Tags; //return the tableData property of a response json object
145+
},
146+
});
147+
}
148148
} );
149149
}());

lib/Controller/AjaxController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ public function deleteClient($id) {
353353
/**
354354
*
355355
* @NoAdminRequired
356+
* @NoCSRFRequired
356357
*/
357358
public function getClients(){
358359
$clients = $this->clientMapper->findAll($this->userId);
@@ -583,6 +584,7 @@ public function deleteTag($id) {
583584
/**
584585
*
585586
* @NoAdminRequired
587+
* @NoCSRFRequired
586588
*/
587589
public function getTags(){
588590
$workItem = $this->request->workItem;

0 commit comments

Comments
 (0)