-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinit.js
More file actions
111 lines (97 loc) · 3.5 KB
/
Copy pathinit.js
File metadata and controls
111 lines (97 loc) · 3.5 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
// from https://stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript
function dateDiffInDays(a, b) {
var _MS_PER_DAY = 1000 * 60 * 60 * 24;
// Discard the time and time-zone information.
var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
return Math.floor((utc2 - utc1) / _MS_PER_DAY);
}
// from http://stackoverflow.com/a/19691491
function addDays(date, days) {
var result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
// when the start date is changed, move the due date by the same number of days
// (or, if fillEmptyDue is set and no due date is set yet, set it to the start date)
function shiftDueWithStart(startSel, dueSel, fillEmptyDue) {
$(startSel).on('change', function() {
var oldVal = parseDay($(startSel).data('oldVal'));
var newVal = parseDay($(startSel).val());
var curDue = parseDay($(dueSel).val());
if (curDue == null) {
if (fillEmptyDue) {
$(dueSel).val($(startSel).val());
}
} else if (oldVal != null && newVal != null) {
$(dueSel).val(formatDate(addDays(curDue, dateDiffInDays(oldVal, newVal))));
}
$(startSel).data('oldVal', $(startSel).val());
});
}
var tagList;
$(document).ready(function() {
$.ajaxSetup({
cache: false,
// required by the server for all modifying requests:
headers: { 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content') }
});
// no inline event handlers, they are blocked by the Content-Security-Policy
$('#inputform, #modifyform').on('submit', function(e) {
e.preventDefault();
});
$('#enter_save').on('click', enter);
$('#emptyTrash').on('click', function(e) {
e.preventDefault();
emptyTrash();
});
$('#showLog').on('click', function(e) {
e.preventDefault();
toggleLog();
});
$("#smallLog").on('click', function() {
updateLog('#log_dialog', logItems.length);
$('#log_dialog').append('<br />',
$('<a href="#"></a>').text($T('LOG_ONOFF')).on('click', function(e) {
e.preventDefault();
toggleLog();
}));
$('#log_dialog').dialog({
modal: true,
minHeight: 150,
width: dialogWidth(600),
maxWidth: 600,
title: 'Log'
});
});
$('#loadMoreCompleted').on('click', function(e) {
e.preventDefault();
reloadData.age += 10;
reload();
});
$('#loadLessCompleted').on('click', function(e) {
e.preventDefault();
reloadData.age -= 10;
if (reloadData.age < 0)
{
reloadData.age = 0;
}
reload();
});
$('#loadIncomplete').on('click', function(e) {
e.preventDefault();
reloadData.incomplete = !reloadData.incomplete;
$('#loadIncomplete').text(reloadData.incomplete?$T('LOAD_INCOMPLETE_HIDE'):$T('LOAD_INCOMPLETE'));
reload();
});
new Tagify($('#modify_tag_edit')[0]);
shiftDueWithStart('#modify_start', '#modify_due', false);
shiftDueWithStart('#enter_start', '#enter_due', true);
$('#filter .tagify__input').on('focus', function() {
let tagStrs = tagList.map( (x) => x.name );
$('#filter_tag_edit')[0].__tagify.settings.whitelist = tagStrs;
});
$('#refresh').on('click', refresh);
reloadTagList();
refresh();
});