-
Notifications
You must be signed in to change notification settings - Fork 3
/
todo-mobile.js
174 lines (165 loc) · 6.05 KB
/
todo-mobile.js
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
164
165
166
167
168
169
170
171
172
173
174
/*
$(document).on("pagebeforeshow", '#modifyPage', function(e, data) {
alert(JSON.stringify(data).replace(/,/g,"\n").replace(/[{}\"]/g, ""));
return true;
});
*/
function clearTable()
{
$('#todoTable').empty();
}
function showDetails(itemid)
{
$.mobile.changePage('#modifyPage', { transition: "slide" });
fillModifyForm(itemid);
$('#modify_recurrenceMode').selectmenu("refresh", true);
$('#modify_recurrenceAnchor').selectmenu("refresh", true);
toggleRecurrenceAnchor();
}
function newTodo()
{
$.mobile.changePage('#modifyPage', { transition: "slide" });
fillModifyForm(-1);
$('#modify_recurrenceMode').selectmenu("refresh", true);
$('#modify_recurrenceAnchor').selectmenu("refresh", true);
toggleRecurrenceAnchor();
}
function renderItem(it, lineNr) {
var hasNote = it.notes != null && it.notes != '';
var hasTags = it.tags != null && it.tags != '';
var isRecurring = it.recurrenceMode != 0;
var today = new Date();
var dueDate = parseDate(it.due);
var complDate = parseDate(it.completionDate);
var createDate = parseDate(it.creationDate);
var dueString = (it.completed == 0) ? formatDate(dueDate): formatDate(complDate);
var repetition = getRecurrenceString(it.recurrenceMode);
var line = '<div class="line'+
((lineNr%2!=0)?' line_odd':'')+
((it.completed==1)?' todo_completed':'')+
((it.deleted==1)?' todo_deleted':'')+
'" id="todo'+it.id+'">';
line += '<span class="todo_lineNr">'+(lineNr+1)+'.</span>'+
'<span class="todo" title="'+$T('CREATED')+': '+formatDate(createDate, true)+
'; '+$T('RECURRENCE')+': '+repetition+
((it.completed != 0)? '; '+$T('DONE')+': '+formatDate(complDate, true):'')+
'"><span class="todotitleonly">'+ it.todo+'</span>'+
(hasNote ? '<span class="note" title="'+it.notes+'"></span>':'')+
(isRecurring ? '<input type="button" class="reactivate" id="reactivate'+it.id+'" />':'')+
((it.completed==0 && dueDate != null && (today - dueDate) > 0) ?
' <span class="exclamation"></span>':'');
if (hasTags) {
line += ' <ul id="todo_tags_'+it.id+'" class="todo_item_tags">';
tags = it.tags.split(",");
for (var i=0; i<tags.length; i++) {
line += '<li>'+tags[i]+'</li>';
}
line += '</ul>';
}
line += '</div>';
$('#todoTable').append(line);
$('#todo_tags_'+it.id).tagit({readOnly: true});
$('#todo'+it.id).on('dblclick', function() {
printItem(it);
});
$('#todo'+it.id).on('click', function() {
showDetails(it.id);
});
if (it.id != -1) {
setListener(it.id);
}
}
function toggleButtons(deleted) {
$('#toggleBtn').closest('.ui-btn').show();
if (deleted) {
$('#restoreBtn').closest('.ui-btn').show();
$('#deleteBtn').closest('.ui-btn').hide();
} else {
$('#restoreBtn').closest('.ui-btn').hide();
$('#deleteBtn').closest('.ui-btn').show();
}
}
$(document).ready(function() {
$('#newBtn').on('click', function() {
emptyModifyForm();
$.mobile.changePage('#modifyPage', { transition: "slide" });
});
$('#refreshBtn').on('click', function() {
refresh();
});
$('#emptyTrashBtn').on('click', function() {
emptyTrash();
});
$('#showLogBtn').on('click', function() {
updateLog('#logtext', logItems.length);
$.mobile.changePage('#logPage', { transition: "slide" });
});
$('#statisticsBtn').on('click', function() {
window.location = 'https://todo.bfroehler.info/statistik.php';
});
// Fix bug resulting from combination of tag-it and jquery-mobile:
// https://github.com/aehlke/tag-it/issues/274
$('#modifyPage').on('pageshow', function(event) {
$('ul#modify_tag_edit li li').unwrap();
$('ul#modify_tag_edit div input').unwrap().wrap('<li />');
var id = parseInt($('#modify_id').val());
var index = findItem(id);
if (id == -1 || index == -1) {
$('#restoreBtn').closest('.ui-btn').hide();
$('#deleteBtn').closest('.ui-btn').hide();
$('#toggleBtn').closest('.ui-btn').hide();
} else {
toggleButtons(itemList[index].deleted == 1);
}
});
$('#restoreBtn').on('click', function() {
var id = parseInt($('#modify_id').val());
restoreItem(id);
$.mobile.changePage('#listPage', { transition: "slide" });
});
$('#toggleBtn').on('click', function() {
var id = parseInt($('#modify_id').val());
var index = findItem(id);
toggleCompleted(id);
$.mobile.changePage('#listPage', { transition: "slide" });
});
$('#deleteBtn').on('click', function() {
var id = parseInt($('#modify_id').val());
trashItem(id);
$.mobile.changePage('#listPage', { transition: "slide" });
});
$('#cancelBtn,#backBtn').on('click', function() {
$.mobile.changePage('#listPage', { transition: "slide" });
});
$('#saveBtn').on('click', function() {
var id = parseInt($('#modify_id').val());
if (id == -1)
{
var stuff = new Todo(-1,
$('#modify_todo').val(),
$('#modify_due').val(),
$('#modify_start').val(),
$('#modify_effort').val(),
0, // currently not taken into account on server, and not modifiable at server
$('#modify_notes').val().trim(),
$('#modify_tags').val(),
0, // deleted items cannot be modified
1, // version
$('#modify_recurrenceMode').val(),
$('#modify_recurenceAnchor').val(),
null,
formatDate(getUTCDate(), true)
);
addItem(stuff);
} else {
storeItem();
}
$.mobile.changePage('#listPage', { transition: "slide" });
});
$('#modify_recurrenceMode').on('change', function(e) {
toggleRecurrenceAnchor();
});
});
function fillTagList(choices)
{
}