Add checkboxes to DVB mux list and an option to delete muxes
This commit is contained in:
parent
0cd6b6d12f
commit
9326be7212
5 changed files with 132 additions and 50 deletions
|
@ -74,6 +74,60 @@ ajaxui_escape_apostrophe(const char *content)
|
|||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
ajax_generate_select_functions(tcp_queue_t *tq, const char *fprefix,
|
||||
char **selvector)
|
||||
{
|
||||
int n;
|
||||
|
||||
tcp_qprintf(tq, "<script type=\"text/javascript\">\r\n"
|
||||
"//<![CDATA[\r\n");
|
||||
|
||||
/* Select all */
|
||||
tcp_qprintf(tq, "%s_sel_all = function() {\r\n", fprefix);
|
||||
for(n = 0; selvector[n] != NULL; n++)
|
||||
tcp_qprintf(tq, "$('sel_%s').checked = true;\r\n", selvector[n]);
|
||||
tcp_qprintf(tq, "}\r\n");
|
||||
|
||||
/* Select none */
|
||||
tcp_qprintf(tq, "%s_sel_none = function() {\r\n", fprefix);
|
||||
for(n = 0; selvector[n] != NULL; n++)
|
||||
tcp_qprintf(tq, "$('sel_%s').checked = false;\r\n", selvector[n]);
|
||||
tcp_qprintf(tq, "}\r\n");
|
||||
|
||||
/* Invert selection */
|
||||
tcp_qprintf(tq, "%s_sel_invert = function() {\r\n", fprefix);
|
||||
for(n = 0; selvector[n] != NULL; n++)
|
||||
tcp_qprintf(tq, "$('sel_%s').checked = !$('sel_%s').checked;\r\n",
|
||||
selvector[n], selvector[n]);
|
||||
tcp_qprintf(tq, "}\r\n");
|
||||
|
||||
/* Invoke AJAX call containing all selected elements */
|
||||
tcp_qprintf(tq,
|
||||
"%s_sel_do = function(op, arg1, arg2, check) {\r\n"
|
||||
"if(check == true && !confirm(\"Are you sure?\")) {return;}\r\n"
|
||||
"var h = new Hash();\r\n"
|
||||
"h.set('arg1', arg1);\r\n"
|
||||
"h.set('arg2', arg2);\r\n", fprefix
|
||||
);
|
||||
|
||||
for(n = 0; selvector[n] != NULL; n++)
|
||||
tcp_qprintf(tq,
|
||||
"if($('sel_%s').checked) {h.set('%s', 'selected') }\r\n",
|
||||
selvector[n], selvector[n]);
|
||||
tcp_qprintf(tq, " new Ajax.Request('/ajax/' + op, "
|
||||
"{parameters: h});\r\n");
|
||||
tcp_qprintf(tq, "}\r\n");
|
||||
tcp_qprintf(tq,
|
||||
"\r\n//]]>\r\n"
|
||||
"</script>\r\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* AJAX table
|
||||
*/
|
||||
|
@ -372,15 +426,18 @@ ajax_menu_bar_from_array(tcp_queue_t *tq, const char *name,
|
|||
*
|
||||
*/
|
||||
void
|
||||
ajax_a_jsfunc(tcp_queue_t *tq, const char *innerhtml, const char *func,
|
||||
const char *trailer)
|
||||
ajax_a_jsfuncf(tcp_queue_t *tq, const char *innerhtml, const char *fmt, ...)
|
||||
{
|
||||
tcp_qprintf(tq, "<a href=\"javascript:void(0)\" "
|
||||
"onClick=\"javascript:%s\">%s</a>%s\r\n",
|
||||
func, innerhtml, trailer);
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
tcp_qprintf(tq, "<a href=\"javascript:void(0)\" onClick=\"javascript:");
|
||||
tcp_qvprintf(tq, fmt, ap);
|
||||
tcp_qprintf(tq, "\">%s</a>", innerhtml);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Titlebar AJAX page
|
||||
*/
|
||||
|
|
|
@ -80,9 +80,6 @@ void ajax_config_init(void);
|
|||
void ajax_menu_bar_from_array(tcp_queue_t *tq, const char *name,
|
||||
const char **vec, int num, int cur);
|
||||
|
||||
void ajax_a_jsfunc(tcp_queue_t *tq, const char *innerhtml, const char *func,
|
||||
const char *trailer);
|
||||
|
||||
int ajax_channelgroup_tab(http_connection_t *hc, http_reply_t *hr);
|
||||
int ajax_config_tab(http_connection_t *hc, http_reply_t *hr);
|
||||
|
||||
|
@ -102,5 +99,10 @@ int ajax_transport_build_list(http_connection_t *hc, tcp_queue_t *tq,
|
|||
int ntransports);
|
||||
|
||||
const char *ajaxui_escape_apostrophe(const char *content);
|
||||
void ajax_generate_select_functions(tcp_queue_t *tq, const char *fprefix,
|
||||
char **selvector);
|
||||
|
||||
void ajax_a_jsfuncf(tcp_queue_t *tq, const char *innerhtml,
|
||||
const char *fmt, ...);
|
||||
|
||||
#endif /* AJAXUI_H_ */
|
||||
|
|
|
@ -252,8 +252,6 @@ ajax_chgroup_editor(http_connection_t *hc, http_reply_t *hr,
|
|||
if(remain == NULL || (tcg = channel_group_by_tag(atoi(remain))) == NULL)
|
||||
return HTTP_STATUS_BAD_REQUEST;
|
||||
|
||||
|
||||
|
||||
tcp_qprintf(tq, "<script type=\"text/javascript\">\r\n"
|
||||
"//<![CDATA[\r\n");
|
||||
|
||||
|
@ -337,16 +335,15 @@ ajax_chgroup_editor(http_connection_t *hc, http_reply_t *hr,
|
|||
}
|
||||
|
||||
tcp_qprintf(tq, "</div>");
|
||||
|
||||
tcp_qprintf(tq, "<hr>\r\n");
|
||||
|
||||
tcp_qprintf(tq, "<div style=\"overflow: auto; width: 100%\">");
|
||||
|
||||
tcp_qprintf(tq, "<div class=\"infoprefixwide\">Select:</div><div>");
|
||||
|
||||
ajax_a_jsfunc(tq, "All", "select_all();", " / ");
|
||||
ajax_a_jsfunc(tq, "None", "select_none();", " / ");
|
||||
ajax_a_jsfunc(tq, "Invert", "select_invert();", "");
|
||||
ajax_a_jsfuncf(tq, "All", "select_all();");
|
||||
tcp_qprintf(tq, " / ");
|
||||
ajax_a_jsfuncf(tq, "None", "select_none();");
|
||||
tcp_qprintf(tq, " / ");
|
||||
ajax_a_jsfuncf(tq, "Invert", "select_invert();");
|
||||
|
||||
tcp_qprintf(tq, "</div></div>\r\n");
|
||||
|
||||
|
|
|
@ -142,12 +142,6 @@ dvb_make_add_link(tcp_queue_t *tq, th_dvb_adapter_t *tda, const char *result)
|
|||
"onClick=\"new Ajax.Updater('addmux', "
|
||||
"'/ajax/dvbadapteraddmux/%s', {method: 'get'})\""
|
||||
">Add new...</a></p>", tda->tda_identifier);
|
||||
|
||||
tcp_qprintf(tq,
|
||||
"<p><a href=\"javascript:void(0);\" "
|
||||
"onClick=\"new Ajax.Request("
|
||||
"'/ajax/dvbadapterdelmuxes/%s', {method: 'get'})\""
|
||||
">Delete all muxes</a></p>", tda->tda_identifier);
|
||||
}
|
||||
|
||||
if(result) {
|
||||
|
@ -548,6 +542,7 @@ ajax_adaptermuxlist(http_connection_t *hc, http_reply_t *hr,
|
|||
int fetype, n, m;
|
||||
th_transport_t *t;
|
||||
int nmuxes = 0;
|
||||
char **selvector;
|
||||
|
||||
if(remain == NULL || (tda = dvb_adapter_find_by_identifier(remain)) == NULL)
|
||||
return HTTP_STATUS_NOT_FOUND;
|
||||
|
@ -564,11 +559,20 @@ ajax_adaptermuxlist(http_connection_t *hc, http_reply_t *hr,
|
|||
"No muxes configured</div>");
|
||||
} else {
|
||||
|
||||
|
||||
selvector = alloca(sizeof(char *) * (nmuxes + 1));
|
||||
n = 0;
|
||||
LIST_FOREACH(tdmi, &tda->tda_muxes, tdmi_adapter_link)
|
||||
selvector[n++] = tdmi->tdmi_identifier;
|
||||
selvector[n] = NULL;
|
||||
|
||||
ajax_generate_select_functions(tq, "mux", selvector);
|
||||
|
||||
ajax_table_top(&ta, hc, tq,
|
||||
(const char *[])
|
||||
{"Freq", "Status", "State", "Name", "Services", NULL},
|
||||
{"Freq", "Status", "State", "Name", "Services", "", NULL},
|
||||
(int[])
|
||||
{4,3,2,4,2});
|
||||
{16,12,8,16,8,2});
|
||||
|
||||
LIST_FOREACH(tdmi, &tda->tda_muxes, tdmi_adapter_link) {
|
||||
|
||||
|
@ -586,7 +590,7 @@ ajax_adaptermuxlist(http_connection_t *hc, http_reply_t *hr,
|
|||
|
||||
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 ?: "<unknown>");
|
||||
ajax_table_cell(&ta, "name", "%s", tdmi->tdmi_network ?: "Unknown");
|
||||
|
||||
n = m = 0;
|
||||
LIST_FOREACH(t, &tdmi->tdmi_transports, tht_mux_link) {
|
||||
|
@ -595,8 +599,26 @@ ajax_adaptermuxlist(http_connection_t *hc, http_reply_t *hr,
|
|||
m++;
|
||||
}
|
||||
ajax_table_cell(&ta, "nsvc", "%d / %d", m, n);
|
||||
ajax_table_cell_checkbox(&ta);
|
||||
}
|
||||
ajax_table_bottom(&ta);
|
||||
tcp_qprintf(tq, "<hr><div style=\"overflow: auto; width: 100%\">");
|
||||
tcp_qprintf(tq, "<div class=\"infoprefix\">Select:</div><div>");
|
||||
ajax_a_jsfuncf(tq, "All", "mux_sel_all();");
|
||||
tcp_qprintf(tq, " / ");
|
||||
ajax_a_jsfuncf(tq, "None", "mux_sel_none();");
|
||||
tcp_qprintf(tq, " / ");
|
||||
ajax_a_jsfuncf(tq, "Invert", "mux_sel_invert();");
|
||||
tcp_qprintf(tq, "</div></div>\r\n");
|
||||
|
||||
tcp_qprintf(tq, "<div style=\"overflow: auto; width: 100%\">");
|
||||
tcp_qprintf(tq, "<div class=\"infoprefix\"> </div><div>");
|
||||
ajax_a_jsfuncf(tq, "Delete selected",
|
||||
"mux_sel_do('dvbadapterdelmux/%s', '', '', true)",
|
||||
tda->tda_identifier);
|
||||
tcp_qprintf(tq, "</div></div>\r\n");
|
||||
|
||||
|
||||
}
|
||||
http_output_html(hc, hr);
|
||||
return 0;
|
||||
|
@ -652,20 +674,24 @@ ajax_dvbmuxeditor(http_connection_t *hc, http_reply_t *hr,
|
|||
* Delete all muxes on an adapter
|
||||
*/
|
||||
static int
|
||||
ajax_adapterdelmuxes(http_connection_t *hc, http_reply_t *hr,
|
||||
const char *remain, void *opaque)
|
||||
ajax_adapterdelmux(http_connection_t *hc, http_reply_t *hr,
|
||||
const char *remain, void *opaque)
|
||||
{
|
||||
th_dvb_adapter_t *tda;
|
||||
th_dvb_mux_instance_t *tdmi;
|
||||
tcp_queue_t *tq = &hr->hr_tq;
|
||||
http_arg_t *ra;
|
||||
|
||||
if(remain == NULL || (tda = dvb_adapter_find_by_identifier(remain)) == NULL)
|
||||
return HTTP_STATUS_NOT_FOUND;
|
||||
|
||||
printf("Deleting all muxes on %s\n", tda->tda_identifier);
|
||||
|
||||
while((tdmi = LIST_FIRST(&tda->tda_muxes)) != NULL) {
|
||||
printf("\tdeleting mux %s\n", tdmi->tdmi_identifier);
|
||||
TAILQ_FOREACH(ra, &hc->hc_req_args, link) {
|
||||
if(strcmp(ra->val, "selected"))
|
||||
continue;
|
||||
|
||||
if((tdmi = dvb_mux_find_by_identifier(ra->key)) == NULL)
|
||||
continue;
|
||||
|
||||
dvb_mux_destroy(tdmi);
|
||||
}
|
||||
|
||||
|
@ -689,7 +715,7 @@ ajax_config_dvb_init(void)
|
|||
http_path_add("/ajax/dvbadaptersummary" , NULL, ajax_adaptersummary);
|
||||
http_path_add("/ajax/dvbadaptereditor", NULL, ajax_adaptereditor);
|
||||
http_path_add("/ajax/dvbadapteraddmux", NULL, ajax_adapteraddmux);
|
||||
http_path_add("/ajax/dvbadapterdelmuxes", NULL, ajax_adapterdelmuxes);
|
||||
http_path_add("/ajax/dvbadapterdelmux", NULL, ajax_adapterdelmux);
|
||||
http_path_add("/ajax/dvbadaptercreatemux", NULL, ajax_adaptercreatemux);
|
||||
http_path_add("/ajax/dvbmuxeditor", NULL, ajax_dvbmuxeditor);
|
||||
|
||||
|
|
|
@ -206,19 +206,24 @@ ajax_transport_build_list(http_connection_t *hc, tcp_queue_t *tq,
|
|||
|
||||
tcp_qprintf(tq, "<div class=\"infoprefix\">Select:</div><div>");
|
||||
|
||||
ajax_a_jsfunc(tq, "All", "select_all();", " / ");
|
||||
ajax_a_jsfunc(tq, "None", "select_none();", " / ");
|
||||
ajax_a_jsfunc(tq, "Invert", "select_invert();", " / ");
|
||||
ajax_a_jsfunc(tq, "All TV-services", "select_tv();", " / ");
|
||||
ajax_a_jsfunc(tq, "All uncrypted TV-services", "select_tv_nocrypt();", "");
|
||||
ajax_a_jsfuncf(tq, "All", "select_all();");
|
||||
tcp_qprintf(tq, " / ");
|
||||
ajax_a_jsfuncf(tq, "None", "select_none();");
|
||||
tcp_qprintf(tq, " / ");
|
||||
ajax_a_jsfuncf(tq, "Invert", "select_invert();");
|
||||
tcp_qprintf(tq, " / ");
|
||||
ajax_a_jsfuncf(tq, "All TV-services", "select_tv();");
|
||||
tcp_qprintf(tq, " / ");
|
||||
ajax_a_jsfuncf(tq, "All uncrypted TV-services", "select_tv_nocrypt();");
|
||||
|
||||
tcp_qprintf(tq, "</div></div>\r\n");
|
||||
|
||||
tcp_qprintf(tq, "<div style=\"overflow: auto; width: 100%\">");
|
||||
tcp_qprintf(tq, "<div class=\"infoprefix\"> </div><div>");
|
||||
|
||||
ajax_a_jsfunc(tq, "Map selected", "selected_do('map');", " / ");
|
||||
ajax_a_jsfunc(tq, "Unmap selected", "selected_do('unmap');", "");
|
||||
ajax_a_jsfuncf(tq, "Map selected", "selected_do('map');");
|
||||
tcp_qprintf(tq, " / ");
|
||||
ajax_a_jsfuncf(tq, "Unmap selected", "selected_do('unmap');");
|
||||
|
||||
tcp_qprintf(tq, "</div></div>");
|
||||
|
||||
|
@ -234,9 +239,8 @@ ajax_transport_rename_channel(http_connection_t *hc, http_reply_t *hr,
|
|||
const char *remain, void *opaque)
|
||||
{
|
||||
th_transport_t *t;
|
||||
const char *newname, *v;
|
||||
const char *newname;
|
||||
tcp_queue_t *tq = &hr->hr_tq;
|
||||
char buf[1000];
|
||||
|
||||
if(remain == NULL || (t = transport_find_by_identifier(remain)) == NULL)
|
||||
return HTTP_STATUS_NOT_FOUND;
|
||||
|
@ -247,15 +251,11 @@ ajax_transport_rename_channel(http_connection_t *hc, http_reply_t *hr,
|
|||
free((void *)t->tht_channelname);
|
||||
t->tht_channelname = strdup(newname);
|
||||
|
||||
v = newname;
|
||||
|
||||
snprintf(buf, sizeof(buf),
|
||||
"tentative_chname('chname_%s', "
|
||||
"'/ajax/transport_rename_channel/%s', '%s')",
|
||||
t->tht_identifier, t->tht_identifier, v);
|
||||
|
||||
ajax_a_jsfunc(tq, v, buf, "");
|
||||
|
||||
ajax_a_jsfuncf(tq, newname,
|
||||
"tentative_chname('chname_%s', "
|
||||
"'/ajax/transport_rename_channel/%s', '%s')",
|
||||
t->tht_identifier, t->tht_identifier, newname);
|
||||
|
||||
http_output_html(hc, hr);
|
||||
t->tht_config_change(t);
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue