diff options
| author | 2023-11-28 09:29:54 +0100 | |
|---|---|---|
| committer | 2023-11-28 09:29:54 +0100 | |
| commit | 5d3b22bfcef0fe4ff7e9ba1bbfce2a421c10528c (patch) | |
| tree | efad47e43be8942e60f698b9b571a0011c1e9699 | |
| parent | More html_entry() refactoring. (diff) | |
| download | snac2-5d3b22bfcef0fe4ff7e9ba1bbfce2a421c10528c.tar.gz snac2-5d3b22bfcef0fe4ff7e9ba1bbfce2a421c10528c.tar.xz snac2-5d3b22bfcef0fe4ff7e9ba1bbfce2a421c10528c.zip | |
Refactored to xs_html the poll part of html_entry().
| -rw-r--r-- | html.c | 83 |
1 files changed, 53 insertions, 30 deletions
| @@ -1512,54 +1512,77 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 1512 | 1512 | ||
| 1513 | if (closed || user == NULL) { | 1513 | if (closed || user == NULL) { |
| 1514 | /* closed poll */ | 1514 | /* closed poll */ |
| 1515 | c = xs_str_cat(c, "<table class=\"snac-poll-result\">\n"); | 1515 | xs_html *poll_result = xs_html_tag("table", |
| 1516 | xs_html_attr("class", "snac-poll-result")); | ||
| 1516 | 1517 | ||
| 1517 | while (xs_list_iter(&p, &v)) { | 1518 | while (xs_list_iter(&p, &v)) { |
| 1518 | const char *name = xs_dict_get(v, "name"); | 1519 | char *name = xs_dict_get(v, "name"); |
| 1519 | const xs_dict *replies = xs_dict_get(v, "replies"); | 1520 | xs_dict *replies = xs_dict_get(v, "replies"); |
| 1520 | 1521 | ||
| 1521 | if (name && replies) { | 1522 | if (name && replies) { |
| 1522 | int nr = xs_number_get(xs_dict_get(replies, "totalItems")); | 1523 | char *ti = (char *)xs_number_str(xs_dict_get(replies, "totalItems")); |
| 1523 | xs *es1 = encode_html(name); | 1524 | |
| 1524 | xs *l = xs_fmt("<tr><td>%s:</td><td>%d</td></tr>\n", es1, nr); | 1525 | xs_html_add(poll_result, |
| 1525 | 1526 | xs_html_tag("tr", | |
| 1526 | c = xs_str_cat(c, l); | 1527 | xs_html_tag("td", |
| 1528 | xs_html_text(name), | ||
| 1529 | xs_html_text(":")), | ||
| 1530 | xs_html_tag("td", | ||
| 1531 | xs_html_text(ti)))); | ||
| 1527 | } | 1532 | } |
| 1528 | } | 1533 | } |
| 1529 | 1534 | ||
| 1530 | c = xs_str_cat(c, "</table>\n"); | 1535 | xs *s1 = xs_html_render(poll_result); |
| 1536 | c = xs_str_cat(c, s1); | ||
| 1531 | } | 1537 | } |
| 1532 | else { | 1538 | else { |
| 1533 | /* poll still active */ | 1539 | /* poll still active */ |
| 1534 | xs *s1 = xs_fmt("<div class=\"snac-poll-form\">\n" | 1540 | xs *vote_action = xs_fmt("%s/admin/vote", user->actor); |
| 1535 | "<form autocomplete=\"off\" " | 1541 | xs_html *form; |
| 1536 | "method=\"post\" action=\"%s/admin/vote\">\n" | 1542 | xs_html *poll = xs_html_tag("div", |
| 1537 | "<input type=\"hidden\" name=\"actor\" value= \"%s\">\n" | 1543 | xs_html_attr("class", "snac-poll-form"), |
| 1538 | "<input type=\"hidden\" name=\"irt\" value=\"%s\">\n", | 1544 | form = xs_html_tag("form", |
| 1539 | user->actor, actor, id); | 1545 | xs_html_attr("autocomplete", "off"), |
| 1546 | xs_html_attr("method", "post"), | ||
| 1547 | xs_html_attr("action", vote_action), | ||
| 1548 | xs_html_sctag("input", | ||
| 1549 | xs_html_attr("type", "hidden"), | ||
| 1550 | xs_html_attr("name", "actor"), | ||
| 1551 | xs_html_attr("value", actor)), | ||
| 1552 | xs_html_sctag("input", | ||
| 1553 | xs_html_attr("type", "hidden"), | ||
| 1554 | xs_html_attr("name", "irt"), | ||
| 1555 | xs_html_attr("value", id)))); | ||
| 1540 | 1556 | ||
| 1541 | while (xs_list_iter(&p, &v)) { | 1557 | while (xs_list_iter(&p, &v)) { |
| 1542 | const char *name = xs_dict_get(v, "name"); | 1558 | char *name = xs_dict_get(v, "name"); |
| 1543 | const xs_dict *replies = xs_dict_get(v, "replies"); | 1559 | xs_dict *replies = xs_dict_get(v, "replies"); |
| 1544 | 1560 | ||
| 1545 | if (name) { | 1561 | if (name) { |
| 1546 | int nr = xs_number_get(xs_dict_get(replies, "totalItems")); | 1562 | char *ti = (char *)xs_number_str(xs_dict_get(replies, "totalItems")); |
| 1547 | xs *es1 = encode_html(name); | 1563 | |
| 1548 | xs *opt = xs_fmt("<input type=\"%s\"" | 1564 | xs_html_add(form, |
| 1549 | " id=\"%s\" value=\"%s\"" | 1565 | xs_html_sctag("input", |
| 1550 | " name=\"question\"> <span title=\"%d\">%s</span><br>\n", | 1566 | xs_html_attr("type", !xs_is_null(oo) ? "radio" : "checkbox"), |
| 1551 | !xs_is_null(oo) ? "radio" : "checkbox", | 1567 | xs_html_attr("id", name), |
| 1552 | es1, es1, nr, es1); | 1568 | xs_html_attr("value", name), |
| 1553 | 1569 | xs_html_attr("name", "question")), | |
| 1554 | s1 = xs_str_cat(s1, opt); | 1570 | xs_html_text(" "), |
| 1571 | xs_html_tag("span", | ||
| 1572 | xs_html_attr("title", ti), | ||
| 1573 | xs_html_text(name)), | ||
| 1574 | xs_html_sctag("br", NULL)); | ||
| 1555 | } | 1575 | } |
| 1556 | } | 1576 | } |
| 1557 | 1577 | ||
| 1558 | xs *s2 = xs_fmt("<p><input type=\"submit\" " | 1578 | xs_html_add(form, |
| 1559 | "class=\"button\" value=\"%s\">\n</form>\n</div>\n\n", L("Vote")); | 1579 | xs_html_tag("p", NULL), |
| 1560 | 1580 | xs_html_sctag("input", | |
| 1561 | s1 = xs_str_cat(s1, s2); | 1581 | xs_html_attr("type", "submit"), |
| 1582 | xs_html_attr("class", "button"), | ||
| 1583 | xs_html_attr("value", L("Vote")))); | ||
| 1562 | 1584 | ||
| 1585 | xs *s1 = xs_html_render(poll); | ||
| 1563 | c = xs_str_cat(c, s1); | 1586 | c = xs_str_cat(c, s1); |
| 1564 | } | 1587 | } |
| 1565 | 1588 | ||