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