-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.pl
More file actions
executable file
·150 lines (132 loc) · 3.22 KB
/
tasks.pl
File metadata and controls
executable file
·150 lines (132 loc) · 3.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
#!/usr/bin/perl
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use strict;
use warnings;
use TaskDBDriver;
use FileHandle;
my $task_file = $ENV{'HOME'} . "/.tasks";
my $q = new CGI;
print $q->header;
if ($q->param('q') eq 'edit') {
show_tasks_form($q);
} elsif ($q->param('q') eq 'Save') {
my $th = new FileHandle ('>' . $task_file);
if (defined $th) {
print $th $q->param('tasks_text');
$th->close;
} else {
print "ERROR: Could not open $task_file to write: $!";
}
show_tasks($q);
} else {
show_tasks($q);
}
# ---------------
# Functions
# ---------------
sub show_tasks {
my $q = shift;
my $tasks_db = new TaskDBDriver ($task_file);
print $q->start_html( -title => 'Tasks',
-script => { -code => page_script() },
-style => { -code => page_style() } ),
$q->start_div( {-id => "wrapper"} ),
$q->h1('Tasks'),
$q->a({-href => $q->url . "?q=edit", -style => 'text-align: center'}, "Edit"),
" | ",
$q->a({-href => "javascript:toggle_completed();", -style => 'text-align: center'}, "Toggle completed"),
$tasks_db->write_db_markup(),
$q->end_html;
}
sub show_tasks_form {
my $q = shift;
my $tasks_db = new TaskDBDriver ($task_file);
print $q->start_html( -title => 'Tasks',
-style => { -code => page_style() } ),
$q->start_div( {-id => "wrapper"} ),
$q->h1('Tasks'),
$q->start_form (-action => $q->url(),
-method => 'POST'),
$q->textarea (-name => 'tasks_text',
-default => $tasks_db->write_db_text(),
-rows => 15,
-columns => 100),
$q->br,
$q->submit (-name => 'q',
-value => 'Save'),
$q->reset(),
$q->a({-href => $q->url, -style => 'text-align: center'}, "Cancel"),
$q->end_form,
$q->end_html;
}
sub page_style {
return qq {
body {
font-family : "Trebuchet MS", sans-serif;
font-size : small;
background-color : white;
}
h1 {
border-bottom : 2px solid #cccccc;
text-align : right;
color : #888888;
font-size : xx-large;
}
#wrapper {
display : table;
margin : 0 auto;
padding : 10px 10px 10px 10px;
width : 700px;
}
.task_db {
padding-top : 7px;
padding-bottom : 7px;
}
.section {
border : thin solid #cccccc;
padding : 0px 0px 0px 0px;
margin-bottom : 10px;
}
.section h2 {
padding : 2px 2px 2px 2px;
margin : 0;
background-color : #cccccc;
}
.section .section_desc {
border : thin solid #eeeeee;
padding : 3px 3px 3px 3px;
}
.section ul {
margin : 3px 3px 3px 3px;
}
li.task_item, li.task_item_done {
line-height : 2em;
}
li.task_item_done {
color : #aaaaaa;
}
.task_tag {
padding : 1px 1px 1px 1px;
}
li.task_item .task_tag {
border : thin solid #aaaaff;
background-color : #aaaaff;
}
li.task_item_done .task_tag {
color : #aaaaaa;
border : thin solid #eeeeee;
background-color : #eeeeee;
}
};
}
sub page_script {
return qq {
function toggle_completed () {
var done_tasks = document.getElementsByClassName ('task_item_done');
for each (var task in done_tasks) {
task.style.display = (task.style.display == 'none') ? 'list-item' : 'none';
}
}
};
}