const char *remain, void *opaque)
{
tcp_queue_t *tq = &hr->hr_tq;
- channel_t *ch;
+ channel_t *ch, *ch2;
+ channel_group_t *chg;
th_transport_t *t;
const char *s;
int i;
"onClick=\"channel_delete('%d', '%s')\">",
ch->ch_tag, ch->ch_name);
- tcp_qprintf(tq, "</div>");
+ tcp_qprintf(tq,
+ "<select "
+ "onChange=\"channel_merge('%d', this.value);\">",
+ ch->ch_tag);
+
+ tcp_qprintf(tq, "<option value=\"n\">Merge to channel:</option>");
+
+ TAILQ_FOREACH(chg, &all_channel_groups, tcg_global_link) {
+ TAILQ_FOREACH(ch2, &chg->tcg_channels, ch_group_link) {
+ if(ch2 != ch)
+ tcp_qprintf(tq, "<option value=\"%d\">%s</option>",
+ ch2->ch_tag, ch2->ch_name);
+ }
+ }
+
+ tcp_qprintf(tq, "</select>");
+ tcp_qprintf(tq, "</div>");
tcp_qprintf(tq, "<hr>\r\n");
tcp_qprintf(tq,
return 0;
}
+/**
+ * Merge channel
+ */
+static int
+ajax_chmerge(http_connection_t *hc, http_reply_t *hr,
+ const char *remain, void *opaque)
+{
+ tcp_queue_t *tq = &hr->hr_tq;
+ channel_t *src, *dst;
+ channel_group_t *tcg;
+ const char *s;
+
+ if(remain == NULL || (src = channel_by_tag(atoi(remain))) == NULL)
+ return HTTP_STATUS_NOT_FOUND;
+
+ if((s = http_arg_get(&hc->hc_req_args, "dst")) == NULL)
+ return HTTP_STATUS_BAD_REQUEST;
+
+ if((dst = channel_by_tag(atoi(s))) == NULL)
+ return HTTP_STATUS_BAD_REQUEST;
+
+ tcg = src->ch_group;
+ channel_merge(dst, src);
+
+ tcp_qprintf(tq,
+ "new Ajax.Updater('groupeditortab', "
+ "'/ajax/chgroup_editor/%d', "
+ "{method: 'get', evalScripts: true});\r\n",
+ tcg->tcg_tag);
+
+ tcp_qprintf(tq, "$('cheditortab').innerHTML='';\r\n");
+
+ http_output(hc, hr, "text/javascript; charset=UTF-8", NULL, 0);
+ return 0;
+}
+
/**
*
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/chdelete", NULL, ajax_chdelete,
AJAX_ACCESS_CONFIG);
+ http_path_add("/ajax/chmerge", NULL, ajax_chmerge,
+ AJAX_ACCESS_CONFIG);
}
function channel_delete(tag, name)
{
- if(confirm("Are you sure you want to delete '" + name + "'") == true) {
+ if(confirm("Are you sure you want to delete '" + name + "'") == true){
a = new Ajax.Request('/ajax/chdelete/' + tag);
}
}
+
+function channel_merge(srctag, dsttag)
+{
+ if(confirm("Are you sure") == true){
+ a = new Ajax.Request('/ajax/chmerge/' + srctag,
+ {parameters: {dst: dsttag}});
+ }
+}
snprintf(buf, sizeof(buf), "%s/channels/%s", settings_dir, ch->ch_sname);
unlink(buf);
}
+
+
+
+/**
+ * Merge transports from channel 'src' to channel 'dst'
+ *
+ * Then, destroy the 'src' channel
+ */
+void
+channel_merge(channel_t *dst, channel_t *src)
+{
+ th_transport_t *t;
+
+ while((t = LIST_FIRST(&src->ch_transports)) != NULL) {
+ transport_unmap_channel(t);
+
+ free(t->tht_servicename);
+ t->tht_servicename = strdup(dst->ch_name);
+
+ transport_map_channel(t);
+ t->tht_config_change(t);
+ }
+
+ channel_delete(src);
+}