now using ListFiller to increase performance
[enigma2-plugins.git] / webinterface / src / usr / lib / enigma2 / python / Plugins / Extensions / WebInterface / 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 debug(text){
12         //$('debug').innerHTML += "DEBUG: "+text+"<br>";
13 }
14 function set(what, value)
15 {
16         //debug(what+"-"+value);
17         element = document.getElementById(what);
18         element.innerHTML = value;
19         $('scriptzone').innerHTML = ""; // deleting set() from page, to keep the page short and to save memory
20 }
21
22 function zap(li)
23 {
24         var request = getHTTPObject();
25         var url = "/web/zap?ZapTo=" + escape(li.id);
26         //debug("requesting "+url);
27         new Ajax.Request( url,
28                         {
29                                 method: 'get' 
30                                 
31                         });
32                 
33 }
34
35 function getHTTPObject() 
36 {
37         var xmlhttp; 
38         /*@cc_on 
39         @if (@_jscript_version >= 5) 
40         try 
41         { 
42                 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
43         } 
44         catch (e) 
45         { 
46                 try 
47                 { 
48                         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
49                 } 
50                 catch (E) 
51                 { 
52                         xmlhttp = false; 
53                 } 
54         } 
55         @else 
56         xmlhttp = false; 
57         @end @*/ 
58         if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
59         { 
60                 try 
61                 { 
62                         xmlhttp = new XMLHttpRequest(); 
63                 } 
64                 catch (e) 
65                 {
66                         xmlhttp = false; 
67                 }
68         } 
69         return xmlhttp; 
70 }
71
72
73 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
74 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
75 //++++ EPG functions                               ++++
76 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
77 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
78 var EPGList = Class.create();
79 EPGList.prototype = {
80         //contructor
81         initialize: function(){
82                 debug("init class EPGList");
83         },
84         getBySearchString: function(string,element){
85                 debug("requesting "+ url_epgsearch+string);
86                 targetElement = element;
87                 new Ajax.Request( url_epgsearch+string,
88                         {
89                                 method: 'get', 
90                                 onComplete: this.incomingEPGrequest
91                         });
92                 
93         },
94         getByServiceReference: function(serviceRef,element){
95                 targetElement = element;
96                 new Ajax.Request(url_epgservice+serviceRef,
97                         {
98                                 method: 'get', 
99                                 onComplete: this.incomingEPGrequest
100                         });
101                 
102         },
103         renderTable: function(epglist){
104                 debug("rendering Table with "+epglist.length+" events");
105                 var html="<table width='100%'>";
106                 for (var i=0; i<epglist.length;i++){
107                         var item = epglist[i];
108                         html +="<tr  bgcolor='gray'>";
109                         html +="<td>"+item.getTimeDay()+"</td>";
110                         html +="<td>"+item.getTimeStartString()+"</td>";
111                         html +="<td>"+item.getTimeEndString()+"</td>";
112                         html +="<td>"+item.getTitle()+"</td>";
113                         html +="<td>"+item.getDescription()+"</td>";
114                         html +="<td>"+item.getDescriptionExtended()+"</td>";
115                         html +="<td>"+(item.getDuration()/60000)+" min.</td>";
116                         html +="<td>"+item.getServiceName()+"</td>";
117                         html +="</tr>";
118                 }
119                 html +="</table>";
120                 targetElement.innerHTML = html;
121                 
122         },
123         incomingEPGrequest: function(originalRequest){
124                 debug("incoming request" +originalRequest.readyState);          
125                 if (originalRequest.readyState == 4)
126                 {
127                         if (originalRequest.responseXML!="no data")
128                         {
129                                 var EPGItems = originalRequest.responseXML.getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
130                                 debug("have "+EPGItems.length+" e2events");
131                                 epglist = new Array();
132                                 for(var i=0;i<EPGItems.length;i++)
133                                 {       
134                                         epglist.push(new EPGEvent(EPGItems.item(i)));
135                                 }
136                                 EPGList.prototype.renderTable(epglist);
137                                 
138                         }                               
139                 }
140         }
141         
142 }
143
144 function EPGEvent(element){     
145         // parsing values from xml-element
146         this.eventID= element.getElementsByTagName('e2eventid').item(0).firstChild.data;
147         this.startTime= element.getElementsByTagName('e2eventstart').item(0).firstChild.data;
148         this.duration= element.getElementsByTagName('e2eventduration').item(0).firstChild.data;
149         this.title= element.getElementsByTagName('e2eventtitle').item(0).firstChild.data;
150         this.description= element.getElementsByTagName('e2eventdescription').item(0).firstChild.data;
151         this.descriptionE= element.getElementsByTagName('e2eventdescriptionextended').item(0).firstChild.data;
152         this.serviceRef= element.getElementsByTagName('e2eventservicereference').item(0).firstChild.data;
153         this.serviceName= element.getElementsByTagName('e2eventservicename').item(0).firstChild.data;
154
155         this.getEventId = function ()
156         {
157                 return this.eventID;
158         }
159         this.getTimeStart = function ()
160         {
161                 var date = new Date(parseInt(this.startTime)*1000);
162                 return date;
163         }
164         this.getTimeStartString = function ()
165         {
166                 var h = this.getTimeStart().getHours();
167                 var m = this.getTimeStart().getMinutes();
168                 if (m < 10){
169                         m="0"+m;
170                 }
171                 return h+":"+m;
172         }
173         this.getTimeDay = function ()
174         {
175                 var Wochentag = new Array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
176                 var wday = Wochentag[this.getTimeStart().getDay()];
177                 var day = this.getTimeStart().getDate();
178                 var month = this.getTimeStart().getMonth()+1;
179                 var year = this.getTimeStart().getFullYear();
180                 
181                 return wday+".&nbsp;"+day+"."+month+"."+year;
182         }
183         this.getTimeEnd = function ()
184         {
185                 var date = new Date((parseInt(this.startTime)+parseInt(this.duration))*1000);
186                 return date;
187         }
188         this.getTimeEndString = function ()
189         {
190                 var h = this.getTimeEnd().getHours();
191                 var m = this.getTimeEnd().getMinutes();
192                 if (m < 10){
193                         m="0"+m;
194                 }
195                 return h+":"+m;
196         }
197         this.getDuration = function ()
198         {
199                 return  new Date(parseInt(this.duration)*1000);
200         }
201         this.getTitle = function ()
202         {
203                 return this.title;
204         }
205         this.getDescription = function ()
206         {
207                 return this.description;
208         }
209         this.getDescriptionExtended = function ()
210         {
211                 return this.descriptionE;
212         }
213         this.getServiceReference = function ()
214         {
215                 return this.serviceRef;
216         }
217         this.getServiceName = function ()
218         {
219                 return this.serviceName.replace(" ","&nbsp;");
220         }
221 }//END class EPGEvent
222 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
223 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
224 //++++ GUI functions                               ++++
225 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
226 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
227 var currentBodyMainElement = null
228
229 function setBodyMainContent(newelementname){
230         newelement =document.getElementById(newelementname);
231         if(currentBodyMainElement != null){
232                 currentBodyMainElement.style.display = "none";
233                 
234         }
235         newelement.style.display = "inline";
236         currentBodyMainElement = newelement;
237 }
238 function doRequest(url,readyFunction){
239         
240         http_request =getHTTPObject();
241         if(readyFunction){
242                 http_request.onreadystatechange = readyFunction;
243         }
244         http_request.open('GET', url, true);
245         http_request.send(null);
246         return http_request;
247 }
248 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
249 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
250 //++++ volume functions                            ++++
251 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
252 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
253
254
255 function getVolume()
256 {
257         doRequest(url_getvolume,handleVolumeRequest);
258 }
259 function setVolume(newvalue)
260 {
261                 doRequest(url_setvolume+newvalue,handleVolumeRequest);
262 }
263 function volumeUp()
264 {
265                 doRequest(url_volumeup,handleVolumeRequest);
266 }
267 function volumeDown()
268 {
269                 doRequest(url_volumedown,handleVolumeRequest);  
270 }
271 function volumeMute()
272 {
273                 doRequest(url_volumemute,handleVolumeRequest);
274 }
275 function handleVolumeRequest(){
276                 if (http_request.readyState == 4) {
277                                 var a = http_request.responseText.split("\n");
278                                 var newvalue = a[1];
279                         var mute=a[2];
280                                 set("Volume_Current",newvalue);
281                                 for (var i = 1; i <= 10; i++)
282                                 {
283                                         if ( (newvalue/10)>=i){
284                                                 $("volume"+i).src = "/webdata/gfx/led_on.png";
285                                         }else{
286                                                 $("volume"+i).src = "/webdata/gfx/led_off.png";
287                                         }
288                                 }
289                                 if (mute == "notmuted"){
290                                         $("speaker").src = "/webdata/gfx/speak_on.png";
291                                 }else{
292                                         $("speaker").src = "/webdata/gfx/speak_off.png";
293                                 }
294                         }       
295 }
296 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
297 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
298 //++++ Bouqet managing functions                   ++++
299 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
300 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
301         function loadRootTVBouqet(){
302                 //rootB = '/web/fetchchannels?ServiceListBrowse='+escape('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet');
303         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');
304                 
305                  
306                 loadRootBouqet(rootB);
307         }
308   function loadRootBouqet(rootB){
309                 
310                 t =getHTTPObject();
311                 t.onreadystatechange = incomingResult;
312                 t.open('GET', rootB, true);
313                 t.send(null);
314                 
315         }
316         function incomingResult(){
317                 if (t.readyState == 4) {
318         // perfekt!
319                         result = t.responseText;
320                         x = result.split("\n");
321                         bouquets = new Array();
322                         for ( var i = 0 ; i < x.length ; i=i+2 ){
323                                 bu = new Array(x[i+1 ],x[i]);
324                                 bouquets.push(bu)
325                         }
326                         refreshSelect(bouquets);
327                 } else {
328         // die Anfrage enthielt Fehler;
329         // die Antwort war z.B. 404 (nicht gefunden)
330         // oder 500 (interner Server-Fehler)
331                 }
332                 
333         }
334         // to add the bouqetts to the list
335         function refreshSelect(arraybouqet){
336                 
337                 sel = document.getElementById("accordionMenueBouqetContent");
338                 // options neu eintragen
339                 html = "<table>";
340                         for ( var i = 0 ; i < arraybouqet.length ; i++ ){
341                         if(arraybouqet[i][0] && arraybouqet[i][1]){
342                                 html+="<tr><td>";
343                                 html+="<a  onclick=\"bouqetSelected(this); setBodyMainContent('BodyContentChannellist');\" id='";
344                                 html+= arraybouqet[i][1];
345                                 html+="'>";
346                                 html+= arraybouqet[i][0];
347                                 html+="</a>";
348                                 html+="</td></tr>";
349                         }
350                 }
351                 html+="</table>";
352                 sel.innerHTML=html;
353                 refreshChannellist(arraybouqet[0][0],arraybouqet[0][1]);
354         }
355         //++++++++++++++++++++++
356         function bouqetSelected(element){
357                 refreshChannellist(element.value,element.id)
358         }
359         
360         function refreshChannellist(bname,bref){
361                 urlx = '/web/fetchchannels?ServiceListBrowse='+escape(bref);
362                 w =getHTTPObject();
363                 w.onreadystatechange = incomingChannellist;
364           w.open('GET', urlx, true);
365           w.send(null);
366           
367                 
368                 
369         }
370                 function incomingChannellist(){
371                         if (w.readyState == 4) {
372                 // alles in Ordnung, Antwort wurde empfangen
373                                 result = w.responseText;
374                                 x = result.split("\n");
375                                 
376                                 
377                                 listerHtml = "<table id=\"ChannelSelect\" >";
378                                 for ( var i = 0 ; i < x.length ; i=i+2 ){
379                                         if(x[i].length>=1 && x[i+1]){
380                                                 
381                                                 listerHtml += '<tr bgcolor="gray"><td><div onclick=\"zap(this)\" id="';
382                                                 listerHtml += x[i];
383                                                 listerHtml += '">';
384                                                 listerHtml += x[i+1];
385                                                 listerHtml += '</div></td>';
386                                                 listerHtml += '<td><a onclick=\"new EPGList().getByServiceReference(this.id,$(\'BodyEPGPanel\'));setBodyMainContent(\'BodyEPGPanel\');\" id="';
387                                                 listerHtml += x[i];
388                                                 listerHtml += '" >EPG</div><div><a href=\"stream.m3u?ref=';
389                                                 listerHtml += x[i];
390                                                 listerHtml += '\">Stream</a></div></td>';
391                                                 listerHtml += '</tr>';
392                                         }
393                                 }
394                                 listerHtml += "</table>";
395                                 document.getElementById("BodyContentChannellist").innerHTML = listerHtml;
396                                 setBodyMainContent('BodyContentChannellist');
397                         } else {
398                 // die Anfrage enthielt Fehler;
399                 // die Antwort war z.B. 404 (nicht gefunden)
400                 // oder 500 (interner Server-Fehler)
401                         }
402                         
403         }
404
405
406