webif:
[enigma2-plugins.git] / webinterface / src / web-data / objects.js
1 // $Header$
2 // store all objects here
3
4 var AjaxThing = Class.create({
5         /**
6          * getUrl
7          * creates a new Ajax.Request
8          * Parameters:
9          * @url - the url to fetch
10          * @parms - an json object containing  {parameter : value} pairs for the request
11          * @callback - function to call @ onSuccess;
12          * @errorback - function to call @ onError;
13          */
14         getUrl: function(url, parms, callback, errorback){
15                 debug("[AjaxThing].getUrl :: url=" + url + " :: parms=" + Object.toJSON(parms));
16                 if (!window.google || !google.gears){ //no gears
17                         try{
18                                 new Ajax.Request(url,
19                                                 {
20                                                         parameters: parms,
21                                                         asynchronous: true,
22                                                         method: 'POST',
23                                                         requestHeaders: ['Cache-Control', 'no-cache,no-store', 'Expires', '-1'],
24                                                         onException: function(o,e){ 
25                                                                         console.log(o); 
26                                                                         console.log(e);
27                                                                         throw(e);
28                                                                 }.bind(this),                           
29                                                         onSuccess: function (transport, json) {                                         
30                                                                 if(callback !== undefined){
31                                                                         callback(transport);
32                                                                 }
33                                                         }.bind(this),
34                                                         onFailure: function(transport){
35                                                                 if(errorback !== undefined){
36                                                                         errorback(transport);
37                                                                 }
38                                                         }.bind(this)
39 //                                                      onComplete: this.requestFinished.bind(this)
40                                                 });
41                         } catch(e) {
42                                 debug('[AbstractContentProvider.getUrl] Exception: '+ e);
43                         }
44                 } else { //we're on gears!
45                         try{
46                                 url = url + "?" + $H(parms).toQueryString();
47                                 
48                                 var request = google.gears.factory.create('beta.httprequest');
49                                 request.open('GET', url);
50         
51         
52                                 request.onreadystatechange = function(){                                
53                                         if(request.readyState == 4){
54                                                 if(request.status == 200){
55                                                         if( callback !== undefined ){
56                                                                 callback(request);
57                                                         }
58                                                 } else {
59                                                         this.errorback(request);
60                                                 }
61                                         }
62                                 }.bind(this);
63                                 request.send();
64                         } catch(e) {
65                                 debug('[AbstractContentProvider.getUrl] Exception: '+ e);
66                         }
67                 }
68         }
69 });
70
71
72 var TemplateEngine = Class.create(AjaxThing, {
73         initialize: function(){
74                 this.templates = {};
75         },
76
77         cache: function(request, tplName){
78                 debug("[TemplateEngine].cache caching template: " + tplName);
79                 this.templates[tplName] = request.responseText;
80         },
81         
82         fetch: function(tplName, callback){
83                 if(this.templates[tplName] === undefined) {
84                         var url = URL.tpl+tplName+".htm";
85                         
86                         this.getUrl(
87                                         url, 
88                                         {},
89                                         function(transport){
90                                                 this.cache(transport, tplName);
91                                                 if(typeof(callback) == 'function'){
92                                                         callback(this.templates[tplName]);
93                                                 }
94                                         }.bind(this)
95                         );
96                 } else {
97                         if(typeof(callback) == 'function'){
98                                 callback(this.templates[tplName]);
99                         }
100                 }
101         },
102         
103         render: function(tpl, data, domElement) {       
104                 var result = tpl.process(data);
105         
106                 try{
107                         $(domElement).update( result );
108                 }catch(ex){
109                         debug("[TemplateEngine].render catched an exception!");
110                         throw ex;
111                 }
112         },
113         
114         onTemplateReady: function(tpl, data, domElement, callback){
115                 this.render(tpl, data, domElement);
116                 if(typeof(callback) == 'function') {
117                         callback();
118                 }
119         },
120         
121         process: function(tplName, data, domElement, callback){
122                 this.fetch( tplName, 
123                                 function(tpl){
124                                         this.onTemplateReady(tpl, data, domElement, callback); 
125                                 }.bind(this) );
126         }
127 });
128 templateEngine = new TemplateEngine();
129
130
131 //START class EPGList 
132
133 function getNodeContent(xml, nodename, defaultString){
134         try{
135                 var node = xml.getElementsByTagName(nodename);
136                 var retVal = node.item(0).firstChild.data;
137
138                 if(retVal === "" || retVal === null){
139                         return 'N/A';           
140                 } else if (retVal === "None"){
141                         return "";
142                 }
143                 
144                 return retVal;
145         } catch(e){
146                 if(typeof(defaultString) !== 'undefined') {
147                         return defaultString;
148                 }               
149         }
150         
151         return 'N/A';
152 }
153
154 function getNamedChildren(xml, parentname, childname){
155         try {
156                 var ret = xml.getElementsByTagName(parentname).item(0).getElementsByTagName(childname);
157                 return ret;
158         } catch (e) {
159                 return {};
160         }
161 }
162
163
164 function dec2hex(nr, len){
165         var hex = parseInt(nr, 10).toString(16).toUpperCase();
166         if(len > 0){
167                 try{
168                         while(hex.length < len){
169                                 hex = "0"+hex;
170                         }
171                 } 
172                 catch(e){
173                         //something went wrong, return -1
174                         hex = -1;
175                 }
176         }
177         hex = '0x' + hex;
178         return hex;
179 }
180
181
182 function quotes2html(txt) {
183         if(txt !== undefined){
184                 return txt.escapeHTML().replace('\n', '<br>');
185         } else {
186                 return "";
187         }
188 }
189
190 function addLeadingZero(nr){
191         if(nr < 10){
192                 return '0' + nr;
193         }
194         return nr;
195 }
196
197 function repeatedReadable(num) {
198         num = Number(num);
199         if (num === 0) {
200                 return "One Time";
201         }
202
203         var retVal = "";
204         var Repeated = {};
205         Repeated["Mo-Su"] = 127;
206         Repeated["Mo-Fr"] = 31;
207         Repeated["Su"] = 64;
208         Repeated["Sa"] = 32;
209         Repeated["Fr"] = 16;
210         Repeated["Th"] = 8;
211         Repeated["We"] = 4;
212         Repeated["Tu"] = 2;
213         Repeated["Mo"] = 1;
214
215         for (var rep in Repeated) {
216                 if (rep.toString() != 'extend') {
217                         var check = Number(Repeated[rep]);
218                         if (!(~num & check)) {
219                                 num -= check;
220                                 if (retVal === '') {
221                                         retVal += rep.toString();
222                                 } else {
223                                         retVal = rep.toString() + ',' + retVal;
224                                 }
225                         }
226                 }
227         }
228         return retVal;
229 }
230
231 function dateToString(date){
232         var dateString = "";
233         dateString += date.getFullYear();
234         dateString += "-" + addLeadingZero(date.getMonth()+1);
235         dateString += "-" + addLeadingZero(date.getDate());
236         dateString += " " + addLeadingZero(date.getHours());
237         dateString += ":" + addLeadingZero(date.getMinutes());
238         return dateString;
239 }
240
241 //START class EPGEvent
242 function EPGEvent(xml, number){ 
243         this.eventID = getNodeContent(xml, 'e2eventid', '');
244         this.startTime = parseNr(getNodeContent(xml, 'e2eventstart', ''));      
245         this.duration = parseNr(getNodeContent(xml, 'e2eventduration', ''));
246         this.currentTime = parseNr(getNodeContent(xml, 'e2eventcurrenttime')),
247         this.title = getNodeContent(xml, 'e2eventtitle', '');
248         this.serviceRef = getNodeContent(xml, 'e2eventservicereference', '');
249         this.serviceName = getNodeContent(xml, 'e2eventservicename', '');
250         this.fileName = getNodeContent(xml, 'e2filename', '');  
251         this.description = getNodeContent(xml, 'e2eventdescription');
252         this.descriptionE = getNodeContent(xml, 'e2eventdescriptionextended');
253         
254         if(typeof(number) != "undefined"){
255                 this.number = number;
256         } else {
257                 this.number = 0;
258         }
259         
260         this.getFilename = function() {
261                 return this.fileName;
262         };
263         this.getEventId = function() {
264                 return this.eventID;
265         };
266         this.getTimeStart = function() {
267                 var date = new Date(this.startTime *1000);
268                 return date;
269         };
270         this.getTimeStartString = function() {
271                 var h = this.getTimeStart().getHours();
272                 var m = this.getTimeStart().getMinutes();
273                 if (m < 10){
274                         m="0"+m;
275                 }
276                 return h+":"+m;
277         };
278         this.getTimeDay = function() {
279                 var weekday = ["So", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
280                 var wday = weekday[this.getTimeStart().getDay()];
281                 var day = this.getTimeStart().getDate();
282                 var month = this.getTimeStart().getMonth()+1;
283                 var year = this.getTimeStart().getFullYear();
284                 
285                 return wday+".&nbsp;"+day+"."+month+"."+year;
286         };
287         this.getTimeBegin = function(){
288                 return this.getTimeStart().getTime()/1000;
289         };
290         this.getTimeEnd = function() {
291                 var date = new Date(( this.startTime + this.duration ) * 1000);
292                 return parseInt( date.getTime()/1000 );
293         };
294         this.getTimeEndString = function() {
295                 var date = new Date(( this.startTime + this.duration ) * 1000);
296                 var h = date.getHours();
297                 var m = date.getMinutes();
298                 if (m < 10){
299                         m="0"+m;
300                 }
301                 return h+":"+m;
302         };
303         this.getDuration = function() {
304                 var date = new Date( this.duration * 1000);
305                 return date;
306         };
307         this.getTimeRemainingString = function() {
308                 
309                 if( this.currentTime <= this.startTime ){
310                         return Math.ceil(this.getDuration() / 60000);
311                 } else {
312                         if( this.getTimeEnd() > 0){
313                                 var remaining = Math.ceil( ( this.getTimeEnd() - this.currentTime ) / 60);
314                                 return remaining;
315                         } else {
316                                 return this.getTimeEnd();
317                         }
318                 }
319         };
320         
321         this.getProgress = function(){
322                 var progress = 100 - ( ( this.getTimeRemainingString() / ( this.getDuration() / 60000 ) ) * 100 );
323                 progress = Math.ceil(progress);
324                 if(isNaN(progress))
325                         progress = 0;
326                 return progress;
327         };
328         
329         this.getTitle = function() {
330                 return this.title;
331         };
332         this.getDescription = function() {
333                 return this.description;
334         };
335         this.getDescriptionExtended = function() {
336                 return this.descriptionE;
337         };
338         this.getServiceReference = function() {
339                 return encodeURIComponent(this.serviceRef);
340         };
341         this.getServiceName = function() {
342                 return this.serviceName;
343         };
344         
345         this.json = {
346                         'date': this.getTimeDay(),
347                         'eventid': this.getEventId(),
348                         'servicereference': this.getServiceReference(),
349                         'servicename': quotes2html(this.getServiceName()),
350                         'title': quotes2html(this.getTitle()),
351                         'shorttitle': quotes2html(this.getTitle().substring(0, 40) ) + '...',
352                         'titleESC': escape(this.getTitle()),
353                         'starttime': this.getTimeStartString(), 
354                         'duration': Math.ceil(this.getDuration()/60000), 
355                         'description': quotes2html(this.getDescription()),
356                         'endtime': this.getTimeEndString(), 
357                         'remaining': this.getTimeRemainingString(),
358                         'progress' : this.getProgress(),
359                         'extdescription': quotes2html(this.getDescriptionExtended()),
360                         'number': String(this.number),
361                         'start': this.getTimeBegin(),
362                         'end': this.getTimeEnd()
363                         };
364         
365         this.toJSON = function() {
366                 return this.json;
367         };
368         
369 }
370 //END class EPGEvent
371 function EPGList(xml){
372         // parsing values from xml-element
373         try{
374                 this.xmlitems = xml.getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
375         } catch (e) {
376                 core.notify("Error Parsing EPG: " + e, false);
377         }
378         
379         this.getArray = function(sortbytime){
380                 var list = [];
381                 var len = this.xmlitems.length;
382                 
383                 if (sortbytime === true){
384                         debug("[EPGList].getArray :: Sort by time!");
385                         var sortList = [];
386                         
387                         for(var i=0; i<len; i++){
388                                 var event = new EPGEvent(this.xmlitems.item(i), i).toJSON();
389                                 sortList.push( [event.starttime, event] );
390                         }
391                         sortList.sort(this.sortFunction);
392                         
393                         list = [];
394                         len = sortList.length;
395                         for(i=0; i<len; i++){
396                                 list.push(sortList[i][1]);
397                         }
398                         
399                         return list;
400                         
401                 }else{
402                         for (i=0; i<len; i++){
403                                 xv = new EPGEvent(this.xmlitems.item(i)).toJSON();
404                                 list.push(xv);                  
405                         }
406                         return list;
407                 }
408         };
409         
410         this.sortFunction = function(a, b){
411           return a[0] - b[0];
412         };
413 }
414
415 function EPGListNowNext(xml){
416         // parsing values from xml-element
417         try{
418                 this.xmlitems = xml.getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
419         } catch (e) {
420                 core.notify("Error Parsing EPG: " + e, false);
421         }
422         
423         this.getArray = function(){
424                 list = [];
425                 var len = this.xmlitems.length;
426                 
427                 var idx = 0;
428                 var cssclass = 'even';
429                 
430                 for (var i=0; i < len; i += 2){
431                         cssclass = cssclass == 'even' ? 'odd' : 'even';
432                         now = new EPGEvent(this.xmlitems.item(i)).toJSON();
433                         next = new EPGEvent(this.xmlitems.item(i+1)).toJSON();
434                         list[idx] = {"now" : now, "next" : next, "cssclass": cssclass};
435                         idx++;
436                 }
437                 return list;
438         };
439 }
440 //END class EPGList
441
442 // START class Service
443 function Service(xml, cssclass){        
444         this.servicereference = getNodeContent(xml, 'e2servicereference', '');
445         this.servicename = getNodeContent(xml, 'e2servicename');
446         this.videowidth = getNodeContent(xml, 'e2videowidth');
447         this.videoheight = getNodeContent(xml, 'e2videoheight');
448         this.videosize = getNodeContent(xml, 'e2servicevideosize');
449         this.widescreen = getNodeContent(xml, 'e2iswidescreen');
450         this.apid = dec2hex( getNodeContent(xml, 'e2apid'),4 );
451         this.vpid = dec2hex( getNodeContent(xml, 'e2vpid'),4 );
452         this.pcrpid = dec2hex( getNodeContent(xml, 'e2pcrpid'),4 );
453         this.pmtpid = dec2hex( getNodeContent(xml, 'e2pmtpid'),4 );
454         this.txtpid = dec2hex( getNodeContent(xml, 'e2txtpid'),4 );
455         this.tsid = dec2hex( getNodeContent(xml, 'e2tsid'),4 );
456         this.onid = dec2hex( getNodeContent(xml, 'e2onid'),4 );
457         this.sid = dec2hex( getNodeContent(xml, 'e2sid'),4 );
458         
459         this.getServiceReference = function(){
460                 return encodeURIComponent(this.servicereference);
461         };
462         
463         this.getClearServiceReference = function(){
464                 return this.servicereference;
465         };
466                 
467         this.getServiceName = function(){
468                 return this.servicename.replace('&quot;', '"');
469         };
470         
471         this.setServiceReference = function(sref){
472                 this.servicereference = sref;
473         };
474                 
475         this.setServiceName = function(sname){
476                 this.servicename = sname.replace('&quot;', '"');
477         };
478         
479         if( typeof( cssclass ) == undefined ){
480                 cssclass = 'odd';
481         }
482         
483         this.json = {   
484                         'servicereference' : this.getServiceReference(),
485                         'servicename' : this.getServiceName(),
486                         'videowidth' : this.videowidth,
487                         'videoheight' : this.videoheight,
488                         'videosize' : this.videosize,
489                         'widescreen' : this.widescreen,
490                         'apid' : this.apid,
491                         'vpid' : this.vpid,
492                         'pcrpid' : this.pcrpid,
493                         'pmtpid' : this.pmtpid,
494                         'txtpid' : this.txtpid,
495                         'tsid' : this.tsid,
496                         'onid' : this.onid,
497                         'sid' : this.sid,
498                         'cssclass' : cssclass
499         };
500         
501         this.toJSON = function(){
502                 return this.json;
503         };
504 }       
505 //END class Service
506
507 // START class ServiceList
508 function ServiceList(xml){
509         this.xmlitems = getNamedChildren(xml, "e2servicelist", "e2service");
510         this.servicelist = [];
511         this.getArray = function(){
512                 if(this.servicelist.length === 0){
513                         var cssclass = 'even';
514                         
515                         var len = this.xmlitems.length;
516                         for (var i=0; i<len; i++){
517                                 cssclass = cssclass == 'even' ? 'odd' : 'even';
518                                 var service = new Service(this.xmlitems.item(i), cssclass).toJSON();
519                                 this.servicelist.push(service);
520                         }
521                 }
522                 
523                 return this.servicelist;
524         };
525 }
526 //END class ServiceList
527
528
529 // START class Movie
530 function Movie(xml, cssclass){  
531         this.servicereference = getNodeContent(xml, 'e2servicereference');
532         this.servicename = getNodeContent(xml, 'e2servicename');
533         this.title = getNodeContent(xml, 'e2title');
534         this.descriptionextended = getNodeContent(xml, 'e2descriptionextended');
535         this.description = getNodeContent(xml, 'e2description');
536         this.tags = getNodeContent(xml, 'e2tags', '&nbsp;');
537         this.filename = getNodeContent(xml, 'e2filename');
538         this.filesize = getNodeContent(xml, 'e2filesize', 0);
539         this.startTime = getNodeContent(xml, 'e2time', 0);
540         this.length = getNodeContent(xml, 'e2length', 0);
541
542         this.getLength = function() {
543                 return this.length;
544         };
545         
546         this.getTimeStart = function() {
547                 var date = new Date(parseInt(this.startTime, 10)*1000);
548                 return date;
549         };
550         
551         this.getTimeStartString = function() {
552                 var h = this.getTimeStart().getHours();
553                 var m = this.getTimeStart().getMinutes();
554                 if (m < 10){
555                         m="0"+m;
556                 }
557                 return h+":"+m;
558         };
559         
560         this.getTimeDay = function() {
561                 var Wochentag = ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"];
562                 var wday = Wochentag[this.getTimeStart().getDay()];
563                 var day = this.getTimeStart().getDate();
564                 var month = this.getTimeStart().getMonth()+1;
565                 var year = this.getTimeStart().getFullYear();
566                 
567                 return wday+".&nbsp;"+day+"."+month+"."+year;
568         };
569
570         this.getServiceReference = function(){
571                 return encodeURIComponent(this.servicereference);
572         };
573         this.getServiceName = function(){
574                 return this.servicename.replace('&quot;', '"');
575         };
576         
577         this.getTitle = function(){
578                 return this.title;
579         };
580         
581         this.getDescription = function(){
582                 return this.description;
583         };
584         
585         this.getDescriptionExtended = function(){
586                 return this.descriptionextended;
587         };
588         
589         this.getTags = function(){              
590                 return this.tags.split(" ");
591         };
592         
593         this.getFilename = function(){          
594                 return encodeURIComponent(this.filename);               
595         };
596         
597         this.getFilesizeMB = function(){                
598                 return Math.round((parseInt(this.filesize, 10)/1024)/1024)+"MB";
599         };
600         
601         if( typeof( cssclass) == 'undefined'){
602                 cssclass = 'odd';
603         }
604         
605         this.json = {
606                         'servicereference': this.getServiceReference(),
607                         'servicename': this.getServiceName(),
608                         'title': this.getTitle(),
609                         'escapedTitle': escape(this.getTitle()),
610                         'description': this.getDescription(), 
611                         'descriptionextended': this.getDescriptionExtended(),
612                         'filename': String(this.getFilename()),
613                         'filesize': this.getFilesizeMB(),
614                         'tags': this.getTags().join(', ') ,
615                         'length': this.getLength() ,
616                         'time': this.getTimeDay()+"&nbsp;"+ this.getTimeStartString(),
617                         'cssclass' : cssclass
618         };
619         
620         this.toJSON = function(){
621                 return this.json;
622         };
623 }       
624 //END class Movie
625
626
627 // START class MovieList
628 function MovieList(xml){
629         this.xmlitems = getNamedChildren(xml, "e2movielist", "e2movie");
630         this.movielist = [];
631         
632         this.getArray = function(){
633                 if(this.movielist.length === 0){
634                         var cssclass = "even";
635                         var len = this.xmlitems.length;
636                         for(var i=0; i<len; i++){
637                                 cssclass = cssclass == 'even' ? 'odd' : 'even';
638                                 
639                                 var movie = new Movie(this.xmlitems.item(i), cssclass).toJSON();
640                                 this.movielist.push(movie);                     
641                         }
642                 }
643                 
644                 return this.movielist;
645         };
646 }
647 //END class MovieList
648
649
650
651 // START class Timer
652 function Timer(xml, cssclass){  
653         this.servicereference = getNodeContent(xml, 'e2servicereference');
654         this.servicename = getNodeContent(xml, 'e2servicename');
655         this.eventid = getNodeContent(xml, 'e2eit');
656         this.name = getNodeContent(xml, 'e2name');
657         this.description = getNodeContent(xml, 'e2description', '');
658         this.descriptionextended = getNodeContent(xml, 'e2descriptionextended', '');
659         this.disabled = getNodeContent(xml, 'e2disabled', '0');
660         this.timebegin = getNodeContent(xml, 'e2timebegin');
661         this.timeend = getNodeContent(xml, 'e2timeend');
662         this.duration = getNodeContent(xml, 'e2duration', '0');
663         this.startprepare = getNodeContent(xml, 'e2startprepare');
664         this.justplay = getNodeContent(xml, 'e2justplay', '');
665         this.afterevent = getNodeContent(xml, 'e2afterevent', '0');
666         this.dirname = getNodeContent(xml, 'e2dirname', '/hdd/movie/');
667         this.tags = getNodeContent(xml, 'e2tags', '');
668         this.logentries = getNodeContent(xml, 'e2logentries');
669         this.tfilename = getNodeContent(xml, 'e2filename');
670         this.backoff = getNodeContent(xml, 'e2backoff');
671         this.nextactivation = getNodeContent(xml, 'e2nextactivation');
672         this.firsttryprepare = getNodeContent(xml, 'e2firsttryprepare');
673         this.state = getNodeContent(xml, 'e2state');
674         this.repeated = getNodeContent(xml, 'e2repeated', '0');
675         this.dontsave = getNodeContent(xml, 'e2dontsave');
676         this.cancled = getNodeContent(xml, 'e2cancled');
677         this.color = getNodeContent(xml, 'e2color');
678         this.toggledisabled = getNodeContent(xml, 'e2toggledisabled');
679         this.toggledisabledimg = getNodeContent(xml, 'e2toggledisabledimg');
680
681         this.getColor = function(){
682                 return this.color;
683         };
684         
685         this.getToggleDisabled = function(){
686                 return this.toggledisabled;
687         };
688         
689         this.getToggleDisabledIMG = function(){
690                 return this.toggledisabledimg;
691         };
692         
693         this.getToggleDisabledText = function(){
694                 var retVal = this.toggledisabled == "0" ? "Enable" : "Disable";
695                 return retVal;
696         };
697         
698         this.getServiceReference = function(){
699                 return encodeURIComponent(this.servicereference);
700         };
701         
702         this.getServiceName = function(){
703                 return this.servicename.replace('&quot;', '"');
704         };
705         
706         this.getEventID = function(){
707                 return this.eventid;
708         };
709         
710         this.getName = function(){
711                 return this.name;
712         };
713         
714         this.getDescription = function(){
715                 return this.description;
716         };
717         
718         this.getDescriptionExtended = function(){
719                 return this.descriptionextended;
720         };
721         
722         this.getDisabled = function(){
723                 return this.disabled;
724         };
725         
726         this.getTimeBegin = function(){
727                 return this.timebegin;
728         };
729         
730         this.getTimeEnd = function(){
731                 return this.timeend;
732         };
733         
734         this.getDuration = function(){
735                 return parseInt(this.duration, 10);
736         };
737         
738         this.getStartPrepare = function(){
739                 return this.startprepare;
740         };
741         
742         this.getJustplay = function(){
743                 return this.justplay;
744         };
745         
746         this.getAfterevent = function(){
747                 return this.afterevent;
748         };
749         
750         this.getDirname = function(){
751                 return this.dirname;
752         };
753
754         this.getTags = function(){
755                 return this.tags;
756         };
757
758         this.getLogentries = function(){
759                 return this.logentries;
760         };
761         
762         this.getFilename = function(){
763                 return this.tfilename;
764         };
765         
766         this.getBackoff = function(){
767                 return this.backoff;
768         };
769         
770         this.getNextActivation = function(){
771                 return this.nextactivation;
772         };
773         
774         this.getFirsttryprepare = function(){
775                 return this.firsttryprepare;
776         };
777         
778         this.getState = function(){
779                 return this.state;
780         };
781         
782         this.getRepeated = function(){
783                 return this.repeated;
784         };
785         
786         this.getDontSave = function(){
787                 return this.dontsave;
788         };
789         
790         this.isCancled = function(){
791                 return this.cancled;
792         };
793         
794         if( typeof( cssclass ) == undefined ){
795                 cssclass = 'odd';
796         }
797         
798         this.beginDate = new Date(Number(this.getTimeBegin()) * 1000);
799         this.endDate = new Date(Number(this.getTimeEnd()) * 1000);
800         
801         this.aftereventReadable = [ 'Nothing', 'Standby',
802                                     'Deepstandby/Shutdown', 'Auto' ];
803         
804         this.justplayReadable = [ 'record', 'zap' ];
805         
806         this.json = {
807                         'servicereference' : this.getServiceReference(),
808                         'servicename' : quotes2html(this.getServiceName()),
809                         'name' : quotes2html(this.getName()),
810                         'description' : quotes2html(this.getDescription()),
811                         'descriptionextended' : quotes2html(this.getDescriptionExtended()),
812                         'begin' : this.getTimeBegin(),
813                         'beginDate' : dateToString(this.beginDate),
814                         'end' : this.getTimeEnd(),
815                         'endDate' : dateToString(this.endDate),
816                         'state' : this.getState(),
817                         'duration' : Math.ceil((this.getDuration() / 60)),
818                         'repeated' : this.getRepeated(),
819                         'repeatedReadable' : repeatedReadable(this.getRepeated()),
820                         'justplay' : this.getJustplay(),
821                         'justplayReadable' : this.justplayReadable[Number(this.getJustplay())],
822                         'afterevent' : this.getAfterevent(),
823                         'aftereventReadable' : this.aftereventReadable[Number(this.getAfterevent())],
824                         'dirname' : this.getDirname(),
825                         'tags' : this.getTags(),
826                         'disabled' : this.getDisabled(),
827                         'onOff' : this.getToggleDisabledIMG(),
828                         'enDis' : this.getToggleDisabledText(),
829                         'cssclass' : cssclass
830         };
831         
832         this.toJSON = function(){
833                 return this.json;
834         };
835 }
836
837
838 // START class TimerList
839 function TimerList(xml){
840         this.xmlitems = getNamedChildren(xml, "e2timerlist", "e2timer");
841         this.timerlist = [];
842         
843         this.getArray = function(){
844                 if(this.timerlist.length === 0){
845                         var cssclass = 'even';
846                         var len = this.xmlitems.length;
847                         for(var i=0; i<len; i++){
848                                 cssclass = cssclass == 'even' ? 'odd' : 'even';
849                                 var timer = new Timer(this.xmlitems.item(i), cssclass).toJSON();
850                                 this.timerlist.push(timer);                     
851                         }
852                 }
853                 
854                 return this.timerlist;
855         };
856 }
857 //END class TimerList
858 function DeviceInfo(xml){
859         xml = xml.getElementsByTagName("e2deviceinfo").item(0);
860         
861         this.info = {};
862         
863         this.nims = [];
864         this.hdds = [];
865         this.nics = [];
866         
867         this.fpversion = "V"+xml.getElementsByTagName('e2fpversion').item(0).firstChild.data;
868         
869         var nimnodes = xml.getElementsByTagName('e2frontends').item(0).getElementsByTagName('e2frontend');                      
870         for(var i = 0; i < nimnodes.length; i++){                                       
871                 try {
872                         var name = nimnodes.item(i).getElementsByTagName('e2name').item(0).firstChild.data;
873                         var model = nimnodes.item(i).getElementsByTagName('e2model').item(0).firstChild.data;
874                         this.nims[i] = { 
875                                         'name' : name, 
876                                         'model' : model
877                         };                                      
878                 } catch (e) {
879                         core.notify("Error parsing frontend data: " + e);
880                 }
881         }
882         
883         
884         var hddnodes = xml.getElementsByTagName('e2hdd');
885         for( var i = 0; i < hddnodes.length; i++){
886                 try{                    
887                         var hdd = hddnodes.item(i);
888         
889                         var model       = hdd.getElementsByTagName('e2model').item(0).firstChild.data;
890                         var capacity = hdd.getElementsByTagName('e2capacity').item(0).firstChild.data;
891                         var free                = hdd.getElementsByTagName('e2free').item(0).firstChild.data;
892         
893                         this.hdds[i] = {        
894                                         'model'         : model,
895                                         'capacity'      : capacity,
896                                         'free'          : free
897                         };
898                 } catch(e){
899                         core.notify("Error parsing HDD data: " + e, false);
900                 }
901         }
902         
903         
904         var nicnodes = xml.getElementsByTagName('e2interface');
905         for( var i = 0; i < nicnodes.length; i++){
906                 try {
907                         var nic = nicnodes.item(i);
908                         var name = nic.getElementsByTagName('e2name').item(0).firstChild.data;
909                         var mac = nic.getElementsByTagName('e2mac').item(0).firstChild.data;
910                         var dhcp = nic.getElementsByTagName('e2dhcp').item(0).firstChild.data;
911                         var ip = nic.getElementsByTagName('e2ip').item(0).firstChild.data;
912                         var gateway = nic.getElementsByTagName('e2gateway').item(0).firstChild.data;
913                         var netmask = nic.getElementsByTagName('e2netmask').item(0).firstChild.data;
914         
915                         this.nics[i] = {
916                                         'name' : name,
917                                         'mac' : mac,
918                                         'dhcp' : dhcp,
919                                         'ip' : ip,
920                                         'gateway' : gateway,
921                                         'netmask' : netmask
922                         };
923                 } catch (e) {
924                         core.notify("Error parsing NIC data: " + e, false);
925                 }
926         }
927         
928         try{
929                 this.info = {
930                                 'devicename' : xml.getElementsByTagName('e2devicename').item(0).firstChild.data,
931                                 'enigmaVersion': xml.getElementsByTagName('e2enigmaversion').item(0).firstChild.data,
932                                 'imageVersion': xml.getElementsByTagName('e2imageversion').item(0).firstChild.data,
933                                 'fpVersion': this.fpversion,
934                                 'webifversion': xml.getElementsByTagName('e2webifversion').item(0).firstChild.data
935                 };
936         } catch (e) {
937                 core.notify("Error parsing deviceinfo data: " + e, false);              
938         }
939         
940         this.json = {
941                         info : this.info,
942                         hdds : this.hdds,               
943                         nics : this.nics,
944                         nims : this.nims
945         };
946         
947         this.toJSON = function(){
948                 return this.json;
949         };
950         
951 }
952
953 function SimpleXMLResult(xml){          
954         try{
955                 this.xmlitems = xml;
956         } catch (e) {
957                 core.notify("Error parsing e2simplexmlresult: " + e, false);
958         }
959
960         this.state = getNodeContent(this.xmlitems, 'e2state', false);
961         this.statetext = getNodeContent(this.xmlitems, 'e2statetext', false);
962         
963         if(!this.state && !this.statetext){
964                 this.state = getNodeContent(this.xmlitems, 'e2result', 'False');
965                 this.statetext = getNodeContent(this.xmlitems, 'e2resulttext', 'Error Parsing XML');
966         }
967         
968         this.getState = function(){
969                 if(this.state == 'True'){
970                         return true;
971                 }else{
972                         return false;
973                 }
974         };
975         
976         this.getStateText = function(){
977                         return this.statetext;
978         };
979 }
980 // END SimpleXMLResult
981
982 // START SimpleXMLList
983 function SimpleXMLList(xml, tagname){
984         // parsing values from xml-element
985         try{
986                 this.xmlitems = xml.getElementsByTagName(tagname);
987         } catch (e) {
988                 core.notify("Error parsing SimpleXMLList: " + e, false);        
989         }
990         
991         this.xmllist = [];
992         
993         this.getList = function(){
994                 if(this.xmllist.length === 0){
995                         var len = this.xmlitems.length;
996                         for(var i=0; i<len; i++){
997                                 this.xmllist.push(this.xmlitems.item(i).firstChild.data);
998                         }
999                 }
1000                 
1001                 return this.xmllist;
1002         };
1003 }
1004 // END SimpleXMLList
1005
1006
1007 // START class Setting
1008 function Setting(xml){  
1009         this.settingvalue = getNodeContent(xml, 'e2settingvalue');
1010         this.settingname = getNodeContent(xml, 'e2settingname');
1011         
1012         this.getSettingValue = function(){
1013                 return this.settingvalue;
1014         };
1015                 
1016         this.getSettingName = function(){
1017                 return this.settingname;
1018         };
1019         
1020 }
1021
1022
1023 // START class Settings
1024 function Settings(xml){
1025         // parsing values from xml-element
1026         try{
1027                 this.xmlitems = xml.getElementsByTagName("e2settings").item(0).getElementsByTagName("e2setting");
1028                 debug("[Settings] Number of items: " + this.xmlitems);
1029         } catch (e) {
1030                 core.notify("Error parsing Settings: " + e, false);     
1031         }       
1032         
1033         this.settings = [];
1034         
1035         this.getArray = function(){
1036                 if(this.settings.length === 0){
1037                         var len = this.xmlitems.length;
1038                         for (var i=0; i < len; i++){
1039                                 var setting = new Setting(this.xmlitems.item(i));
1040                                 this.settings.push(setting);                    
1041                         }
1042                 }
1043                 
1044                 return this.settings;           
1045         };
1046 }
1047 //END class Settings
1048
1049 //START class FileList
1050 function FileList(xml){
1051         // parsing values from xml-element
1052         try{
1053                 this.xmlitems = xml.getElementsByTagName("e2filelist").item(0).getElementsByTagName("e2file");
1054         } catch (e) {
1055                 core.notify("Error parsing FileList: " + e, false);
1056         }
1057         this.filelist = [];
1058
1059         this.getArray = function(){
1060                 if(this.filelist.length === 0){
1061                         var len = this.xmlitems.length;
1062                         for(var i = 0; i < len; i++){
1063                                 var file = new File(this.xmlitems.item(i));
1064                                 this.filelist.push(file);
1065                         }
1066                 }
1067
1068                 return this.filelist;
1069         };
1070 }
1071 //END class FileList
1072
1073 //START class File
1074 function File(xml){     
1075         // parsing values from xml-element
1076         this.servicereference = getNodeContent(xml, 'e2servicereference', 'Filesystems');
1077         this.isdirectory = getNodeContent(xml, 'e2isdirectory');
1078         this.root = getNodeContent(xml, 'e2root', 'Filesystems');
1079
1080         this.getServiceReference = function(){
1081                 return this.servicereference;
1082         };
1083         
1084         this.getNameOnly = function(){
1085                 if(this.root == '/' || this.isdirectory == "True") {
1086                         return this.servicereference.replace(this.root, '');
1087                 } else {
1088                         return this.servicereference.replace('4097:0:0:0:0:0:0:0:0:0:', '').replace(this.root, '');
1089                 }
1090         };
1091         
1092         this.getIsDirectory = function(){
1093                 return this.isdirectory;
1094         };
1095         
1096         this.getRoot = function(){
1097                 return this.root;
1098         };
1099 }       
1100 //END class File
1101
1102 //class Volume
1103 var Vol = Class.create({
1104         initialize: function(xml){
1105                 this.result = getNodeContent(xml, 'e2result', 'False');
1106                 this.resultText = getNodeContent(xml, 'e2resulttext', 'Parser Error!');
1107                 this.volume = getNodeContent(xml, 'e2current', '100');          
1108                 var mute = getNodeContent(xml, 'e2ismuted', 'False');
1109                 this.isMuted = mute == "True" ? true : false;
1110                 this.states = [];
1111                 
1112                 for(var i = 1; i <= 10; i++){
1113                         var enabled = false;
1114                         if(this.volume >= i * 10){
1115                                 enabled = true;
1116                         }               
1117                         this.states[i-1] = {'enabled' : enabled, 'percent' : i*10};
1118                 }
1119                 
1120                 this.json = {
1121                                 result : this.result,
1122                                 resultText : this.resultText,
1123                                 volume : this.volume,
1124                                 isMuted : this.isMuted,
1125                                 states : this.states
1126                 };
1127         },
1128
1129         toJSON: function(){
1130                 return this.json;
1131         }
1132 });
1133
1134 var Powerstate = Class.create({
1135         initialize: function(xml){
1136                 this.instandby = (getNodeContent(xml, "e2instandby").strip() == "true");
1137         },
1138         
1139         isStandby: function(){
1140                 return this.instandby;
1141         }
1142 });
1143
1144 var Signal = Class.create({
1145         initialize: function(xml){
1146                 this.snrdb = getNodeContent(xml, 'e2snrdb');
1147                 this.snr = getNodeContent(xml, 'e2snr');
1148                 this.ber = getNodeContent(xml, 'e2ber');
1149                 this.acg = getNodeContent(xml, 'e2acg');
1150                 
1151                 this.json = {
1152                         'snrdb' : this.snrdb,
1153                         'snr' : this.snr,
1154                         'ber' : this.ber,
1155                         'acg' : this.acg
1156                 };
1157         },
1158         
1159         toJSON: function(){
1160                 return this.json;
1161         }
1162
1163 });
1164 //END class Volume