Added functionality to wap-page timerlist aswell as a new page for powerstate
[enigma2-plugins.git] / webinterface / src / web-data / objects.js
1
2 // store all objects here
3
4 //START class EPGList
5 function EPGList(xml){
6         // parsing values from xml-element
7         //debug('init EPGList'+xml);
8         try{
9                 this.xmlitems = xml.getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
10         } catch (e) { debug("EPGList parsing Error");}
11         
12         this.getArray = function(sortbytime){
13                 debug("sort EPGList by time "+sortbytime);
14                 if (sortbytime = true){
15                         var sort1 = new Array();
16                         for(var i=0;i<this.xmlitems.length;i++){
17                                 var xv = new EPGEvent(this.xmlitems.item(i));
18                                 sort1.push(new Array(xv.startTime,xv));
19                         }
20                         sort1.sort(this.sortFunction);
21                         var sort2 = new Array();
22                         for(var i=0;i<sort1.length;i++){
23                                 sort2.push(sort1[i][1]);
24                         }
25                         return sort2;
26                 }else{
27                         var listxy = new Array();
28                         for (var i=0;i<this.xmlitems.length;i++){
29                                 var xv = new EPGEvent(this.xmlitems.item(i));
30                                 listxy.push(xv);                        
31                         }
32                         return listxy;
33                 }
34         }
35         this.sortFunction = function(a,b){
36           return a[0] - b[0];
37         }
38 }
39 //END class EPGList
40
41 //START class EPGEvent
42 function EPGEvent(xml){ 
43         // parsing values from xml-element
44         try{
45                 this.eventID = xml.getElementsByTagName('e2eventid').item(0).firstChild.data;
46                 this.startTime = xml.getElementsByTagName('e2eventstart').item(0).firstChild.data;
47                 this.duration = xml.getElementsByTagName('e2eventduration').item(0).firstChild.data;
48                 this.title = xml.getElementsByTagName('e2eventtitle').item(0).firstChild.data;
49                 this.serviceRef = xml.getElementsByTagName('e2eventservicereference').item(0).firstChild.data;
50                 this.serviceName = xml.getElementsByTagName('e2eventservicename').item(0).firstChild.data;
51                 this.fileName = xml.getElementsByTagName('e2filename').item(0).firstChild.data;
52         } catch (e) {
53                 //debug("EPGEvent parsing Error");
54         }       
55         try{
56                 this.description = xml.getElementsByTagName('e2eventdescription').item(0).firstChild.data;
57         } catch (e) {   this.description= 'N/A';        }
58         
59         try{
60                 this.descriptionE = xml.getElementsByTagName('e2eventdescriptionextended').item(0).firstChild.data;
61         } catch (e) {   this.descriptionE = 'N/A';      }
62
63         this.getFilename = function ()
64         {
65                 return this.fileName;
66         }
67         this.getEventId = function ()
68         {
69                 return this.eventID;
70         }
71         this.getTimeStart = function ()
72         {
73                 var date = new Date(parseInt(this.startTime)*1000);
74                 return date;
75         }
76         this.getTimeStartString = function ()
77         {
78                 var h = this.getTimeStart().getHours();
79                 var m = this.getTimeStart().getMinutes();
80                 if (m < 10){
81                         m="0"+m;
82                 }
83                 return h+":"+m;
84         }
85         this.getTimeDay = function ()
86         {
87                 var Wochentag = new Array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
88                 var wday = Wochentag[this.getTimeStart().getDay()];
89                 var day = this.getTimeStart().getDate();
90                 var month = this.getTimeStart().getMonth()+1;
91                 var year = this.getTimeStart().getFullYear();
92                 
93                 return wday+".&nbsp;"+day+"."+month+"."+year;
94         }
95         this.getTimeBegin = function(){
96                 return this.getTimeStart().getTime()/1000
97         }
98         this.getTimeEnd = function ()
99         {
100                 var date = new Date((parseInt(this.startTime)+parseInt(this.duration))*1000);
101                 return date.getTime()/1000
102         }
103         this.getTimeEndString = function ()
104         {
105                 var date = new Date((parseInt(this.startTime)+parseInt(this.duration))*1000);
106                 var h = date.getHours();
107                 var m = date.getMinutes();
108                 if (m < 10){
109                         m="0"+m;
110                 }
111                 return h+":"+m;
112         }
113         this.getDuration = function ()
114         {
115                 return  new Date(parseInt(this.duration)*1000);
116         }
117         this.getTitle = function ()
118         {
119                 return this.title;
120         }
121         this.getDescription = function ()
122         {
123                 return this.description;
124         }
125         this.getDescriptionExtended = function ()
126         {
127                 return this.descriptionE;
128         }
129         this.getServiceReference = function ()
130         {
131                 return encodeURIComponent(this.serviceRef);
132         }
133         this.getServiceName = function ()
134         {
135                 return this.serviceName.replace(" ","&nbsp;");
136         }
137 }
138 //END class EPGEvent
139
140 //START class Service
141 function ServiceReference(xml){ 
142         // parsing values from xml-element
143         //debug('init ServiceReference'+xml);
144         try{
145                 this.servicereference = xml.getElementsByTagName('e2servicereference').item(0).firstChild.data;
146                 this.servicename = xml.getElementsByTagName('e2servicename').item(0).firstChild.data;
147         } catch (e) {
148                 //debug("Service parsing Error "+e);
149         }
150         
151         this.getServiceReference = function(){
152                 return encodeURIComponent(this.servicereference);
153         }
154         this.getClearServiceReference = function(){
155                 return this.servicereference;
156         }
157                 
158         this.getServiceName = function(){
159                 return this.servicename.replace('&quot;', '"');
160         }
161         this.setServiceReference = function(toInsert){
162                 this.servicereference = toInsert;
163         }
164                 
165         this.setServiceName = function(toInsert){
166                 this.servicename = toInsert.replace('&quot;', '"');
167         }
168 }       
169 //END class Service
170
171 //START class ServiceList
172 function ServiceList(xml){
173         // parsing values from xml-element
174         //debug('init ServiceList'+xml);
175         try{
176                 this.xmlitems = xml.getElementsByTagName("e2servicelist").item(0).getElementsByTagName("e2service");
177         } catch (e) {
178                 //debug("Service parsing Error");
179         }
180         this.getArray = function(){
181                 var listxy = new Array();
182                 for (var i=0;i<this.xmlitems.length;i++){
183                         var xv = new ServiceReference(this.xmlitems.item(i));
184                         listxy.push(xv);                        
185                 }
186                 return listxy;
187         }
188 }
189 //END class ServiceList
190
191 //START class MovieList
192 function MovieList(xml){
193         // parsing values from xml-element
194         debug('init MovieList'+xml);
195         try{
196                 this.xmlitems = xml.getElementsByTagName("e2movielist").item(0).getElementsByTagName("e2movie");
197         } catch (e) {
198                 debug("MovieList parsing Error");
199         }
200         this.getArray = function(){
201                 var listxy = new Array();
202                 for(var i=0;i<this.xmlitems.length;i++){
203                         //debug("parsing movie "+i+" of "+this.xmlitems.length);
204                         var xv = new Movie(this.xmlitems.item(i));
205                         listxy.push(xv);                        
206                 }
207                 return listxy;
208         }
209 }
210 //END class MovieList
211
212 //START class Movie
213 function Movie(xml){    
214         // parsing values from xml-element
215         //debug('init Movie');
216         try{
217                 this.servicereference = xml.getElementsByTagName('e2servicereference').item(0).firstChild.data;
218         } catch (e) {
219                 this.servicereference = "N/A";
220         }
221         try{
222                 this.servicename = xml.getElementsByTagName('e2servicename').item(0).firstChild.data;
223         } catch (e) {
224                 this.servicename = "N/A";
225         }
226         try{
227                 this.title = xml.getElementsByTagName('e2title').item(0).firstChild.data;
228         } catch (e) {
229                 this.title = "N/A";
230         }
231         try{
232                 this.descriptionextended = xml.getElementsByTagName('e2descriptionextended').item(0).firstChild.data;
233         } catch (e) {
234                 this.descriptionextended = "N/A";
235         }
236         try{
237                 this.description = xml.getElementsByTagName('e2description').item(0).firstChild.data;
238         } catch (e) {
239                 this.description = "N/A";
240         }
241         try{
242                 this.tags = xml.getElementsByTagName('e2tags').item(0).firstChild.data;
243         } catch (e) {
244                 this.tags = "no&nbsp;tags"; // no whitespaces... tags will be splittet later
245         }
246         try{
247                 this.filename = xml.getElementsByTagName('e2filename').item(0).firstChild.data;
248         } catch (e) {
249                 this.filename = "n/a";
250         }
251         this.getServiceReference = function(){
252                 return encodeURIComponent(this.servicereference);
253         }
254         this.getServiceName = function(){
255                 return this.servicename.replace('&quot;', '"');
256         }       
257         this.getTitle = function(){
258                 return this.title;
259         }       
260         this.getDescription = function(){
261                 return this.description;
262         }       
263         this.getDescriptionExtended = function(){
264                 return this.descriptionextended;
265         }       
266         this.getTags = function(){              
267                 return this.tags.split(" ");
268         }       
269         this.getFilename = function(){          
270                 return encodeURIComponent(this.filename);
271                 
272         }       
273 }       
274 //END class Movie
275
276 //START class TimerList
277 function TimerList(xml){
278         // parsing values from xml-element
279         try{
280                 this.xmlitems = xml.getElementsByTagName("e2timerlist").item(0).getElementsByTagName("e2timer");
281         } catch (e) {
282                 debug("TimerList parsing Error");
283         }
284         this.getArray = function(){
285                 var listxy = new Array();
286                 for(var i=0;i<this.xmlitems.length;i++){
287                         //debug("parsing timer "+i+" of "+this.xmlitems.length);
288                         var xv = new Timer(this.xmlitems.item(i));
289                         listxy.push(xv);                        
290                 }
291                 return listxy;
292         }
293 }
294 //END class TimerList
295
296 //START class Timer
297 function Timer(xml){    
298         // parsing values from xml-element
299         //debug('init Timer');
300         try{
301                 this.servicereference = xml.getElementsByTagName('e2servicereference').item(0).firstChild.data;
302         } catch (e) {
303                 this.servicereference = "N/A";
304         }
305         try{
306                 this.servicename = xml.getElementsByTagName('e2servicename').item(0).firstChild.data;
307         } catch (e) {
308                 this.servicename = "N/A";
309         }
310         try{
311                 this.eventid = xml.getElementsByTagName('e2eit').item(0).firstChild.data;
312         } catch (e) {
313                 this.eventid = "N/A";
314         }
315         try{
316                 this.name = xml.getElementsByTagName('e2name').item(0).firstChild.data;
317         } catch (e) {
318                 this.name = "N/A";
319         }
320         try{
321                 this.description = xml.getElementsByTagName('e2description').item(0).firstChild.data;
322         } catch (e) {
323                 this.description = "N/A";
324         }
325         try{
326                 this.descriptionextended = xml.getElementsByTagName('e2descriptionextended').item(0).firstChild.data;
327         } catch (e) {
328                 this.descriptionextended = "N/A";
329         }
330         try{
331                 this.disabled = xml.getElementsByTagName('e2disabled').item(0).firstChild.data;
332         } catch (e) {
333                 this.disabled = "0";
334         }
335         try{
336                 this.timebegin = xml.getElementsByTagName('e2timebegin').item(0).firstChild.data;
337         } catch (e) {
338                 this.timebegin = "N/A";
339         }
340         try{
341                 this.timeend = xml.getElementsByTagName('e2timeend').item(0).firstChild.data;
342         } catch (e) {
343                 this.timeend = "N/A";
344         }
345         try{
346                 this.duration = xml.getElementsByTagName('e2duration').item(0).firstChild.data;
347         } catch (e) {           
348                 this.duration = "0";
349         }
350         try{
351                 this.startprepare = xml.getElementsByTagName('e2startprepare').item(0).firstChild.data;
352         } catch (e) {
353                 this.startprepare = "N/A";
354         }
355         try{
356                 this.justplay = xml.getElementsByTagName('e2justplay').item(0).firstChild.data;
357         } catch (e) {
358                 this.justplay = "";
359         }
360         try{
361                 this.afterevent = xml.getElementsByTagName('e2afterevent').item(0).firstChild.data;
362         } catch (e) {
363                 this.afterevent = "0";
364         }
365         try{
366                 this.logentries = xml.getElementsByTagName('e2logentries').item(0).firstChild.data;
367         } catch (e) {
368                 this.logentries = "N/A";
369         }
370         try{
371                 this.tfilename = xml.getElementsByTagName('e2filename').item(0).firstChild.data;
372         } catch (e) {
373                 this.tfilename = "N/A";
374         }
375         try{
376                 this.backoff = xml.getElementsByTagName('e2backoff').item(0).firstChild.data;
377         } catch (e) {
378                 this.backoff = "N/A";
379         }
380         try{
381                 this.nextactivation = xml.getElementsByTagName('e2nextactivation').item(0).firstChild.data;
382         } catch (e) {
383                 this.nextactivation = "N/A";
384         }
385         try{
386                 this.firsttryprepare = xml.getElementsByTagName('e2firsttryprepare').item(0).firstChild.data;
387         } catch (e) {
388                 this.firsttryprepare = "N/A";
389         }
390         try{
391                 this.state = xml.getElementsByTagName('e2state').item(0).firstChild.data;
392         } catch (e) {
393                 this.state = "N/A";
394         }
395         try{
396                 this.repeated = xml.getElementsByTagName('e2repeated').item(0).firstChild.data;
397         } catch (e) {
398                 this.repeated = "0";
399         }
400         try{
401                 this.dontsave = xml.getElementsByTagName('e2dontsave').item(0).firstChild.data;
402         } catch (e) {
403                 this.dontsave = "N/A";
404         }
405         try{
406                 this.cancled = xml.getElementsByTagName('e2cancled').item(0).firstChild.data;
407         } catch (e) {
408                 this.cancled = "N/A";
409         }
410         try{
411                 this.color = xml.getElementsByTagName('e2color').item(0).firstChild.data;
412         } catch (e) {
413                 this.color = "N/A";
414         }
415         try{
416                 this.toggledisabled = xml.getElementsByTagName('e2toggledisabled').item(0).firstChild.data;
417         } catch (e) {
418                 this.toggledisabled = "N/A";
419         }
420         try{
421                 this.toggledisabledimg = xml.getElementsByTagName('e2toggledisabledimg').item(0).firstChild.data;
422         } catch (e) {
423                 this.toggledisabledimg = "N/A";
424         }
425
426         this.getColor = function(){
427                 return this.color;
428         }
429         this.getToggleDisabled = function(){
430                 return this.toggledisabled;
431         }
432         this.getToggleDisabledIMG = function(){
433                 return this.toggledisabledimg;
434         }
435         
436         this.getServiceReference = function(){
437                 return encodeURIComponent(this.servicereference);
438         }
439         this.getServiceName = function(){
440                 return this.servicename.replace('&quot;', '"');
441         }       
442         this.getEventID = function(){
443                 return this.eventid;
444         }       
445         this.getName = function(){
446                 return this.name;
447         }       
448         this.getDescription = function(){
449                 return this.description;
450         }       
451         this.getDescriptionExtended = function(){
452                 return this.descriptionextended;
453         }       
454         this.getDisabled = function(){
455                 return this.disabled;
456         }
457         this.getTimeBegin = function(){
458                 return this.timebegin;
459         }       
460         this.getTimeEnd = function(){
461                 return this.timeend;
462         }       
463         this.getDuration = function(){
464                 return parseInt(this.duration);
465         }       
466         this.getStartPrepare = function(){
467                 return this.startprepare;
468         }       
469         this.getJustplay = function(){
470                 return this.justplay;
471         }       
472         this.getAfterevent = function(){
473                 return this.afterevent;
474         }       
475         this.getLogentries = function(){
476                 return this.logentries;
477         }       
478         this.getFilename = function(){
479                 return this.tfilename;
480         }       
481         this.getBackoff = function(){
482                 return this.backoff;
483         }       
484         this.getNextActivation = function(){
485                 return this.nextactivation;
486         }       
487         this.getFirsttryprepare = function(){
488                 return this.firsttryprepare;
489         }       
490         this.getState = function(){
491                 return this.state;
492         }       
493         this.getRepeated = function(){
494                 return this.repeated;
495         }       
496         this.getDontSave = function(){
497                 return this.dontsave;
498         }       
499         this.isCancled = function(){
500                 return this.cancled;
501         }       
502 }
503 // START SimpleXMLResult ehemals TimerAddResult
504 function SimpleXMLResult(xml){
505         // parsing values from xml-element
506         debug('init SimpleXMLResult'+xml);
507         try{
508                 this.xmlitems = xml.getElementsByTagName("e2simplexmlresult").item(0);
509                 debug(xml.getElementsByTagName("e2simplexmlresult").length);
510         } catch (e) {
511                 debug("SimpleXMLResult parsing e2simplexmlresult"+e);
512         }
513         try{
514                 this.state = this.xmlitems.getElementsByTagName("e2state").item(0).firstChild.data;
515         } catch (e) {
516                 debug("SimpleXMLResult parsing e2state"+e);
517         }
518         try{
519                 this.statetext = this.xmlitems.getElementsByTagName("e2statetext").item(0).firstChild.data;
520         } catch (e) {
521                 debug("SimpleXMLResult parsing e2statetext"+e);
522         }
523         
524         this.getState = function(){
525                 if(this.state == 'True'){
526                         return true;
527                 }else{
528                         return false;
529                 }
530         }
531         this.getStateText = function(){
532                         return this.statetext;
533         }
534 }
535 // END SimpleXMLResult
536
537 //START class Settings
538 function Settings(xml){
539         // parsing values from xml-element
540         //debug('init ServiceList'+xml);
541         try{
542                 this.xmlitems = xml.getElementsByTagName("e2settings").item(0).getElementsByTagName("e2setting");
543                 debug(this.xmlitems);
544         } catch (e) {
545                 //debug("Service parsing Error");
546         }
547         this.getArray = function(){
548                 var listxy = new Array();
549                 for (var i=0;i<this.xmlitems.length;i++){
550                         var xv = new Setting(this.xmlitems.item(i));
551                         listxy.push(xv);                        
552                 }
553                 return listxy;
554         }
555 }
556 //END class Settings
557
558 //START class Setting
559 function Setting(xml){  
560         // parsing values from xml-element
561         //debug('init ServiceReference'+xml);
562         try{
563                 this.settingvalue = xml.getElementsByTagName('e2settingvalue').item(0).firstChild.data;
564                 this.settingname = xml.getElementsByTagName('e2settingname').item(0).firstChild.data;
565                 
566         } catch (e) {
567                 //debug("Service parsing Error "+e);
568         }
569         
570         this.getSettingValue = function(){
571                 return this.settingvalue;
572         }
573                 
574         this.getSettingName = function(){
575                 return this.settingname;
576         }
577         
578 }