forked from mtierltd/timetracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoals.js
More file actions
163 lines (144 loc) · 6.22 KB
/
goals.js
File metadata and controls
163 lines (144 loc) · 6.22 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
var $ = require("jquery");
require("jquery-migrate");
// var moment = require("moment");
require("jqueryui");
//require("jqueryui/jquery-ui.css");
import Tabulator from 'tabulator-tables';
require('tabulator-tables/dist/css/tabulator.css');
import 'select2/dist/js/select2.full.js'
require('select2/dist/css/select2.css');
require('../../css/style.css');
(function() {
$.ajaxSetup({
headers: { 'RequestToken': OC.requestToken }
});
$( function() {
var newGoalProjectId;
$(document).ready(function() {
$("#dialog-confirm").dialog({
autoOpen: false,
modal: true
});
});
$("#project-select").select2({
width: '200px',
escapeMarkup : function(markup) { return markup; },
placeholder: "Select project",
allowClear: true,
templateResult: function formatState (project) {
var color = '#ffffff';
if (project.color) {
color = project.color;
}
var $state = $(
'<span class="select-project"><span class="select-project-color" style="background-color:'+color+';" ></span>' + project.text + '</span>'
);
return $state;
},
ajax: {
tags: true,
url: OC.generateUrl('/apps/timetracker/ajax/projects'),
dataType: 'json',
delay: 250,
processResults: function (data, page) { //json parse
return {
results: $.map(data.Projects,function(val, i){
return { id: val.id, text:val.name, color: val.color};
}),
pagination: {
more: false,
}
};
},
cache: false,
},
});
$('#project-select').on("select2:select select2:unselect", function(e) {
newGoalProjectId = ($(e.target).val() != null)? $(e.target).val() : "";
});
$("#new-goal-submit").click(function () {
if ($("#new-goal-hours").val().trim() == '')
return false;
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/add-goal');
var jqxhr = $.post( baseUrl, {
projectId : newGoalProjectId,
hours: $("#new-goal-hours").val(),
interval: $("#new-goal-interval").val(),
}, function() {
getGoals();
})
.done(function(data, status, jqXHR) {
var response = data;
if ('Error' in response){
alert(response.Error);
}
})
.fail(function() {
alert( "error" );
})
return false;
});
getGoals();
function getGoals(){
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/goals');
var editIcon = function(cell, formatterParams){ //plain text value
return "<i class='fa fa-edit'></i>";
};
var columns = [
{title:"#", field:"", formatter:"rownum", width: 40, align: "center"},
{title:"Project", field:"projectName", widthGrow:1}, //column will be allocated 1/5 of the remaining space
{title:"Target Hours", field:"hours", widthGrow:1}, //column will be allocated 1/5 of the remaining space
{title:"Interval", field:"interval", widthGrow:1}, //column will be allocated 1/5 of the remaining space
{title:"Started At", field:"createdAt", widthGrow:1, mutator: function(value, data, type, params, component){
return new Date(data.createdAt*1000).toDateString();}
}, //column will be allocated 1/5 of the remaining space
{title:"Hours spent current interval", field:"workedHoursCurrentPeriod", widthGrow:1}, //column will be allocated 1/5 of the remaining space
{title:"Past Debt in Hours", field:"debtHours", widthGrow:1}, //column will be allocated 1/5 of the remaining space
{title:"Remaining Hours", field:"remainingHours", widthGrow:1}, //column will be allocated 1/5 of the remaining space
{title:"Total Remaining Hours", field:"totalRemainingHours", widthGrow:1}, //column will be allocated 1/5 of the remaining space
{formatter:"buttonCross", width:40, align:"center", cellClick:function(e, cell) {
$("#dialog-confirm").dialog({
buttons : {
"Confirm" : {click: function() {
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/delete-goal/'+cell.getRow().getData().id);
var jqxhr = $.post( baseUrl, function() {
getGoals();
$("#dialog-confirm").dialog("close");
})
.done(function(data, status, jqXHR) {
var response = data;
if ('Error' in response){
alert(response.Error);
}
})
.fail(function() {
alert( "error" );
})
return false;
},
text: 'Confirm',
class:'primary'
},
"Cancel" : function() {
$(this).dialog("close");
}
}
});
$("#dialog-confirm").dialog('open');
//cell.getRow().delete();
}},
];
var table = new Tabulator("#goals", {
ajaxURL:baseUrl,
layout:"fitColumns",
columns:columns,
rowClick:function(e, row){
return false;
},
ajaxResponse:function(url, params, response){
return response.Goals; //return the tableData property of a response json object
},
});
}
} );
}());