add RSS aka Livebookmarks for Recordings
[enigma2-plugins.git] / webinterface / src / web-data / tools.js
1 var url_getvolume = '/web/vol?set=info'; 
2 var url_setvolume = '/web/vol?set=set'; // plus new value eq. set=set15
3 var url_volumeup = '/web/vol?set=up';
4 var url_volumedown = '/web/vol?set=down';
5 var url_volumemute = '/web/vol?set=mute';
6
7 var url_epgservice = "/web/epgservice?ref="; // plus serviceRev
8 var url_epgsearch = "/web/epgsearch?search="; // plus serviceRev
9 var url_epgnownext = "/web/epgnownext?ref="; // plus serviceRev
10
11 function getHTTPObject( ){
12     var xmlHttp = false;
13             
14     // try to create a new instance of the xmlhttprequest object        
15     try{
16         // Internet Explorer
17         if( window.ActiveXObject ){
18             for( var i = 5; i; i-- ){
19                 try{
20                     // loading of a newer version of msxml dll (msxml3 - msxml5) failed
21                     // use fallback solution
22                     // old style msxml version independent, deprecated
23                     if( i == 2 ){
24                         xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );    
25                     }
26                     // try to use the latest msxml dll
27                     else{
28                         
29                         xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
30                     }
31                     break;
32                 }
33                 catch( excNotLoadable ){                        
34                     xmlHttp = false;
35                 }
36             }
37         }
38         // Mozilla, Opera und Safari
39         else if( window.XMLHttpRequest ){
40             xmlHttp = new XMLHttpRequest();
41         }
42     }
43     // loading of xmlhttp object failed
44     catch( excNotLoadable ){
45         xmlHttp = false;
46     }
47     return xmlHttp ;
48 }
49
50
51 function debug(text){
52 //      document.getElementById('BodyContentDebugbox').innerHTML += "DEBUG: "+text+"<br>";
53 }
54
55 function showhide(id){
56         o = document.getElementById(id).style;
57         o.display = (o.display!="none")? "none":"";
58 }
59
60 function set(what, value){
61         //debug(what+"-"+value);
62         element = document.getElementById(what);
63         element.innerHTML = value;
64         //$('scriptzone').innerHTML = ""; // deleting set() from page, to keep the page short and to save memory
65 }
66
67 function getXML(request){
68         if (document.implementation && document.implementation.createDocument){
69                 debug("using responseXML");
70                 var xmlDoc = request.responseXML
71         }
72         else if (window.ActiveXObject){
73                 debug("Creating XML for IE");
74                 var xmlInsert = document.createElement('xml');
75
76                 xmlInsert.setAttribute('innerHTML',request.responseText);
77                 xmlInsert.setAttribute('id','_MakeAUniqueID');
78                 document.body.appendChild(xmlInsert);
79                 xmlDoc = document.getElementById('_MakeAUniqueID');
80                 document.body.removeChild(document.getElementById('_MakeAUniqueID'));
81         } else {
82                 debug("Your Browser Sucks!");
83         }
84         return xmlDoc;
85 }
86
87 function zap(li){
88         var request = getHTTPObject();
89         var url = "/web/zap?ZapTo=" + escape(li.id);
90         //debug("requesting "+url);
91         new Ajax.Request( url,
92                         {
93                                 method: 'get' 
94                                 
95                         });
96                 
97 }
98
99 function openWindow(t, inner, w, h){
100                         id = new Date().toUTCString()
101                         
102                         //debug(id);
103                         var win = new Window(id, {className: "alphacube", title: t, width:w, height:h});
104                         win.getContent().innerHTML = inner;
105                         win.setDestroyOnClose();
106                         win.showCenter();
107                         debug("opening Window: "+t);
108 }
109
110 function messageBox(t, m){
111         Dialog.alert(m, {windowParameters: {title: t, className: "alphacube", width:200}, okLabel: "Close"});
112 }
113 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
114 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
115 //++++ EPG functions                               ++++
116 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
117 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
118 var EPGList = Class.create();
119 EPGList.prototype = {
120         //contructor
121         initialize: function(){
122                 debug("init class EPGList");
123         },
124         getBySearchString: function(string){
125                 debug("requesting "+ url_epgsearch+string);
126                 new Ajax.Request( url_epgsearch+string,
127                         {
128                                 method: 'get', 
129                                 onComplete: this.incomingEPGrequest
130                         });
131                 
132         },
133         getByServiceReference: function(serviceRef){
134                 new Ajax.Request(url_epgservice+serviceRef,
135                         {
136                                 method: 'get', 
137                                 onComplete: this.incomingEPGrequest
138                         });
139                 
140         },
141         
142         
143         renderTable: function(epglist){
144                 debug("rendering Table with "+epglist.length+" events");
145                 var html='<table width="100%" border="0" cellspacing="1" cellpadding="0">';
146                 for (var i=0; i < epglist.length; i++){
147                         try{
148                                 var item = epglist[i];
149                                 
150                                 html +='<tr style="background-color: #DDDDDD;">';
151                                 html +='<td width="10%">'+item.getTimeDay()+'</td>';
152                                 html +='<td width="30%">'+item.getServiceName()+'</td>';
153                                 html +='<td>'+item.getTitle()+'&nbsp;<a target="_blank" href="/web/epgsearch.rss?search='+item.getTitle()+'" ><img src="/webdata/gfx/feed.png" title="RSS-Feed for this Title" border="0"></a></td>';
154                                 html +='</tr>';
155                                 
156                                 html +='<tr style="background-color: #DDDDDD;">';
157                                 html +='<td>'+item.getTimeStartString()+'</td>';
158                                 html +='<td>'+(item.getDuration()/60000)+' min.</td>';
159                                 html +='<td>'+item.getDescription()+'</td>';
160                                 html +='</tr>';
161                                 
162                                 html +='<tr style="background-color: #DDDDDD;">';
163                                 html +='<td valign="top">'+item.getTimeEndString()+'</td>';
164                                 html +='<td colspan="2">'+item.getDescriptionExtended()+'</td>';
165                                 html +='</tr>';
166                                 
167                                 
168                                 html +='<tr style="background-color: #AAAAAA;">';
169                                 html +='<td colspan="3">&nbsp;</td>';
170                                 html +='</tr>';
171                         } catch (blubb) {
172                                 //debug("Error rendering: "+blubb);
173                         }
174                 }
175                 
176                 html +="</table>";
177                 //element.innerHTML = html;
178                 openWindow("Electronic Program Guide", html, 900, 500);
179                 
180         },
181         incomingEPGrequest: function(request){
182                 debug("incoming request" +request.readyState);          
183                 if (request.readyState == 4)
184                 {
185                         var EPGItems = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
186                         
187                         debug("have "+EPGItems.length+" e2events");
188                         if(EPGItems.length > 0){
189                         
190                                 epglist = new Array();
191                                 for(var i=0; i < EPGItems.length; i++){         
192                                         epglist.push(new EPGEvent(EPGItems.item(i)));
193                                 }
194                                 debug("Calling prototype.renderTable(epglist)");
195                                 EPGList.prototype.renderTable(epglist);
196                                 
197                         } else {
198                                 messageBox('No Items found!', 'Sorry but i could not find any EPG Content containing your search value');
199                         }
200                         
201                 }
202         }
203         
204 }
205
206 function EPGEvent(element){     
207         // parsing values from xml-element
208         try{
209                 this.eventID= element.getElementsByTagName('e2eventid').item(0).firstChild.data;
210                 this.startTime= element.getElementsByTagName('e2eventstart').item(0).firstChild.data;
211                 this.duration= element.getElementsByTagName('e2eventduration').item(0).firstChild.data;
212                 this.title= element.getElementsByTagName('e2eventtitle').item(0).firstChild.data;
213                 this.description= element.getElementsByTagName('e2eventdescription').item(0).firstChild.data;
214                 this.descriptionE= element.getElementsByTagName('e2eventdescriptionextended').item(0).firstChild.data;
215                 this.serviceRef= element.getElementsByTagName('e2eventservicereference').item(0).firstChild.data;
216                 this.serviceName= element.getElementsByTagName('e2eventservicename').item(0).firstChild.data;
217         } catch (bullshit) {
218                 //debug("Bullshit is:"+bullshit);
219         }
220         this.getEventId = function ()
221         {
222                 return this.eventID;
223         }
224         this.getTimeStart = function ()
225         {
226                 var date = new Date(parseInt(this.startTime)*1000);
227                 return date;
228         }
229         this.getTimeStartString = function ()
230         {
231                 var h = this.getTimeStart().getHours();
232                 var m = this.getTimeStart().getMinutes();
233                 if (m < 10){
234                         m="0"+m;
235                 }
236                 return h+":"+m;
237         }
238         this.getTimeDay = function ()
239         {
240                 var Wochentag = new Array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
241                 var wday = Wochentag[this.getTimeStart().getDay()];
242                 var day = this.getTimeStart().getDate();
243                 var month = this.getTimeStart().getMonth()+1;
244                 var year = this.getTimeStart().getFullYear();
245                 
246                 return wday+".&nbsp;"+day+"."+month+"."+year;
247         }
248         this.getTimeEnd = function ()
249         {
250                 var date = new Date((parseInt(this.startTime)+parseInt(this.duration))*1000);
251                 return date;
252         }
253         this.getTimeEndString = function ()
254         {
255                 var h = this.getTimeEnd().getHours();
256                 var m = this.getTimeEnd().getMinutes();
257                 if (m < 10){
258                         m="0"+m;
259                 }
260                 return h+":"+m;
261         }
262         this.getDuration = function ()
263         {
264                 return  new Date(parseInt(this.duration)*1000);
265         }
266         this.getTitle = function ()
267         {
268                 return this.title;
269         }
270         this.getDescription = function ()
271         {
272                 return this.description;
273         }
274         this.getDescriptionExtended = function ()
275         {
276                 return this.descriptionE;
277         }
278         this.getServiceReference = function ()
279         {
280                 return this.serviceRef;
281         }
282         this.getServiceName = function ()
283         {
284                 return this.serviceName.replace(" ","&nbsp;");
285         }
286 }//END class EPGEvent
287
288 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
289 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
290 //++++ GUI functions                               ++++
291 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
292 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
293 var currentBodyMainElement = null
294
295 function setBodyMainContent(newelementname){
296         newelement =document.getElementById(newelementname);
297         if(currentBodyMainElement != null){
298                 currentBodyMainElement.style.display = "none";
299                 
300         }
301         newelement.style.display = "";
302         currentBodyMainElement = newelement;
303 }
304 function doRequest(url,readyFunction){
305         
306         http_request =getHTTPObject();
307         if(readyFunction){
308                 http_request.onreadystatechange = readyFunction;
309         }
310         http_request.open('GET', url, true);
311         http_request.send(null);
312         return http_request;
313 }
314 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
315 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
316 //++++ volume functions                            ++++
317 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
318 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
319
320 function initVolumePanel(){
321         $('VolumePanel').innerHTML += "<img onclick='volumeUp()' src='/webdata/gfx/arrow_up.png'>"; 
322         $('VolumePanel').innerHTML += "<img onclick='volumeDown()' src='/webdata/gfx/arrow_down.png'>"; 
323         $('VolumePanel').innerHTML += "<img id='volume1' onclick='volumeSet(10)' src='/webdata/gfx/led_off.png'>"; 
324         $('VolumePanel').innerHTML += "<img id='volume2' onclick='volumeSet(20)' src='/webdata/gfx/led_off.png'>"; 
325         $('VolumePanel').innerHTML += "<img id='volume3' onclick='volumeSet(30)' src='/webdata/gfx/led_off.png'>"; 
326         $('VolumePanel').innerHTML += "<img id='volume4' onclick='volumeSet(40)' src='/webdata/gfx/led_off.png'>"; 
327         $('VolumePanel').innerHTML += "<img id='volume5' onclick='volumeSet(50)' src='/webdata/gfx/led_off.png'>"; 
328         $('VolumePanel').innerHTML += "<img id='volume6' onclick='volumeSet(60)' src='/webdata/gfx/led_off.png'>"; 
329         $('VolumePanel').innerHTML += "<img id='volume7' onclick='volumeSet(70)' src='/webdata/gfx/led_off.png'>"; 
330         $('VolumePanel').innerHTML += "<img id='volume8' onclick='volumeSet(80)' src='/webdata/gfx/led_off.png'>"; 
331         $('VolumePanel').innerHTML += "<img id='volume9' onclick='volumeSet(90)' src='/webdata/gfx/led_off.png'>"; 
332         $('VolumePanel').innerHTML += "<img id='volume10' onclick='volumeSet(100)' src='/webdata/gfx/led_off.png'>"; 
333         $('VolumePanel').innerHTML += "<img id='speaker' onclick='volumeMute()' src='/webdata/gfx/speak_on.png'>";
334         getVolume(); 
335 }
336 function getVolume()
337 {
338         doRequest(url_getvolume,handleVolumeRequest);
339 }
340 function volumeSet(newvalue)
341 {
342         doRequest(url_setvolume+newvalue,handleVolumeRequest);
343 }
344 function volumeUp()
345 {
346         doRequest(url_volumeup,handleVolumeRequest);
347 }
348 function volumeDown()
349 {
350         doRequest(url_volumedown,handleVolumeRequest);  
351 }
352 function volumeMute()
353 {
354         doRequest(url_volumemute,handleVolumeRequest);
355 }
356 function handleVolumeRequest(){
357         if (http_request.readyState == 4) {
358                 var b = getXML(http_request).getElementsByTagName("e2volume");
359                 debug(b.item(0).getElementsByTagName('e2current').length); 
360                 var newvalue = b.item(0).getElementsByTagName('e2current').item(0).firstChild.data;
361                 var mute = b.item(0).getElementsByTagName('e2ismuted').item(0).firstChild.data;
362                 //debug("volume"+newvalue+";"+mute);
363                 for (var i = 1; i <= 10; i++)
364                 {
365                         if ( (newvalue/10)>=i){
366                                 $("volume"+i).src = "/webdata/gfx/led_on.png";
367                         }else{
368                                 $("volume"+i).src = "/webdata/gfx/led_off.png";
369                         }
370                 }
371                 if (mute == "False"){
372                         $("speaker").src = "/webdata/gfx/speak_on.png";
373                 }else{
374                         $("speaker").src = "/webdata/gfx/speak_off.png";
375                 }
376         }       
377 }
378 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
379 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
380 //++++ Bouqet managing functions                   ++++
381 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
382 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
383 function loadRootTVBouqet(){
384         //rootB = '/web/fetchchannels?ServiceListBrowse='+escape('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet');
385         rootB = '/web/fetchchannels?ServiceListBrowse='+escape('1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17) || (type == 195) || (type == 25)  FROM BOUQUET &quot;bouquets.tv&quot; ORDER BY bouquet');
386
387         loadRootBouqet(rootB);
388 }
389 function loadRootBouqet(rootB){
390         
391         t = getHTTPObject();
392         t.onreadystatechange = incomingResult;
393         t.open('GET', rootB, true);
394         t.send(null);
395         
396 }
397
398 function incomingResult(){
399         if((t.readyState == 4) && (t.status == 200)) {
400         // perfekt!
401                 
402                 var b = getXML(t).getElementsByTagName("e2servicelist").item(0).getElementsByTagName("e2service");
403
404                 bouquets = new Array();
405                 for ( var i=0; i < b.length; i++){
406                         bRef = b.item(i).getElementsByTagName('e2servicereference').item(0).firstChild.data;
407                         bName = b.item(i).getElementsByTagName('e2servicename').item(0).firstChild.data;
408                         
409                         bu = new Array(bName,bRef);
410                         bouquets.push(bu)
411                 }
412                 refreshSelect(bouquets);
413         } else {
414         // die Anfrage enthielt Fehler;
415         // die Antwort war z.B. 404 (nicht gefunden)
416         // oder 500 (interner Server-Fehler)
417         }
418         
419 }
420
421 // to add the bouqetts to the list
422 function refreshSelect(arraybouqet){
423         
424         sel = document.getElementById("accordionMenueBouqetContent");
425         // options neu eintragen
426         html = "<table>";
427                 for ( var i = 0 ; i < arraybouqet.length ; i++ ){
428                 if(arraybouqet[i][0] && arraybouqet[i][1]){
429                         html+="<tr><td>";
430                         html+="<a  onclick=\"bouqetSelected(this); setBodyMainContent('BodyContentChannellist');\" id='";
431                         html+= arraybouqet[i][1];
432                         html+="'>";
433                         html+= arraybouqet[i][0];
434                         html+="</a>";
435                         html+="</td></tr>";
436                 }
437         }
438         html+="</table>";
439         sel.innerHTML=html;
440         refreshChannellist(arraybouqet[0][0],arraybouqet[0][1]);
441 }
442
443 //++++++++++++++++++++++
444 function bouqetSelected(element){
445         refreshChannellist(element.value,element.id)
446 }
447
448 function refreshChannellist(bname,bref){
449         urlx = '/web/fetchchannels?ServiceListBrowse='+escape(bref);
450         w =getHTTPObject();
451         w.onreadystatechange = incomingChannellist;
452         w.open('GET', urlx, true);
453         w.send(null);   
454 }
455                         
456 function incomingChannellist(){
457         if(w.readyState == 4){
458
459                 services = getXML(w).getElementsByTagName("e2servicelist").item(0).getElementsByTagName("e2service");
460                 
461                 listerHtml      = '<table border="0" cellpadding="0" cellspacing="0" class="BodyContentChannellist">\n';
462                 listerHtml += '<thead class="fixedHeader">\n';
463                 listerHtml += '<tr>\n';
464                 listerHtml += '<th colspan="2" style="color: #FFFFFF;">ServiceList</th>\n';
465                 listerHtml += '<th style="text-align: right;" style="color: #FFFFFF;">'
466                 listerHtml += '<form onSubmit="new EPGList().getBySearchString(document.getElementById(\'searchText\').value); return false;">';
467                 listerHtml += '<input type="text" id="searchText" onfocus="this.value=\'\'" value="EPG suchen"/>';
468                 listerHtml += '<input type="image" src="/webdata/gfx/search.png" alt="suche starten">';
469                 listerHtml += '</form>'
470                 listerHtml += '</tr>\n';
471                 listerHtml += '</thead>\n';
472                 listerHtml += '<tbody class="scrollContent">\n';
473                 
474                 debug("got "+services.length+" Services");
475                 
476                 for ( var i = 0; i < (services.length ); i++){
477                         sRef = services.item(i).getElementsByTagName('e2servicereference').item(0).firstChild.data;
478                         sName = services.item(i).getElementsByTagName('e2servicename').item(0).firstChild.data;
479
480                         listerHtml += '<tr><td onclick="zap(this)" id="';
481                         listerHtml += sRef;
482                         listerHtml += '">\n';
483                         listerHtml += sName;
484                         listerHtml += '</td>\n';
485                         listerHtml += '<td onclick="new EPGList().getByServiceReference(this.id);" id="';
486                         listerHtml += sRef;
487                         listerHtml += '" >EPG</td>\n';
488                         listerHtml += '<td><a target="blank" href="stream.m3u?ref=';
489                         listerHtml += sRef;
490                         listerHtml += '\">Stream</a></td>\n';
491                         listerHtml += '</tr>\n';
492                 }
493                 
494                 listerHtml += "</tbody></table>\n";
495                 document.getElementById('BodyContentChannellist').innerHTML = listerHtml;
496                 setBodyMainContent('BodyContentChannellist');
497         }
498 }
499
500
501
502
503