diff --git a/ajaxui/ajaxui.c b/ajaxui/ajaxui.c index 84782f12..7ba7d34d 100644 --- a/ajaxui/ajaxui.c +++ b/ajaxui/ajaxui.c @@ -75,68 +75,161 @@ ajaxui_escape_apostrophe(const char *content) } /** - * AJAX table header + * AJAX table */ void -ajax_table_header(http_connection_t *hc, tcp_queue_t *tq, - const char *names[], int weights[], - int scrollbar, int columnsizes[]) +ajax_table_top(ajax_table_t *t, http_connection_t *hc, tcp_queue_t *tq, + const char *names[], int weights[]) { int n = 0, i, tw = 0; while(names[n]) { tw += weights[n]; n++; } + assert(n <= 20); + + t->columns = n; + + memset(t, 0, sizeof(ajax_table_t)); + + t->tq = tq; for(i = 0; i < n; i++) - columnsizes[i] = 100 * weights[i] / tw; + t->csize[i] = 100 * weights[i] / tw; - if(scrollbar) - tcp_qprintf(tq, "
"); - - tcp_qprintf(tq, "
"); + tcp_qprintf(tq, "
"); + tcp_qprintf(tq, "
"); + for(i = 0; i < n; i++) tcp_qprintf(tq, "
%s
", - columnsizes[i], *names[i] ? names[i]: " "); - - tcp_qprintf(tq, "
"); - if(scrollbar) - tcp_qprintf(tq, "
"); + t->csize[i], *names[i] ? names[i]: " "); + tcp_qprintf(tq, "

\r\n"); } - - + /** - * AJAX table row + * AJAX table new row */ void -ajax_table_row(tcp_queue_t *tq, const char *cells[], int columnsizes[], - int *bgptr, const char *idprefix[], const char *idpostfix) +ajax_table_row_start(ajax_table_t *t, const char *id) { - int i = 0; + t->rowid = id; + t->rowcol = !t->rowcol; + tcp_qprintf(t->tq, "%s
", + t->inrow ? "
\r\n" : "", + t->rowcol ? "background: #fff; " : ""); + t->inrow = 1; + t->curcol = 0; +} - tcp_qprintf(tq, "
", - *bgptr ? "background: #fff; " : ""); - - *bgptr = !*bgptr; - - while(cells[i]) { - tcp_qprintf(tq, - "
%s
", - idprefix && idprefix[i] ? "id=\"" : "", - idprefix && idprefix[i] ? idprefix[i] : "", - idprefix && idprefix[i] && idpostfix ? "_" : "", - idprefix && idprefix[i] && idpostfix ? idpostfix : "", - idprefix && idprefix[i] ? "\" " : "", - columnsizes[i], cells[i]); - i++; - } - tcp_qprintf(tq, "
\r\n"); +/** + * AJAX table new row + */ +void +ajax_table_subrow_start(ajax_table_t *t) +{ + tcp_qprintf(t->tq, "
"); + t->curcol = 0; } +/** + * AJAX table new row + */ +void +ajax_table_subrow_end(ajax_table_t *t) +{ + tcp_qprintf(t->tq, "
"); + t->curcol = 0; +} +/** + * AJAX table new row + */ +void +ajax_table_details_start(ajax_table_t *t) +{ + assert(t->inrow == 1); + t->inrow = 0; + /* Extra info */ + tcp_qprintf(t->tq, "
", + t->rowid, t->rowcol ? "background: #fff; " : ""); +} + +/** + * AJAX table new row + */ +void +ajax_table_details_end(ajax_table_t *t) +{ + /* Extra info */ + tcp_qprintf(t->tq, "
"); +} + + +/** + * AJAX table cell + */ +void +ajax_table_cell(ajax_table_t *t, const char *id, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + + if(t->rowid && id) { + tcp_qprintf(t->tq, "
rowid); + } else { + tcp_qprintf(t->tq, "tq, + " style=\"float: left; width: %d%%\">", t->csize[t->curcol]); + t->curcol++; + if(t->curcol == 20) + abort(); + + if(fmt == NULL) + tcp_qprintf(t->tq, " "); + else + tcp_qvprintf(t->tq, fmt, ap); + + va_end(ap); + tcp_qprintf(t->tq, "
"); +} + +/** + * AJAX table cell for toggling display of more details + */ +void +ajax_table_cell_detail_toggler(ajax_table_t *t) +{ + ajax_table_cell(t, NULL, + "" + "More", + t->rowid, t->rowid); +} + +/** + * AJAX table cell for selecting row + */ +void +ajax_table_cell_checkbox(ajax_table_t *t) +{ + ajax_table_cell(t, NULL, + "", + t->rowid); +} + +/** + * AJAX table footer + */ +void +ajax_table_bottom(ajax_table_t *t) +{ + tcp_qprintf(t->tq, "%s", t->inrow ? "" : ""); +} + /** * AJAX box start */ diff --git a/ajaxui/ajaxui.css b/ajaxui/ajaxui.css index d58d951e..c1821699 100644 --- a/ajaxui/ajaxui.css +++ b/ajaxui/ajaxui.css @@ -54,6 +54,13 @@ img { border: 0; } * Misc classes */ +.normaltable { + height: 300px; + overflow: auto; + overflow-y: scroll; + overflow-x: hidden; + } + .iconbackdrop { background: #fff; height: 64px; diff --git a/ajaxui/ajaxui.h b/ajaxui/ajaxui.h index d1b3839d..6b1d8473 100644 --- a/ajaxui/ajaxui.h +++ b/ajaxui/ajaxui.h @@ -25,11 +25,41 @@ typedef enum { AJAX_BOX_BORDER, } ajax_box_t; + void ajax_box_begin(tcp_queue_t *tq, ajax_box_t type, const char *id, const char *style, const char *title); void ajax_box_end(tcp_queue_t *tq, ajax_box_t type); + + +typedef struct { + int columns; + int curcol; + + int inrow; + const char *rowid; + + int csize[20]; + tcp_queue_t *tq; + int rowcol; +} ajax_table_t; + +void ajax_table_top(ajax_table_t *t, http_connection_t *hc, tcp_queue_t *tq, + const char *names[], int weights[]); +void ajax_table_row_start(ajax_table_t *t, const char *id); +void ajax_table_cell(ajax_table_t *t, const char *id, const char *fmt, ...); +void ajax_table_bottom(ajax_table_t *t); +void ajax_table_cell_detail_toggler(ajax_table_t *t); +void ajax_table_cell_checkbox(ajax_table_t *t); +void ajax_table_details_start(ajax_table_t *t); +void ajax_table_details_end(ajax_table_t *t); +void ajax_table_subrow_start(ajax_table_t *t); +void ajax_table_subrow_end(ajax_table_t *t); + + + + void ajax_js(tcp_queue_t *tq, const char *fmt, ...); @@ -71,14 +101,6 @@ int ajax_transport_build_list(http_connection_t *hc, tcp_queue_t *tq, struct th_transport_list *tlist, int ntransports); - -void ajax_table_header(http_connection_t *hc, tcp_queue_t *tq, - const char *names[], int weights[], - int scrollbar, int columnsizes[]); - -void ajax_table_row(tcp_queue_t *tq, const char *cells[], int columnsizes[], - int *bgptr, const char *idprefix[], const char *idpostfix); - const char *ajaxui_escape_apostrophe(const char *content); #endif /* AJAXUI_H_ */ diff --git a/ajaxui/ajaxui_config_dvb.c b/ajaxui/ajaxui_config_dvb.c index a1a8344b..079b9c57 100644 --- a/ajaxui/ajaxui_config_dvb.c +++ b/ajaxui/ajaxui_config_dvb.c @@ -540,21 +540,15 @@ static int ajax_adaptermuxlist(http_connection_t *hc, http_reply_t *hr, const char *remain, void *opaque) { + ajax_table_t ta; th_dvb_mux_instance_t *tdmi; tcp_queue_t *tq = &hr->hr_tq; th_dvb_adapter_t *tda; - char buf[50], buf2[500], buf3[20]; - const char *txt; + char buf[50]; int fetype, n, m; th_transport_t *t; - int o = 1, v; - int csize[10]; int nmuxes = 0; - int displines = 21; - - const char *cells[10]; - if(remain == NULL || (tda = dvb_adapter_find_by_identifier(remain)) == NULL) return HTTP_STATUS_NOT_FOUND; @@ -565,71 +559,45 @@ ajax_adaptermuxlist(http_connection_t *hc, http_reply_t *hr, LIST_FOREACH(tdmi, &tda->tda_muxes, tdmi_adapter_link) nmuxes++; - ajax_table_header(hc, tq, - (const char *[]) - {"Freq", "Status", "State", "Name", "Services", NULL}, - (int[]){4,3,2,4,2}, - nmuxes > displines, - csize); - - tcp_qprintf(tq, "
"); - - v = displines; - if(nmuxes < displines) - v = nmuxes; - - tcp_qprintf(tq, "
", - tda->tda_identifier, v * 14); - if(nmuxes == 0) { tcp_qprintf(tq, "
" "No muxes configured
"); - } else LIST_FOREACH(tdmi, &tda->tda_muxes, tdmi_adapter_link) { + } else { - tdmi_displayname(tdmi, buf, sizeof(buf)); + ajax_table_top(&ta, hc, tq, + (const char *[]) + {"Freq", "Status", "State", "Name", "Services", NULL}, + (int[]) + {4,3,2,4,2}); - snprintf(buf2, sizeof(buf2), - "%s", tdmi->tdmi_identifier, buf); + LIST_FOREACH(tdmi, &tda->tda_muxes, tdmi_adapter_link) { + tdmi_displayname(tdmi, buf, sizeof(buf)); - cells[0] = buf2; - cells[1] = dvb_mux_status(tdmi); + ajax_table_row_start(&ta, tdmi->tdmi_identifier); - switch(tdmi->tdmi_state) { - case TDMI_IDLE: txt = "Idle"; break; - case TDMI_IDLESCAN: txt = "Scanning"; break; - case TDMI_RUNNING: txt = "Running"; break; - default: txt = "???"; break; + ajax_table_cell(&ta, NULL, + "%s", + tdmi->tdmi_identifier, buf); + + ajax_table_cell(&ta, "status", "%s", dvb_mux_status(tdmi)); + ajax_table_cell(&ta, "state", "%s", dvb_mux_state(tdmi)); + ajax_table_cell(&ta, "name", "%s", tdmi->tdmi_network ?: ""); + + n = m = 0; + LIST_FOREACH(t, &tdmi->tdmi_transports, tht_mux_link) { + n++; + if(transport_is_available(t)) + m++; + } + ajax_table_cell(&ta, "nsvc", "%d / %d", m, n); } - - cells[2] = txt; - - txt = tdmi->tdmi_network; - if(txt == NULL) - txt = "Unknown"; - - cells[3] = txt; - - n = m = 0; - LIST_FOREACH(t, &tdmi->tdmi_transports, tht_mux_link) { - n++; - if(transport_is_available(t)) - m++; - } - snprintf(buf3, sizeof(buf3), "%d / %d", m, n); - cells[4] = buf3; - cells[5] = NULL; - - ajax_table_row(tq, cells, csize, &o, - (const char *[]){NULL, "status", "state", "name", "nsvc"}, - tdmi->tdmi_identifier); - + ajax_table_bottom(&ta); } - tcp_qprintf(tq, "
"); http_output_html(hc, hr); return 0; } diff --git a/ajaxui/ajaxui_config_transport.c b/ajaxui/ajaxui_config_transport.c index 53d955ce..31532321 100644 --- a/ajaxui/ajaxui_config_transport.c +++ b/ajaxui/ajaxui_config_transport.c @@ -42,14 +42,10 @@ int ajax_transport_build_list(http_connection_t *hc, tcp_queue_t *tq, struct th_transport_list *tlist, int numtransports) { - char buf[1000]; th_transport_t *t; - const char *v; - int o = 1; th_stream_t *st; const char *extra; - int displines = 21; - int csize[10]; + ajax_table_t ta; tcp_qprintf(tq, "