Remove old ajaxui

This commit is contained in:
Andreas Öman 2008-09-05 16:23:29 +00:00
parent 880fbebec9
commit 50f4709051
28 changed files with 0 additions and 13051 deletions

View file

@ -1,686 +0,0 @@
/*
* tvheadend, AJAX / HTML user interface
* Copyright (C) 2008 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "tvhead.h"
#include "http.h"
#include "ajaxui.h"
#include "ajaxui_mailbox.h"
#include "dispatch.h"
#include "obj/ajaxui.cssh"
#include "obj/prototype.jsh"
#include "obj/builder.jsh"
#include "obj/controls.jsh"
#include "obj/dragdrop.jsh"
#include "obj/effects.jsh"
#include "obj/scriptaculous.jsh"
#include "obj/slider.jsh"
#include "obj/tvheadend.jsh"
#include "obj/sbbody_l.gifh"
#include "obj/sbbody_r.gifh"
#include "obj/sbhead_l.gifh"
#include "obj/sbhead_r.gifh"
#include "obj/mapped.pngh"
#include "obj/unmapped.pngh"
extern const char *htsversion;
const char *ajax_tabnames[] = {
[AJAX_TAB_CHANNELS] = "Channels",
[AJAX_TAB_RECORDER] = "Recorder",
[AJAX_TAB_CONFIGURATION] = "Configuration",
[AJAX_TAB_ABOUT] = "About",
};
const char *
ajaxui_escape_apostrophe(const char *content)
{
static char buf[2000];
int i = 0;
while(i < sizeof(buf) - 2 && *content) {
if(*content == '\'')
buf[i++] = '\\';
buf[i++] = *content++;
}
buf[i] = 0;
return buf;
}
/**
*
*/
void
ajax_generate_select_functions(htsbuf_queue_t *hq, const char *fprefix,
char **selvector)
{
int n;
htsbuf_qprintf(hq, "<script type=\"text/javascript\">\r\n"
"//<![CDATA[\r\n");
/* Select all */
htsbuf_qprintf(hq, "%s_sel_all = function() {\r\n", fprefix);
for(n = 0; selvector[n] != NULL; n++)
htsbuf_qprintf(hq, "$('sel_%s').checked = true;\r\n", selvector[n]);
htsbuf_qprintf(hq, "}\r\n");
/* Select none */
htsbuf_qprintf(hq, "%s_sel_none = function() {\r\n", fprefix);
for(n = 0; selvector[n] != NULL; n++)
htsbuf_qprintf(hq, "$('sel_%s').checked = false;\r\n", selvector[n]);
htsbuf_qprintf(hq, "}\r\n");
/* Invert selection */
htsbuf_qprintf(hq, "%s_sel_invert = function() {\r\n", fprefix);
for(n = 0; selvector[n] != NULL; n++)
htsbuf_qprintf(hq, "$('sel_%s').checked = !$('sel_%s').checked;\r\n",
selvector[n], selvector[n]);
htsbuf_qprintf(hq, "}\r\n");
/* Invoke AJAX call containing all selected elements */
htsbuf_qprintf(hq,
"%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++)
htsbuf_qprintf(hq,
"if($('sel_%s').checked) {h.set('%s', 'selected') }\r\n",
selvector[n], selvector[n]);
htsbuf_qprintf(hq, " new Ajax.Request('/ajax/' + op, "
"{parameters: h});\r\n");
htsbuf_qprintf(hq, "}\r\n");
htsbuf_qprintf(hq,
"\r\n//]]>\r\n"
"</script>\r\n");
}
/**
* AJAX table
*/
void
ajax_table_top(ajax_table_t *t, http_connection_t *hc, htsbuf_queue_t *hq,
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->hq = hq;
for(i = 0; i < n; i++)
t->csize[i] = 100 * weights[i] / tw;
htsbuf_qprintf(hq, "<div style=\"padding-right: 20px\">");
htsbuf_qprintf(hq, "<div style=\"overflow: auto; width: 100%%\">");
for(i = 0; i < n; i++)
htsbuf_qprintf(hq, "<div style=\"float: left; width: %d%%\">%s</div>",
t->csize[i], *names[i] ? names[i]: "&nbsp;");
htsbuf_qprintf(hq, "</div></div><hr><div class=\"normaltable\">\r\n");
}
/**
* AJAX table new row
*/
void
ajax_table_row_start(ajax_table_t *t, const char *id)
{
t->rowid = id;
t->rowcol = !t->rowcol;
htsbuf_qprintf(t->hq, "%s<div style=\"%soverflow: auto; width: 100%\">",
t->inrow ? "</div>\r\n" : "",
t->rowcol ? "background: #fff; " : "");
t->inrow = 1;
t->curcol = 0;
}
/**
* AJAX table new row
*/
void
ajax_table_subrow_start(ajax_table_t *t)
{
htsbuf_qprintf(t->hq, "<div style=\"overflow: auto; width: 100%\">");
t->curcol = 0;
}
/**
* AJAX table new row
*/
void
ajax_table_subrow_end(ajax_table_t *t)
{
htsbuf_qprintf(t->hq, "</div>");
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 */
htsbuf_qprintf(t->hq, "</div><div id=\"details_%s\" style=\"%sdisplay: none\">",
t->rowid, t->rowcol ? "background: #fff; " : "");
}
/**
* AJAX table new row
*/
void
ajax_table_details_end(ajax_table_t *t)
{
/* Extra info */
htsbuf_qprintf(t->hq, "</div>");
}
/**
* 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) {
htsbuf_qprintf(t->hq, "<div id=\"%s_%s\"", id, t->rowid);
} else {
htsbuf_qprintf(t->hq, "<div");
}
htsbuf_qprintf(t->hq,
" style=\"float: left; width: %d%%\">", t->csize[t->curcol]);
t->curcol++;
if(t->curcol == 20)
abort();
if(fmt == NULL)
htsbuf_qprintf(t->hq, "&nbsp;");
else
htsbuf_vqprintf(t->hq, fmt, ap);
va_end(ap);
htsbuf_qprintf(t->hq, "</div>");
}
/**
* AJAX table cell for toggling display of more details
*/
void
ajax_table_cell_detail_toggler(ajax_table_t *t)
{
ajax_table_cell(t, NULL,
"<a id=\"toggle_details_%s\" href=\"javascript:void(0)\" "
"onClick=\"showhide('details_%s')\" >"
"More</a>",
t->rowid, t->rowid);
}
/**
* AJAX table cell for selecting row
*/
void
ajax_table_cell_checkbox(ajax_table_t *t)
{
ajax_table_cell(t, NULL,
"<input id=\"sel_%s\" type=\"checkbox\" class=\"nicebox\">",
t->rowid);
}
/**
* AJAX table footer
*/
void
ajax_table_bottom(ajax_table_t *t)
{
htsbuf_qprintf(t->hq, "%s</div>", t->inrow ? "</div>" : "");
}
/**
* AJAX box start
*/
void
ajax_box_begin(htsbuf_queue_t *hq, ajax_box_t type,
const char *id, const char *style, const char *title)
{
char id0[100], style0[100];
if(id != NULL)
snprintf(id0, sizeof(id0), "id=\"%s\" ", id);
else
id0[0] = 0;
if(style != NULL)
snprintf(style0, sizeof(style0), "style=\"%s\" ", style);
else
style0[0] = 0;
switch(type) {
case AJAX_BOX_SIDEBOX:
htsbuf_qprintf(hq,
"<div class=\"sidebox\">"
"<div class=\"boxhead\"><h2>%s</h2></div>\r\n"
" <div class=\"boxbody\" %s%s>",
title, id0, style0);
break;
case AJAX_BOX_FILLED:
htsbuf_qprintf(hq,
"<div style=\"margin: 3px\">"
"<b class=\"filledbox\">"
"<b class=\"filledbox1\"><b></b></b>"
"<b class=\"filledbox2\"><b></b></b>"
"<b class=\"filledbox3\"></b>"
"<b class=\"filledbox4\"></b>"
"<b class=\"filledbox5\"></b></b>"
"<div class=\"filledboxfg\" %s%s>\r\n",
id0, style0);
break;
case AJAX_BOX_BORDER:
htsbuf_qprintf(hq,
"<div style=\"margin: 3px\">"
"<b class=\"borderbox\">"
"<b class=\"borderbox1\"><b></b></b>"
"<b class=\"borderbox2\"><b></b></b>"
"<b class=\"borderbox3\"></b></b>"
"<div class=\"borderboxfg\" %s%s>\r\n",
id0, style0);
break;
}
}
/**
* AJAX box end
*/
void
ajax_box_end(htsbuf_queue_t *hq, ajax_box_t type)
{
switch(type) {
case AJAX_BOX_SIDEBOX:
htsbuf_qprintf(hq,"</div></div>");
break;
case AJAX_BOX_FILLED:
htsbuf_qprintf(hq,
"</div>"
"<b class=\"filledbox\">"
"<b class=\"filledbox5\"></b>"
"<b class=\"filledbox4\"></b>"
"<b class=\"filledbox3\"></b>"
"<b class=\"filledbox2\"><b></b></b>"
"<b class=\"filledbox1\"><b></b></b></b>"
"</div>\r\n");
break;
case AJAX_BOX_BORDER:
htsbuf_qprintf(hq,
"</div>"
"<b class=\"borderbox\">"
"<b class=\"borderbox3\"></b>"
"<b class=\"borderbox2\"><b></b></b>"
"<b class=\"borderbox1\"><b></b></b></b>"
"</div>\r\n");
break;
}
}
/**
*
*/
void
ajax_js(htsbuf_queue_t *hq, const char *fmt, ...)
{
va_list ap;
htsbuf_qprintf(hq,
"<script type=\"text/javascript\">\r\n"
"//<![CDATA[\r\n");
va_start(ap, fmt);
htsbuf_vqprintf(hq, fmt, ap);
va_end(ap);
htsbuf_qprintf(hq,
"\r\n//]]>\r\n"
"</script>\r\n");
}
/**
* Based on the given char[] array, generate a menu bar
*/
void
ajax_menu_bar_from_array(htsbuf_queue_t *hq, const char *name,
const char **vec, int num, int cur)
{
int i;
htsbuf_qprintf(hq, "<ul class=\"menubar\">");
for(i = 0; i < num; i++) {
htsbuf_qprintf(hq,
"<li%s>"
"<a href=\"javascript:switchtab('%s', '%d')\">%s</a>"
"</li>",
cur == i ? " style=\"font-weight:bold;\"" : "", name,
i, vec[i]);
}
htsbuf_qprintf(hq, "</ul>");
}
/**
*
*/
void
ajax_a_jsfuncf(htsbuf_queue_t *hq, const char *innerhtml, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
htsbuf_qprintf(hq, "<a href=\"javascript:void(0)\" onClick=\"javascript:");
htsbuf_vqprintf(hq, fmt, ap);
htsbuf_qprintf(hq, "\">%s</a>", innerhtml);
}
/**
*
*/
void
ajax_button(htsbuf_queue_t *hq, const char *caption, const char *code, ...)
{
va_list ap;
va_start(ap, code);
htsbuf_qprintf(hq, "<input type=\"button\" value=\"%s\" onClick=\"",
caption);
htsbuf_vqprintf(hq, code, ap);
htsbuf_qprintf(hq, "\">");
}
/*
* Titlebar AJAX page
*/
static int
ajax_page_titlebar(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
if(remain == NULL)
return HTTP_STATUS_NOT_FOUND;
ajax_menu_bar_from_array(&hr->hr_q, "top",
ajax_tabnames, AJAX_TABS, atoi(remain));
http_output_html(hc, hr);
return 0;
}
/**
* About
*/
static int
ajax_about_tab(http_connection_t *hc, http_reply_t *hr)
{
htsbuf_queue_t *hq = &hr->hr_q;
htsbuf_qprintf(hq, "<center>");
htsbuf_qprintf(hq, "<div style=\"padding: auto; width: 400px\">");
ajax_box_begin(hq, AJAX_BOX_SIDEBOX, NULL, NULL, "About");
htsbuf_qprintf(hq, "<div style=\"text-align: center\">");
htsbuf_qprintf(hq,
"<p>HTS / Tvheadend</p>"
"<p>(c) 2006-2008 Andreas \303\226man</p>"
"<p>Latest release and information is available at:</p>"
"<p><a href=\"http://www.lonelycoder.com/hts/\">"
"http://www.lonelycoder.com/hts/</a></p>"
"<p>&nbsp;</p>"
"<p>This webinterface is powered by</p>"
"<p><a href=\"http://www.prototypejs.org/\">Prototype</a>"
" and "
"<a href=\"http://script.aculo.us/\">script.aculo.us</a>"
"</p>"
"<p>&nbsp;</p>"
"<p>Media formats and codecs by</p>"
"<p><a href=\"http://www.ffmpeg.org/\">FFmpeg</a></p>"
);
htsbuf_qprintf(hq, "</div>");
ajax_box_end(hq, AJAX_BOX_SIDEBOX);
htsbuf_qprintf(hq, "</div>");
htsbuf_qprintf(hq, "</center>");
http_output_html(hc, hr);
return 0;
}
/*
* Tab AJAX page
*
* Find the 'tab' id and continue with tab specific code
*/
static int
ajax_page_tab(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
int tab;
if(remain == NULL)
return HTTP_STATUS_NOT_FOUND;
tab = atoi(remain);
switch(tab) {
case AJAX_TAB_CHANNELS:
return ajax_channelgroup_tab(hc, hr);
case AJAX_TAB_CONFIGURATION:
return ajax_config_tab(hc, hr);
case AJAX_TAB_ABOUT:
return ajax_about_tab(hc, hr);
default:
return HTTP_STATUS_NOT_FOUND;
}
return 0;
}
/*
* Root page
*/
static int
ajax_page_root(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *hq = &hr->hr_q;
htsbuf_qprintf(hq,
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\r\n"
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
/*
"<!DOCTYPE html "
"PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\r\n"
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
*/
"\r\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\" "
"xml:lang=\"en\" lang=\"en\">"
"<head>"
"<title>HTS/Tvheadend</title>"
"<meta http-equiv=\"Content-Type\" "
"content=\"text/html; charset=utf-8\">\r\n"
"<link href=\"/ajax/ajaxui.css\" rel=\"stylesheet\" "
"type=\"text/css\">\r\n"
"<script src=\"/ajax/prototype.js\" type=\"text/javascript\">"
"</script>\r\n"
"<script src=\"/ajax/effects.js\" type=\"text/javascript\">"
"</script>\r\n"
"<script src=\"/ajax/dragdrop.js\" type=\"text/javascript\">"
"</script>\r\n"
"<script src=\"/ajax/controls.js\" type=\"text/javascript\">"
"</script>\r\n"
"<script src=\"/ajax/tvheadend.js\" type=\"text/javascript\">"
"</script>\r\n"
"</head>"
"<body>");
htsbuf_qprintf(hq, "<div style=\"overflow: auto; width: 100%\">");
htsbuf_qprintf(hq, "<div style=\"float: left; width: 100%\">");
ajax_box_begin(hq, AJAX_BOX_FILLED, NULL, NULL, NULL);
htsbuf_qprintf(hq,
"<div style=\"width: 100%%; overflow: hidden\">"
"<div style=\"float: left; width: 30%%\">"
"Tvheadend (%s)"
"</div>"
"<div style=\"float: left; width: 40%%\" id=\"topmenu\"></div>"
"<div style=\"float: left; width: 30%%; text-align: right\">"
"&nbsp;"
"</div>"
"</div>",
htsversion);
ajax_mailbox_start(hq);
ajax_box_end(hq, AJAX_BOX_FILLED);
htsbuf_qprintf(hq, "<div id=\"topdeck\"></div>");
ajax_js(hq, "switchtab('top', '0')");
#if 0
htsbuf_qprintf(hq, "</div><div style=\"float: left; width: 20%\">");
ajax_box_begin(hq, AJAX_BOX_SIDEBOX, "statusbox", NULL, "System status");
ajax_box_end(hq, AJAX_BOX_SIDEBOX);
#endif
htsbuf_qprintf(hq, "</div></div></body></html>");
http_output_html(hc, hr);
return 0;
}
/**
* AJAX user interface
*/
void
ajaxui_start(void)
{
http_path_add("/ajax/index.html", NULL, ajax_page_root,
ACCESS_WEB_INTERFACE);
http_path_add("/ajax/topmenu", NULL, ajax_page_titlebar,
ACCESS_WEB_INTERFACE);
http_path_add("/ajax/toptab", NULL, ajax_page_tab,
ACCESS_WEB_INTERFACE);
/* Stylesheet */
http_resource_add("/ajax/ajaxui.css", embedded_ajaxui,
sizeof(embedded_ajaxui), "text/css", "gzip");
#define ADD_JS_RESOURCE(path, name) \
http_resource_add(path, name, sizeof(name), "text/javascript", "gzip")
/* Prototype */
ADD_JS_RESOURCE("/ajax/prototype.js", embedded_prototype);
/* Scriptaculous */
ADD_JS_RESOURCE("/ajax/builder.js", embedded_builder);
ADD_JS_RESOURCE("/ajax/controls.js", embedded_controls);
ADD_JS_RESOURCE("/ajax/dragdrop.js", embedded_dragdrop);
ADD_JS_RESOURCE("/ajax/effects.js", embedded_effects);
ADD_JS_RESOURCE("/ajax/scriptaculous.js", embedded_scriptaculous);
ADD_JS_RESOURCE("/ajax/slider.js", embedded_slider);
/* Tvheadend */
ADD_JS_RESOURCE("/ajax/tvheadend.js", embedded_tvheadend);
/* Embedded images */
http_resource_add("/sidebox/sbbody-l.gif", embedded_sbbody_l,
sizeof(embedded_sbbody_l), "image/gif", NULL);
http_resource_add("/sidebox/sbbody-r.gif", embedded_sbbody_r,
sizeof(embedded_sbbody_r), "image/gif", NULL);
http_resource_add("/sidebox/sbhead-l.gif", embedded_sbhead_l,
sizeof(embedded_sbhead_l), "image/gif", NULL);
http_resource_add("/sidebox/sbhead-r.gif", embedded_sbhead_r,
sizeof(embedded_sbhead_r), "image/gif", NULL);
http_resource_add("/gfx/unmapped.png", embedded_unmapped,
sizeof(embedded_unmapped), "image/png", NULL);
http_resource_add("/gfx/mapped.png", embedded_mapped,
sizeof(embedded_mapped), "image/png", NULL);
ajax_mailbox_init();
ajax_channels_init();
ajax_config_init();
ajax_config_transport_init();
}

View file

@ -1,329 +0,0 @@
body {
font: 11px Lucida Grande, Verdana, Arial, Helvetica, sans serif;
}
select {
font: 11px Lucida Grande, Verdana, Arial, Helvetica, sans serif;
}
input {
font: 11px Lucida Grande, Verdana, Arial, Helvetica, sans serif;
}
a, a:hover, a:visited, a:active {
color: #aa6600;
}
img { border: 0; }
.draglist {
margin:0;
padding:0;
list-style-type: none;
}
.draglist li {
margin:0;
padding:0px;
cursor:move;
}
.normallist {
margin:0;
margin-top:10px;
padding:0;
list-style-type: none;
}
.normallist li {
margin:0;
padding:0px;
}
/**
* Input classes
*/
.nicebox {
margin: 1px;
padding: 0px;
border: 0px;
width: 11px;
height: 11px;
}
/**
* Misc classes
*/
.event3 {
height: 42px
}
.compact {
float: left;
height: 100%;
overflow: hidden;
}
.fullrow {
overflow: auto;
width: 100%;
height: 14px;
}
.cell_100_center {
margin-top: 2px;
margin-bottom: 2px;
width: 100%;
text-align: center;
}
.cell_50 {
margin-top: 2px;
margin-bottom: 2px;
float: left;
width: 50%;
}
.cell_20 {
margin-top: 2px;
margin-bottom: 2px;
float: left;
width: 20%;
}
.normaltable {
height: 300px;
overflow: auto;
overflow-y: scroll;
overflow-x: hidden;
}
.iconbackdrop {
background: #fff;
height: 64px;
width: 64px;
float: left;
margin: 2px;
text-align: center;
margin-right: 4px;
}
.infoprefix {
float: left;
width: 50px;
text-align: right;
}
.infoprefixwide {
padding-right: 5px;
float: left;
width: 100px;
text-align: right;
}
.infoprefixwidefat {
padding-right: 5px;
float: left;
width: 100px;
text-align: right;
margin-top: 4px;
}
.infoprefixwidewidefat {
padding-right: 5px;
float: left;
width: 130px;
text-align: right;
margin-top: 4px;
}
.pidheader {
float: left;
text-decoration: underline;
}
.chgroupaction {
text-align: right;
}
/**
* Box with round edges
*/
.filledbox {
display:block;
}
.filledbox * {
display:block;
height:1px;
overflow:hidden;
font-size:.01em;
background:#dddddd;
}
.filledbox1 {
margin-left:3px;
margin-right:3px;
padding-left:1px;
padding-right:1px;
border-left:1px solid #f0f0f0;
border-right:1px solid #f0f0f0;
background:#e5e5e5;
}
.filledbox2 {
margin-left:1px;
margin-right:1px;
padding-right:1px;
padding-left:1px;
border-left:1px solid #fbfbfb;
border-right:1px solid #fbfbfb;
background:#e3e3e3;
}
.filledbox3 {
margin-left:1px;
margin-right:1px;
border-left:1px solid #e3e3e3;
border-right:1px solid #e3e3e3;
}
.filledbox4 {
border-left:1px solid #f0f0f0;
border-right:1px solid #f0f0f0;
}
.filledbox5 {
border-left:1px solid #e5e5e5;
border-right:1px solid #e5e5e5;
}
.filledboxfg {
padding-left:5px;
padding-right:5px;
background:#dddddd;
}
/**
* Box with rounded edges
*/
.borderbox {
display:block;
}
.borderbox * {
display:block;
height:1px;
overflow:hidden;
font-size:.01em;
}
.borderbox1 {
margin-left:4px;
margin-right:4px;
padding-left:1px;
padding-right:1px;
background: #000000;
border-left:1px solid #000;
border-right:1px solid #000;
}
.borderbox2 {
margin-left:2px;
margin-right:2px;
padding-right:1px;
padding-left:1px;
border-left:2px solid #000;
border-right:2px solid #000;
}
.borderbox3 {
margin-left:1px;
margin-right:1px;
border-left:1px solid #000;
border-right:1px solid #000;
}
.borderboxfg {
border-left:1px solid #000;
border-right:1px solid #000;
padding-left:5px;
padding-right:5px;
}
/**
* Menubar
*/
.menubar {
margin: 0px;
padding: 0px;
text-align: center;
height: 15px;
}
.menubar li {
margin-left: 5px;
margin-right: 5px;
display: inline;
list-style-type: none;
}
.menubar a {
color: #000000;
text-decoration: none;
}
/**
* Sidebox
*
* from http://www.vertexwerks.com/tests/sidebox/
*/
/* Show only to IE PC \*/
* html .boxhead h2 {height: 1%;} /* For IE 5 PC */
.sidebox {
margin: 0 auto; /* center for now */
background: url(/sidebox/sbbody-r.gif) no-repeat bottom right;
font-size: 100%;
}
.boxhead {
background: url(/sidebox/sbhead-r.gif) no-repeat top right;
margin: 0;
padding: 0;
text-align: center;
}
.boxhead h2 {
background: url(/sidebox/sbhead-l.gif) no-repeat top left;
margin: 0;
padding: 22px 30px 5px;
color: white;
font-weight: bold;
font-size: 1.4em;
line-height: 1em;
text-shadow: rgba(0,0,0,.4) 0px 2px 5px; /* Safari-only, but cool */
}
.boxbody {
background: url(/sidebox/sbbody-l.gif) no-repeat bottom left;
margin: 0;
padding: 5px 30px 31px;
}

View file

@ -1,127 +0,0 @@
/*
* tvheadend, AJAX user interface
* Copyright (C) 2007 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <htmlui://www.gnu.org/licenses/>.
*/
#ifndef AJAXUI_H_
#define AJAXUI_H_
#include "access.h"
#define AJAX_ACCESS_CONFIG (ACCESS_WEB_INTERFACE | ACCESS_ADMIN)
#define AJAX_ACCESS_ACCESSCTRL \
(ACCESS_WEB_INTERFACE | ACCESS_ADMIN | ACCESS_ADMIN_ACCESS)
typedef enum {
AJAX_BOX_FILLED,
AJAX_BOX_SIDEBOX,
AJAX_BOX_BORDER,
} ajax_box_t;
void ajax_box_begin(htsbuf_queue_t *q, ajax_box_t type,
const char *id, const char *style, const char *title);
void ajax_box_end(htsbuf_queue_t *q, ajax_box_t type);
typedef struct {
int columns;
int curcol;
int inrow;
const char *rowid;
int csize[20];
htsbuf_queue_t *hq;
int rowcol;
} ajax_table_t;
void ajax_table_top(ajax_table_t *t, http_connection_t *hc, htsbuf_queue_t *q,
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(htsbuf_queue_t *q, const char *fmt, ...);
TAILQ_HEAD(ajax_menu_entry_queue, ajax_menu_entry);
#define AJAX_TAB_CHANNELS 0
#define AJAX_TAB_RECORDER 1
#define AJAX_TAB_CONFIGURATION 2
#define AJAX_TAB_ABOUT 3
#define AJAX_TABS 4
void ajax_mailbox_init(void);
void ajaxui_start(void);
void ajax_channels_init(void);
void ajax_config_init(void);
void ajax_menu_bar_from_array(htsbuf_queue_t *q, const char *name,
const char **vec, int num, int cur);
int ajax_channelgroup_tab(http_connection_t *hc, http_reply_t *hr);
int ajax_config_tab(http_connection_t *hc, http_reply_t *hr);
int ajax_config_channels_tab(http_connection_t *hc, http_reply_t *hr);
void ajax_config_channels_init(void);
int ajax_config_dvb_tab(http_connection_t *hc, http_reply_t *hr);
void ajax_config_dvb_init(void);
int ajax_config_xmltv_tab(http_connection_t *hc, http_reply_t *hr);
void ajax_config_xmltv_init(void);
int ajax_config_access_tab(http_connection_t *hc, http_reply_t *hr);
void ajax_config_access_init(void);
int ajax_config_cwc_tab(http_connection_t *hc, http_reply_t *hr);
void ajax_config_cwc_init(void);
void ajax_config_transport_init(void);
int ajax_transport_build_list(http_connection_t *hc, htsbuf_queue_t *q,
struct th_transport_tree *tlist,
int ntransports);
const char *ajaxui_escape_apostrophe(const char *content);
void ajax_generate_select_functions(htsbuf_queue_t *q, const char *fprefix,
char **selvector);
void ajax_a_jsfuncf(htsbuf_queue_t *q, const char *innerhtml,
const char *fmt, ...);
void ajax_button(htsbuf_queue_t *q,
const char *caption, const char *code, ...);
void ajax_transport_build_mapper_state(char *buf, size_t siz,
th_transport_t *t, int mapped);
#endif /* AJAXUI_H_ */

View file

@ -1,243 +0,0 @@
/*
* tvheadend, AJAX / HTML user interface
* Copyright (C) 2008 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "tvhead.h"
#include "http.h"
#include "ajaxui.h"
#include "channels.h"
#include "epg.h"
static void
ajax_channelgroupmenu_content(htsbuf_queue_t *tq, int current)
{
channel_group_t *tcg;
htsbuf_qprintf(tq, "<ul class=\"menubar\">");
TAILQ_FOREACH(tcg, &all_channel_groups, tcg_global_link) {
if(tcg->tcg_hidden)
continue;
if(current < 1)
current = tcg->tcg_tag;
htsbuf_qprintf(tq,
"<li%s>"
"<a href=\"javascript:switchtab('channelgroup', '%d')\">%s</a>"
"</li>",
current == tcg->tcg_tag ? " style=\"font-weight:bold;\"" : "",
tcg->tcg_tag, tcg->tcg_name);
}
htsbuf_qprintf(tq, "</ul>");
}
/*
* Channelgroup menu bar
*/
static int
ajax_channelgroup_menu(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
if(remain == NULL)
return HTTP_STATUS_NOT_FOUND;
ajax_channelgroupmenu_content(tq, atoi(remain));
http_output_html(hc, hr);
return 0;
}
static void
ajax_output_event(htsbuf_queue_t *tq, event_t *e, int flags, int color)
{
struct tm a, b;
time_t stop;
htsbuf_qprintf(tq, "<div class=\"fullrow\"%s>",
color ? "style=\"background: #fff\" " : "");
localtime_r(&e->e_start, &a);
stop = e->e_start + e->e_duration;
localtime_r(&stop, &b);
htsbuf_qprintf(tq,
"<div class=\"compact\" style=\"width: 35%%\">"
"%02d:%02d-%02d:%02d"
"</div>",
a.tm_hour, a.tm_min, b.tm_hour, b.tm_min);
htsbuf_qprintf(tq,
"<div class=\"compact\" style=\"width: 65%%\">"
"%s"
"</div>",
e->e_title);
htsbuf_qprintf(tq, "</div>");
}
static void
ajax_list_events(htsbuf_queue_t *tq, channel_t *ch, int lines)
{
event_t *e;
int i;
e = epg_event_find_current_or_upcoming(ch);
for(i = 0; i < 3 && e != NULL; i++) {
ajax_output_event(tq, e, 0, !(i & 1));
e = TAILQ_NEXT(e, e_channel_link);
}
}
/*
* Display a list of all channels within the given group
*
* Group is given by 'tag' as an ASCII string in remain
*/
static int
ajax_channel_tab(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
channel_t *ch;
channel_group_t *tcg;
char dispname[20];
struct sockaddr_in *si;
int nchs = 0;
if(remain == NULL || (tcg = channel_group_by_tag(atoi(remain))) == NULL)
return HTTP_STATUS_NOT_FOUND;
TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
if(LIST_FIRST(&ch->ch_transports) == NULL)
continue;
nchs++;
htsbuf_qprintf(tq, "<div style=\"float:left; width: 25%%\">");
snprintf(dispname, sizeof(dispname), "%s", ch->ch_name);
strcpy(dispname + sizeof(dispname) - 4, "...");
ajax_box_begin(tq, AJAX_BOX_SIDEBOX, NULL, NULL, dispname);
/* inner */
htsbuf_qprintf(tq,
"<div style=\"width: 100%%; overflow: hidden; height:36px\">");
htsbuf_qprintf(tq,
"<div style=\"float: left; height:32px; width:32px; "
"margin: 2px\">");
if(ch->ch_icon != NULL) {
htsbuf_qprintf(tq, "<img src=\"%s\" style=\"width:32px\">",
ch->ch_icon);
}
htsbuf_qprintf(tq, "</div>");
htsbuf_qprintf(tq, "<div style=\"float:left; text-align: right\">");
si = (struct sockaddr_in *)&hc->hc_tcp_session.tcp_self_addr;
htsbuf_qprintf(tq,
"<a href=\"rtsp://%s:%d/%s\">Stream</a>",
inet_ntoa(si->sin_addr), ntohs(si->sin_port),
ch->ch_sname);
htsbuf_qprintf(tq, "</div>");
htsbuf_qprintf(tq, "</div>");
htsbuf_qprintf(tq, "<div id=\"events%d\" style=\"height:42px\">", ch->ch_tag);
ajax_list_events(tq, ch, 3);
htsbuf_qprintf(tq, "</div>");
ajax_box_end(tq, AJAX_BOX_SIDEBOX);
htsbuf_qprintf(tq, "</div>");
}
if(nchs == 0)
htsbuf_qprintf(tq, "<div style=\"text-align: center; font-weight: bold\">"
"No channels in this group</div>");
http_output_html(hc, hr);
return 0;
}
/*
* Channel (group)s AJAX page
*
* This is the top level menu for this c-file
*/
int
ajax_channelgroup_tab(http_connection_t *hc, http_reply_t *hr)
{
htsbuf_queue_t *tq = &hr->hr_q;
ajax_box_begin(tq, AJAX_BOX_FILLED, "channelgroupmenu", NULL, NULL);
ajax_box_end(tq, AJAX_BOX_FILLED);
htsbuf_qprintf(tq, "<div id=\"channelgroupdeck\"></div>");
htsbuf_qprintf(tq,
"<script type=\"text/javascript\">"
"switchtab('channelgroup', '0')"
"</script>");
http_output_html(hc, hr);
return 0;
}
/**
*
*/
void
ajax_channels_init(void)
{
http_path_add("/ajax/channelgroupmenu", NULL, ajax_channelgroup_menu,
ACCESS_WEB_INTERFACE);
http_path_add("/ajax/channelgrouptab", NULL, ajax_channel_tab,
ACCESS_WEB_INTERFACE);
}

View file

@ -1,146 +0,0 @@
/*
* tvheadend, AJAX / HTML user interface
* Copyright (C) 2008 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "tvhead.h"
#include "http.h"
#include "ajaxui.h"
#include "channels.h"
#define AJAX_CONFIG_TAB_CHANNELS 0
#define AJAX_CONFIG_TAB_DVB 1
#define AJAX_CONFIG_TAB_XMLTV 2
#define AJAX_CONFIG_TAB_CWC 3
#define AJAX_CONFIG_TAB_ACCESS 4
#define AJAX_CONFIG_TABS 5
const char *ajax_config_tabnames[] = {
[AJAX_CONFIG_TAB_CHANNELS] = "Channels & Groups",
[AJAX_CONFIG_TAB_DVB] = "DVB adapters",
[AJAX_CONFIG_TAB_XMLTV] = "XML-TV",
[AJAX_CONFIG_TAB_CWC] = "Code-word Client",
[AJAX_CONFIG_TAB_ACCESS] = "Access control",
};
/*
* Titlebar AJAX page
*/
static int
ajax_config_menu(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
if(remain == NULL)
return HTTP_STATUS_NOT_FOUND;
ajax_menu_bar_from_array(tq, "config",
ajax_config_tabnames, AJAX_CONFIG_TABS,
atoi(remain));
http_output_html(hc, hr);
return 0;
}
/*
* Tab AJAX page
*
* Switch to different tabs
*/
static int
ajax_config_dispatch(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
int tab;
if(remain == NULL)
return HTTP_STATUS_NOT_FOUND;
tab = atoi(remain);
switch(tab) {
case AJAX_CONFIG_TAB_CHANNELS:
return ajax_config_channels_tab(hc, hr);
case AJAX_CONFIG_TAB_DVB:
return ajax_config_dvb_tab(hc, hr);
case AJAX_CONFIG_TAB_XMLTV:
return ajax_config_xmltv_tab(hc, hr);
case AJAX_CONFIG_TAB_CWC:
return ajax_config_cwc_tab(hc, hr);
case AJAX_CONFIG_TAB_ACCESS:
return ajax_config_access_tab(hc, hr);
default:
return HTTP_STATUS_NOT_FOUND;
}
return 0;
}
/*
* Config root menu AJAX page
*
* This is the top level menu for this c-file
*/
int
ajax_config_tab(http_connection_t *hc, http_reply_t *hr)
{
htsbuf_queue_t *tq = &hr->hr_q;
ajax_box_begin(tq, AJAX_BOX_FILLED, "configmenu", NULL, NULL);
ajax_box_end(tq, AJAX_BOX_FILLED);
htsbuf_qprintf(tq, "<div id=\"configdeck\"></div>");
htsbuf_qprintf(tq,
"<script type=\"text/javascript\">"
"switchtab('config', '0')"
"</script>");
http_output_html(hc, hr);
return 0;
}
/**
*
*/
void
ajax_config_init(void)
{
http_path_add("/ajax/configmenu", NULL, ajax_config_menu,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/configtab", NULL, ajax_config_dispatch,
AJAX_ACCESS_CONFIG);
ajax_config_channels_init();
ajax_config_dvb_init();
ajax_config_xmltv_init();
ajax_config_access_init();
ajax_config_cwc_init();
}

View file

@ -1,322 +0,0 @@
/*
* tvheadend, AJAX / HTML user interface
* Copyright (C) 2008 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "tvhead.h"
#include "http.h"
#include "ajaxui.h"
#include "channels.h"
#include "psi.h"
#include "transports.h"
#include "ajaxui_mailbox.h"
static struct strtab accesstypetab[] = {
{ "stream", ACCESS_STREAMING },
{ "rec", ACCESS_RECORDER_VIEW },
{ "recedit", ACCESS_RECORDER_CHANGE },
{ "admin", ACCESS_ADMIN },
{ "webui", ACCESS_WEB_INTERFACE },
{ "access", ACCESS_ADMIN_ACCESS },
};
/**
* Access configuration
*/
int
ajax_config_access_tab(http_connection_t *hc, http_reply_t *hr)
{
htsbuf_queue_t *tq = &hr->hr_q;
if(access_verify(hc->hc_username, hc->hc_password,
(struct sockaddr *)&hc->hc_tcp_session.tcp_peer_addr,
AJAX_ACCESS_ACCESSCTRL))
return HTTP_STATUS_UNAUTHORIZED;
htsbuf_qprintf(tq, "<div style=\"overflow: auto; width: 100%\">");
ajax_box_begin(tq, AJAX_BOX_SIDEBOX, NULL, NULL, "Access control");
htsbuf_qprintf(tq, "<div id=\"alist\"></div>");
ajax_js(tq,
"new Ajax.Updater('alist', '/ajax/accesslist', "
"{method: 'get', evalScripts: true});");
htsbuf_qprintf(tq, "<hr><div style=\"overflow: auto; width: 100%\">");
htsbuf_qprintf(tq,
"<div style=\"height: 20px;\">"
"<div style=\"float: left; margin-right: 4px\">"
"<input type=\"text\" id=\"newuser\">"
"<input type=\"button\" value=\"Add\" "
"onClick=\"new Ajax.Request('/ajax/accessadd', "
"{parameters: {name: $F('newuser')}, method: 'post'})\">"
"</div>"
"</div>");
htsbuf_qprintf(tq, "</div>\r\n");
ajax_box_end(tq, AJAX_BOX_SIDEBOX);
htsbuf_qprintf(tq, "</div>");
http_output_html(hc, hr);
return 0;
}
static void
ajax_access_checkbox(ajax_table_t *ta, access_entry_t *ae, int mask,
const char *n)
{
ajax_table_cell(ta, NULL,
"<input %stype=\"checkbox\" class=\"nicebox\" "
"onChange=\"new Ajax.Request('/ajax/accesschange/%d', "
"{parameters: {entry: '%s', checked: this.checked}})\">",
ae->ae_rights & mask ? "checked " : "",
ae->ae_tally, n);
}
/**
*
*/
static int
ajax_accesslist(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
access_entry_t *ae;
ajax_table_t ta;
char id[100];
ajax_table_top(&ta, hc, tq,
(const char *[]){"User or Prefix",
"Password",
"Streaming",
"Recorder",
"Recorder edit",
"Admin",
"Web UI",
"Accessedit",
"",
NULL},
(int[]){2, 2, 1, 1, 1, 1, 1, 1, 1, 1});
TAILQ_FOREACH(ae, &access_entries, ae_link) {
snprintf(id, sizeof(id), "%d", ae->ae_tally);
ajax_table_row_start(&ta, id);
ajax_table_cell(&ta, NULL, "%s", ae->ae_title);
if(access_is_prefix(ae)) {
ajax_table_cell(&ta, NULL, "%s", "n/a");
} else {
ajax_table_cell(&ta, "password",
"<a href=\"javascript:void(0)\" "
"onClick=\"makedivinput('password_%d', "
"'/ajax/accesssetpw/%d')\">"
"%s</a>",
ae->ae_tally, ae->ae_tally,
ae->ae_password != NULL ? "Change..." : "Set...");
}
ajax_access_checkbox(&ta, ae, ACCESS_STREAMING, "stream");
ajax_access_checkbox(&ta, ae, ACCESS_RECORDER_VIEW, "rec");
ajax_access_checkbox(&ta, ae, ACCESS_RECORDER_CHANGE, "recedit");
ajax_access_checkbox(&ta, ae, ACCESS_ADMIN, "admin");
ajax_access_checkbox(&ta, ae, ACCESS_WEB_INTERFACE, "webui");
ajax_access_checkbox(&ta, ae, ACCESS_ADMIN_ACCESS, "access");
ajax_table_cell(&ta, NULL,
"<a href=\"javascript:void(0)\" "
"onClick=\"dellistentry('/ajax/accessdel', '%d', '%s')\">"
"Delete...</a>",
ae->ae_tally, ae->ae_title);
}
ajax_table_bottom(&ta);
http_output_html(hc, hr);
return 0;
}
/**
*
*/
static int
ajax_accessadd(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
access_entry_t *ae;
const char *t;
if((t = http_arg_get(&hc->hc_req_args, "name")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
htsbuf_qprintf(tq, "$('newuser').clear();\r\n");
if(t == NULL || strlen(t) < 1 || strchr(t, '\'') || strchr(t, '"')) {
htsbuf_qprintf(tq, "alert('Invalid username');\r\n");
} else {
ae = access_add(t);
if(ae == NULL) {
htsbuf_qprintf(tq, "alert('Invalid prefix');\r\n");
} else {
htsbuf_qprintf(tq,
"new Ajax.Updater('alist', '/ajax/accesslist', "
"{method: 'get', evalScripts: true});\r\n");
}
}
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}
/**
*
*/
static int
ajax_accesschange(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
// htsbuf_queue_t *tq = &hr->hr_tq;
access_entry_t *ae;
const char *e, *c;
int bit;
if(remain == NULL || (ae = access_by_id(atoi(remain))) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((e = http_arg_get(&hc->hc_req_args, "entry")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((bit = str2val(e, accesstypetab)) < 0)
return HTTP_STATUS_BAD_REQUEST;
if((c = http_arg_get(&hc->hc_req_args, "checked")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if(!strcasecmp(c, "false")) {
ae->ae_rights &= ~bit;
} else if(!strcasecmp(c, "true")) {
ae->ae_rights |= bit;
} else {
return HTTP_STATUS_BAD_REQUEST;
}
access_save();
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}
/**
*
*/
static int
ajax_accessdel(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
access_entry_t *ae;
const char *e;
if((e = http_arg_get(&hc->hc_req_args, "id")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((ae = access_by_id(atoi(e))) == NULL)
return HTTP_STATUS_BAD_REQUEST;
access_delete(ae);
htsbuf_qprintf(tq,
"new Ajax.Updater('alist', '/ajax/accesslist', "
"{method: 'get', evalScripts: true});\r\n");
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}
/**
*
*/
static int
ajax_accesssetpw(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
access_entry_t *ae;
const char *e;
if(remain == NULL || (ae = access_by_id(atoi(remain))) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((e = http_arg_get(&hc->hc_req_args, "value")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
free(ae->ae_password);
ae->ae_password = strdup(e);
access_save();
htsbuf_qprintf(tq,
"$('password_%d').innerHTML= '"
"<a href=\"javascript:void(0)\" "
"onClick=\"makedivinput(\\'password_%d\\', "
"\\'/ajax/accesssetpw/%d\\')\">"
"%s</a>';",
ae->ae_tally, ae->ae_tally, ae->ae_tally, "Change...");
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}
/**
*
*/
void
ajax_config_access_init(void)
{
http_path_add("/ajax/accesslist" , NULL, ajax_accesslist,
AJAX_ACCESS_ACCESSCTRL);
http_path_add("/ajax/accessadd" , NULL, ajax_accessadd,
AJAX_ACCESS_ACCESSCTRL);
http_path_add("/ajax/accesschange" , NULL, ajax_accesschange,
AJAX_ACCESS_ACCESSCTRL);
http_path_add("/ajax/accessdel" , NULL, ajax_accessdel,
AJAX_ACCESS_ACCESSCTRL);
http_path_add("/ajax/accesssetpw" , NULL, ajax_accesssetpw,
AJAX_ACCESS_ACCESSCTRL);
}

View file

@ -1,755 +0,0 @@
/*
* tvheadend, AJAX / HTML user interface
* Copyright (C) 2008 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "tvhead.h"
#include "http.h"
#include "ajaxui.h"
#include "channels.h"
/**
* Render a channel group widget
*/
static void
ajax_chgroup_build(htsbuf_queue_t *tq, channel_group_t *tcg)
{
htsbuf_qprintf(tq, "<li id=\"chgrp_%d\">", tcg->tcg_tag);
ajax_box_begin(tq, AJAX_BOX_BORDER, NULL, NULL, NULL);
htsbuf_qprintf(tq, "<div style=\"overflow: auto; width: 100%\">");
htsbuf_qprintf(tq,
"<div style=\"float: left; width: 60%\">"
"<a href=\"javascript:void(0)\" "
"onClick=\"$('cheditortab').innerHTML=''; "
"new Ajax.Updater('groupeditortab', "
"'/ajax/chgroup_editor/%d', "
"{method: 'get', evalScripts: true})\" >"
"%s</a></div>",
tcg->tcg_tag, tcg->tcg_name);
if(tcg != defgroup) {
htsbuf_qprintf(tq,
"<div style=\"float: left; width: 40%\" "
"class=\"chgroupaction\">"
"<a href=\"javascript:void(0)\" "
"onClick=\"dellistentry('/ajax/chgroup_del','%d', '%s');\""
">Delete</a></div>",
tcg->tcg_tag, tcg->tcg_name);
}
htsbuf_qprintf(tq, "</div>");
ajax_box_end(tq, AJAX_BOX_BORDER);
htsbuf_qprintf(tq, "</li>");
}
/**
* Update order of channel groups
*/
static int
ajax_chgroup_updateorder(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
channel_group_t *tcg;
htsbuf_queue_t *tq = &hr->hr_q;
http_arg_t *ra;
TAILQ_FOREACH(ra, &hc->hc_req_args, link) {
if(strcmp(ra->key, "channelgrouplist[]") ||
(tcg = channel_group_by_tag(atoi(ra->val))) == NULL)
continue;
TAILQ_REMOVE(&all_channel_groups, tcg, tcg_global_link);
TAILQ_INSERT_TAIL(&all_channel_groups, tcg, tcg_global_link);
}
channel_group_settings_write();
htsbuf_qprintf(tq, "<span id=\"updatedok\">Updated on server</span>");
ajax_js(tq, "Effect.Fade('updatedok')");
http_output_html(hc, hr);
return 0;
}
/**
* Add a new channel group
*/
static int
ajax_chgroup_add(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
channel_group_t *tcg;
htsbuf_queue_t *tq = &hr->hr_q;
const char *name;
if((name = http_arg_get(&hc->hc_req_args, "name")) != NULL) {
TAILQ_FOREACH(tcg, &all_channel_groups, tcg_global_link)
if(!strcmp(name, tcg->tcg_name))
break;
if(tcg == NULL) {
tcg = channel_group_find(name, 1);
ajax_chgroup_build(tq, tcg);
/* We must recreate the Sortable object */
ajax_js(tq, "Sortable.destroy(\"channelgrouplist\")");
ajax_js(tq, "Sortable.create(\"channelgrouplist\", "
"{onUpdate:function(){updatelistonserver("
"'channelgrouplist', "
"'/ajax/chgroup_updateorder', "
"'list-info'"
")}});");
}
}
http_output_html(hc, hr);
return 0;
}
/**
* Delete a channel group
*/
static int
ajax_chgroup_del(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
channel_group_t *tcg;
htsbuf_queue_t *tq = &hr->hr_q;
const char *id;
if((id = http_arg_get(&hc->hc_req_args, "id")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((tcg = channel_group_by_tag(atoi(id))) == NULL)
return HTTP_STATUS_BAD_REQUEST;
htsbuf_qprintf(tq, "$('chgrp_%d').remove();", tcg->tcg_tag);
http_output(hc, hr, "text/javascript; charset=UTF-8", NULL, 0);
channel_group_destroy(tcg);
return 0;
}
/**
* Channel group & channel configuration
*/
int
ajax_config_channels_tab(http_connection_t *hc, http_reply_t *hr)
{
htsbuf_queue_t *tq = &hr->hr_q;
channel_group_t *tcg;
htsbuf_qprintf(tq, "<div style=\"float: left; width: 30%\">");
ajax_box_begin(tq, AJAX_BOX_SIDEBOX, "channelgroups",
NULL, "Channel groups");
htsbuf_qprintf(tq, "<div style=\"height:15px; text-align:center\" "
"id=\"list-info\"></div>");
htsbuf_qprintf(tq, "<ul id=\"channelgrouplist\" class=\"draglist\">");
TAILQ_FOREACH(tcg, &all_channel_groups, tcg_global_link) {
if(tcg->tcg_hidden)
continue;
ajax_chgroup_build(tq, tcg);
}
htsbuf_qprintf(tq, "</ul>");
ajax_js(tq, "Sortable.create(\"channelgrouplist\", "
"{onUpdate:function(){updatelistonserver("
"'channelgrouplist', "
"'/ajax/chgroup_updateorder', "
"'list-info'"
")}});");
/**
* Add new group
*/
htsbuf_qprintf(tq, "<hr>");
ajax_box_begin(tq, AJAX_BOX_BORDER, NULL, NULL, NULL);
htsbuf_qprintf(tq,
"<div style=\"height: 25px\">"
"<div style=\"float: left\">"
"<input type=\"text\" id=\"newchgrp\">"
"</div>"
"<div style=\"float: right\">"
"<input type=\"button\" value=\"Add\" "
"onClick=\"javascript:addlistentry_by_widget("
"'channelgrouplist', 'chgroup_add', 'newchgrp');\">"
"</div></div>");
ajax_box_end(tq, AJAX_BOX_BORDER);
ajax_box_end(tq, AJAX_BOX_SIDEBOX);
htsbuf_qprintf(tq, "</div>");
htsbuf_qprintf(tq,
"<div id=\"groupeditortab\" "
"style=\"overflow: auto; float: left; width: 30%\"></div>");
htsbuf_qprintf(tq,
"<div id=\"cheditortab\" "
"style=\"overflow: auto; float: left; width: 40%\"></div>");
http_output_html(hc, hr);
return 0;
}
/**
* Display all channels within the group
*/
static int
ajax_chgroup_editor(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
channel_t *ch;
channel_group_t *tcg, *tcg2;
th_transport_t *t;
char buf[10];
int nsources;
ajax_table_t ta;
if(remain == NULL || (tcg = channel_group_by_tag(atoi(remain))) == NULL)
return HTTP_STATUS_BAD_REQUEST;
htsbuf_qprintf(tq, "<script type=\"text/javascript\">\r\n"
"//<![CDATA[\r\n");
/* Select all */
htsbuf_qprintf(tq, "select_all = function() {\r\n");
TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
htsbuf_qprintf(tq,
"$('sel_%d').checked = true;\r\n",
ch->ch_tag);
}
htsbuf_qprintf(tq, "}\r\n");
/* Select none */
htsbuf_qprintf(tq, "select_none = function() {\r\n");
TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
htsbuf_qprintf(tq,
"$('sel_%d').checked = false;\r\n",
ch->ch_tag);
}
htsbuf_qprintf(tq, "}\r\n");
/* Invert selection */
htsbuf_qprintf(tq, "select_invert = function() {\r\n");
TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
htsbuf_qprintf(tq,
"$('sel_%d').checked = !$('sel_%d').checked;\r\n",
ch->ch_tag, ch->ch_tag);
}
htsbuf_qprintf(tq, "}\r\n");
/* Invert selection */
htsbuf_qprintf(tq, "select_sources = function() {\r\n");
TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
htsbuf_qprintf(tq,
"$('sel_%d').checked = %s;\r\n",
ch->ch_tag, LIST_FIRST(&ch->ch_transports) ? "true" : "false");
}
htsbuf_qprintf(tq, "}\r\n");
/* Invoke AJAX call containing all selected elements */
htsbuf_qprintf(tq,
"select_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"
);
TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
htsbuf_qprintf(tq,
"if($('sel_%d').checked) {h.set('%d', 'selected') }\r\n",
ch->ch_tag, ch->ch_tag);
}
htsbuf_qprintf(tq, " new Ajax.Request('/ajax/chop/' + op, "
"{parameters: h});\r\n");
htsbuf_qprintf(tq, "}\r\n");
htsbuf_qprintf(tq,
"\r\n//]]>\r\n"
"</script>\r\n");
ajax_box_begin(tq, AJAX_BOX_SIDEBOX, NULL, NULL, tcg->tcg_name);
ajax_table_top(&ta, hc, tq, (const char *[])
{"Channelname", "Sources", "", NULL},
(int[]){8,2,1});
TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
snprintf(buf, sizeof(buf), "%d", ch->ch_tag);
ajax_table_row_start(&ta, buf);
nsources = 0;
LIST_FOREACH(t, &ch->ch_transports, tht_ch_link)
nsources++;
ajax_table_cell(&ta, NULL,
"<a href=\"javascript:void(0)\" "
"onclick=\"new Ajax.Updater('cheditortab', "
"'/ajax/cheditor/%d', {method: 'get'})\""
">%s</a>", ch->ch_tag, ch->ch_name);
ajax_table_cell(&ta, NULL, "%d", nsources);
ajax_table_cell_checkbox(&ta);
}
ajax_table_bottom(&ta);
htsbuf_qprintf(tq, "<hr>\r\n");
htsbuf_qprintf(tq, "<div style=\"text-align: center; "
"overflow: auto; width: 100%\">");
ajax_button(tq, "Select all", "select_all()");
ajax_button(tq, "Select none", "select_none()");
ajax_button(tq, "Invert selection", "select_invert()");
ajax_button(tq, "Select channels with sources", "select_sources()");
htsbuf_qprintf(tq, "</div>\r\n");
htsbuf_qprintf(tq, "<hr>\r\n");
htsbuf_qprintf(tq, "<div style=\"text-align: center; "
"overflow: auto; width: 100%\">");
ajax_button(tq,
"Delete all selected...",
"select_do('delete', '%d', 0, true);", tcg->tcg_tag);
htsbuf_qprintf(tq,
"<select id=\"movetarget\" "
"onChange=\"select_do('changegroup', "
"$('movetarget').value, '%d', false)\">", tcg->tcg_tag);
htsbuf_qprintf(tq,
"<option value="">Move selected channels to group:</option>");
TAILQ_FOREACH(tcg2, &all_channel_groups, tcg_global_link) {
if(tcg2->tcg_hidden || tcg == tcg2)
continue;
htsbuf_qprintf(tq, "<option value=\"%d\">%s</option>",
tcg2->tcg_tag, tcg2->tcg_name);
}
htsbuf_qprintf(tq, "</select></div>");
htsbuf_qprintf(tq, "</div>");
htsbuf_qprintf(tq, "</div>");
ajax_box_end(tq, AJAX_BOX_SIDEBOX);
http_output_html(hc, hr);
return 0;
}
/**
*
*/
static struct strtab sourcetypetab[] = {
{ "DVB", TRANSPORT_DVB },
{ "V4L", TRANSPORT_V4L },
{ "IPTV", TRANSPORT_IPTV },
{ "AVgen", TRANSPORT_AVGEN },
{ "File", TRANSPORT_STREAMEDFILE },
};
static struct strtab cdlongname[] = {
{ "None", COMMERCIAL_DETECT_NONE },
{ "Swedish TV4 Teletext", COMMERCIAL_DETECT_TTP192 },
};
/**
* Display all channels within the group
*/
static int
ajax_cheditor(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
channel_t *ch, *ch2;
channel_group_t *chg;
th_transport_t *t;
const char *s;
int i;
if(remain == NULL || (ch = channel_by_tag(atoi(remain))) == NULL)
return HTTP_STATUS_BAD_REQUEST;
ajax_box_begin(tq, AJAX_BOX_SIDEBOX, NULL, NULL, ch->ch_name);
if(ch->ch_icon != NULL) {
htsbuf_qprintf(tq,
"<div style=\"width: 100%; text-align:center\">"
"<img src=\"%s\"></div>", ch->ch_icon);
}
htsbuf_qprintf(tq, "<div>Sources:</div>");
LIST_FOREACH(t, &ch->ch_transports, tht_ch_link) {
ajax_box_begin(tq, AJAX_BOX_BORDER, NULL, NULL, NULL);
htsbuf_qprintf(tq, "<div style=\"overflow: auto; width: 100%\">");
htsbuf_qprintf(tq, "<div style=\"float: left; width: 13%%\">%s</div>",
val2str(t->tht_type, sourcetypetab) ?: "???");
htsbuf_qprintf(tq, "<div style=\"float: left; width: 87%%\">\"%s\"%s</div>",
t->tht_svcname, t->tht_scrambled ? " - (scrambled)" : "");
s = t->tht_sourcename ? t->tht_sourcename(t) : NULL;
htsbuf_qprintf(tq, "</div><div style=\"overflow: auto; width: 100%\">");
htsbuf_qprintf(tq,
"<div style=\"float: left; width: 13%%\">"
"<input %stype=\"checkbox\" class=\"nicebox\" "
"onClick=\"new Ajax.Request('/ajax/transport_chdisable/%s', "
"{parameters: {enabled: this.checked}});\">"
"</div>", t->tht_disabled ? "" : "checked ",
t->tht_identifier);
if(s != NULL)
htsbuf_qprintf(tq, "<div style=\"float: left; width: 87%%\">%s</div>",
s);
htsbuf_qprintf(tq, "</div>");
ajax_box_end(tq, AJAX_BOX_BORDER);
}
htsbuf_qprintf(tq, "<hr>\r\n");
htsbuf_qprintf(tq, "<div style=\"overflow: auto; width:100%%\">");
htsbuf_qprintf(tq,
"<input type=\"button\" value=\"Rename...\" "
"onClick=\"channel_rename('%d', '%s')\">",
ch->ch_tag, ch->ch_name);
htsbuf_qprintf(tq,
"<input type=\"button\" value=\"Delete...\" "
"onClick=\"channel_delete('%d', '%s')\">",
ch->ch_tag, ch->ch_name);
htsbuf_qprintf(tq,
"<select "
"onChange=\"channel_merge('%d', this.value);\">",
ch->ch_tag);
htsbuf_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)
htsbuf_qprintf(tq, "<option value=\"%d\">%s</option>",
ch2->ch_tag, ch2->ch_name);
}
}
htsbuf_qprintf(tq, "</select>");
htsbuf_qprintf(tq, "</div>");
htsbuf_qprintf(tq, "<hr>\r\n");
htsbuf_qprintf(tq,
"<div class=\"infoprefixwidewidefat\">"
"Commercial detection:</div>"
"<div>"
"<select "
"onChange=\"new Ajax.Request('/ajax/chsetcomdetect/%d', "
"{parameters: {how: this.value}});\">",
ch->ch_tag);
for(i = 0; i < sizeof(cdlongname) / sizeof(cdlongname[0]); i++) {
htsbuf_qprintf(tq, "<option %svalue=%d>%s</option>",
cdlongname[i].val == ch->ch_commercial_detection ?
"selected " : "",
cdlongname[i].val, cdlongname[i].str);
}
htsbuf_qprintf(tq, "</select></div>");
htsbuf_qprintf(tq, "</div>");
ajax_box_end(tq, AJAX_BOX_SIDEBOX);
http_output_html(hc, hr);
return 0;
}
/**
* Change group for channel(s)
*/
static int
ajax_changegroup(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
channel_t *ch;
channel_group_t *tcg;
http_arg_t *ra;
const char *s;
const char *curgrp;
if((s = http_arg_get(&hc->hc_req_args, "arg1")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((curgrp = http_arg_get(&hc->hc_req_args, "arg2")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
tcg = channel_group_by_tag(atoi(s));
if(tcg == NULL)
return HTTP_STATUS_BAD_REQUEST;
TAILQ_FOREACH(ra, &hc->hc_req_args, link) {
if(strcmp(ra->val, "selected"))
continue;
if((ch = channel_by_tag(atoi(ra->key))) != NULL)
channel_set_group(ch, tcg);
}
htsbuf_qprintf(tq,
"$('cheditortab').innerHTML=''; "
"new Ajax.Updater('groupeditortab', "
"'/ajax/chgroup_editor/%s', "
"{method: 'get', evalScripts: true});", curgrp);
http_output(hc, hr, "text/javascript; charset=UTF-8", NULL, 0);
return 0;
}
/**
* Change commercial detection type for channel(s)
*/
static int
ajax_chsetcomdetect(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
channel_t *ch;
const char *s;
if(remain == NULL || (ch = channel_by_tag(atoi(remain))) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((s = http_arg_get(&hc->hc_req_args, "how")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
ch->ch_commercial_detection = atoi(s);
channel_settings_write(ch);
http_output(hc, hr, "text/javascript; charset=UTF-8", NULL, 0);
return 0;
}
/**
* Rename a channel
*/
static int
ajax_chrename(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
channel_t *ch;
const char *s;
if(remain == NULL || (ch = channel_by_tag(atoi(remain))) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((s = http_arg_get(&hc->hc_req_args, "newname")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if(channel_rename(ch, s)) {
htsbuf_qprintf(tq, "alert('Channel already exist');");
} else {
htsbuf_qprintf(tq,
"new Ajax.Updater('groupeditortab', "
"'/ajax/chgroup_editor/%d', "
"{method: 'get', evalScripts: true});\r\n",
ch->ch_group->tcg_tag);
htsbuf_qprintf(tq,
"new Ajax.Updater('cheditortab', "
"'/ajax/cheditor/%d', "
"{method: 'get', evalScripts: true});\r\n",
ch->ch_tag);
}
http_output(hc, hr, "text/javascript; charset=UTF-8", NULL, 0);
return 0;
}
/**
* Delete channel
*/
static int
ajax_chdelete(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
channel_t *ch;
channel_group_t *tcg;
if(remain == NULL || (ch = channel_by_tag(atoi(remain))) == NULL)
return HTTP_STATUS_BAD_REQUEST;
tcg = ch->ch_group;
channel_delete(ch);
htsbuf_qprintf(tq,
"new Ajax.Updater('groupeditortab', "
"'/ajax/chgroup_editor/%d', "
"{method: 'get', evalScripts: true});\r\n",
tcg->tcg_tag);
htsbuf_qprintf(tq, "$('cheditortab').innerHTML='';\r\n");
http_output(hc, hr, "text/javascript; charset=UTF-8", NULL, 0);
return 0;
}
/**
* Merge channel
*/
static int
ajax_chmerge(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
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);
htsbuf_qprintf(tq,
"new Ajax.Updater('groupeditortab', "
"'/ajax/chgroup_editor/%d', "
"{method: 'get', evalScripts: true});\r\n",
tcg->tcg_tag);
htsbuf_qprintf(tq, "$('cheditortab').innerHTML='';\r\n");
http_output(hc, hr, "text/javascript; charset=UTF-8", NULL, 0);
return 0;
}
/**
* Change group for channel(s)
*/
static int
ajax_chdeletemulti(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *tq = &hr->hr_q;
channel_t *ch;
http_arg_t *ra;
const char *curgrp;
if((curgrp = http_arg_get(&hc->hc_req_args, "arg1")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
TAILQ_FOREACH(ra, &hc->hc_req_args, link) {
if(strcmp(ra->val, "selected"))
continue;
if((ch = channel_by_tag(atoi(ra->key))) != NULL)
channel_delete(ch);
}
htsbuf_qprintf(tq,
"$('cheditortab').innerHTML=''; "
"new Ajax.Updater('groupeditortab', "
"'/ajax/chgroup_editor/%s', "
"{method: 'get', evalScripts: true});", curgrp);
http_output(hc, hr, "text/javascript; charset=UTF-8", NULL, 0);
return 0;
}
/**
*
*/
void
ajax_config_channels_init(void)
{
http_path_add("/ajax/chgroup_add" , NULL, ajax_chgroup_add,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/chgroup_del" , NULL, ajax_chgroup_del,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/chgroup_updateorder", NULL, ajax_chgroup_updateorder,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/chgroup_editor", NULL, ajax_chgroup_editor,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/cheditor", NULL, ajax_cheditor,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/chop/changegroup", NULL, ajax_changegroup,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/chsetcomdetect", NULL, ajax_chsetcomdetect,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/chrename", NULL, ajax_chrename,
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);
http_path_add("/ajax/chop/delete", NULL, ajax_chdeletemulti,
AJAX_ACCESS_CONFIG);
}

View file

@ -1,264 +0,0 @@
/*
* tvheadend, AJAX / HTML user interface
* Copyright (C) 2008 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "tvhead.h"
#include "http.h"
#include "ajaxui.h"
#include "cwc.h"
/**
* CWC configuration
*/
int
ajax_config_cwc_tab(http_connection_t *hc, http_reply_t *hr)
{
htsbuf_queue_t *q = &hr->hr_q;
ajax_box_begin(q, AJAX_BOX_SIDEBOX, NULL, NULL, "Code-word Client");
htsbuf_qprintf(q, "<div id=\"cwclist\"></div>");
ajax_js(q,
"new Ajax.Updater('cwclist', '/ajax/cwclist', "
"{method: 'get', evalScripts: true});");
htsbuf_qprintf(q, "<hr><div style=\"overflow: auto; width: 100%\">");
htsbuf_qprintf(q,
"<div class=\"cell_100\">"
"<div class=\"infoprefixwidewidefat\">Hostname:</div>"
"<div>"
"<input type=\"text\" size=40 id=\"hostname\">"
"</div></div>");
htsbuf_qprintf(q,
"<div class=\"cell_100\">"
"<div class=\"infoprefixwidewidefat\">Port:</div>"
"<div>"
"<input type=\"text\" id=\"port\">"
"</div></div>");
htsbuf_qprintf(q,
"<div class=\"cell_100\">"
"<div class=\"infoprefixwidewidefat\">Username:</div>"
"<div>"
"<input type=\"text\" id=\"username\">"
"</div></div>");
htsbuf_qprintf(q,
"<div class=\"cell_100\">"
"<div class=\"infoprefixwidewidefat\">Password:</div>"
"<div>"
"<input type=\"password\" id=\"password\">"
"</div></div>");
htsbuf_qprintf(q,
"<div class=\"cell_100\">"
"<div class=\"infoprefixwidewidefat\">DES-key:</div>"
"<div>"
"<input type=\"text\" size=50 id=\"deskey\">"
"</div></div>");
htsbuf_qprintf(q,
"<br>"
"<input type=\"button\" value=\"Add new server entry\" "
"onClick=\"new Ajax.Request('/ajax/cwcadd', "
"{parameters: {"
"'hostname': $F('hostname'), "
"'port': $F('port'), "
"'username': $F('username'), "
"'password': $F('password'), "
"'deskey': $F('deskey') "
"}})"
"\">");
htsbuf_qprintf(q, "</div>\r\n");
ajax_box_end(q, AJAX_BOX_SIDEBOX);
htsbuf_qprintf(q, "</div>");
http_output_html(hc, hr);
return 0;
}
/**
*
*/
static int
ajax_cwclist(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *q = &hr->hr_q;
ajax_table_t ta;
cwc_t *cwc;
char id[20];
ajax_table_top(&ta, hc, q,
(const char *[]){"Code-word Server",
"Username",
"Enabled",
"Status",
"",
NULL},
(int[]){3, 2, 1, 12, 1});
TAILQ_FOREACH(cwc, &cwcs, cwc_link) {
snprintf(id, sizeof(id), "cwc_%d", cwc->cwc_id);
ajax_table_row_start(&ta, id);
ajax_table_cell(&ta, NULL, "%s:%d",
cwc->cwc_tcp_session.tcp_hostname,
cwc->cwc_tcp_session.tcp_port);
ajax_table_cell(&ta, NULL, "%s", cwc->cwc_username);
ajax_table_cell(&ta, NULL,
"<input %stype=\"checkbox\" class=\"nicebox\" "
"onChange=\"new Ajax.Request('/ajax/cwcchange', "
"{parameters: {checked: this.checked, id: %d}})\">",
cwc->cwc_tcp_session.tcp_enabled
? "checked " : "", cwc->cwc_id);
ajax_table_cell(&ta, "status", cwc_status_to_text(cwc));
ajax_table_cell(&ta, NULL,
"<a href=\"javascript:void(0)\" "
"onClick=\"dellistentry('/ajax/cwcdel', '%d', '%s')\">"
"Delete...</a>",
cwc->cwc_id, cwc->cwc_tcp_session.tcp_hostname);
}
ajax_table_bottom(&ta);
http_output_html(hc, hr);
return 0;
}
/**
*
*/
static int
ajax_cwcadd(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *q = &hr->hr_q;
const char *errtxt;
errtxt = cwc_add(http_arg_get(&hc->hc_req_args, "hostname"),
http_arg_get(&hc->hc_req_args, "port"),
http_arg_get(&hc->hc_req_args, "username"),
http_arg_get(&hc->hc_req_args, "password"),
http_arg_get(&hc->hc_req_args, "deskey"),
"1", 1, 1);
if(errtxt != NULL) {
htsbuf_qprintf(q, "alert('%s');", errtxt);
} else {
htsbuf_qprintf(q, "$('hostname').clear();\r\n");
htsbuf_qprintf(q, "$('port').clear();\r\n");
htsbuf_qprintf(q, "$('username').clear();\r\n");
htsbuf_qprintf(q, "$('password').clear();\r\n");
htsbuf_qprintf(q, "$('deskey').clear();\r\n");
htsbuf_qprintf(q,
"new Ajax.Updater('cwclist', '/ajax/cwclist', "
"{method: 'get', evalScripts: true});");
}
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}
/**
*
*/
static int
ajax_cwcdel(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
htsbuf_queue_t *q = &hr->hr_q;
const char *txt;
cwc_t *cwc;
if((txt = http_arg_get(&hc->hc_req_args, "id")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((cwc = cwc_find(atoi(txt))) == NULL)
return HTTP_STATUS_BAD_REQUEST;
cwc_delete(cwc);
htsbuf_qprintf(q,
"new Ajax.Updater('cwclist', '/ajax/cwclist', "
"{method: 'get', evalScripts: true});");
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}
/**
*
*/
static int
ajax_cwcchange(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
// htsbuf_queue_t *q = &hr->hr_q;
const char *txt;
cwc_t *cwc;
if((txt = http_arg_get(&hc->hc_req_args, "id")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((cwc = cwc_find(atoi(txt))) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((txt = http_arg_get(&hc->hc_req_args, "checked")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
cwc_set_enable(cwc, !strcmp(txt, "true"));
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}
/**
*
*/
void
ajax_config_cwc_init(void)
{
http_path_add("/ajax/cwclist" , NULL, ajax_cwclist,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/cwcadd" , NULL, ajax_cwcadd,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/cwcdel" , NULL, ajax_cwcdel,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/cwcchange" , NULL, ajax_cwcchange,
AJAX_ACCESS_CONFIG);
}

File diff suppressed because it is too large Load diff

View file

@ -1,338 +0,0 @@
/*
* tvheadend, AJAX / HTML user interface
* Copyright (C) 2008 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "tvhead.h"
#include "http.h"
#include "ajaxui.h"
#include "channels.h"
#include "psi.h"
#include "transports.h"
#include "serviceprobe.h"
/**
*
*/
int
ajax_transport_build_list(http_connection_t *hc, htsbuf_queue_t *tq,
struct th_transport_tree *tlist, int numtransports)
{
th_transport_t *t;
ajax_table_t ta;
htsbuf_qprintf(tq, "<script type=\"text/javascript\">\r\n"
"//<![CDATA[\r\n");
/* Select all */
htsbuf_qprintf(tq, "select_all = function() {\r\n");
RB_FOREACH(t, tlist, tht_tmp_link) {
htsbuf_qprintf(tq,
"$('sel_%s').checked = true;\r\n",
t->tht_identifier);
}
htsbuf_qprintf(tq, "}\r\n");
/* Select none */
htsbuf_qprintf(tq, "select_none = function() {\r\n");
RB_FOREACH(t, tlist, tht_tmp_link) {
htsbuf_qprintf(tq,
"$('sel_%s').checked = false;\r\n",
t->tht_identifier);
}
htsbuf_qprintf(tq, "}\r\n");
/* Invert selection */
htsbuf_qprintf(tq, "select_invert = function() {\r\n");
RB_FOREACH(t, tlist, tht_tmp_link) {
htsbuf_qprintf(tq,
"$('sel_%s').checked = !$('sel_%s').checked;\r\n",
t->tht_identifier, t->tht_identifier);
}
htsbuf_qprintf(tq, "}\r\n");
/* Select TV transports */
htsbuf_qprintf(tq, "select_tv = function() {\r\n");
RB_FOREACH(t, tlist, tht_tmp_link) {
htsbuf_qprintf(tq,
"$('sel_%s').checked = %s;\r\n",
t->tht_identifier,
transport_is_tv(t) ? "true" : "false");
}
htsbuf_qprintf(tq, "}\r\n");
/* Select unscrambled TV transports */
htsbuf_qprintf(tq, "select_tv_nocrypt = function() {\r\n");
RB_FOREACH(t, tlist, tht_tmp_link) {
htsbuf_qprintf(tq,
"$('sel_%s').checked = %s;\r\n",
t->tht_identifier,
transport_is_tv(t) && !t->tht_scrambled ? "true" : "false");
}
htsbuf_qprintf(tq, "}\r\n");
/* Perform the given op on all transprots */
htsbuf_qprintf(tq, "selected_do = function(op) {\r\n"
"var h = new Hash();\r\n"
);
RB_FOREACH(t, tlist, tht_tmp_link) {
htsbuf_qprintf(tq,
"if($('sel_%s').checked) {h.set('%s', 'selected') }\r\n",
t->tht_identifier, t->tht_identifier);
}
htsbuf_qprintf(tq, " new Ajax.Request('/ajax/transport_op/' + op, "
"{parameters: h});\r\n");
htsbuf_qprintf(tq, "}\r\n");
htsbuf_qprintf(tq,
"\r\n//]]>\r\n"
"</script>\r\n");
/* Top */
htsbuf_qprintf(tq, "<form id=\"transports\">");
ajax_table_top(&ta, hc, tq,
(const char *[]){"Last status", "Crypto",
"Type", "Source service",
"", "Target channel", "", NULL},
(int[]){8,4,4,12,3,12,1});
RB_FOREACH(t, tlist, tht_tmp_link) {
ajax_table_row_start(&ta, t->tht_identifier);
ajax_table_cell(&ta, "status",
transport_status_to_text(t->tht_last_status));
ajax_table_cell(&ta, NULL, "%s", t->tht_scrambled ? "Yes" : "No");
ajax_table_cell(&ta, NULL, "%s", transport_servicetype_txt(t));
ajax_table_cell(&ta, NULL, "%s", t->tht_svcname ?: "");
ajax_table_cell(&ta, NULL,
"<a href=\"javascript:void(0)\" "
"onClick=\"new Ajax.Request('/ajax/transport_op/toggle', "
"{parameters: {'%s': 'selected'}})\">"
"<img id=\"map_%s\" src=\"/gfx/%smapped.png\"></a>",
t->tht_identifier, t->tht_identifier,
t->tht_ch ? "" : "un");
if(t->tht_ch == NULL) {
/* Unmapped */
ajax_table_cell(&ta, "chname",
"<a href=\"javascript:void(0)\" "
"onClick=\"tentative_chname('chname%s', "
"'/ajax/transport_rename_channel/%s', '%s')\">"
"%s</a>",
t->tht_identifier, t->tht_identifier,
t->tht_chname, t->tht_chname);
} else {
ajax_table_cell(&ta, "chname", "%s", t->tht_ch->ch_name);
}
ajax_table_cell_checkbox(&ta);
}
ajax_table_bottom(&ta);
htsbuf_qprintf(tq, "<hr>\r\n");
htsbuf_qprintf(tq, "<div style=\"overflow: auto; width: 100%\">");
ajax_button(tq, "Select all", "select_all()");
ajax_button(tq, "Select none", "select_none()");
// htsbuf_qprintf(tq, "</div>\r\n");
//htsbuf_qprintf(tq, "<div style=\"overflow: auto; width: 100%\">");
ajax_button(tq, "Map selected", "selected_do('map');");
ajax_button(tq, "Unmap selected", "selected_do('unmap');");
ajax_button(tq, "Test and map selected", "selected_do('probe');");
htsbuf_qprintf(tq, "</div>");
htsbuf_qprintf(tq, "</form>");
return 0;
}
/**
* Rename of unmapped channel
*/
static int
ajax_transport_rename_channel(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
th_transport_t *t;
const char *newname;
htsbuf_queue_t *tq = &hr->hr_q;
if(remain == NULL || (t = transport_find_by_identifier(remain)) == NULL)
return HTTP_STATUS_NOT_FOUND;
if((newname = http_arg_get(&hc->hc_req_args, "newname")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
free((void *)t->tht_chname);
t->tht_chname = strdup(newname);
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;
}
/**
*
*/
void
ajax_transport_build_mapper_state(char *buf, size_t siz, th_transport_t *t,
int mapped)
{
if(mapped) {
snprintf(buf, siz,
"$('chname_%s').innerHTML='%s';\n\r"
"$('map_%s').src='/gfx/mapped.png';\n\r",
t->tht_identifier, t->tht_ch->ch_name,
t->tht_identifier);
} else {
snprintf(buf, siz,
"$('chname_%s').innerHTML='"
"<a href=\"javascript:void(0)\" "
"onClick=\"javascript:tentative_chname(\\'chname_%s\\', "
"\\'/ajax/transport_rename_channel/%s\\', \\'%s\\')\">%s</a>"
"';\n\r"
"$('map_%s').src='/gfx/unmapped.png';\n\r",
t->tht_identifier, t->tht_identifier, t->tht_identifier,
t->tht_chname, t->tht_chname, t->tht_identifier);
}
}
/**
*
*/
static void
ajax_map_unmap_channel(th_transport_t *t, htsbuf_queue_t *tq, int map)
{
char buf[1000];
if(map)
transport_map_channel(t, NULL);
else
transport_unmap_channel(t);
ajax_transport_build_mapper_state(buf, sizeof(buf), t, map);
htsbuf_qprintf(tq, "%s", buf);
}
/**
*
*/
static int
ajax_transport_op(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
th_transport_t *t;
htsbuf_queue_t *tq = &hr->hr_q;
const char *op = remain;
http_arg_t *ra;
if(op == NULL)
return HTTP_STATUS_NOT_FOUND;
TAILQ_FOREACH(ra, &hc->hc_req_args, link) {
if(strcmp(ra->val, "selected"))
continue;
if((t = transport_find_by_identifier(ra->key)) == NULL)
continue;
if(!strcmp(op, "toggle")) {
ajax_map_unmap_channel(t, tq, t->tht_ch ? 0 : 1);
} else if(!strcmp(op, "map") && t->tht_ch == NULL) {
ajax_map_unmap_channel(t, tq, 1);
} else if(!strcmp(op, "unmap") && t->tht_ch != NULL) {
ajax_map_unmap_channel(t, tq, 0);
} else if(!strcmp(op, "probe")) {
serviceprobe_add(t);
continue;
}
t->tht_config_change(t);
}
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}
/**
*
*/
static int
ajax_transport_chdisable(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
th_transport_t *t;
const char *s;
if(remain == NULL || (t = transport_find_by_identifier(remain)) == NULL)
return HTTP_STATUS_NOT_FOUND;
if((s = http_arg_get(&hc->hc_req_args, "enabled")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
t->tht_disabled = !strcasecmp(s, "false");
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
t->tht_config_change(t);
return 0;
}
/**
*
*/
void
ajax_config_transport_init(void)
{
http_path_add("/ajax/transport_rename_channel", NULL,
ajax_transport_rename_channel,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/transport_op", NULL,
ajax_transport_op,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/transport_chdisable", NULL,
ajax_transport_chdisable,
AJAX_ACCESS_CONFIG);
}

View file

@ -1,334 +0,0 @@
/*
* tvheadend, AJAX / HTML user interface
* Copyright (C) 2008 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "tvhead.h"
#include "http.h"
#include "ajaxui.h"
#include "channels.h"
#include "epg_xmltv.h"
#include "psi.h"
#include "transports.h"
#include "ajaxui_mailbox.h"
/**
* XMLTV configuration
*/
int
ajax_config_xmltv_tab(http_connection_t *hc, http_reply_t *hr)
{
htsbuf_queue_t *tq = &hr->hr_q;
xmltv_grabber_t *xg;
int ngrabbers = 0;
ajax_table_t ta;
htsbuf_qprintf(tq, "<div style=\"overflow: auto; width: 100%\">");
switch(xmltv_globalstatus) {
default:
htsbuf_qprintf(tq, "<p style=\"text-align: center; font-weight: bold\">"
"XMLTV subsystem is not yet fully initialized, please retry "
"in a few seconds</p></div>");
http_output_html(hc, hr);
return 0;
case XMLTVSTATUS_FIND_GRABBERS_NOT_FOUND:
htsbuf_qprintf(tq, "<p style=\"text-align: center; font-weight: bold\">"
"XMLTV subsystem can not initialize</p>"
"<p style=\"text-align: center\">"
"Make sure that the 'tv_find_grabbers' executable is in "
"the system path</p></div>");
http_output_html(hc, hr);
return 0;
case XMLTVSTATUS_RUNNING:
break;
}
htsbuf_qprintf(tq, "<div style=\"float: left; width:45%\">");
ajax_box_begin(tq, AJAX_BOX_SIDEBOX, NULL, NULL, "XMLTV grabbers");
LIST_FOREACH(xg, &xmltv_grabbers, xg_link)
ngrabbers++;
ajax_table_top(&ta, hc, tq,
(const char *[]){"Grabber", "Status", NULL},
(int[]){4,2});
LIST_FOREACH(xg, &xmltv_grabbers, xg_link) {
ajax_table_row_start(&ta, xg->xg_identifier);
ajax_table_cell(&ta, NULL,
"<a href=\"javascript:void(0);\" "
"onClick=\"new Ajax.Updater('grabberpane', "
"'/ajax/xmltvgrabber/%s', {method: 'get', evalScripts: true})\""
">%s</a>", xg->xg_identifier, xg->xg_title);
ajax_table_cell(&ta, "status", xmltv_grabber_status(xg));
}
ajax_table_bottom(&ta);
ajax_box_end(tq, AJAX_BOX_SIDEBOX);
htsbuf_qprintf(tq, "</div>"
"<div id=\"grabberpane\" style=\"float: left; width:55%\">"
"</div>");
htsbuf_qprintf(tq, "</div>");
http_output_html(hc, hr);
return 0;
}
/**
* Generate displaylisting
*/
static void
xmltv_grabber_chlist(htsbuf_queue_t *tq, xmltv_grabber_t *xg)
{
xmltv_channel_t *xc;
channel_group_t *tcg;
channel_t *ch;
htsbuf_qprintf(tq,
"<div style=\"overflow: auto; height: 450px\">");
TAILQ_FOREACH(xc, &xg->xg_channels, xc_link) {
htsbuf_qprintf(tq,
"<div style=\"overflow: auto; width: 100%%\">");
htsbuf_qprintf(tq, "<div class=\"iconbackdrop\">");
if(xc->xc_icon_url != NULL) {
htsbuf_qprintf(tq,
"<img style=\"border: 0px;\" src=\"%s\" height=62px\">",
xc->xc_icon_url);
} else {
htsbuf_qprintf(tq,
"<div style=\"margin-top: 20px; text-align: center\">"
"No icon</div>");
}
htsbuf_qprintf(tq, "</div>"); /* iconbackdrop */
htsbuf_qprintf(tq,
"<div class=\"infoprefixwide\">Name:</div>"
"<div>%s (%s)</div>", xc->xc_displayname, xc->xc_name);
htsbuf_qprintf(tq,
"<div class=\"infoprefixwide\">Auto mapper:</div>"
"<div>%s</div>", xc->xc_bestmatch ?: "(no channel)");
htsbuf_qprintf(tq,
"<div class=\"infoprefixwidefat\">Channel:</div>"
"<select class=\"textinput\" "
"onChange=\"new Ajax.Request('/ajax/xmltvgrabberchmap/%s', "
"{parameters: { xmltvch: '%s', channel: this.value }})\">",
xg->xg_identifier, xc->xc_name);
htsbuf_qprintf(tq, "<option value=\"auto\">Automatic mapper</option>",
!xc->xc_disabled && xc->xc_channel == NULL ? " selected" : "");
htsbuf_qprintf(tq, "<option value=\"none\"%s>No channel</option>",
xc->xc_disabled ? " selected" : "");
TAILQ_FOREACH(tcg, &all_channel_groups, tcg_global_link) {
if(tcg->tcg_hidden)
continue;
TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
if(LIST_FIRST(&ch->ch_transports) == NULL)
continue;
htsbuf_qprintf(tq, "<option value=\"%d\"%s>%s</option>",
ch->ch_tag,
!strcmp(ch->ch_name, xc->xc_channel ?: "")
? " selected " : "", ch->ch_name);
}
}
htsbuf_qprintf(tq, "</select>");
htsbuf_qprintf(tq, "</div><hr>\r\n");
}
htsbuf_qprintf(tq, "</div>");
}
/**
* Display detailes about a grabber
*/
static int
ajax_xmltvgrabber(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
xmltv_grabber_t *xg;
htsbuf_queue_t *tq = &hr->hr_q;
if(remain == NULL || (xg = xmltv_grabber_find(remain)) == NULL)
return HTTP_STATUS_NOT_FOUND;
ajax_box_begin(tq, AJAX_BOX_SIDEBOX, NULL, NULL, xg->xg_title);
htsbuf_qprintf(tq,"<div id=\"details_%s\">", xg->xg_identifier);
if(xg->xg_enabled == 0) {
htsbuf_qprintf(tq,
"<p>This grabber is currently not enabled, click "
"<a href=\"javascript:void(0);\" "
"onClick=\"new Ajax.Request('/ajax/xmltvgrabbermode/%s', "
"{parameters: {'mode': 'enable'}})\">here</a> "
"to enable it</p>");
} else if(xg->xg_status == XMLTV_GRAB_OK) {
xmltv_grabber_chlist(tq, xg);
} else {
htsbuf_qprintf(tq, "<p>%s</p>", xmltv_grabber_status_long(xg));
}
htsbuf_qprintf(tq,"</div>");
ajax_box_end(tq, AJAX_BOX_SIDEBOX);
http_output_html(hc, hr);
return 0;
}
/**
* Enable / Disable a grabber
*/
static int
ajax_xmltvgrabbermode(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
xmltv_grabber_t *xg;
htsbuf_queue_t *tq = &hr->hr_q;
if(remain == NULL || (xg = xmltv_grabber_find(remain)) == NULL)
return HTTP_STATUS_NOT_FOUND;
xmltv_grabber_enable(xg);
htsbuf_qprintf(tq,"$('details_%s').innerHTML='Please wait...';",
xg->xg_identifier);
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}
/**
* Enable / Disable a grabber
*/
static int
ajax_xmltvgrabberlist(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
xmltv_grabber_t *xg;
htsbuf_queue_t *tq = &hr->hr_q;
if(remain == NULL || (xg = xmltv_grabber_find(remain)) == NULL)
return HTTP_STATUS_NOT_FOUND;
xmltv_grabber_chlist(tq, xg);
http_output_html(hc, hr);
return 0;
}
/**
* Change mapping of a channel for a grabber
*/
static int
ajax_xmltvgrabberchmap(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
xmltv_grabber_t *xg;
xmltv_channel_t *xc;
const char *xmltvname;
const char *chname;
channel_t *ch;
// htsbuf_queue_t *tq = &hr->hr_tq;
if(remain == NULL || (xg = xmltv_grabber_find(remain)) == NULL)
return HTTP_STATUS_NOT_FOUND;
if((xmltvname = http_arg_get(&hc->hc_req_args, "xmltvch")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
if((chname = http_arg_get(&hc->hc_req_args, "channel")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
TAILQ_FOREACH(xc, &xg->xg_channels, xc_link)
if(!strcmp(xc->xc_name, xmltvname))
break;
if(xc == NULL)
return HTTP_STATUS_BAD_REQUEST;
pthread_mutex_lock(&xg->xg_mutex);
free(xc->xc_channel);
xc->xc_channel = NULL;
xc->xc_disabled = 0;
if(!strcmp(chname, "none")) {
xc->xc_disabled = 1;
} else if(!strcmp(chname, "auto")) {
} else if((ch = channel_by_tag(atoi(chname))) != NULL) {
xc->xc_disabled = 0;
xc->xc_channel = strdup(ch->ch_name);
}
pthread_mutex_unlock(&xg->xg_mutex);
xmltv_config_save();
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}
/**
*
*/
void
ajax_config_xmltv_init(void)
{
http_path_add("/ajax/xmltvgrabber" , NULL, ajax_xmltvgrabber,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/xmltvgrabbermode" , NULL, ajax_xmltvgrabbermode,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/xmltvgrabberlist" , NULL, ajax_xmltvgrabberlist,
AJAX_ACCESS_CONFIG);
http_path_add("/ajax/xmltvgrabberchmap" , NULL, ajax_xmltvgrabberchmap,
AJAX_ACCESS_CONFIG);
}

View file

@ -1,502 +0,0 @@
/*
* tvheadend, AJAX / HTML Mailboxes
* Copyright (C) 2008 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <libavutil/md5.h>
#include "tvhead.h"
#include "dispatch.h"
#include "http.h"
#include "ajaxui.h"
#include "transports.h"
#include "epg_xmltv.h"
#include "dvb_support.h"
#include "ajaxui_mailbox.h"
#include "cwc.h"
#define MAILBOX_UNUSED_TIMEOUT 15
#define MAILBOX_EMPTY_REPLY_TIMEOUT 10
//#define mbdebug(fmt...) printf(fmt);
#define mbdebug(fmt...)
static LIST_HEAD(, ajaxui_mailbox) mailboxes;
int mailbox_tally;
TAILQ_HEAD(ajaxui_letter_queue, ajaxui_letter);
typedef struct ajaxui_letter {
TAILQ_ENTRY(ajaxui_letter) al_link;
char *al_payload_a;
char *al_payload_b;
} ajaxui_letter_t;
typedef struct ajaxui_mailbox {
LIST_ENTRY(ajaxui_mailbox) amb_link;
char *amb_boxid; /* an md5hash */
dtimer_t amb_timer;
http_reply_t *amb_hr; /* Pending request */
struct ajaxui_letter_queue amb_letters;
} ajaxui_mailbox_t;
/**
*
*/
static void
al_destroy(ajaxui_mailbox_t *amb, ajaxui_letter_t *al)
{
TAILQ_REMOVE(&amb->amb_letters, al, al_link);
free(al->al_payload_a);
free(al->al_payload_b);
free(al);
}
/**
*
*/
static void
amb_destroy(ajaxui_mailbox_t *amb)
{
ajaxui_letter_t *al;
mbdebug("mailbox[%s]: destroyed\n", amb->amb_boxid);
while((al = TAILQ_FIRST(&amb->amb_letters)) != NULL)
al_destroy(amb, al);
LIST_REMOVE(amb, amb_link);
dtimer_disarm(&amb->amb_timer);
free(amb->amb_boxid);
free(amb);
}
/**
*
*/
static void
ajax_mailbox_unused(void *opaque, int64_t now)
{
ajaxui_mailbox_t *amb = opaque;
assert(amb->amb_hr == NULL);
amb_destroy(amb);
}
/**
*
*/
static void
ajax_mailbox_connection_lost(http_reply_t *hr, void *opaque)
{
ajaxui_mailbox_t *amb = opaque;
assert(hr == amb->amb_hr);
amb_destroy(amb);
}
/**
*
*/
static ajaxui_mailbox_t *
ajax_mailbox_create(const char *id)
{
ajaxui_mailbox_t *amb = calloc(1, sizeof(ajaxui_mailbox_t));
amb->amb_boxid = strdup(id);
mailbox_tally++;
LIST_INSERT_HEAD(&mailboxes, amb, amb_link);
TAILQ_INIT(&amb->amb_letters);
dtimer_arm(&amb->amb_timer, ajax_mailbox_unused, amb,
MAILBOX_UNUSED_TIMEOUT);
return amb;
}
/**
*
*/
void
ajax_mailbox_start(htsbuf_queue_t *hq)
{
struct timeval tv;
uint8_t sum[16];
char id[33];
int i;
struct AVMD5 *ctx;
ctx = alloca(av_md5_size);
gettimeofday(&tv, NULL);
av_md5_init(ctx);
av_md5_update(ctx, (void *)&tv, sizeof(tv));
av_md5_update(ctx, (void *)&mailbox_tally, sizeof(uint32_t));
av_md5_final(ctx, sum);
for(i = 0; i < 16; i++) {
id[i * 2 + 0] = "0123456789abcdef"[sum[i] >> 4];
id[i * 2 + 1] = "0123456789abcdef"[sum[i] & 15];
}
id[32] = 0;
mbdebug("Generated mailbox %s\n", id);
ajax_mailbox_create(id);
ajax_js(hq, "mailboxquery('%s')", id);
}
/**
*
*/
static void
ajax_mailbox_reply(ajaxui_mailbox_t *amb, http_reply_t *hr)
{
ajaxui_letter_t *al;
/* Modify the hidden element (as described in ajax_mailbox_start()),
if this div no longer exist, the rest of the javascript will bail
out and we will not be reloaded */
mbdebug("mailbox[%s]: sending reply\n", amb->amb_boxid);
while((al = TAILQ_FIRST(&amb->amb_letters)) != NULL) {
htsbuf_qprintf(&hr->hr_q, "try {\r\n");
htsbuf_qprintf(&hr->hr_q, "%s%s",
al->al_payload_a, al->al_payload_b ?: "");
mbdebug("\t%s%s", al->al_payload_a, al->al_payload_b ?: "");
htsbuf_qprintf(&hr->hr_q, "}\r\n"
"catch(err) {}\r\n");
al_destroy(amb, al);
}
htsbuf_qprintf(&hr->hr_q, "mailboxquery('%s');\r\n", amb->amb_boxid);
http_output(hr->hr_connection, hr, "text/javascript", NULL, 0);
amb->amb_hr = NULL;
/* Arm a timer in case the browser won't call back */
dtimer_arm(&amb->amb_timer, ajax_mailbox_unused, amb,
MAILBOX_UNUSED_TIMEOUT);
}
/**
*
*/
static void
ajax_mailbox_empty_reply(void *opaque, int64_t now)
{
ajaxui_mailbox_t *amb = opaque;
http_reply_t *hr = amb->amb_hr;
ajax_mailbox_reply(amb, hr);
http_continue(hr->hr_connection);
}
/**
* Poll callback
*
* Prepare the mailbox for reply
*/
static int
ajax_mailbox_poll(http_connection_t *hc, http_reply_t *hr,
const char *remain, void *opaque)
{
ajaxui_mailbox_t *amb;
if(remain == NULL)
return HTTP_STATUS_NOT_FOUND;
mbdebug("mailbox[%s]: Incomming request ... ", remain);
LIST_FOREACH(amb, &mailboxes, amb_link)
if(!strcmp(amb->amb_boxid, remain))
break;
if(amb == NULL) {
amb = ajax_mailbox_create(remain);
mbdebug("creating mailbox ... ");
}
if(amb->amb_hr != NULL) {
mbdebug("mailbox already processing\n");
return 409;
}
if(TAILQ_FIRST(&amb->amb_letters) != NULL) {
/* Pending letters, direct reply */
mbdebug("direct reply\n");
ajax_mailbox_reply(amb, hr);
return 0;
}
mbdebug("nothing in queue, waiting\n");
amb->amb_hr = hr;
hr->hr_opaque = amb;
hr->hr_destroy = ajax_mailbox_connection_lost;
dtimer_arm(&amb->amb_timer, ajax_mailbox_empty_reply, amb,
MAILBOX_EMPTY_REPLY_TIMEOUT);
return 0;
}
/**
*
*/
void
ajax_mailbox_init(void)
{
http_path_add("/ajax/mailbox", NULL, ajax_mailbox_poll,
ACCESS_WEB_INTERFACE);
}
/**
* Delayed delivery of mailbox replies
*/
static void
ajax_mailbox_deliver(void *opaque, int64_t now)
{
ajaxui_mailbox_t *amb = opaque;
http_connection_t *hc;
hc = amb->amb_hr->hr_connection;
ajax_mailbox_reply(amb, amb->amb_hr);
http_continue(hc);
}
/**
*
*/
static void
ajax_mailbox_add_to_subscription(const char *subscription,
const char *content_a, const char *content_b)
{
ajaxui_mailbox_t *amb;
ajaxui_letter_t *al;
LIST_FOREACH(amb, &mailboxes, amb_link) {
/* Avoid inserting the same message twice */
TAILQ_FOREACH(al, &amb->amb_letters, al_link) {
if(!strcmp(al->al_payload_a, content_a))
break;
}
if(al == NULL) {
al = malloc(sizeof(ajaxui_letter_t));
al->al_payload_a = strdup(content_a);
} else {
/* Already exist, just move to tail */
TAILQ_REMOVE(&amb->amb_letters, al, al_link);
free(al->al_payload_b);
}
al->al_payload_b = content_b ? strdup(content_b) : NULL;
TAILQ_INSERT_TAIL(&amb->amb_letters, al, al_link);
if(amb->amb_hr != NULL)
dtimer_arm_hires(&amb->amb_timer, ajax_mailbox_deliver, amb,
getclock_hires() + 100000);
}
}
/**
*
*/
static void
ajax_mailbox_update_div(const char *subscription, const char *prefix,
const char *postfix, const char *content)
{
char buf_a[500];
char buf_b[500];
content = ajaxui_escape_apostrophe(content);
snprintf(buf_a, sizeof(buf_a), "$('%s_%s').innerHTML=", prefix, postfix);
snprintf(buf_b, sizeof(buf_b), "'%s';\n\r", content);
ajax_mailbox_add_to_subscription(subscription, buf_a, buf_b);
}
static void
ajax_mailbox_reload_div(const char *subscription, const char *prefix,
const char *postfix, const char *url)
{
char buf[1000];
snprintf(buf, sizeof(buf), "new Ajax.Updater('%s_%s', '%s', "
"{method: 'get', evalScripts: true});\r\n",
prefix, postfix, url);
ajax_mailbox_add_to_subscription(subscription, buf, NULL);
}
void
ajax_mailbox_tdmi_state_change(th_dvb_mux_instance_t *tdmi)
{
ajax_mailbox_update_div(tdmi->tdmi_adapter->tda_identifier,
"state", tdmi->tdmi_identifier,
dvb_mux_state(tdmi));
}
void
ajax_mailbox_tdmi_qual_change(th_dvb_mux_instance_t *tdmi)
{
char buf[10];
snprintf(buf, sizeof(buf), "%d%%",
dvb_quality_to_percent(tdmi->tdmi_quality));
ajax_mailbox_update_div(tdmi->tdmi_adapter->tda_identifier,
"qual", tdmi->tdmi_identifier,
buf);
}
void
ajax_mailbox_tdmi_name_change(th_dvb_mux_instance_t *tdmi)
{
ajax_mailbox_update_div(tdmi->tdmi_adapter->tda_identifier,
"name", tdmi->tdmi_identifier,
tdmi->tdmi_network ?: "<noname>");
}
void
ajax_mailbox_tdmi_status_change(th_dvb_mux_instance_t *tdmi)
{
ajax_mailbox_update_div(tdmi->tdmi_adapter->tda_identifier,
"status", tdmi->tdmi_identifier,
tdmi->tdmi_last_status);
}
void
ajax_mailbox_tdmi_services_change(th_dvb_mux_instance_t *tdmi)
{
th_transport_t *t;
char buf[20];
int n, m;
n = m = 0;
LIST_FOREACH(t, &tdmi->tdmi_transports, tht_mux_link) {
n++;
if(transport_is_available(t))
m++;
}
snprintf(buf, sizeof(buf), "%d / %d", m, n);
ajax_mailbox_update_div(tdmi->tdmi_adapter->tda_identifier,
"nsvc", tdmi->tdmi_identifier,
buf);
}
void
ajax_mailbox_tda_change(th_dvb_adapter_t *tda)
{
char buf[500];
snprintf(buf, sizeof(buf), "/ajax/dvbadaptermuxlist/%s",
tda->tda_identifier);
ajax_mailbox_reload_div(tda->tda_identifier,
"dvbmuxlist", tda->tda_identifier,
buf);
}
void
ajax_mailbox_xmltv_grabber_status_change(xmltv_grabber_t *xg)
{
char buf[500];
ajax_mailbox_update_div("xmltvgrabbers",
"status", xg->xg_identifier,
xmltv_grabber_status(xg));
if(xg->xg_status == XMLTV_GRAB_OK) {
snprintf(buf, sizeof(buf), "/ajax/xmltvgrabberlist/%s", xg->xg_identifier);
ajax_mailbox_reload_div("xmltvgrabbers",
"details", xg->xg_identifier,
buf);
} else {
ajax_mailbox_update_div(xg->xg_identifier,
"details", xg->xg_identifier,
xmltv_grabber_status_long(xg));
}
}
void
ajax_mailbox_transport_status_change(struct th_transport *t)
{
ajax_mailbox_update_div("xmltvgrabbers",
"status", t->tht_identifier,
transport_status_to_text(t->tht_last_status));
}
void
ajax_mailbox_cwc_status_change(struct cwc *cwc)
{
char id[20];
snprintf(id, sizeof(id), "cwc_%d", cwc->cwc_id);
ajax_mailbox_update_div("cwc", "status", id, cwc_status_to_text(cwc));
}

View file

@ -1,48 +0,0 @@
/*
* tvheadend, AJAX user interface
* Copyright (C) 2007 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <htmlui://www.gnu.org/licenses/>.
*/
#ifndef AJAXUI_MAILBOX_H_
#define AJAXUI_MAILBOX_H_
#include <libhts/htsbuf.h>
void ajax_mailbox_tdmi_state_change(th_dvb_mux_instance_t *tdmi);
void ajax_mailbox_tdmi_qual_change(th_dvb_mux_instance_t *tdmi);
void ajax_mailbox_tdmi_name_change(th_dvb_mux_instance_t *tdmi);
void ajax_mailbox_tdmi_status_change(th_dvb_mux_instance_t *tdmi);
void ajax_mailbox_tdmi_services_change(th_dvb_mux_instance_t *tdmi);
void ajax_mailbox_tda_change(th_dvb_adapter_t *tda);
void ajax_mailbox_start(htsbuf_queue_t *hq);
struct xmltv_grabber;
void ajax_mailbox_xmltv_grabber_status_change(struct xmltv_grabber *xg);
struct th_transport;
void ajax_mailbox_transport_status_change(struct th_transport *t);
struct cwc;
void ajax_mailbox_cwc_status_change(struct cwc *cwc);
#endif /* AJAXUI_MAILBOX_H_ */

Binary file not shown.

Before

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 495 B

File diff suppressed because it is too large Load diff

View file

@ -1,136 +0,0 @@
// script.aculo.us builder.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
//
// script.aculo.us is freely distributable under the terms of an MIT-style license.
// For details, see the script.aculo.us web site: http://script.aculo.us/
var Builder = {
NODEMAP: {
AREA: 'map',
CAPTION: 'table',
COL: 'table',
COLGROUP: 'table',
LEGEND: 'fieldset',
OPTGROUP: 'select',
OPTION: 'select',
PARAM: 'object',
TBODY: 'table',
TD: 'table',
TFOOT: 'table',
TH: 'table',
THEAD: 'table',
TR: 'table'
},
// note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
// due to a Firefox bug
node: function(elementName) {
elementName = elementName.toUpperCase();
// try innerHTML approach
var parentTag = this.NODEMAP[elementName] || 'div';
var parentElement = document.createElement(parentTag);
try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
} catch(e) {}
var element = parentElement.firstChild || null;
// see if browser added wrapping tags
if(element && (element.tagName.toUpperCase() != elementName))
element = element.getElementsByTagName(elementName)[0];
// fallback to createElement approach
if(!element) element = document.createElement(elementName);
// abort if nothing could be created
if(!element) return;
// attributes (or text)
if(arguments[1])
if(this._isStringOrNumber(arguments[1]) ||
(arguments[1] instanceof Array) ||
arguments[1].tagName) {
this._children(element, arguments[1]);
} else {
var attrs = this._attributes(arguments[1]);
if(attrs.length) {
try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
parentElement.innerHTML = "<" +elementName + " " +
attrs + "></" + elementName + ">";
} catch(e) {}
element = parentElement.firstChild || null;
// workaround firefox 1.0.X bug
if(!element) {
element = document.createElement(elementName);
for(attr in arguments[1])
element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
}
if(element.tagName.toUpperCase() != elementName)
element = parentElement.getElementsByTagName(elementName)[0];
}
}
// text, or array of children
if(arguments[2])
this._children(element, arguments[2]);
return element;
},
_text: function(text) {
return document.createTextNode(text);
},
ATTR_MAP: {
'className': 'class',
'htmlFor': 'for'
},
_attributes: function(attributes) {
var attrs = [];
for(attribute in attributes)
attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) +
'="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'&quot;') + '"');
return attrs.join(" ");
},
_children: function(element, children) {
if(children.tagName) {
element.appendChild(children);
return;
}
if(typeof children=='object') { // array can hold nodes and text
children.flatten().each( function(e) {
if(typeof e=='object')
element.appendChild(e)
else
if(Builder._isStringOrNumber(e))
element.appendChild(Builder._text(e));
});
} else
if(Builder._isStringOrNumber(children))
element.appendChild(Builder._text(children));
},
_isStringOrNumber: function(param) {
return(typeof param=='string' || typeof param=='number');
},
build: function(html) {
var element = this.node('div');
$(element).update(html.strip());
return element.down();
},
dump: function(scope) {
if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
"BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
"FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
"KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
"PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
"TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
tags.each( function(tag){
scope[tag] = function() {
return Builder.node.apply(Builder, [tag].concat($A(arguments)));
}
});
}
}

View file

@ -1,965 +0,0 @@
// script.aculo.us controls.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
// (c) 2005-2007 Jon Tirsen (http://www.tirsen.com)
// Contributors:
// Richard Livsey
// Rahul Bhargava
// Rob Wills
//
// script.aculo.us is freely distributable under the terms of an MIT-style license.
// For details, see the script.aculo.us web site: http://script.aculo.us/
// Autocompleter.Base handles all the autocompletion functionality
// that's independent of the data source for autocompletion. This
// includes drawing the autocompletion menu, observing keyboard
// and mouse events, and similar.
//
// Specific autocompleters need to provide, at the very least,
// a getUpdatedChoices function that will be invoked every time
// the text inside the monitored textbox changes. This method
// should get the text for which to provide autocompletion by
// invoking this.getToken(), NOT by directly accessing
// this.element.value. This is to allow incremental tokenized
// autocompletion. Specific auto-completion logic (AJAX, etc)
// belongs in getUpdatedChoices.
//
// Tokenized incremental autocompletion is enabled automatically
// when an autocompleter is instantiated with the 'tokens' option
// in the options parameter, e.g.:
// new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
// will incrementally autocomplete with a comma as the token.
// Additionally, ',' in the above example can be replaced with
// a token array, e.g. { tokens: [',', '\n'] } which
// enables autocompletion on multiple tokens. This is most
// useful when one of the tokens is \n (a newline), as it
// allows smart autocompletion after linebreaks.
if(typeof Effect == 'undefined')
throw("controls.js requires including script.aculo.us' effects.js library");
var Autocompleter = { }
Autocompleter.Base = Class.create({
baseInitialize: function(element, update, options) {
element = $(element)
this.element = element;
this.update = $(update);
this.hasFocus = false;
this.changed = false;
this.active = false;
this.index = 0;
this.entryCount = 0;
this.oldElementValue = this.element.value;
if(this.setOptions)
this.setOptions(options);
else
this.options = options || { };
this.options.paramName = this.options.paramName || this.element.name;
this.options.tokens = this.options.tokens || [];
this.options.frequency = this.options.frequency || 0.4;
this.options.minChars = this.options.minChars || 1;
this.options.onShow = this.options.onShow ||
function(element, update){
if(!update.style.position || update.style.position=='absolute') {
update.style.position = 'absolute';
Position.clone(element, update, {
setHeight: false,
offsetTop: element.offsetHeight
});
}
Effect.Appear(update,{duration:0.15});
};
this.options.onHide = this.options.onHide ||
function(element, update){ new Effect.Fade(update,{duration:0.15}) };
if(typeof(this.options.tokens) == 'string')
this.options.tokens = new Array(this.options.tokens);
// Force carriage returns as token delimiters anyway
if (!this.options.tokens.include('\n'))
this.options.tokens.push('\n');
this.observer = null;
this.element.setAttribute('autocomplete','off');
Element.hide(this.update);
Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
},
show: function() {
if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
if(!this.iefix &&
(Prototype.Browser.IE) &&
(Element.getStyle(this.update, 'position')=='absolute')) {
new Insertion.After(this.update,
'<iframe id="' + this.update.id + '_iefix" '+
'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
this.iefix = $(this.update.id+'_iefix');
}
if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
},
fixIEOverlapping: function() {
Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
this.iefix.style.zIndex = 1;
this.update.style.zIndex = 2;
Element.show(this.iefix);
},
hide: function() {
this.stopIndicator();
if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
if(this.iefix) Element.hide(this.iefix);
},
startIndicator: function() {
if(this.options.indicator) Element.show(this.options.indicator);
},
stopIndicator: function() {
if(this.options.indicator) Element.hide(this.options.indicator);
},
onKeyPress: function(event) {
if(this.active)
switch(event.keyCode) {
case Event.KEY_TAB:
case Event.KEY_RETURN:
this.selectEntry();
Event.stop(event);
case Event.KEY_ESC:
this.hide();
this.active = false;
Event.stop(event);
return;
case Event.KEY_LEFT:
case Event.KEY_RIGHT:
return;
case Event.KEY_UP:
this.markPrevious();
this.render();
Event.stop(event);
return;
case Event.KEY_DOWN:
this.markNext();
this.render();
Event.stop(event);
return;
}
else
if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
(Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
this.changed = true;
this.hasFocus = true;
if(this.observer) clearTimeout(this.observer);
this.observer =
setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
},
activate: function() {
this.changed = false;
this.hasFocus = true;
this.getUpdatedChoices();
},
onHover: function(event) {
var element = Event.findElement(event, 'LI');
if(this.index != element.autocompleteIndex)
{
this.index = element.autocompleteIndex;
this.render();
}
Event.stop(event);
},
onClick: function(event) {
var element = Event.findElement(event, 'LI');
this.index = element.autocompleteIndex;
this.selectEntry();
this.hide();
},
onBlur: function(event) {
// needed to make click events working
setTimeout(this.hide.bind(this), 250);
this.hasFocus = false;
this.active = false;
},
render: function() {
if(this.entryCount > 0) {
for (var i = 0; i < this.entryCount; i++)
this.index==i ?
Element.addClassName(this.getEntry(i),"selected") :
Element.removeClassName(this.getEntry(i),"selected");
if(this.hasFocus) {
this.show();
this.active = true;
}
} else {
this.active = false;
this.hide();
}
},
markPrevious: function() {
if(this.index > 0) this.index--
else this.index = this.entryCount-1;
this.getEntry(this.index).scrollIntoView(true);
},
markNext: function() {
if(this.index < this.entryCount-1) this.index++
else this.index = 0;
this.getEntry(this.index).scrollIntoView(false);
},
getEntry: function(index) {
return this.update.firstChild.childNodes[index];
},
getCurrentEntry: function() {
return this.getEntry(this.index);
},
selectEntry: function() {
this.active = false;
this.updateElement(this.getCurrentEntry());
},
updateElement: function(selectedElement) {
if (this.options.updateElement) {
this.options.updateElement(selectedElement);
return;
}
var value = '';
if (this.options.select) {
var nodes = $(selectedElement).select('.' + this.options.select) || [];
if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
} else
value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
var bounds = this.getTokenBounds();
if (bounds[0] != -1) {
var newValue = this.element.value.substr(0, bounds[0]);
var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
if (whitespace)
newValue += whitespace[0];
this.element.value = newValue + value + this.element.value.substr(bounds[1]);
} else {
this.element.value = value;
}
this.oldElementValue = this.element.value;
this.element.focus();
if (this.options.afterUpdateElement)
this.options.afterUpdateElement(this.element, selectedElement);
},
updateChoices: function(choices) {
if(!this.changed && this.hasFocus) {
this.update.innerHTML = choices;
Element.cleanWhitespace(this.update);
Element.cleanWhitespace(this.update.down());
if(this.update.firstChild && this.update.down().childNodes) {
this.entryCount =
this.update.down().childNodes.length;
for (var i = 0; i < this.entryCount; i++) {
var entry = this.getEntry(i);
entry.autocompleteIndex = i;
this.addObservers(entry);
}
} else {
this.entryCount = 0;
}
this.stopIndicator();
this.index = 0;
if(this.entryCount==1 && this.options.autoSelect) {
this.selectEntry();
this.hide();
} else {
this.render();
}
}
},
addObservers: function(element) {
Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
Event.observe(element, "click", this.onClick.bindAsEventListener(this));
},
onObserverEvent: function() {
this.changed = false;
this.tokenBounds = null;
if(this.getToken().length>=this.options.minChars) {
this.getUpdatedChoices();
} else {
this.active = false;
this.hide();
}
this.oldElementValue = this.element.value;
},
getToken: function() {
var bounds = this.getTokenBounds();
return this.element.value.substring(bounds[0], bounds[1]).strip();
},
getTokenBounds: function() {
if (null != this.tokenBounds) return this.tokenBounds;
var value = this.element.value;
if (value.strip().empty()) return [-1, 0];
var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);
var offset = (diff == this.oldElementValue.length ? 1 : 0);
var prevTokenPos = -1, nextTokenPos = value.length;
var tp;
for (var index = 0, l = this.options.tokens.length; index < l; ++index) {
tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1);
if (tp > prevTokenPos) prevTokenPos = tp;
tp = value.indexOf(this.options.tokens[index], diff + offset);
if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp;
}
return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]);
}
});
Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) {
var boundary = Math.min(newS.length, oldS.length);
for (var index = 0; index < boundary; ++index)
if (newS[index] != oldS[index])
return index;
return boundary;
};
Ajax.Autocompleter = Class.create(Autocompleter.Base, {
initialize: function(element, update, url, options) {
this.baseInitialize(element, update, options);
this.options.asynchronous = true;
this.options.onComplete = this.onComplete.bind(this);
this.options.defaultParams = this.options.parameters || null;
this.url = url;
},
getUpdatedChoices: function() {
this.startIndicator();
var entry = encodeURIComponent(this.options.paramName) + '=' +
encodeURIComponent(this.getToken());
this.options.parameters = this.options.callback ?
this.options.callback(this.element, entry) : entry;
if(this.options.defaultParams)
this.options.parameters += '&' + this.options.defaultParams;
new Ajax.Request(this.url, this.options);
},
onComplete: function(request) {
this.updateChoices(request.responseText);
}
});
// The local array autocompleter. Used when you'd prefer to
// inject an array of autocompletion options into the page, rather
// than sending out Ajax queries, which can be quite slow sometimes.
//
// The constructor takes four parameters. The first two are, as usual,
// the id of the monitored textbox, and id of the autocompletion menu.
// The third is the array you want to autocomplete from, and the fourth
// is the options block.
//
// Extra local autocompletion options:
// - choices - How many autocompletion choices to offer
//
// - partialSearch - If false, the autocompleter will match entered
// text only at the beginning of strings in the
// autocomplete array. Defaults to true, which will
// match text at the beginning of any *word* in the
// strings in the autocomplete array. If you want to
// search anywhere in the string, additionally set
// the option fullSearch to true (default: off).
//
// - fullSsearch - Search anywhere in autocomplete array strings.
//
// - partialChars - How many characters to enter before triggering
// a partial match (unlike minChars, which defines
// how many characters are required to do any match
// at all). Defaults to 2.
//
// - ignoreCase - Whether to ignore case when autocompleting.
// Defaults to true.
//
// It's possible to pass in a custom function as the 'selector'
// option, if you prefer to write your own autocompletion logic.
// In that case, the other options above will not apply unless
// you support them.
Autocompleter.Local = Class.create(Autocompleter.Base, {
initialize: function(element, update, array, options) {
this.baseInitialize(element, update, options);
this.options.array = array;
},
getUpdatedChoices: function() {
this.updateChoices(this.options.selector(this));
},
setOptions: function(options) {
this.options = Object.extend({
choices: 10,
partialSearch: true,
partialChars: 2,
ignoreCase: true,
fullSearch: false,
selector: function(instance) {
var ret = []; // Beginning matches
var partial = []; // Inside matches
var entry = instance.getToken();
var count = 0;
for (var i = 0; i < instance.options.array.length &&
ret.length < instance.options.choices ; i++) {
var elem = instance.options.array[i];
var foundPos = instance.options.ignoreCase ?
elem.toLowerCase().indexOf(entry.toLowerCase()) :
elem.indexOf(entry);
while (foundPos != -1) {
if (foundPos == 0 && elem.length != entry.length) {
ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
elem.substr(entry.length) + "</li>");
break;
} else if (entry.length >= instance.options.partialChars &&
instance.options.partialSearch && foundPos != -1) {
if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
foundPos + entry.length) + "</li>");
break;
}
}
foundPos = instance.options.ignoreCase ?
elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
elem.indexOf(entry, foundPos + 1);
}
}
if (partial.length)
ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
return "<ul>" + ret.join('') + "</ul>";
}
}, options || { });
}
});
// AJAX in-place editor and collection editor
// Full rewrite by Christophe Porteneuve <tdd@tddsworld.com> (April 2007).
// Use this if you notice weird scrolling problems on some browsers,
// the DOM might be a bit confused when this gets called so do this
// waits 1 ms (with setTimeout) until it does the activation
Field.scrollFreeActivate = function(field) {
setTimeout(function() {
Field.activate(field);
}, 1);
}
Ajax.InPlaceEditor = Class.create({
initialize: function(element, url, options) {
this.url = url;
this.element = element = $(element);
this.prepareOptions();
this._controls = { };
arguments.callee.dealWithDeprecatedOptions(options); // DEPRECATION LAYER!!!
Object.extend(this.options, options || { });
if (!this.options.formId && this.element.id) {
this.options.formId = this.element.id + '-inplaceeditor';
if ($(this.options.formId))
this.options.formId = '';
}
if (this.options.externalControl)
this.options.externalControl = $(this.options.externalControl);
if (!this.options.externalControl)
this.options.externalControlOnly = false;
this._originalBackground = this.element.getStyle('background-color') || 'transparent';
this.element.title = this.options.clickToEditText;
this._boundCancelHandler = this.handleFormCancellation.bind(this);
this._boundComplete = (this.options.onComplete || Prototype.emptyFunction).bind(this);
this._boundFailureHandler = this.handleAJAXFailure.bind(this);
this._boundSubmitHandler = this.handleFormSubmission.bind(this);
this._boundWrapperHandler = this.wrapUp.bind(this);
this.registerListeners();
},
checkForEscapeOrReturn: function(e) {
if (!this._editing || e.ctrlKey || e.altKey || e.shiftKey) return;
if (Event.KEY_ESC == e.keyCode)
this.handleFormCancellation(e);
else if (Event.KEY_RETURN == e.keyCode)
this.handleFormSubmission(e);
},
createControl: function(mode, handler, extraClasses) {
var control = this.options[mode + 'Control'];
var text = this.options[mode + 'Text'];
if ('button' == control) {
var btn = document.createElement('input');
btn.type = 'submit';
btn.value = text;
btn.className = 'editor_' + mode + '_button';
if ('cancel' == mode)
btn.onclick = this._boundCancelHandler;
this._form.appendChild(btn);
this._controls[mode] = btn;
} else if ('link' == control) {
var link = document.createElement('a');
link.href = '#';
link.appendChild(document.createTextNode(text));
link.onclick = 'cancel' == mode ? this._boundCancelHandler : this._boundSubmitHandler;
link.className = 'editor_' + mode + '_link';
if (extraClasses)
link.className += ' ' + extraClasses;
this._form.appendChild(link);
this._controls[mode] = link;
}
},
createEditField: function() {
var text = (this.options.loadTextURL ? this.options.loadingText : this.getText());
var fld;
if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) {
fld = document.createElement('input');
fld.type = 'text';
var size = this.options.size || this.options.cols || 0;
if (0 < size) fld.size = size;
} else {
fld = document.createElement('textarea');
fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows);
fld.cols = this.options.cols || 40;
}
fld.name = this.options.paramName;
fld.value = text; // No HTML breaks conversion anymore
fld.className = 'editor_field';
if (this.options.submitOnBlur)
fld.onblur = this._boundSubmitHandler;
this._controls.editor = fld;
if (this.options.loadTextURL)
this.loadExternalText();
this._form.appendChild(this._controls.editor);
},
createForm: function() {
var ipe = this;
function addText(mode, condition) {
var text = ipe.options['text' + mode + 'Controls'];
if (!text || condition === false) return;
ipe._form.appendChild(document.createTextNode(text));
};
this._form = $(document.createElement('form'));
this._form.id = this.options.formId;
this._form.addClassName(this.options.formClassName);
this._form.onsubmit = this._boundSubmitHandler;
this.createEditField();
if ('textarea' == this._controls.editor.tagName.toLowerCase())
this._form.appendChild(document.createElement('br'));
if (this.options.onFormCustomization)
this.options.onFormCustomization(this, this._form);
addText('Before', this.options.okControl || this.options.cancelControl);
this.createControl('ok', this._boundSubmitHandler);
addText('Between', this.options.okControl && this.options.cancelControl);
this.createControl('cancel', this._boundCancelHandler, 'editor_cancel');
addText('After', this.options.okControl || this.options.cancelControl);
},
destroy: function() {
if (this._oldInnerHTML)
this.element.innerHTML = this._oldInnerHTML;
this.leaveEditMode();
this.unregisterListeners();
},
enterEditMode: function(e) {
if (this._saving || this._editing) return;
this._editing = true;
this.triggerCallback('onEnterEditMode');
if (this.options.externalControl)
this.options.externalControl.hide();
this.element.hide();
this.createForm();
this.element.parentNode.insertBefore(this._form, this.element);
if (!this.options.loadTextURL)
this.postProcessEditField();
if (e) Event.stop(e);
},
enterHover: function(e) {
if (this.options.hoverClassName)
this.element.addClassName(this.options.hoverClassName);
if (this._saving) return;
this.triggerCallback('onEnterHover');
},
getText: function() {
return this.element.innerHTML;
},
handleAJAXFailure: function(transport) {
this.triggerCallback('onFailure', transport);
if (this._oldInnerHTML) {
this.element.innerHTML = this._oldInnerHTML;
this._oldInnerHTML = null;
}
},
handleFormCancellation: function(e) {
this.wrapUp();
if (e) Event.stop(e);
},
handleFormSubmission: function(e) {
var form = this._form;
var value = $F(this._controls.editor);
this.prepareSubmission();
var params = this.options.callback(form, value) || '';
if (Object.isString(params))
params = params.toQueryParams();
params.editorId = this.element.id;
if (this.options.htmlResponse) {
var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);
Object.extend(options, {
parameters: params,
onComplete: this._boundWrapperHandler,
onFailure: this._boundFailureHandler
});
new Ajax.Updater({ success: this.element }, this.url, options);
} else {
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
Object.extend(options, {
parameters: params,
onComplete: this._boundWrapperHandler,
onFailure: this._boundFailureHandler
});
new Ajax.Request(this.url, options);
}
if (e) Event.stop(e);
},
leaveEditMode: function() {
this.element.removeClassName(this.options.savingClassName);
this.removeForm();
this.leaveHover();
this.element.style.backgroundColor = this._originalBackground;
this.element.show();
if (this.options.externalControl)
this.options.externalControl.show();
this._saving = false;
this._editing = false;
this._oldInnerHTML = null;
this.triggerCallback('onLeaveEditMode');
},
leaveHover: function(e) {
if (this.options.hoverClassName)
this.element.removeClassName(this.options.hoverClassName);
if (this._saving) return;
this.triggerCallback('onLeaveHover');
},
loadExternalText: function() {
this._form.addClassName(this.options.loadingClassName);
this._controls.editor.disabled = true;
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
Object.extend(options, {
parameters: 'editorId=' + encodeURIComponent(this.element.id),
onComplete: Prototype.emptyFunction,
onSuccess: function(transport) {
this._form.removeClassName(this.options.loadingClassName);
var text = transport.responseText;
if (this.options.stripLoadedTextTags)
text = text.stripTags();
this._controls.editor.value = text;
this._controls.editor.disabled = false;
this.postProcessEditField();
}.bind(this),
onFailure: this._boundFailureHandler
});
new Ajax.Request(this.options.loadTextURL, options);
},
postProcessEditField: function() {
var fpc = this.options.fieldPostCreation;
if (fpc)
$(this._controls.editor)['focus' == fpc ? 'focus' : 'activate']();
},
prepareOptions: function() {
this.options = Object.clone(Ajax.InPlaceEditor.DefaultOptions);
Object.extend(this.options, Ajax.InPlaceEditor.DefaultCallbacks);
[this._extraDefaultOptions].flatten().compact().each(function(defs) {
Object.extend(this.options, defs);
}.bind(this));
},
prepareSubmission: function() {
this._saving = true;
this.removeForm();
this.leaveHover();
this.showSaving();
},
registerListeners: function() {
this._listeners = { };
var listener;
$H(Ajax.InPlaceEditor.Listeners).each(function(pair) {
listener = this[pair.value].bind(this);
this._listeners[pair.key] = listener;
if (!this.options.externalControlOnly)
this.element.observe(pair.key, listener);
if (this.options.externalControl)
this.options.externalControl.observe(pair.key, listener);
}.bind(this));
},
removeForm: function() {
if (!this._form) return;
this._form.remove();
this._form = null;
this._controls = { };
},
showSaving: function() {
this._oldInnerHTML = this.element.innerHTML;
this.element.innerHTML = this.options.savingText;
this.element.addClassName(this.options.savingClassName);
this.element.style.backgroundColor = this._originalBackground;
this.element.show();
},
triggerCallback: function(cbName, arg) {
if ('function' == typeof this.options[cbName]) {
this.options[cbName](this, arg);
}
},
unregisterListeners: function() {
$H(this._listeners).each(function(pair) {
if (!this.options.externalControlOnly)
this.element.stopObserving(pair.key, pair.value);
if (this.options.externalControl)
this.options.externalControl.stopObserving(pair.key, pair.value);
}.bind(this));
},
wrapUp: function(transport) {
this.leaveEditMode();
// Can't use triggerCallback due to backward compatibility: requires
// binding + direct element
this._boundComplete(transport, this.element);
}
});
Object.extend(Ajax.InPlaceEditor.prototype, {
dispose: Ajax.InPlaceEditor.prototype.destroy
});
Ajax.InPlaceCollectionEditor = Class.create(Ajax.InPlaceEditor, {
initialize: function($super, element, url, options) {
this._extraDefaultOptions = Ajax.InPlaceCollectionEditor.DefaultOptions;
$super(element, url, options);
},
createEditField: function() {
var list = document.createElement('select');
list.name = this.options.paramName;
list.size = 1;
this._controls.editor = list;
this._collection = this.options.collection || [];
if (this.options.loadCollectionURL)
this.loadCollection();
else
this.checkForExternalText();
this._form.appendChild(this._controls.editor);
},
loadCollection: function() {
this._form.addClassName(this.options.loadingClassName);
this.showLoadingText(this.options.loadingCollectionText);
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
Object.extend(options, {
parameters: 'editorId=' + encodeURIComponent(this.element.id),
onComplete: Prototype.emptyFunction,
onSuccess: function(transport) {
var js = transport.responseText.strip();
if (!/^\[.*\]$/.test(js)) // TODO: improve sanity check
throw 'Server returned an invalid collection representation.';
this._collection = eval(js);
this.checkForExternalText();
}.bind(this),
onFailure: this.onFailure
});
new Ajax.Request(this.options.loadCollectionURL, options);
},
showLoadingText: function(text) {
this._controls.editor.disabled = true;
var tempOption = this._controls.editor.firstChild;
if (!tempOption) {
tempOption = document.createElement('option');
tempOption.value = '';
this._controls.editor.appendChild(tempOption);
tempOption.selected = true;
}
tempOption.update((text || '').stripScripts().stripTags());
},
checkForExternalText: function() {
this._text = this.getText();
if (this.options.loadTextURL)
this.loadExternalText();
else
this.buildOptionList();
},
loadExternalText: function() {
this.showLoadingText(this.options.loadingText);
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
Object.extend(options, {
parameters: 'editorId=' + encodeURIComponent(this.element.id),
onComplete: Prototype.emptyFunction,
onSuccess: function(transport) {
this._text = transport.responseText.strip();
this.buildOptionList();
}.bind(this),
onFailure: this.onFailure
});
new Ajax.Request(this.options.loadTextURL, options);
},
buildOptionList: function() {
this._form.removeClassName(this.options.loadingClassName);
this._collection = this._collection.map(function(entry) {
return 2 === entry.length ? entry : [entry, entry].flatten();
});
var marker = ('value' in this.options) ? this.options.value : this._text;
var textFound = this._collection.any(function(entry) {
return entry[0] == marker;
}.bind(this));
this._controls.editor.update('');
var option;
this._collection.each(function(entry, index) {
option = document.createElement('option');
option.value = entry[0];
option.selected = textFound ? entry[0] == marker : 0 == index;
option.appendChild(document.createTextNode(entry[1]));
this._controls.editor.appendChild(option);
}.bind(this));
this._controls.editor.disabled = false;
Field.scrollFreeActivate(this._controls.editor);
}
});
//**** DEPRECATION LAYER FOR InPlace[Collection]Editor! ****
//**** This only exists for a while, in order to let ****
//**** users adapt to the new API. Read up on the new ****
//**** API and convert your code to it ASAP! ****
Ajax.InPlaceEditor.prototype.initialize.dealWithDeprecatedOptions = function(options) {
if (!options) return;
function fallback(name, expr) {
if (name in options || expr === undefined) return;
options[name] = expr;
};
fallback('cancelControl', (options.cancelLink ? 'link' : (options.cancelButton ? 'button' :
options.cancelLink == options.cancelButton == false ? false : undefined)));
fallback('okControl', (options.okLink ? 'link' : (options.okButton ? 'button' :
options.okLink == options.okButton == false ? false : undefined)));
fallback('highlightColor', options.highlightcolor);
fallback('highlightEndColor', options.highlightendcolor);
};
Object.extend(Ajax.InPlaceEditor, {
DefaultOptions: {
ajaxOptions: { },
autoRows: 3, // Use when multi-line w/ rows == 1
cancelControl: 'link', // 'link'|'button'|false
cancelText: 'cancel',
clickToEditText: 'Click to edit',
externalControl: null, // id|elt
externalControlOnly: false,
fieldPostCreation: 'activate', // 'activate'|'focus'|false
formClassName: 'inplaceeditor-form',
formId: null, // id|elt
highlightColor: '#ffff99',
highlightEndColor: '#ffffff',
hoverClassName: '',
htmlResponse: true,
loadingClassName: 'inplaceeditor-loading',
loadingText: 'Loading...',
okControl: 'button', // 'link'|'button'|false
okText: 'ok',
paramName: 'value',
rows: 1, // If 1 and multi-line, uses autoRows
savingClassName: 'inplaceeditor-saving',
savingText: 'Saving...',
size: 0,
stripLoadedTextTags: false,
submitOnBlur: false,
textAfterControls: '',
textBeforeControls: '',
textBetweenControls: ''
},
DefaultCallbacks: {
callback: function(form) {
return Form.serialize(form);
},
onComplete: function(transport, element) {
// For backward compatibility, this one is bound to the IPE, and passes
// the element directly. It was too often customized, so we don't break it.
new Effect.Highlight(element, {
startcolor: this.options.highlightColor, keepBackgroundImage: true });
},
onEnterEditMode: null,
onEnterHover: function(ipe) {
ipe.element.style.backgroundColor = ipe.options.highlightColor;
if (ipe._effect)
ipe._effect.cancel();
},
onFailure: function(transport, ipe) {
alert('Error communication with the server: ' + transport.responseText.stripTags());
},
onFormCustomization: null, // Takes the IPE and its generated form, after editor, before controls.
onLeaveEditMode: null,
onLeaveHover: function(ipe) {
ipe._effect = new Effect.Highlight(ipe.element, {
startcolor: ipe.options.highlightColor, endcolor: ipe.options.highlightEndColor,
restorecolor: ipe._originalBackground, keepBackgroundImage: true
});
}
},
Listeners: {
click: 'enterEditMode',
keydown: 'checkForEscapeOrReturn',
mouseover: 'enterHover',
mouseout: 'leaveHover'
}
});
Ajax.InPlaceCollectionEditor.DefaultOptions = {
loadingCollectionText: 'Loading options...'
};
// Delayed observer, like Form.Element.Observer,
// but waits for delay after last key input
// Ideal for live-search fields
Form.Element.DelayedObserver = Class.create({
initialize: function(element, delay, callback) {
this.delay = delay || 0.5;
this.element = $(element);
this.callback = callback;
this.timer = null;
this.lastValue = $F(this.element);
Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));
},
delayedListener: function(event) {
if(this.lastValue == $F(this.element)) return;
if(this.timer) clearTimeout(this.timer);
this.timer = setTimeout(this.onTimerEvent.bind(this), this.delay * 1000);
this.lastValue = $F(this.element);
},
onTimerEvent: function() {
this.timer = null;
this.callback(this.element, $F(this.element));
}
});

View file

@ -1,974 +0,0 @@
// script.aculo.us dragdrop.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// (c) 2005-2007 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
//
// script.aculo.us is freely distributable under the terms of an MIT-style license.
// For details, see the script.aculo.us web site: http://script.aculo.us/
if(Object.isUndefined(Effect))
throw("dragdrop.js requires including script.aculo.us' effects.js library");
var Droppables = {
drops: [],
remove: function(element) {
this.drops = this.drops.reject(function(d) { return d.element==$(element) });
},
add: function(element) {
element = $(element);
var options = Object.extend({
greedy: true,
hoverclass: null,
tree: false
}, arguments[1] || { });
// cache containers
if(options.containment) {
options._containers = [];
var containment = options.containment;
if(Object.isArray(containment)) {
containment.each( function(c) { options._containers.push($(c)) });
} else {
options._containers.push($(containment));
}
}
if(options.accept) options.accept = [options.accept].flatten();
Element.makePositioned(element); // fix IE
options.element = element;
this.drops.push(options);
},
findDeepestChild: function(drops) {
deepest = drops[0];
for (i = 1; i < drops.length; ++i)
if (Element.isParent(drops[i].element, deepest.element))
deepest = drops[i];
return deepest;
},
isContained: function(element, drop) {
var containmentNode;
if(drop.tree) {
containmentNode = element.treeNode;
} else {
containmentNode = element.parentNode;
}
return drop._containers.detect(function(c) { return containmentNode == c });
},
isAffected: function(point, element, drop) {
return (
(drop.element!=element) &&
((!drop._containers) ||
this.isContained(element, drop)) &&
((!drop.accept) ||
(Element.classNames(element).detect(
function(v) { return drop.accept.include(v) } ) )) &&
Position.within(drop.element, point[0], point[1]) );
},
deactivate: function(drop) {
if(drop.hoverclass)
Element.removeClassName(drop.element, drop.hoverclass);
this.last_active = null;
},
activate: function(drop) {
if(drop.hoverclass)
Element.addClassName(drop.element, drop.hoverclass);
this.last_active = drop;
},
show: function(point, element) {
if(!this.drops.length) return;
var drop, affected = [];
this.drops.each( function(drop) {
if(Droppables.isAffected(point, element, drop))
affected.push(drop);
});
if(affected.length>0)
drop = Droppables.findDeepestChild(affected);
if(this.last_active && this.last_active != drop) this.deactivate(this.last_active);
if (drop) {
Position.within(drop.element, point[0], point[1]);
if(drop.onHover)
drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element));
if (drop != this.last_active) Droppables.activate(drop);
}
},
fire: function(event, element) {
if(!this.last_active) return;
Position.prepare();
if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active))
if (this.last_active.onDrop) {
this.last_active.onDrop(element, this.last_active.element, event);
return true;
}
},
reset: function() {
if(this.last_active)
this.deactivate(this.last_active);
}
}
var Draggables = {
drags: [],
observers: [],
register: function(draggable) {
if(this.drags.length == 0) {
this.eventMouseUp = this.endDrag.bindAsEventListener(this);
this.eventMouseMove = this.updateDrag.bindAsEventListener(this);
this.eventKeypress = this.keyPress.bindAsEventListener(this);
Event.observe(document, "mouseup", this.eventMouseUp);
Event.observe(document, "mousemove", this.eventMouseMove);
Event.observe(document, "keypress", this.eventKeypress);
}
this.drags.push(draggable);
},
unregister: function(draggable) {
this.drags = this.drags.reject(function(d) { return d==draggable });
if(this.drags.length == 0) {
Event.stopObserving(document, "mouseup", this.eventMouseUp);
Event.stopObserving(document, "mousemove", this.eventMouseMove);
Event.stopObserving(document, "keypress", this.eventKeypress);
}
},
activate: function(draggable) {
if(draggable.options.delay) {
this._timeout = setTimeout(function() {
Draggables._timeout = null;
window.focus();
Draggables.activeDraggable = draggable;
}.bind(this), draggable.options.delay);
} else {
window.focus(); // allows keypress events if window isn't currently focused, fails for Safari
this.activeDraggable = draggable;
}
},
deactivate: function() {
this.activeDraggable = null;
},
updateDrag: function(event) {
if(!this.activeDraggable) return;
var pointer = [Event.pointerX(event), Event.pointerY(event)];
// Mozilla-based browsers fire successive mousemove events with
// the same coordinates, prevent needless redrawing (moz bug?)
if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return;
this._lastPointer = pointer;
this.activeDraggable.updateDrag(event, pointer);
},
endDrag: function(event) {
if(this._timeout) {
clearTimeout(this._timeout);
this._timeout = null;
}
if(!this.activeDraggable) return;
this._lastPointer = null;
this.activeDraggable.endDrag(event);
this.activeDraggable = null;
},
keyPress: function(event) {
if(this.activeDraggable)
this.activeDraggable.keyPress(event);
},
addObserver: function(observer) {
this.observers.push(observer);
this._cacheObserverCallbacks();
},
removeObserver: function(element) { // element instead of observer fixes mem leaks
this.observers = this.observers.reject( function(o) { return o.element==element });
this._cacheObserverCallbacks();
},
notify: function(eventName, draggable, event) { // 'onStart', 'onEnd', 'onDrag'
if(this[eventName+'Count'] > 0)
this.observers.each( function(o) {
if(o[eventName]) o[eventName](eventName, draggable, event);
});
if(draggable.options[eventName]) draggable.options[eventName](draggable, event);
},
_cacheObserverCallbacks: function() {
['onStart','onEnd','onDrag'].each( function(eventName) {
Draggables[eventName+'Count'] = Draggables.observers.select(
function(o) { return o[eventName]; }
).length;
});
}
}
/*--------------------------------------------------------------------------*/
var Draggable = Class.create({
initialize: function(element) {
var defaults = {
handle: false,
reverteffect: function(element, top_offset, left_offset) {
var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02;
new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur,
queue: {scope:'_draggable', position:'end'}
});
},
endeffect: function(element) {
var toOpacity = Object.isNumber(element._opacity) ? element._opacity : 1.0;
new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
queue: {scope:'_draggable', position:'end'},
afterFinish: function(){
Draggable._dragging[element] = false
}
});
},
zindex: 1000,
revert: false,
quiet: false,
scroll: false,
scrollSensitivity: 20,
scrollSpeed: 15,
snap: false, // false, or xy or [x,y] or function(x,y){ return [x,y] }
delay: 0
};
if(!arguments[1] || Object.isUndefined(arguments[1].endeffect))
Object.extend(defaults, {
starteffect: function(element) {
element._opacity = Element.getOpacity(element);
Draggable._dragging[element] = true;
new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
}
});
var options = Object.extend(defaults, arguments[1] || { });
this.element = $(element);
if(options.handle && Object.isString(options.handle))
this.handle = this.element.down('.'+options.handle, 0);
if(!this.handle) this.handle = $(options.handle);
if(!this.handle) this.handle = this.element;
if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) {
options.scroll = $(options.scroll);
this._isScrollChild = Element.childOf(this.element, options.scroll);
}
Element.makePositioned(this.element); // fix IE
this.options = options;
this.dragging = false;
this.eventMouseDown = this.initDrag.bindAsEventListener(this);
Event.observe(this.handle, "mousedown", this.eventMouseDown);
Draggables.register(this);
},
destroy: function() {
Event.stopObserving(this.handle, "mousedown", this.eventMouseDown);
Draggables.unregister(this);
},
currentDelta: function() {
return([
parseInt(Element.getStyle(this.element,'left') || '0'),
parseInt(Element.getStyle(this.element,'top') || '0')]);
},
initDrag: function(event) {
if(!Object.isUndefined(Draggable._dragging[this.element]) &&
Draggable._dragging[this.element]) return;
if(Event.isLeftClick(event)) {
// abort on form elements, fixes a Firefox issue
var src = Event.element(event);
if((tag_name = src.tagName.toUpperCase()) && (
tag_name=='INPUT' ||
tag_name=='SELECT' ||
tag_name=='OPTION' ||
tag_name=='BUTTON' ||
tag_name=='TEXTAREA')) return;
var pointer = [Event.pointerX(event), Event.pointerY(event)];
var pos = Position.cumulativeOffset(this.element);
this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) });
Draggables.activate(this);
Event.stop(event);
}
},
startDrag: function(event) {
this.dragging = true;
if(!this.delta)
this.delta = this.currentDelta();
if(this.options.zindex) {
this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0);
this.element.style.zIndex = this.options.zindex;
}
if(this.options.ghosting) {
this._clone = this.element.cloneNode(true);
this.element._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
if (!this.element._originallyAbsolute)
Position.absolutize(this.element);
this.element.parentNode.insertBefore(this._clone, this.element);
}
if(this.options.scroll) {
if (this.options.scroll == window) {
var where = this._getWindowScroll(this.options.scroll);
this.originalScrollLeft = where.left;
this.originalScrollTop = where.top;
} else {
this.originalScrollLeft = this.options.scroll.scrollLeft;
this.originalScrollTop = this.options.scroll.scrollTop;
}
}
Draggables.notify('onStart', this, event);
if(this.options.starteffect) this.options.starteffect(this.element);
},
updateDrag: function(event, pointer) {
if(!this.dragging) this.startDrag(event);
if(!this.options.quiet){
Position.prepare();
Droppables.show(pointer, this.element);
}
Draggables.notify('onDrag', this, event);
this.draw(pointer);
if(this.options.change) this.options.change(this);
if(this.options.scroll) {
this.stopScrolling();
var p;
if (this.options.scroll == window) {
with(this._getWindowScroll(this.options.scroll)) { p = [ left, top, left+width, top+height ]; }
} else {
p = Position.page(this.options.scroll);
p[0] += this.options.scroll.scrollLeft + Position.deltaX;
p[1] += this.options.scroll.scrollTop + Position.deltaY;
p.push(p[0]+this.options.scroll.offsetWidth);
p.push(p[1]+this.options.scroll.offsetHeight);
}
var speed = [0,0];
if(pointer[0] < (p[0]+this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[0]+this.options.scrollSensitivity);
if(pointer[1] < (p[1]+this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[1]+this.options.scrollSensitivity);
if(pointer[0] > (p[2]-this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[2]-this.options.scrollSensitivity);
if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity);
this.startScrolling(speed);
}
// fix AppleWebKit rendering
if(Prototype.Browser.WebKit) window.scrollBy(0,0);
Event.stop(event);
},
finishDrag: function(event, success) {
this.dragging = false;
if(this.options.quiet){
Position.prepare();
var pointer = [Event.pointerX(event), Event.pointerY(event)];
Droppables.show(pointer, this.element);
}
if(this.options.ghosting) {
if (!this.element._originallyAbsolute)
Position.relativize(this.element);
delete this.element._originallyAbsolute;
Element.remove(this._clone);
this._clone = null;
}
var dropped = false;
if(success) {
dropped = Droppables.fire(event, this.element);
if (!dropped) dropped = false;
}
if(dropped && this.options.onDropped) this.options.onDropped(this.element);
Draggables.notify('onEnd', this, event);
var revert = this.options.revert;
if(revert && Object.isFunction(revert)) revert = revert(this.element);
var d = this.currentDelta();
if(revert && this.options.reverteffect) {
if (dropped == 0 || revert != 'failure')
this.options.reverteffect(this.element,
d[1]-this.delta[1], d[0]-this.delta[0]);
} else {
this.delta = d;
}
if(this.options.zindex)
this.element.style.zIndex = this.originalZ;
if(this.options.endeffect)
this.options.endeffect(this.element);
Draggables.deactivate(this);
Droppables.reset();
},
keyPress: function(event) {
if(event.keyCode!=Event.KEY_ESC) return;
this.finishDrag(event, false);
Event.stop(event);
},
endDrag: function(event) {
if(!this.dragging) return;
this.stopScrolling();
this.finishDrag(event, true);
Event.stop(event);
},
draw: function(point) {
var pos = Position.cumulativeOffset(this.element);
if(this.options.ghosting) {
var r = Position.realOffset(this.element);
pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY;
}
var d = this.currentDelta();
pos[0] -= d[0]; pos[1] -= d[1];
if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) {
pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft;
pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop;
}
var p = [0,1].map(function(i){
return (point[i]-pos[i]-this.offset[i])
}.bind(this));
if(this.options.snap) {
if(Object.isFunction(this.options.snap)) {
p = this.options.snap(p[0],p[1],this);
} else {
if(Object.isArray(this.options.snap)) {
p = p.map( function(v, i) {
return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this))
} else {
p = p.map( function(v) {
return (v/this.options.snap).round()*this.options.snap }.bind(this))
}
}}
var style = this.element.style;
if((!this.options.constraint) || (this.options.constraint=='horizontal'))
style.left = p[0] + "px";
if((!this.options.constraint) || (this.options.constraint=='vertical'))
style.top = p[1] + "px";
if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
},
stopScrolling: function() {
if(this.scrollInterval) {
clearInterval(this.scrollInterval);
this.scrollInterval = null;
Draggables._lastScrollPointer = null;
}
},
startScrolling: function(speed) {
if(!(speed[0] || speed[1])) return;
this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed];
this.lastScrolled = new Date();
this.scrollInterval = setInterval(this.scroll.bind(this), 10);
},
scroll: function() {
var current = new Date();
var delta = current - this.lastScrolled;
this.lastScrolled = current;
if(this.options.scroll == window) {
with (this._getWindowScroll(this.options.scroll)) {
if (this.scrollSpeed[0] || this.scrollSpeed[1]) {
var d = delta / 1000;
this.options.scroll.scrollTo( left + d*this.scrollSpeed[0], top + d*this.scrollSpeed[1] );
}
}
} else {
this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000;
this.options.scroll.scrollTop += this.scrollSpeed[1] * delta / 1000;
}
Position.prepare();
Droppables.show(Draggables._lastPointer, this.element);
Draggables.notify('onDrag', this);
if (this._isScrollChild) {
Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer);
Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000;
Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000;
if (Draggables._lastScrollPointer[0] < 0)
Draggables._lastScrollPointer[0] = 0;
if (Draggables._lastScrollPointer[1] < 0)
Draggables._lastScrollPointer[1] = 0;
this.draw(Draggables._lastScrollPointer);
}
if(this.options.change) this.options.change(this);
},
_getWindowScroll: function(w) {
var T, L, W, H;
with (w.document) {
if (w.document.documentElement && documentElement.scrollTop) {
T = documentElement.scrollTop;
L = documentElement.scrollLeft;
} else if (w.document.body) {
T = body.scrollTop;
L = body.scrollLeft;
}
if (w.innerWidth) {
W = w.innerWidth;
H = w.innerHeight;
} else if (w.document.documentElement && documentElement.clientWidth) {
W = documentElement.clientWidth;
H = documentElement.clientHeight;
} else {
W = body.offsetWidth;
H = body.offsetHeight
}
}
return { top: T, left: L, width: W, height: H };
}
});
Draggable._dragging = { };
/*--------------------------------------------------------------------------*/
var SortableObserver = Class.create({
initialize: function(element, observer) {
this.element = $(element);
this.observer = observer;
this.lastValue = Sortable.serialize(this.element);
},
onStart: function() {
this.lastValue = Sortable.serialize(this.element);
},
onEnd: function() {
Sortable.unmark();
if(this.lastValue != Sortable.serialize(this.element))
this.observer(this.element)
}
});
var Sortable = {
SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/,
sortables: { },
_findRootElement: function(element) {
while (element.tagName.toUpperCase() != "BODY") {
if(element.id && Sortable.sortables[element.id]) return element;
element = element.parentNode;
}
},
options: function(element) {
element = Sortable._findRootElement($(element));
if(!element) return;
return Sortable.sortables[element.id];
},
destroy: function(element){
var s = Sortable.options(element);
if(s) {
Draggables.removeObserver(s.element);
s.droppables.each(function(d){ Droppables.remove(d) });
s.draggables.invoke('destroy');
delete Sortable.sortables[s.element.id];
}
},
create: function(element) {
element = $(element);
var options = Object.extend({
element: element,
tag: 'li', // assumes li children, override with tag: 'tagname'
dropOnEmpty: false,
tree: false,
treeTag: 'ul',
overlap: 'vertical', // one of 'vertical', 'horizontal'
constraint: 'vertical', // one of 'vertical', 'horizontal', false
containment: element, // also takes array of elements (or id's); or false
handle: false, // or a CSS class
only: false,
delay: 0,
hoverclass: null,
ghosting: false,
quiet: false,
scroll: false,
scrollSensitivity: 20,
scrollSpeed: 15,
format: this.SERIALIZE_RULE,
// these take arrays of elements or ids and can be
// used for better initialization performance
elements: false,
handles: false,
onChange: Prototype.emptyFunction,
onUpdate: Prototype.emptyFunction
}, arguments[1] || { });
// clear any old sortable with same element
this.destroy(element);
// build options for the draggables
var options_for_draggable = {
revert: true,
quiet: options.quiet,
scroll: options.scroll,
scrollSpeed: options.scrollSpeed,
scrollSensitivity: options.scrollSensitivity,
delay: options.delay,
ghosting: options.ghosting,
constraint: options.constraint,
handle: options.handle };
if(options.starteffect)
options_for_draggable.starteffect = options.starteffect;
if(options.reverteffect)
options_for_draggable.reverteffect = options.reverteffect;
else
if(options.ghosting) options_for_draggable.reverteffect = function(element) {
element.style.top = 0;
element.style.left = 0;
};
if(options.endeffect)
options_for_draggable.endeffect = options.endeffect;
if(options.zindex)
options_for_draggable.zindex = options.zindex;
// build options for the droppables
var options_for_droppable = {
overlap: options.overlap,
containment: options.containment,
tree: options.tree,
hoverclass: options.hoverclass,
onHover: Sortable.onHover
}
var options_for_tree = {
onHover: Sortable.onEmptyHover,
overlap: options.overlap,
containment: options.containment,
hoverclass: options.hoverclass
}
// fix for gecko engine
Element.cleanWhitespace(element);
options.draggables = [];
options.droppables = [];
// drop on empty handling
if(options.dropOnEmpty || options.tree) {
Droppables.add(element, options_for_tree);
options.droppables.push(element);
}
(options.elements || this.findElements(element, options) || []).each( function(e,i) {
var handle = options.handles ? $(options.handles[i]) :
(options.handle ? $(e).select('.' + options.handle)[0] : e);
options.draggables.push(
new Draggable(e, Object.extend(options_for_draggable, { handle: handle })));
Droppables.add(e, options_for_droppable);
if(options.tree) e.treeNode = element;
options.droppables.push(e);
});
if(options.tree) {
(Sortable.findTreeElements(element, options) || []).each( function(e) {
Droppables.add(e, options_for_tree);
e.treeNode = element;
options.droppables.push(e);
});
}
// keep reference
this.sortables[element.id] = options;
// for onupdate
Draggables.addObserver(new SortableObserver(element, options.onUpdate));
},
// return all suitable-for-sortable elements in a guaranteed order
findElements: function(element, options) {
return Element.findChildren(
element, options.only, options.tree ? true : false, options.tag);
},
findTreeElements: function(element, options) {
return Element.findChildren(
element, options.only, options.tree ? true : false, options.treeTag);
},
onHover: function(element, dropon, overlap) {
if(Element.isParent(dropon, element)) return;
if(overlap > .33 && overlap < .66 && Sortable.options(dropon).tree) {
return;
} else if(overlap>0.5) {
Sortable.mark(dropon, 'before');
if(dropon.previousSibling != element) {
var oldParentNode = element.parentNode;
element.style.visibility = "hidden"; // fix gecko rendering
dropon.parentNode.insertBefore(element, dropon);
if(dropon.parentNode!=oldParentNode)
Sortable.options(oldParentNode).onChange(element);
Sortable.options(dropon.parentNode).onChange(element);
}
} else {
Sortable.mark(dropon, 'after');
var nextElement = dropon.nextSibling || null;
if(nextElement != element) {
var oldParentNode = element.parentNode;
element.style.visibility = "hidden"; // fix gecko rendering
dropon.parentNode.insertBefore(element, nextElement);
if(dropon.parentNode!=oldParentNode)
Sortable.options(oldParentNode).onChange(element);
Sortable.options(dropon.parentNode).onChange(element);
}
}
},
onEmptyHover: function(element, dropon, overlap) {
var oldParentNode = element.parentNode;
var droponOptions = Sortable.options(dropon);
if(!Element.isParent(dropon, element)) {
var index;
var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only});
var child = null;
if(children) {
var offset = Element.offsetSize(dropon, droponOptions.overlap) * (1.0 - overlap);
for (index = 0; index < children.length; index += 1) {
if (offset - Element.offsetSize (children[index], droponOptions.overlap) >= 0) {
offset -= Element.offsetSize (children[index], droponOptions.overlap);
} else if (offset - (Element.offsetSize (children[index], droponOptions.overlap) / 2) >= 0) {
child = index + 1 < children.length ? children[index + 1] : null;
break;
} else {
child = children[index];
break;
}
}
}
dropon.insertBefore(element, child);
Sortable.options(oldParentNode).onChange(element);
droponOptions.onChange(element);
}
},
unmark: function() {
if(Sortable._marker) Sortable._marker.hide();
},
mark: function(dropon, position) {
// mark on ghosting only
var sortable = Sortable.options(dropon.parentNode);
if(sortable && !sortable.ghosting) return;
if(!Sortable._marker) {
Sortable._marker =
($('dropmarker') || Element.extend(document.createElement('DIV'))).
hide().addClassName('dropmarker').setStyle({position:'absolute'});
document.getElementsByTagName("body").item(0).appendChild(Sortable._marker);
}
var offsets = Position.cumulativeOffset(dropon);
Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'});
if(position=='after')
if(sortable.overlap == 'horizontal')
Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'});
else
Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'});
Sortable._marker.show();
},
_tree: function(element, options, parent) {
var children = Sortable.findElements(element, options) || [];
for (var i = 0; i < children.length; ++i) {
var match = children[i].id.match(options.format);
if (!match) continue;
var child = {
id: encodeURIComponent(match ? match[1] : null),
element: element,
parent: parent,
children: [],
position: parent.children.length,
container: $(children[i]).down(options.treeTag)
}
/* Get the element containing the children and recurse over it */
if (child.container)
this._tree(child.container, options, child)
parent.children.push (child);
}
return parent;
},
tree: function(element) {
element = $(element);
var sortableOptions = this.options(element);
var options = Object.extend({
tag: sortableOptions.tag,
treeTag: sortableOptions.treeTag,
only: sortableOptions.only,
name: element.id,
format: sortableOptions.format
}, arguments[1] || { });
var root = {
id: null,
parent: null,
children: [],
container: element,
position: 0
}
return Sortable._tree(element, options, root);
},
/* Construct a [i] index for a particular node */
_constructIndex: function(node) {
var index = '';
do {
if (node.id) index = '[' + node.position + ']' + index;
} while ((node = node.parent) != null);
return index;
},
sequence: function(element) {
element = $(element);
var options = Object.extend(this.options(element), arguments[1] || { });
return $(this.findElements(element, options) || []).map( function(item) {
return item.id.match(options.format) ? item.id.match(options.format)[1] : '';
});
},
setSequence: function(element, new_sequence) {
element = $(element);
var options = Object.extend(this.options(element), arguments[2] || { });
var nodeMap = { };
this.findElements(element, options).each( function(n) {
if (n.id.match(options.format))
nodeMap[n.id.match(options.format)[1]] = [n, n.parentNode];
n.parentNode.removeChild(n);
});
new_sequence.each(function(ident) {
var n = nodeMap[ident];
if (n) {
n[1].appendChild(n[0]);
delete nodeMap[ident];
}
});
},
serialize: function(element) {
element = $(element);
var options = Object.extend(Sortable.options(element), arguments[1] || { });
var name = encodeURIComponent(
(arguments[1] && arguments[1].name) ? arguments[1].name : element.id);
if (options.tree) {
return Sortable.tree(element, arguments[1]).children.map( function (item) {
return [name + Sortable._constructIndex(item) + "[id]=" +
encodeURIComponent(item.id)].concat(item.children.map(arguments.callee));
}).flatten().join('&');
} else {
return Sortable.sequence(element, arguments[1]).map( function(item) {
return name + "[]=" + encodeURIComponent(item);
}).join('&');
}
}
}
// Returns true if child is contained within element
Element.isParent = function(child, element) {
if (!child.parentNode || child == element) return false;
if (child.parentNode == element) return true;
return Element.isParent(child.parentNode, element);
}
Element.findChildren = function(element, only, recursive, tagName) {
if(!element.hasChildNodes()) return null;
tagName = tagName.toUpperCase();
if(only) only = [only].flatten();
var elements = [];
$A(element.childNodes).each( function(e) {
if(e.tagName && e.tagName.toUpperCase()==tagName &&
(!only || (Element.classNames(e).detect(function(v) { return only.include(v) }))))
elements.push(e);
if(recursive) {
var grandchildren = Element.findChildren(e, only, recursive, tagName);
if(grandchildren) elements.push(grandchildren);
}
});
return (elements.length>0 ? elements.flatten() : []);
}
Element.offsetSize = function (element, type) {
return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')];
}

