timekeeper

[Abandoned unfinished] CGI web application in C for time tracking. (My first, just a learning project)
Log | Files | Refs | README

commit ce568ee3b4bbbf1ef07ea1ac2d5f005fa2a46295
parent 8afbecf74dd0dbe552b25bb983b9029df4e95a77
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Tue, 12 Mar 2024 20:22:49 -0700

Move main page export form to a function

Also move it to the top of the page again.

Diffstat:
Mpages/main.c | 43+++++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/pages/main.c b/pages/main.c @@ -297,6 +297,29 @@ gettf(char *tfs) } enum kcgi_err +exportform(struct pagedata *pd) +{ + enum kcgi_err status; + + if ((status = khtml_attr(&pd->html, KELEM_FORM, + KATTR_ACTION, pd->pages[PageExport], KATTR__MAX)) != KCGI_OK || + (status = khtml_elem(&pd->html, KELEM_LABEL)) != KCGI_OK || + (status = khtml_putc(&pd->html, ' ')) != KCGI_OK || + (status = khtml_attr(&pd->html, KELEM_INPUT, + KATTR_TYPE, "submit", + KATTR_VALUE, "Export", KATTR__MAX)) != KCGI_OK || + (status = khtml_attr(&pd->html, KELEM_INPUT, + KATTR_TYPE, "checkbox", + KATTR_NAME, keys[KeyFormat].name, + KATTR_VALUE, ".epoch", KATTR__MAX)) != KCGI_OK || + (status = khtml_puts(&pd->html, "Epoch times")) != KCGI_OK || + (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK || + (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK) + return status; + return KCGI_OK; +} + +enum kcgi_err pagemain(struct pagedata *pd) { static char *css[] = { "css/main.css", "css/timesheet.css", NULL }; @@ -345,28 +368,12 @@ pagemain(struct pagedata *pd) } if ((status = htmlwithin(pd, KELEM_H1, "Timekeeper")) != KCGI_OK || - (status = printtimes(pd, times)) != KCGI_OK || - (status = htmlscript(pd, "scripts/counter.js")) != KCGI_OK || - (status = htmlscript(pd, "scripts/localize.js")) != KCGI_OK) { + (status = exportform(pd)) != KCGI_OK || + (status = printtimes(pd, times)) != KCGI_OK) { freetimesheet(times); return status; } freetimesheet(times); - if ((status = htmlwithin(pd, KELEM_H2, "Export")) != KCGI_OK || - (status = khtml_attr(&pd->html, KELEM_FORM, - KATTR_ACTION, pd->pages[PageExport], KATTR__MAX)) != KCGI_OK || - (status = khtml_attr(&pd->html, KELEM_INPUT, - KATTR_TYPE, "checkbox", - KATTR_NAME, keys[KeyFormat].name, - KATTR_VALUE, ".epoch", KATTR__MAX)) != KCGI_OK || - (status = khtml_puts(&pd->html, " Use UNIX epoch times")) != KCGI_OK || - (status = khtml_elem(&pd->html, KELEM_BR)) != KCGI_OK || - (status = khtml_attr(&pd->html, KELEM_INPUT, - KATTR_TYPE, "submit", - KATTR_VALUE, "Export", KATTR__MAX)) != KCGI_OK || - (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK) - return status; - return endpage(pd, &template); }