-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwishes_pages.cpp
More file actions
139 lines (106 loc) · 3.64 KB
/
wishes_pages.cpp
File metadata and controls
139 lines (106 loc) · 3.64 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
//=======================================================================
// Copyright (c) 2013-2020 Baptiste Wicht.
// Distributed under the terms of the MIT License.
// (See accompanying file LICENSE or copy at
// http://opensource.org/licenses/MIT)
//=======================================================================
#include "wishes.hpp"
#include "pages/html_writer.hpp"
#include "pages/wishes_pages.hpp"
#include "http.hpp"
using namespace budget;
namespace {
void add_importance_picker(budget::writer& w, unsigned long importance) {
w << R"=====(
<div class="form-group">
<label for="input_importance">Importance</label>
<select class="form-control" id="input_importance" name="input_importance">
)=====";
if (importance == 1) {
w << "<option selected value=\"1\">Low</option>";
} else {
w << "<option value=\"1\">Low</option>";
}
if (importance == 2) {
w << "<option selected value=\"2\">Medium</option>";
} else {
w << "<option value=\"2\">Medium</option>";
}
if (importance == 3) {
w << "<option selected value=\"3\">High</option>";
} else {
w << "<option value=\"3\">High</option>";
}
w << R"=====(
</select>
</div>
)=====";
}
void add_urgency_picker(budget::writer& w, unsigned long urgency) {
w << R"=====(
<div class="form-group">
<label for="input_urgency">Urgency</label>
<select class="form-control" id="input_urgency" name="input_urgency">
)=====";
if (urgency == 1) {
w << "<option selected value=\"1\">Low</option>";
} else {
w << "<option value=\"1\">Low</option>";
}
if (urgency == 2) {
w << "<option selected value=\"2\">Medium</option>";
} else {
w << "<option value=\"2\">Medium</option>";
}
if (urgency == 3) {
w << "<option selected value=\"3\">High</option>";
} else {
w << "<option value=\"3\">High</option>";
}
w << R"=====(
</select>
</div>
)=====";
}
} // namespace
void budget::wishes_list_page(html_writer& w) {
budget::list_wishes(w);
make_tables_sortable(w);
}
void budget::wishes_status_page(html_writer& w) {
budget::status_wishes(w);
make_tables_sortable(w);
}
void budget::wishes_estimate_page(html_writer& w) {
budget::estimate_wishes(w);
make_tables_sortable(w);
}
void budget::add_wishes_page(html_writer& w) {
w << title_begin << "New Wish" << title_end;
form_begin(w, "/api/wishes/add/", "/wishes/add/");
add_name_picker(w);
add_importance_picker(w, 2);
add_urgency_picker(w, 2);
add_amount_picker(w);
form_end(w);
}
void budget::edit_wishes_page(html_writer& w, const httplib::Request& req) {
if (!validate_parameters(w, req, {"input_id", "back_page"})) {
return;
}
auto input_id = req.get_param_value("input_id");
if (!wish_exists(budget::to_number<size_t>(input_id))) {
return display_error_message(w, "The wish {} does not exist", input_id);
}
auto back_page = req.get_param_value("back_page");
w << title_begin << "Edit wish " << input_id << title_end;
form_begin_edit(w, "/api/wishes/edit/", back_page, input_id);
auto wish = wish_get(budget::to_number<size_t>(input_id));
add_name_picker(w, wish.name);
add_importance_picker(w, wish.importance);
add_urgency_picker(w, wish.urgency);
add_amount_picker(w, budget::money_to_string(wish.amount));
add_paid_picker(w, wish.paid);
add_paid_amount_picker(w, budget::money_to_string(wish.paid_amount));
form_end(w);
}