Skip to content

Commit 4ca39ba

Browse files
author
Harm Akkerman
committed
Use enter to create a new timeline entry
1 parent 63ccf40 commit 4ca39ba

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

js/src/timer.js

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ require('../../css/style.css');
1313
var dtf = require("./dateformat.js");
1414

1515
(
16-
16+
1717

1818
function() {
19-
19+
2020
$.ajaxSetup({
2121
headers: { 'RequestToken': OC.requestToken }
2222
});
@@ -25,6 +25,10 @@ function() {
2525

2626

2727
$( function() {
28+
$('#work-input-form').on('submit', function(e) {
29+
e.preventDefault();
30+
createWorkItem();
31+
});
2832
var days='30';
2933
var start = moment().startOf('day').subtract(29, 'days');
3034
var end = moment().endOf('day');
@@ -70,7 +74,7 @@ function() {
7074
'`': '`',
7175
'=': '='
7276
};
73-
77+
7478
function escapeHtml (string) {
7579
return String(string).replace(/[&<>"'`=\/]/g, function (s) {
7680
return entityMap[s];
@@ -116,10 +120,10 @@ function() {
116120

117121
validateManualEntryFields();
118122
});
119-
123+
120124
$("#dialog-manual-entry").dialog({
121125
autoOpen: false,
122-
buttons :
126+
buttons :
123127
[ {
124128
id: 'confirm-button',
125129
text: "Confirm",
@@ -183,7 +187,7 @@ function() {
183187
alert( "error" );
184188
})
185189
.always(function() {
186-
190+
187191
});
188192

189193
}
@@ -223,7 +227,7 @@ function() {
223227
//contentType: "application/json; charset=utf-8"
224228
});
225229
$.getJSON( baseUrl, function( data ) {
226-
230+
227231
if (data.running.length > 0){
228232
localStorage.setItem('isTimerStarted', true);
229233
localStorage.setItem('timerStartTime', data.running[0].start);
@@ -246,15 +250,15 @@ function() {
246250
$('#timer').html(secondsToTimer(0));
247251
$('#start-tracking > span').addClass("play-button").removeClass("stop-button");
248252
}
249-
253+
250254

251255
var days = [];
252256
$.each( data.days, function( dayName, dayMap ) {
253-
257+
254258
var dayItems = [];
255259
$.each(dayMap, function (dayItemName, workItem){
256260
var children = [];
257-
261+
258262
$.each(workItem.children, function (ckey, child){
259263
children.push(
260264
"<li>"+
@@ -302,8 +306,8 @@ function() {
302306
days.push( "<div class='day-work-intervals'>"+
303307
"<ul>"+
304308
"<li class='day-list-item'>" +
305-
"<div class='day-name'>" + dayName +"</div>"+
306-
dayItems.join("") +
309+
"<div class='day-name'>" + dayName +"</div>"+
310+
dayItems.join("") +
307311
"</li>"+
308312
"</ul>"+
309313
"</div>" );
@@ -348,7 +352,7 @@ function() {
348352
$('.wi-child-name').click(function(e) {
349353
e.preventDefault();
350354
dialogWorkItemEditForm.target = e.target;
351-
355+
352356
var form = dialogWorkItemEditForm.find( "form" )
353357
form.find("#name").val($(e.target).data("name"));
354358
form.find("#details").val($(e.target).data("details"));
@@ -358,9 +362,7 @@ function() {
358362
})
359363
$('.wi-play').click(function(e) {
360364
e.preventDefault();
361-
$('#work-input').val($(this).data('work-name'));
362-
startTimer($(this).data('projectid'), $(this).data('tagids'));
363-
return false;
365+
createWorkItem();
364366
})
365367
$('.wi-trash').click(function(e) {
366368
$("#dialog-confirm").dialog({
@@ -425,11 +427,11 @@ function() {
425427
},
426428
ajax: {
427429
url: projectsAjaxUrl,
428-
430+
429431
dataType: 'json',
430432
delay: 250,
431433
processResults: function (data) { //json parse
432-
return {
434+
return {
433435
results: $.map(data.Projects,function(val, i){
434436
return { id: val.id, text:val.name, color: val.color};
435437
}),
@@ -439,35 +441,35 @@ function() {
439441
};
440442
},
441443
cache: false,
442-
444+
443445
},
444446
});
445447
$(this).data('myid',id);
446-
448+
447449
$(this).val(projectId).trigger('change');
448450
//clearInterval(interval);
449451
//}.bind(this),0);
450452
});
451-
453+
452454
var tagsAjaxUrl = OC.generateUrl('/apps/timetracker/ajax/tags');
453455
$(".set-tag").each(function(){
454456
//var interval = setInterval( function() {
455-
457+
456458

457459
$(this).select2({
458460
tags: true,
459461
containerCssClass:'tags-select',
460462
placeholder: "Select tags...",
461463
allowClear: true,
462-
463-
ajax: {
464+
465+
ajax: {
464466
url: function () { return tagsAjaxUrl+'?workItem='+$(this).data('myid');},
465467
data: function (params){
466468
var query = {
467469
q: params.term,
468470
type: 'public'
469471
}
470-
472+
471473
// Query parameters will be ?search=[term]&type=public
472474
return query;
473475
},
@@ -478,7 +480,7 @@ function() {
478480
dataType: 'json',
479481
delay: 250,
480482
processResults: function (data) { //json parse
481-
return {
483+
return {
482484
results: $.map(data.Tags,function(val, i){
483485
return { id: val.id, text:val.name};
484486
}),
@@ -501,8 +503,8 @@ function() {
501503
var myid = $(e.target).data('myid');
502504
var selectedId = $(e.target).val();
503505
var jqxhr = $.post( "ajax/update-work-interval/"+myid,{projectId:selectedId}, function() {
504-
505-
506+
507+
506508
})
507509
.done(function(data, status, jqXHR) {
508510
var response = data;
@@ -524,7 +526,7 @@ function() {
524526
}, 0);
525527
});
526528

527-
$(".set-tag").on("change", function (e) {
529+
$(".set-tag").on("change", function (e) {
528530
var myid = $(e.target).data('myid');
529531
var selectedTag = $(e.target).val();
530532
var jqxhr = $.post( "ajax/update-work-interval/"+myid,{tagId:selectedTag.join(",")}, function() {
@@ -553,6 +555,12 @@ function() {
553555
});
554556
}
555557

558+
function createWorkItem() {
559+
$('#work-input').val($(this).data('work-name'));
560+
startTimer($(this).data('projectid'), $(this).data('tagids'));
561+
return false;
562+
}
563+
556564
function startTimer(projectId = null, tags = ""){
557565
if(localStorage.getItem('isTimerStarted') === 'true'){
558566
stopTimer(startTimer, [projectId, tags]);
@@ -579,10 +587,10 @@ function() {
579587
}).always(function() {
580588
getWorkItems();
581589
});
582-
590+
583591
}
584592
function stopTimer(onStopped = null, args = []){
585-
593+
586594
var workName = $('#work-input').val();
587595
if (workName == ''){
588596
workName = 'no description';
@@ -608,15 +616,15 @@ function() {
608616
alert( "error" );
609617
})
610618
.always(function() {
611-
619+
612620
});
613621
}
614622

615623

616624

617625
$( "#datepicker-from" ).datepicker();
618626
$( "#datepicker-to" ).datepicker();
619-
627+
620628
if(localStorage.getItem('isTimerStarted') === 'true'){
621629
$('#start-tracking > span').addClass("stop-button").removeClass("play-button");
622630
} else {
@@ -631,5 +639,5 @@ function() {
631639
return false;
632640
});
633641
} );
634-
642+
635643
}());

templates/content/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div id="timetracker-content">
22
<div id="top-work-bar">
33
<div id="work-input-container">
4-
<form>
4+
<form id="work-input-form">
55
<input tabindex="1" type="text" spellcheck="false" autocomplete="off" class="" value="" placeholder="What have you done?" id="work-input">
66
</form>
77
</div>
@@ -66,4 +66,4 @@
6666
<div class="clearfix"> </div>
6767
<div id="work-intervals">
6868
</div>
69-
</div>
69+
</div>

0 commit comments

Comments
 (0)