File diff suppressed because it is too large Load diff

View file

@ -1,58 +0,0 @@
// script.aculo.us scriptaculous.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// For details, see the script.aculo.us web site: http://script.aculo.us/
var Scriptaculous = {
Version: '1.8.1',
require: function(libraryName) {
// inserting via DOM fails in Safari 2.0, so brute force approach
document.write('<script type="text/javascript" src="'+libraryName+'"><\/script>');
},
REQUIRED_PROTOTYPE: '1.6.0',
load: function() {
function convertVersionString(versionString){
var r = versionString.split('.');
return parseInt(r[0])*100000 + parseInt(r[1])*1000 + parseInt(r[2]);
}
if((typeof Prototype=='undefined') ||
(typeof Element == 'undefined') ||
(typeof Element.Methods=='undefined') ||
(convertVersionString(Prototype.Version) <
convertVersionString(Scriptaculous.REQUIRED_PROTOTYPE)))
throw("script.aculo.us requires the Prototype JavaScript framework >= " +
Scriptaculous.REQUIRED_PROTOTYPE);
$A(document.getElementsByTagName("script")).findAll( function(s) {
return (s.src && s.src.match(/scriptaculous\.js(\?.*)?$/))
}).each( function(s) {
var path = s.src.replace(/scriptaculous\.js(\?.*)?$/,'');
var includes = s.src.match(/\?.*load=([a-z,]*)/);
(includes ? includes[1] : 'builder,effects,dragdrop,controls,slider,sound').split(',').each(
function(include) { Scriptaculous.require(path+include+'.js') });
});
}
}
Scriptaculous.load();

