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