1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Working on the time tracker

This commit is contained in:
Hillel Coren 2017-10-01 09:55:45 +03:00
parent 6a66000db7
commit 30668086e2
2 changed files with 40 additions and 9 deletions

View File

@ -220,7 +220,8 @@
<tr data-bindx="event: { mouseover: showActions, mouseout: hideActions }"> <tr data-bindx="event: { mouseover: showActions, mouseout: hideActions }">
<td style="padding: 0 6px 10px 0"> <td style="padding: 0 6px 10px 0">
{!! Former::text('date') {!! Former::text('date')
->data_bindx("") ->data_bind("datepicker: startDate, valueUpdate: 'afterkeydown'")
->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))
->raw() !!} ->raw() !!}
</td> </td>
<td style="padding: 0 6px 10px 6px"> <td style="padding: 0 6px 10px 6px">
@ -376,7 +377,6 @@
var tasks = {!! $tasks !!}; var tasks = {!! $tasks !!};
var clients = {!! $clients !!}; var clients = {!! $clients !!};
var projects = {!! $projects !!}; var projects = {!! $projects !!};
var dateTimeFormat = '{{ $account->getMomentDateTimeFormat() }}';
var timezone = '{{ $account->getTimezone() }}'; var timezone = '{{ $account->getTimezone() }}';
var clientMap = {}; var clientMap = {};

View File

@ -20,6 +20,22 @@
return new Date(1970, 0, 1, hours, minutes, seconds, 0); return new Date(1970, 0, 1, hours, minutes, seconds, 0);
} }
ko.bindingHandlers.datepicker = {
init: function (element, valueAccessor, allBindingsAccessor) {
$(element).datepicker();
$(element).change(function() {
var value = valueAccessor();
value($(element).datepicker('getDate'));
})
},
update: function (element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
if (value) {
$(element).datepicker('setDate', new Date(value * 1000));
}
}
};
ko.bindingHandlers.timepicker = { ko.bindingHandlers.timepicker = {
init: function (element, valueAccessor, allBindingsAccessor) { init: function (element, valueAccessor, allBindingsAccessor) {
var options = allBindingsAccessor().timepickerOptions || {}; var options = allBindingsAccessor().timepickerOptions || {};
@ -32,9 +48,15 @@
ko.utils.registerEventHandler(element, 'change', function () { ko.utils.registerEventHandler(element, 'change', function () {
var value = valueAccessor(); var value = valueAccessor();
var dateTime = $(element).timepicker('getTime'); var field = $(element).attr('name');
if (dateTime) { var time = 0;
time = dateTime.getTime() / 1000; if (field == 'duration') {
time = $(element).timepicker('getSecondsFromMidnight');
} else {
var dateTime = $(element).timepicker('getTime');
if (dateTime) {
time = dateTime.getTime() / 1000;
}
} }
value(time); value(time);
}); });
@ -46,7 +68,9 @@
if (field == 'duration') { if (field == 'duration') {
$(element).timepicker('setTime', intToTime(value)); $(element).timepicker('setTime', intToTime(value));
} else { } else {
$(element).timepicker('setTime', new Date(value * 1000)); if (value) {
$(element).timepicker('setTime', new Date(value * 1000));
}
} }
//console.log(field + ': ' + value); //console.log(field + ': ' + value);
@ -948,6 +972,15 @@
self.endTime(data[1]); self.endTime(data[1]);
}; };
self.startDate = ko.computed({
read: function () {
return self.startTime();
},
write: function(value) {
console.log('New Date: ' + value);
}
});
self.order = ko.computed(function() { self.order = ko.computed(function() {
return self.startTime(); return self.startTime();
}); });
@ -969,12 +1002,10 @@
read: function () { read: function () {
model.clock(); // bind to the clock model.clock(); // bind to the clock
var endTime = self.endTime() ? self.endTime() : moment().unix(); var endTime = self.endTime() ? self.endTime() : moment().unix();
//console.log('duration: ' + (endTime - self.startTime()));
return endTime - self.startTime(); return endTime - self.startTime();
}, },
write: function(value) { write: function(value) {
console.log('duration: ' + value); self.endTime(self.startTime() + value);
//self.endTime(value);
} }
}); });