View file

@ -1,275 +0,0 @@
// script.aculo.us slider.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
// Copyright (c) 2005-2007 Marty Haught, Thomas Fuchs
//
// script.aculo.us is freely distributable under the terms of an MIT-style license.
// For details, see the script.aculo.us web site: http://script.aculo.us/
if (!Control) var Control = { };
// options:
// axis: 'vertical', or 'horizontal' (default)
//
// callbacks:
// onChange(value)
// onSlide(value)
Control.Slider = Class.create({
initialize: function(handle, track, options) {
var slider = this;
if (Object.isArray(handle)) {
this.handles = handle.collect( function(e) { return $(e) });
} else {
this.handles = [$(handle)];
}
this.track = $(track);
this.options = options || { };
this.axis = this.options.axis || 'horizontal';
this.increment = this.options.increment || 1;
this.step = parseInt(this.options.step || '1');
this.range = this.options.range || $R(0,1);
this.value = 0; // assure backwards compat
this.values = this.handles.map( function() { return 0 });
this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
this.options.startSpan = $(this.options.startSpan || null);
this.options.endSpan = $(this.options.endSpan || null);
this.restricted = this.options.restricted || false;
this.maximum = this.options.maximum || this.range.end;
this.minimum = this.options.minimum || this.range.start;
// Will be used to align the handle onto the track, if necessary
this.alignX = parseInt(this.options.alignX || '0');
this.alignY = parseInt(this.options.alignY || '0');
this.trackLength = this.maximumOffset() - this.minimumOffset();
this.handleLength = this.isVertical() ?
(this.handles[0].offsetHeight != 0 ?
this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) :
(this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth :
this.handles[0].style.width.replace(/px$/,""));
this.active = false;
this.dragging = false;
this.disabled = false;
if (this.options.disabled) this.setDisabled();
// Allowed values array
this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
if (this.allowedValues) {
this.minimum = this.allowedValues.min();
this.maximum = this.allowedValues.max();
}
this.eventMouseDown = this.startDrag.bindAsEventListener(this);
this.eventMouseUp = this.endDrag.bindAsEventListener(this);
this.eventMouseMove = this.update.bindAsEventListener(this);
// Initialize handles in reverse (make sure first handle is active)
this.handles.each( function(h,i) {
i = slider.handles.length-1-i;
slider.setValue(parseFloat(
(Object.isArray(slider.options.sliderValue) ?
slider.options.sliderValue[i] : slider.options.sliderValue) ||
slider.range.start), i);
h.makePositioned().observe("mousedown", slider.eventMouseDown);
});
this.track.observe("mousedown", this.eventMouseDown);
document.observe("mouseup", this.eventMouseUp);
document.observe("mousemove", this.eventMouseMove);
this.initialized = true;
},
dispose: function() {
var slider = this;
Event.stopObserving(this.track, "mousedown", this.eventMouseDown);
Event.stopObserving(document, "mouseup", this.eventMouseUp);
Event.stopObserving(document, "mousemove", this.eventMouseMove);
this.handles.each( function(h) {
Event.stopObserving(h, "mousedown", slider.eventMouseDown);
});
},
setDisabled: function(){
this.disabled = true;
},
setEnabled: function(){
this.disabled = false;
},
getNearestValue: function(value){
if (this.allowedValues){
if (value >= this.allowedValues.max()) return(this.allowedValues.max());
if (value <= this.allowedValues.min()) return(this.allowedValues.min());
var offset = Math.abs(this.allowedValues[0] - value);
var newValue = this.allowedValues[0];
this.allowedValues.each( function(v) {
var currentOffset = Math.abs(v - value);
if (currentOffset <= offset){
newValue = v;
offset = currentOffset;
}
});
return newValue;
}
if (value > this.range.end) return this.range.end;
if (value < this.range.start) return this.range.start;
return value;
},
setValue: function(sliderValue, handleIdx){
if (!this.active) {
this.activeHandleIdx = handleIdx || 0;
this.activeHandle = this.handles[this.activeHandleIdx];
this.updateStyles();
}
handleIdx = handleIdx || this.activeHandleIdx || 0;
if (this.initialized && this.restricted) {
if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
sliderValue = this.values[handleIdx-1];
if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
sliderValue = this.values[handleIdx+1];
}
sliderValue = this.getNearestValue(sliderValue);
this.values[handleIdx] = sliderValue;
this.value = this.values[0]; // assure backwards compat
this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] =
this.translateToPx(sliderValue);
this.drawSpans();
if (!this.dragging || !this.event) this.updateFinished();
},
setValueBy: function(delta, handleIdx) {
this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta,
handleIdx || this.activeHandleIdx || 0);
},
translateToPx: function(value) {
return Math.round(
((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) *
(value - this.range.start)) + "px";
},
translateToValue: function(offset) {
return ((offset/(this.trackLength-this.handleLength) *
(this.range.end-this.range.start)) + this.range.start);
},
getRange: function(range) {
var v = this.values.sortBy(Prototype.K);
range = range || 0;
return $R(v[range],v[range+1]);
},
minimumOffset: function(){
return(this.isVertical() ? this.alignY : this.alignX);
},
maximumOffset: function(){
return(this.isVertical() ?
(this.track.offsetHeight != 0 ? this.track.offsetHeight :
this.track.style.height.replace(/px$/,"")) - this.alignY :
(this.track.offsetWidth != 0 ? this.track.offsetWidth :
this.track.style.width.replace(/px$/,"")) - this.alignX);
},
isVertical: function(){
return (this.axis == 'vertical');
},
drawSpans: function() {
var slider = this;
if (this.spans)
$R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
if (this.options.startSpan)
this.setSpan(this.options.startSpan,
$R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
if (this.options.endSpan)
this.setSpan(this.options.endSpan,
$R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
},
setSpan: function(span, range) {
if (this.isVertical()) {
span.style.top = this.translateToPx(range.start);
span.style.height = this.translateToPx(range.end - range.start + this.range.start);
} else {
span.style.left = this.translateToPx(range.start);
span.style.width = this.translateToPx(range.end - range.start + this.range.start);
}
},
updateStyles: function() {
this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
Element.addClassName(this.activeHandle, 'selected');
},
startDrag: function(event) {
if (Event.isLeftClick(event)) {
if (!this.disabled){
this.active = true;
var handle = Event.element(event);
var pointer = [Event.pointerX(event), Event.pointerY(event)];
var track = handle;
if (track==this.track) {
var offsets = Position.cumulativeOffset(this.track);
this.event = event;
this.setValue(this.translateToValue(
(this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2)
));
var offsets = Position.cumulativeOffset(this.activeHandle);
this.offsetX = (pointer[0] - offsets[0]);
this.offsetY = (pointer[1] - offsets[1]);
} else {
// find the handle (prevents issues with Safari)
while((this.handles.indexOf(handle) == -1) && handle.parentNode)
handle = handle.parentNode;
if (this.handles.indexOf(handle)!=-1) {
this.activeHandle = handle;
this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
this.updateStyles();
var offsets = Position.cumulativeOffset(this.activeHandle);
this.offsetX = (pointer[0] - offsets[0]);
this.offsetY = (pointer[1] - offsets[1]);
}
}
}
Event.stop(event);
}
},
update: function(event) {
if (this.active) {
if (!this.dragging) this.dragging = true;
this.draw(event);
if (Prototype.Browser.WebKit) window.scrollBy(0,0);
Event.stop(event);
}
},
draw: function(event) {
var pointer = [Event.pointerX(event), Event.pointerY(event)];
var offsets = Position.cumulativeOffset(this.track);
pointer[0] -= this.offsetX + offsets[0];
pointer[1] -= this.offsetY + offsets[1];
this.event = event;
this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
if (this.initialized && this.options.onSlide)
this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
},
endDrag: function(event) {
if (this.active && this.dragging) {
this.finishDrag(event, true);
Event.stop(event);
}
this.active = false;
this.dragging = false;
},
finishDrag: function(event, success) {
this.active = false;
this.dragging = false;
this.updateFinished();
},
updateFinished: function() {
if (this.initialized && this.options.onChange)
this.options.onChange(this.values.length>1 ? this.values : this.value, this);
this.event = null;
}
});

View file

@ -1,130 +0,0 @@
function switchtab(name, index)
{
a = new Ajax.Updater(name + 'deck', '/ajax/' + name + 'tab/' + index,
{ method: 'get', evalScripts: true});
a = new Ajax.Updater(name + 'menu', '/ajax/' + name + 'menu/' + index,
{ method: 'get', evalScripts: true});
};
function updatelistonserver(listid, url, resultid)
{
// document.getElementById(resultid).innerHTML = "Updating...";
a = new Ajax.Updater(resultid, url,
{ evalScripts: true,
parameters:Sortable.serialize(listid)});
};
function addlistentry(listid, url, name)
{
if(name == null || name == "") {
alert("Emtpy name is not allowed");
} else {
a = new Ajax.Updater(listid, url,
{ evalScripts: true,
parameters: { name: name },
insertion: Insertion.Bottom
});
}
}
function dellistentry(url, id, name)
{
if(confirm("Are you sure you want to delete '" + name + "'") == true) {
a = new Ajax.Request(url, { parameters: { id: id }});
}
}
function addlistentry_by_widget(listid, url, widget)
{
name = $F(widget);
$(widget).clear();
addlistentry(listid, url, name);
}
function showhide(name)
{
ctrlname = 'toggle_' + name;
if(document.getElementById(ctrlname).innerHTML == 'More') {
document.getElementById(ctrlname).innerHTML = 'Less';
new Effect.Appear(name, {duration: 0.5});
} else {
document.getElementById(ctrlname).innerHTML = 'More';
new Effect.Fade(name, {duration: 0.5});
}
}
function tentative_chname(id, url, name)
{
var newname = prompt("Enter name of channel", name);
if(newname != null && newname != name) {
a = new Ajax.Updater(id, url,
{ evalScripts: true,
parameters: { newname: newname }});
}
}
function mailboxquery(boxid)
{
new Ajax.Request('/ajax/mailbox/' + boxid,
{
onFailure: function(req) { alert(req.responseText); },
onException: function(t,e) { alert(e); }
})
}
function dvb_adapter_rename(id, oldname)
{
newname = prompt("Enter new name for adapter", oldname);
if(newname != null && newname != oldname) {
a = new Ajax.Request('/ajax/dvbadapterrename/' + id,
{ parameters: { 'newname': newname}});
}
}
function dvb_adapter_delete(id, name)
{
if(confirm("Are you sure you want to delete '" + name + "'") == true) {
a = new Ajax.Request('/ajax/dvbadapterdelete/' + id);
}
}
function makedivinput(id, url)
{
$(id).innerHTML='<div style="width:100%; overflow:auto">' +
'<div style="width:75%; float:left">' +
'<input id="val' + id + '" type="password">' +
'</div>' +
'<div style="width:25%; float:left">' +
'<input type="button" value="Set" ' +
'onClick="new Ajax.Request(\'' + url + '\', ' +
'{parameters: {value: $F(\'val' + id + '\')}})">' +
'</div></div>';
}
function channel_rename(tag, oldname)
{
newname = prompt("Enter new name", oldname);
if(newname != null && newname != oldname) {
a = new Ajax.Request('/ajax/chrename/' + tag,
{ parameters: { 'newname': newname}});
}
}
function channel_delete(tag, name)
{
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}});
}
}

View file

@ -410,8 +410,6 @@ typedef struct th_transport {
LIST_ENTRY(th_transport) tht_mux_link;
RB_ENTRY(th_transport) tht_tmp_link;
LIST_ENTRY(th_transport) tht_active_link;
LIST_HEAD(, th_subscription) tht_subscriptions;