commit 4421a6d229ef441ce89fdd46f2792f0404bd6cd6
parent 4855d21a1d1f5184899fa4543246dde9341a8bb4
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Mon, 11 Mar 2024 18:10:02 -0700
Fix counter HTML generation
- Close elements at more appropriate times
- Set the counter ID when needed
Diffstat:
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/pages/main.c b/pages/main.c
@@ -55,7 +55,7 @@ printhours(struct pagedata *pd, struct timesheet *ts)
final = (ts->set & EndTimeFlag ||
(ts->set & BreakStartTimeFlag && !(ts->set & BreakEndTimeFlag)));
- if (final)
+ if (!final)
status = khtml_attr(&pd->html, KELEM_TIME,
KATTR_ID, "counter", KATTR_DATETIME, datetime, KATTR__MAX);
else
@@ -64,22 +64,25 @@ printhours(struct pagedata *pd, struct timesheet *ts)
if (status)
return status;
- if ((status = khtml_printf(&pd->html, "%.2lld:%.2lld:%.2lld", hr, mn, sc)) != KCGI_OK)
+ if ((status =
+ khtml_printf(&pd->html, "%.2lld:%.2lld:%.2lld", hr, mn, sc)) != KCGI_OK ||
+ (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK)
return status;
if (!final) {
- if ((status = khtml_elem(&pd->html, KELEM_NOSCRIPT)) != KCGI_OK ||
+ if ((status = khtml_attr(&pd->html, KELEM_SCRIPT,
+ KATTR_SRC, "scripts/counter.js", KATTR__MAX)) != KCGI_OK ||
+ (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK ||
+ (status = khtml_elem(&pd->html, KELEM_NOSCRIPT)) != KCGI_OK ||
(status = khtml_attr(&pd->html, KELEM_A,
KATTR_HREF, pd->pages[PageMain], KATTR__MAX)) != KCGI_OK ||
(status = khtml_putc(&pd->html, ' ')) != KCGI_OK ||
(status = htmlwithin(pd, KELEM_BUTTON, "Reload")) != KCGI_OK ||
- (status = khtml_attr(&pd->html, KELEM_SCRIPT,
- KATTR_SRC, "scripts/counter.js", KATTR__MAX)) != KCGI_OK ||
- (status = khtml_closeelem(&pd->html, 3)) != KCGI_OK)
+ (status = khtml_closeelem(&pd->html, 2)) != KCGI_OK)
return status;
}
- return khtml_closeelem(&pd->html, 1);
+ return KCGI_OK;
}
enum kcgi_err