source: ipk/source.sh4/swapsystem_webif/var/swap/extensions/WebInterface/web-data/tools.js@ 9260

Last change on this file since 9260 was 9260, checked in by madie, 15 years ago

[ipk] add webif for swap only for ufs910

File size: 36.9 KB
Line 
1//$Header: /cvsroot/enigma2-plugins/enigma2-plugins/webinterface/src/web-data/tools.js,v 1.219 2010-07-26 10:28:43 sreichholf Exp $
2var templates = {};
3var loadedChannellist = {};
4
5var epgListData = {};
6var signalPanelData = {};
7
8var mediaPlayerStarted = false;
9var popUpBlockerHinted = false;
10
11var settings = null;
12var parentControlList = null;
13
14var requestcounter = 0;
15
16var debugWin = '';
17var signalWin = '';
18var webRemoteWin = '';
19var EPGListWin = '';
20
21var currentBouquet = bouquetsTv;
22
23var updateBouquetItemsPoller = '';
24var updateCurrentPoller = '';
25var signalPanelUpdatePoller = '';
26
27var hideNotifierTimeout = '';
28
29var isActive = {};
30isActive.getCurrent = false;
31
32var currentLocation = "/hdd/movie";
33var locationsList = [];
34var tagsList = [];
35
36var boxtype = "";
37
38function startUpdateCurrentPoller(){
39 clearInterval(updateCurrentPoller);
40 updateCurrentPoller = setInterval(updateItems, userprefs.data.updateCurrentInterval);
41}
42function stopUpdateCurrentPoller(){
43 clearInterval(updateCurrentPoller);
44}
45function getXML(request){
46 var xmlDoc = "";
47
48 if(window.ActiveXObject){ // we're on IE
49 xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
50 xmlDoc.async="false";
51 xmlDoc.loadXML(request.responseText);
52 } else { //we're not on IE
53 if (!window.google || !google.gears){
54 xmlDoc = request.responseXML;
55 } else { //no responseXML on gears
56 xmlDoc = (new DOMParser()).parseFromString(request.responseText, "text/xml");
57 }
58 }
59
60 return xmlDoc;
61}
62/*
63* Set boxtype Variable for being able of determining model specific stuff correctly (like WebRemote)
64*/
65function incomingDeviceInfoBoxtype(request){
66 debug("[incomingAboutBoxtype] returned");
67 boxtype = getXML(request).getElementsByTagName("e2devicename").item(0).firstChild.data;
68
69 debug("[incomingAboutBoxtype] Boxtype: " + boxtype);
70}
71function getBoxtype(){
72 doRequest(URL.deviceinfo, incomingDeviceInfoBoxtype, false);
73}
74function toggleStandby(){
75 sendPowerState(0);
76}
77function incomingPowerState(request){
78 var standby = getXML(request).getElementsByTagName("e2instandby").item(0).firstChild.data;
79
80 var signal = $('openSignalPanel');
81 var signalImg = $('openSignalPanelImg');
82
83 if(standby.strip() == "false"){
84 signal.stopObserving('click', openSignalPanel);
85 signal.observe('click', openSignalPanel);
86
87 signalImg.src = "/web-data/img/signal.png";
88 signalImg.title = "Show Signal Panel";
89
90 } else {
91 signal.stopObserving('click', openSignalPanel);
92
93 signalImg.src = "/web-data/img/signal_off.png";
94 signalImg.title = "Please disable standby first";
95 }
96}
97function getPowerState(){
98 doRequest(URL.powerstate, incomingPowerState);
99}
100function set(element, value){
101 element = parent.$(element);
102 if (element){
103 element.update(value);
104 }
105}
106function hideNotifier(){
107 $('notification').fade({duration : 0.5 });
108}
109function notify(text, state){
110 notif = $('notification');
111
112 if(notif !== null){
113 //clear possibly existing hideNotifier timeout of a previous notfication
114 clearTimeout(hideNotifierTimeout);
115 if(state === false){
116 notif.style.background = "#C00";
117 } else {
118 notif.style.background = "#85C247";
119 }
120
121 set('notification', "<div>"+text+"</div>");
122 notif.appear({duration : 0.5, to: 0.9 });
123 hideNotifierTimeout = setTimeout(hideNotifier, 10000);
124 }
125}
126function simpleResultHandler(simpleResult){
127 notify(simpleResult.getStateText(), simpleResult.getState());
128}
129function startUpdateBouquetItemsPoller(){
130 debug("[startUpdateBouquetItemsPoller] called");
131 clearInterval(updateBouquetItemsPoller);
132 updateBouquetItemsPoller = setInterval(updateItemsLazy, userprefs.data.updateBouquetInterval);
133}
134function stopUpdateBouquetItemsPoller(){
135 debug("[stopUpdateBouquetItemsPoller] called");
136 clearInterval(updateBouquetItemsPoller);
137}
138//General Helpers
139function parseNr(num) {
140 if(isNaN(num)){
141 return 0;
142 } else {
143 return parseInt(num);
144 }
145}
146function dec2hex(nr, len){
147
148 var hex = parseInt(nr, 10).toString(16).toUpperCase();
149 if(len > 0){
150 try{
151 while(hex.length < len){
152 hex = "0"+hex;
153 }
154 }
155 catch(e){
156 //something went wrong, return -1
157 hex = -1;
158 }
159 }
160
161 hex = '0x' + hex;
162
163 return hex;
164}
165function quotes2html(txt) {
166 if(typeof(txt) != "undefined"){
167 return txt.escapeHTML().replace('\n', '<br>');
168 } else {
169 return "";
170 }
171}
172function addLeadingZero(nr){
173 if(nr < 10){
174 return '0' + nr;
175 }
176 return nr;
177}
178function dateToString(date){
179
180 var dateString = "";
181
182 dateString += date.getFullYear();
183 dateString += "-" + addLeadingZero(date.getMonth()+1);
184 dateString += "-" + addLeadingZero(date.getDate());
185 dateString += " " + addLeadingZero(date.getHours());
186 dateString += ":" + addLeadingZero(date.getMinutes());
187
188 return dateString;
189}
190function showhide(id){
191 var s = $(id).style;
192 s.display = (s.display!="none")? "none":"";
193}
194function show(id){
195 try{
196 $(id).style.display = "";
197 } catch(e) {
198 debug("[show] Could not show element with id: " + id);
199 }
200}
201function hide(id){
202 try{
203 $(id).style.display = "none";
204 } catch(e) {
205 debug("[hide] Could not hide element with id: " + id);
206 }
207}
208/*
209* Sets the Loading Notification to the given HTML Element
210* @param targetElement - The element the Ajax-Loader should be set in
211*/
212function setAjaxLoad(targetElement){
213 $(targetElement).update( getAjaxLoad() );
214}
215//Ajax Request Helpers
216//requestindikator
217function requestIndicatorUpdate(){
218 /*debug(requestcounter+" open requests");
219 if(requestcounter>=1){
220 $('RequestIndicator').style.display = "inline";
221 }else{
222 $('RequestIndicator').style.display = "none";
223 }*/
224}
225function requestStarted(){
226 requestcounter +=1;
227 requestIndicatorUpdate();
228}
229function requestFinished(){
230 requestcounter -= 1;
231 requestIndicatorUpdate();
232}
233//Popup And Messagebox Helpers
234function messageBox(m){
235 alert(m);
236}
237function popUpBlockerHint(){
238 if(!popUpBlockerHinted){
239 popUpBlockerHinted = true;
240 messageBox("Please disable your Popup-Blocker for enigma2 WebControl to work flawlessly!");
241
242 }
243}
244function setWindowContent(window, html){
245 window.document.write(html);
246 window.document.close();
247}
248function openPopup(title, html, width, height, x, y){
249 try {
250 var popup = window.open('about:blank',title,'scrollbars=yes, width='+width+',height='+height);
251 setWindowContent(popup, html);
252 return popup;
253 } catch(e){
254 popUpBlockerHint();
255 return "";
256 }
257}
258function openPopupPage(title, uri, width, height, x, y){
259 try {
260 var popup = window.open(uri,title,'scrollbars=yes, width='+width+',height='+height);
261 return popup;
262 } catch(e){
263 popUpBlockerHint();
264 return "";
265 }
266}
267function debug(text){
268 var DBG = userprefs.data.debug || false;
269
270 if(DBG){
271 try{
272 if(!debugWin.closed && debugWin.location){
273 var inner = debugWin.document.getElementById('debugContent').innerHTML;
274 debugWin.document.getElementById('debugContent').innerHTML = new Date().toLocaleString() + ": "+text+"<br>" + inner;
275 } else {
276 openDebug();
277
278 setTimeout( function(){
279 var inner = debugWin.document.getElementById('debugContent').innerHTML;
280 debugWin.document.getElementById('debugContent').innerHTML = new Date().toLocaleString() + ": "+text+"<br>" + inner;
281 },
282 1000
283 );
284 }
285 } catch (Exception) {}
286 }
287}
288function saveSettings(){
289 userprefs.load();
290
291 var debug = $('enableDebug').checked;
292 var changed = false;
293 if(typeof(debug) != "undefined"){
294 if( userprefs.data.debug != debug ){
295 userprefs.data.debug = debug;
296 changed = true;
297
298 if(debug){
299 openDebug();
300 }
301 }
302 }
303
304 var updateCurrentInterval = parseNr( $F('updateCurrentInterval') ) * 1000;
305 if( updateCurrentInterval < 10000){
306 updateCurrentInterval = 120000;
307 }
308
309 if( userprefs.data.updateCurrentInterval != updateCurrentInterval){
310 userprefs.data.updateCurrentInterval = updateCurrentInterval;
311
312 changed = true;
313 startUpdateCurrentPoller();
314 }
315
316 var updateBouquetInterval = parseNr( $F('updateBouquetInterval') ) * 1000;
317 if( updateBouquetInterval < 60000){
318 updateBouquetInterval = 300000;
319 }
320
321 if( userprefs.data.updateBouquetInterval != updateBouquetInterval){
322 userprefs.data.updateBouquetInterval = updateBouquetInterval;
323
324 changed = true;
325 startUpdateBouquetItemsPoller();
326 }
327
328 if(changed){
329 userprefs.save();
330 }
331}
332//Template Helpers
333function saveTpl(request, tplName){
334 debug("[saveTpl] saving template: " + tplName);
335 templates[tplName] = request.responseText;
336}
337function renderTpl(tpl, data, domElement) {
338 var result = tpl.process(data);
339
340 try{
341 $(domElement).update( result );
342 }catch(ex){
343 // debug("[renderTpl] exception: " + ex);
344 }
345}
346function fetchTpl(tplName, callback){
347 if(typeof(templates[tplName]) == "undefined") {
348 var url = URL.tpl+tplName+".htm";
349
350 doRequest(
351 url,
352 function(transport){
353 saveTpl(transport, tplName);
354 if(typeof(callback) == 'function'){
355 callback();
356 }
357 }
358 );
359 } else {
360 if(typeof(callback) == 'function'){
361 callback();
362 }
363 }
364}
365function incomingProcessTpl(request, data, domElement, callback){
366 if(request.readyState == 4){
367 renderTpl(request.responseText, data, domElement);
368 if(typeof(callback) == 'function') {
369 callback();
370 }
371 }
372}
373function processTpl(tplName, data, domElement, callback){
374 var url = URL.tpl+tplName+".htm";
375
376 doRequest(url,
377 function(transport){
378 incomingProcessTpl(transport, data, domElement, callback);
379 }
380 );
381}
382//Debugging Window
383function openDebug(){
384 var uri = URL.tpl+'tplDebug.htm';
385 debugWin = openPopupPage("Debug", uri, 500, 300);
386}
387function requestFailed(transport){
388 var notifText = "Request failed for: " + transport.request.url + "<br>Status: " + transport.status + " " + transport.statusText;
389 notify(notifText, false);
390}
391function doRequest(url, readyFunction){
392 requestStarted();
393 var request = '';
394 // gears or not that's the question here
395 if (!window.google || !google.gears){ //no gears, how sad
396// debug("NO GEARS!!");
397 try{
398 request = new Ajax.Request(url,
399 {
400 asynchronous: true,
401 method: 'GET',
402 requestHeaders: ['Cache-Control', 'no-cache,no-store', 'Expires', '-1'],
403 onException: function(o,e){ throw(e); },
404 onSuccess: function (transport, json) {
405 if(typeof(readyFunction) != "undefined"){
406 readyFunction(transport);
407 }
408 },
409 onFailure: function(transport){
410 requestFailed(transport);
411 },
412 onComplete: requestFinished
413 });
414 } catch(e) {}
415 } else { //we're on gears!
416 try{
417 request = google.gears.factory.create('beta.httprequest');
418 request.open('GET', url);
419
420
421 request.onreadystatechange = function(){
422 if(request.readyState == 4){
423 if(request.status == 200){
424 if( typeof(readyFunction) != "undefined" ){
425 readyFunction(request);
426 }
427 } else {
428 requestFailed(transport);
429 }
430 }
431 };
432 request.send();
433 } catch(e) {}
434 }
435}
436//Parental Control
437function incomingParentControl(request) {
438 if(request.readyState == 4){
439 parentControlList = new ServiceList(getXML(request)).getArray();
440 debug("[incomingParentControl] Got "+parentControlList.length + " services");
441 }
442}
443function getParentControl() {
444 doRequest(URL.parentcontrol, incomingParentControl, false);
445}
446function getParentControlByRef(txt) {
447 debug("[getParentControlByRef] ("+txt+")");
448 for(var i = 0; i < parentControlList.length; i++) {
449 debug( "[getParentControlByRef] "+parentControlList[i].getClearServiceReference() );
450 if(String(parentControlList[i].getClearServiceReference()) == String(txt)) {
451 return parentControlList[i].getClearServiceReference();
452 }
453 }
454 return "";
455}
456//Settings
457function getSettingByName(txt) {
458 debug("[getSettingByName] (" + txt + ")");
459 for(var i = 0; i < settings.length; i++) {
460 debug("("+settings[i].getSettingName()+") (" +settings[i].getSettingValue()+")");
461 if(String(settings[i].getSettingName()) == String(txt)) {
462 return settings[i].getSettingValue().toLowerCase();
463 }
464 }
465 return "";
466}
467function parentPin(servicereference) {
468 debug("[parentPin] parentControlList");
469 servicereference = decodeURIComponent(servicereference);
470 if(parentControlList === null || String(getSettingByName("config.ParentalControl.configured")) != "true") {
471 return true;
472 }
473 //debug("parentPin " + parentControlList.length);
474 if(getParentControlByRef(servicereference) == servicereference) {
475 if(String(getSettingByName("config.ParentalControl.type.value")) == "whitelist") {
476 debug("[parentPin] Channel in whitelist");
477 return true;
478 }
479 } else {
480 debug("[parentPin] sRef differs ");
481 return true;
482 }
483 debug("[parentPin] Asking for PIN");
484
485 var userInput = prompt('Parental Control is enabled!<br> Please enter the Parental Control PIN','PIN');
486 if (userInput !== '' && userInput !== null) {
487 if(String(userInput) == String(getSettingByName("config.ParentalControl.servicepin.0")) ) {
488 return true;
489 } else {
490 return parentPin(servicereference);
491 }
492 } else {
493 return false;
494 }
495}
496function incomingGetDreamboxSettings(request){
497 if(request.readyState == 4){
498 settings = new Settings(getXML(request)).getArray();
499
500 debug("[incomingGetDreamboxSettings] config.ParentalControl.configured="+ getSettingByName("config.ParentalControl.configured"));
501
502 if(String(getSettingByName("config.ParentalControl.configured")) == "true") {
503 getParentControl();
504 }
505 }
506}
507function getDreamboxSettings(){
508 doRequest(URL.settings, incomingGetDreamboxSettings, false);
509}
510//Subservices
511function incomingSubServiceRequest(request){
512 if(request.readyState == 4){
513 var services = new ServiceList(getXML(request)).getArray();
514 debug("[incomingSubServiceRequest] Got " + services.length + " SubServices");
515
516 if(services.length > 1) {
517
518 var first = services[0];
519
520 // we already have the main service in our servicelist so we'll
521 // start with the second element
522 services.shift();
523
524 var data = { subservices : services };
525
526
527 var id = 'SUB'+first.servicereference;
528 show('tr' + id);
529 processTpl('tplSubServices', data, id);
530 }
531 }
532}
533function getSubServices(bouquet) {
534 doRequest(URL.subservices, incomingSubServiceRequest, false);
535}
536function delayedGetSubservices(){
537 setTimeout(getSubServices, 5000);
538}
539//zap zap
540function zap(servicereference){
541 doRequest("/web/zap?sRef=" + servicereference);
542 setTimeout(updateItemsLazy, 7000); //reload epg and subservices
543 setTimeout(updateItems, 3000);
544}
545//SignalPanel
546function updateSignalPanel(){
547 var html = templates.tplSignalPanel.process(signalPanelData);
548
549 if (!signalWin.closed && signalWin.location) {
550 setWindowContent(signalWin, html);
551 } else {
552 clearInterval(signalPanelUpdatePoller);
553 signalPanelUpdatePoller = '';
554 }
555}
556function incomingSignalPanel(request){
557 var namespace = {};
558
559 if (request.readyState == 4){
560 var xml = getXML(request).getElementsByTagName("e2frontendstatus").item(0);
561 namespace = {
562 snrdb : xml.getElementsByTagName('e2snrdb').item(0).firstChild.data,
563 snr : xml.getElementsByTagName('e2snr').item(0).firstChild.data,
564 ber : xml.getElementsByTagName('e2ber').item(0).firstChild.data,
565 acg : xml.getElementsByTagName('e2acg').item(0).firstChild.data
566 };
567 }
568
569 signalPanelData = { signal : namespace };
570 fetchTpl('tplSignalPanel', updateSignalPanel);
571}
572function reloadSignalPanel(){
573 doRequest(URL.signal, incomingSignalPanel, false);
574}
575function openSignalPanel(){
576 if (!(!signalWin.closed && signalWin.location)){
577 signalWin = openPopup('SignalPanel', '', 220, 120);
578 if(signalPanelUpdatePoller === ''){
579 signalPanelUpdatePoller = setInterval(reloadSignalPanel, 5000);
580 }
581 }
582 reloadSignalPanel();
583}
584//EPG functions
585function showEpgList(){
586 var html = templates.tplEpgList.process(epgListData);
587
588 if (!EPGListWin.closed && EPGListWin.location) {
589 setWindowContent(EPGListWin, html);
590 } else {
591 EPGListWin = openPopup("EPG", html, 900, 500);
592 }
593}
594function incomingEPGrequest(request){
595 debug("[incomingEPGrequest] readyState" +request.readyState);
596 if (request.readyState == 4){
597 var EPGItems = new EPGList(getXML(request)).getArray(true);
598 debug("[incomingEPGrequest] got "+EPGItems.length+" e2events");
599
600 if( EPGItems.length > 0){
601 epgListData = {epg : EPGItems};
602 fetchTpl('tplEpgList', showEpgList);
603 } else {
604 messageBox('No Items found!', 'Sorry but I could not find any EPG Content containing your search value');
605 }
606 }
607}
608function loadEPGBySearchString(string){
609 doRequest(URL.epgsearch+escape(string),incomingEPGrequest, false);
610}
611function loadEPGByServiceReference(servicereference){
612 doRequest(URL.epgservice+servicereference,incomingEPGrequest, false);
613}
614function buildServiceListEPGItem(epgevent, type){
615 var data = { epg : epgevent,
616 nownext: type
617 };
618
619 var id = type + epgevent.servicereference;
620
621 show('tr' + id);
622
623 if(typeof(templates.tplServiceListEPGItem) != "undefined"){
624 renderTpl(templates.tplServiceListEPGItem, data, id, true);
625 } else {
626 debug("[buildServiceListEPGItem] tplServiceListEPGItem N/A");
627 }
628}
629function incomingServiceEPGNowNext(request, type){
630 if(request.readyState == 4){
631 var epgevents = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
632 for (var c = 0; c < epgevents.length; c++){
633 try{
634 var epgEvt = new EPGEvent(epgevents.item(c), c).toJSON();
635 } catch (e){
636 debug("[incomingServiceEPGNowNext]" + e);
637 }
638
639 if (epgEvt.eventid != ''){
640 buildServiceListEPGItem(epgEvt, type);
641 }
642 }
643 }
644}
645function incomingServiceEPGNow(request){
646 incomingServiceEPGNowNext(request, 'NOW');
647}
648function incomingServiceEPGNext(request){
649 incomingServiceEPGNowNext(request, 'NEXT');
650}
651function loadServiceEPGNowNext(servicereference, next){
652 var url = URL.epgnow+servicereference;
653
654 if(typeof(next) == 'undefined'){
655 doRequest(url, incomingServiceEPGNow, false);
656 } else {
657 url = URL.epgnext+servicereference;
658 doRequest(url, incomingServiceEPGNext, false);
659 }
660}
661function getBouquetEpg(){
662 loadServiceEPGNowNext(currentBouquet);
663 loadServiceEPGNowNext(currentBouquet, true);
664}
665function recordNowPopup(){
666 var result = confirm(
667 "OK: Record current event\n" +
668 "Cancel: Start infinite recording"
669 );
670
671 if( result === true || result === false){
672 recordNowDecision(result);
673 }
674}
675//+++++++++++++++++++++++++++++++++++++++++++++++++++++
676//+++++++++++++++++++++++++++++++++++++++++++++++++++++
677//++++ volume functions ++++
678//+++++++++++++++++++++++++++++++++++++++++++++++++++++
679//+++++++++++++++++++++++++++++++++++++++++++++++++++++
680function handleVolumeRequest(request){
681 if (request.readyState == 4) {
682 var b = getXML(request).getElementsByTagName("e2volume");
683 var newvalue = b.item(0).getElementsByTagName('e2current').item(0).firstChild.data;
684 var mute = b.item(0).getElementsByTagName('e2ismuted').item(0).firstChild.data;
685 debug("[handleVolumeRequest] Volume " + newvalue + " | Mute: " + mute);
686
687 for (var i = 1; i <= 10; i++) {
688 if ( (newvalue/10)>=i){
689 $("volume"+i).src = "/web-data/img/led_on.png";
690 }else{
691 $("volume"+i).src = "/web-data/img/led_off.png";
692 }
693 }
694 if (mute == "False"){
695 $("speaker").src = "/web-data/img/speak_on.png";
696 }else{
697 $("speaker").src = "/web-data/img/speak_off.png";
698 }
699 }
700}
701function getVolume(){
702 doRequest(URL.getvolume, handleVolumeRequest, false);
703}
704function volumeSet(val){
705 doRequest(URL.setvolume+val, handleVolumeRequest, false);
706}
707function volumeUp(){
708 doRequest(URL.volumeup, handleVolumeRequest, false);
709}
710function volumeDown(){
711 doRequest(URL.volumedown, handleVolumeRequest, false);
712}
713function volumeMute(){
714 doRequest(URL.volumemute, handleVolumeRequest, false);
715}
716function initVolumePanel(){
717 getVolume();
718}
719//Channels and Bouquets
720function incomingChannellist(request){
721 var serviceList = null;
722 if(typeof(loadedChannellist[currentBouquet]) != "undefined"){
723 serviceList = loadedChannellist[currentBouquet];
724 } else if(request.readyState == 4) {
725 serviceList = new ServiceList(getXML(request)).getArray();
726 debug("[incomingChannellist] got "+serviceList.length+" Services");
727 }
728 if(serviceList !== null) {
729 var data = { services : serviceList };
730
731 processTpl('tplServiceList', data, 'contentServices', getBouquetEpg);
732 delayedGetSubservices();
733 } else {
734 debug("[incomingChannellist] services is null");
735 }
736}
737function loadBouquet(servicereference, name){
738 debug("[loadBouquet] called");
739 setAjaxLoad('contentServices');
740
741 currentBouquet = servicereference;
742
743 setContentHd(name);
744
745 var input = new Element('input');
746 input.id = 'serviceSearch';
747 input.value = 'Search for service';
748
749 $('contentHdExt').update(input);
750
751 input.observe('focus', onServiceSearchFocus);
752 input.observe('keyup', serviceSearch);
753
754 startUpdateBouquetItemsPoller();
755 doRequest(URL.getservices+servicereference, incomingChannellist, true);
756}
757function incomingBouquetListInitial(request){
758 if (request.readyState == 4) {
759 var bouquetList = new ServiceList(getXML(request)).getArray();
760 debug("[incomingBouquetListInitial] Got " + bouquetList.length + " TV Bouquets!");
761
762 // loading first entry of TV Favorites as default for ServiceList
763 incomingBouquetList(
764 request,
765 function(){
766 loadBouquet(bouquetList[0].servicereference, bouquetList[0].servicename);;
767 }
768 );
769 }
770}
771function incomingBouquetList(request, callback){
772 if (request.readyState == 4) {
773 var bouquetList = new ServiceList(getXML(request)).getArray();
774 debug("[incomingBouquetList] got " + bouquetList.length + " TV Bouquets!");
775 var data = { bouquets : bouquetList };
776
777 if( $('contentBouquets') != "undefined" && $('contentBouquets') != null ){
778 processTpl('tplBouquetList', data, 'contentBouquets');
779 if(typeof(callback) == 'function')
780 callback();
781 } else {
782 processTpl(
783 'tplBouquetsAndServices',
784 null,
785 'contentMain',
786 function(){
787 processTpl('tplBouquetList', data, 'contentBouquets');
788 if(typeof(callback) == 'function')
789 callback();
790 }
791 );
792 }
793 }
794}
795function initChannelList(){
796 var url = URL.getservices+encodeURIComponent(bouquetsTv);
797 currentBouquet = bouquetsTv;
798
799 doRequest(url, incomingBouquetListInitial, true);
800}
801//Movies
802function initMovieList(){
803 // get videodirs, last_videodir, and all tags
804 doRequest(URL.getcurrlocation, incomingMovieListCurrentLocation, false);
805}
806function incomingMovieListCurrentLocation(request){
807 if(request.readyState == 4){
808 result = new SimpleXMLList(getXML(request), "e2location");
809 currentLocation = result.getList()[0];
810 debug("[incomingMovieListCurrentLocation].currentLocation" + currentLocation);
811 doRequest(URL.getlocations, incomingMovieListLocations, false);
812 }
813}
814function incomingMovieListLocations(request){
815 if(request.readyState == 4){
816 result = new SimpleXMLList(getXML(request), "e2location");
817 locationsList = result.getList();
818
819 if (locationsList.length === 0) {
820 locationsList = ["/hdd/movie"];
821 }
822 doRequest(URL.gettags, incomingMovieListTags, false);
823 }
824}
825function incomingMovieListTags(request){
826 if(request.readyState == 4){
827 result = new SimpleXMLList(getXML(request), "e2tag");
828 tagsList = result.getList();
829 }
830}
831function createOptionListSimple(lst, selected) {
832 var namespace = Array();
833 var i = 0;
834 var found = false;
835
836 for (i = 0; i < lst.length; i++) {
837 if (lst[i] == selected) {
838 found = true;
839 }
840 }
841
842 if (!found) {
843 lst = [ selected ].concat(lst);
844 }
845
846 for (i = 0; i < lst.length; i++) {
847 namespace[i] = {
848 'value': lst[i],
849 'txt': lst[i],
850 'selected': (lst[i] == selected ? "selected" : " ")};
851 }
852
853 return namespace;
854}
855function loadMovieNav(){
856 // fill in menus
857 var data = {
858 dirname: createOptionListSimple(locationsList, currentLocation),
859 tags: createOptionListSimple(tagsList, "")
860 };
861
862 processTpl('tplNavMovies', data, 'navContent');
863}
864function incomingMovieList(request){
865 if(request.readyState == 4){
866
867 var movieList = new MovieList(getXML(request)).getArray();
868 debug("[incomingMovieList] Got "+movieList.length+" movies");
869
870 var data = { movies : movieList };
871 processTpl('tplMovieList', data, 'contentMain');
872 }
873}
874function loadMovieList(loc, tag){
875 if(typeof(loc) == 'undefined'){
876 loc = currentLocation;
877 }
878 if(typeof(tag) == 'undefined'){
879 tag = '';
880 }
881 debug("[loadMovieList] Loading movies in location '"+loc+"' with tag '"+tag+"'");
882 doRequest(URL.movielist+"?dirname="+loc+"&tag="+tag, incomingMovieList, false);
883}
884function incomingDelMovieResult(request) {
885 debug("[incomingDelMovieResult] called");
886 if(request.readyState == 4){
887 var result = new SimpleXMLResult(getXML(request));
888 if(result.getState()){
889 loadMovieList();
890 }
891 simpleResultHandler(result);
892 }
893}
894function delMovie(sref ,servicename, title, description) {
895 debug("[delMovie] File(" + unescape(sref) + "), servicename(" + servicename + ")," +
896 "title(" + unescape(title) + "), description(" + description + ")");
897
898 result = confirm( "Are you sure want to delete the Movie?\n" +
899 "Servicename: " + servicename + "\n" +
900 "Title: " + unescape(title) + "\n" +
901 "Description: " + description + "\n");
902
903 if(result){
904 debug("[delMovie] ok confirm panel");
905 doRequest(URL.moviedelete+"?sRef="+unescape(sref), incomingDelMovieResult, false);
906 return true;
907 }
908 else{
909 debug("[delMovie] cancel confirm panel");
910 return false;
911 }
912}
913//Send Messages and Receive the Answer
914function incomingMessageResult(request){
915 if(request.readyState== 4){
916 var result = new SimpleXMLResult(getXML(request));
917 simpleResultHandler(result);
918 }
919}
920function getMessageAnswer() {
921 doRequest(URL.messageanswer, incomingMessageResult, false);
922}
923function sendMessage(messagetext, messagetype, messagetimeout){
924 if(!messagetext){
925 messagetext = $('MessageSendFormText').value;
926 }
927 if(!messagetimeout){
928 messagetimeout = $('MessageSendFormTimeout').value;
929 }
930 if(!messagetype){
931 var index = $('MessageSendFormType').selectedIndex;
932 messagetype = $('MessageSendFormType').options[index].value;
933 }
934 if(parseNr(messagetype) === 0){
935 doRequest(URL.message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout);
936 setTimeout(getMessageAnswer, parseNr(messagetimeout)*1000);
937 } else {
938 doRequest(URL.message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout, incomingMessageResult, false);
939 }
940}
941//Screenshots
942function getScreenShot(what) {
943 debug("[getScreenShot] called");
944
945 var buffer = new Image();
946 var downloadStart;
947 var data = {};
948
949 buffer.onload = function () {
950 debug("[getScreenShot] image assigned");
951
952 data = { img : { src : buffer.src } };
953 processTpl('tplGrab', data, 'contentMain');
954
955 return true;
956 };
957
958 buffer.onerror = function (meldung) {
959 debug("[getScreenShot] Loading image failed");
960 return true;
961 };
962
963 switch(what){
964 case "o":
965 what = "&o=&n=";
966 break;
967 case "v":
968 what = "&v=";
969 break;
970 default:
971 what = "";
972 break;
973 }
974
975 downloadStart = new Date().getTime();
976 buffer.src = '/grab?format=jpg&r=720&' + what + '&filename=/tmp/' + downloadStart;
977}
978function getVideoShot() {
979 getScreenShot("v");
980}
981function getOsdShot(){
982 getScreenShot("o");
983}
984//RemoteControl Code
985function incomingRemoteControlResult(request){
986// if(request.readyState == 4){
987// var b = getXML(request).getElementsByTagName("e2remotecontrol");
988// var result = b.item(0).getElementsByTagName('e2result').item(0).firstChild.data;
989// var resulttext = b.item(0).getElementsByTagName('e2resulttext').item(0).firstChild.data;
990// }
991}
992function openWebRemote(){
993 var template = templates.tplWebRemote;
994 template = templates.tplWebRemote;
995
996 if (!webRemoteWin.closed && webRemoteWin.location) {
997 setWindowContent(webRemoteWin, template);
998 } else {
999 webRemoteWin = openPopup('WebRemote', template, 250, 620);
1000 }
1001
1002}
1003function loadAndOpenWebRemote(){
1004 fetchTpl('tplWebRemote', openWebRemote);
1005}
1006function sendRemoteControlRequest(command){
1007 var long = webRemoteWin.document.getElementById('long')
1008 if(long.checked){
1009 doRequest(URL.remotecontrol+'?command='+command+'&type=long', incomingRemoteControlResult, false);
1010 long.checked = undefined;
1011 } else {
1012 doRequest(URL.remotecontrol+'?command='+command, incomingRemoteControlResult, false);
1013 }
1014
1015 if(webRemoteWin.document.getElementById('getScreen').checked) {
1016 if(webRemoteWin.document.getElementById('getVideo').checked){
1017 getScreenShot();
1018 } else {
1019 getScreenShot("o");
1020 }
1021 }
1022}
1023// Array.insert( index, value ) - Insert value at index, without overwriting existing keys
1024Array.prototype.insert = function( j, v ) {
1025 if( j>=0 ) {
1026 var a = this.slice(), b = a.splice( j );
1027 a[j] = v;
1028 return a.concat( b );
1029 }
1030};
1031
1032//Array.splice() - Remove or replace several elements and return any deleted
1033//elements
1034if( typeof Array.prototype.splice==='undefined' ) {
1035 Array.prototype.splice = function( a, c ) {
1036 var e = arguments, d = this.copy(), f = a, l = this.length;
1037
1038 if( !c ) {
1039 c = l - a;
1040 }
1041
1042 for( var i = 0; i < e.length - 2; i++ ) {
1043 this[a + i] = e[i + 2];
1044 }
1045
1046
1047 for( var j = a; j < l - c; j++ ) {
1048 this[j + e.length - 2] = d[j - c];
1049 }
1050 this.length -= c - e.length + 2;
1051
1052 return d.slice( f, f + c );
1053 };
1054}
1055function ifChecked(rObj) {
1056 if(rObj.checked) {
1057 return rObj.value;
1058 } else {
1059 return "";
1060 }
1061}
1062//Device Info
1063/*
1064 * Handles an incoming request for /web/deviceinfo Parses the Data, and calls
1065 * everything needed to render the Template using the parsed data and set the
1066 * result into contentMain @param request - the XHR
1067 */
1068function incomingDeviceInfo(request) {
1069 if(request.readyState == 4){
1070 debug("[incomingDeviceInfo] called");
1071 var deviceInfo = new DeviceInfo(getXML(request));
1072
1073 processTpl('tplDeviceInfo', deviceInfo, 'contentMain');
1074 }
1075}
1076/*
1077 * Show Device Info Information in contentMain
1078 */
1079function showDeviceInfo() {
1080 doRequest(URL.deviceinfo, incomingDeviceInfo, false);
1081}
1082function showSettings(){
1083 var debug = userprefs.data.debug;
1084 var debugChecked = "";
1085 if(debug){
1086 debugChecked = 'checked';
1087 }
1088
1089 var updateCurrentInterval = userprefs.data.updateCurrentInterval / 1000;
1090 var updateBouquetInterval = userprefs.data.updateBouquetInterval / 1000;
1091
1092
1093 data = {'debug' : debugChecked,
1094 'updateCurrentInterval' : updateCurrentInterval,
1095 'updateBouquetInterval' : updateBouquetInterval
1096 };
1097 processTpl('tplSettings', data, 'contentMain');
1098}
1099// Spezial functions, mostly for testing purpose
1100function openHiddenFunctions(){
1101 openPopup("Extra Hidden Functions",tplExtraHiddenFunctions,300,100,920,0);
1102}
1103function startDebugWindow() {
1104 DBG = true;
1105 debugWin = openPopup("DEBUG", "", 300, 300,920,140, "debugWindow");
1106}
1107function restartTwisted() {
1108 doRequest( "/web/restarttwisted" );
1109}
1110//Powerstate
1111/*
1112 * Sets the Powerstate @param newState - the new Powerstate Possible Values
1113 * (also see WebComponents/Sources/PowerState.py) #-1: get current state # 0:
1114 * toggle standby # 1: poweroff/deepstandby # 2: rebootdreambox # 3:
1115 * rebootenigma
1116 */
1117function sendPowerState(newState){
1118 doRequest( URL.powerstate+'?newstate='+newState, incomingPowerState);
1119}
1120//Currently Running Service
1121function incomingCurrent(request){
1122 // debug("[incomingCurrent called]");
1123 if(request.readyState == 4){
1124 try{
1125 var xml = getXML(request);
1126 var epg = new EPGList(xml).getArray();
1127 epg = epg[0];
1128
1129 var service = new Service(xml).toJSON();
1130
1131 var data = {
1132 'current' : epg,
1133 'service' : service
1134 };
1135
1136 if(typeof(templates.tplCurrent) != "undefined"){
1137 var display = 'none';
1138 try{
1139 var display = $('trExtCurrent').style.display;
1140 } catch(e){}
1141
1142 renderTpl(templates.tplCurrent, data, "currentContent");
1143 $('trExtCurrent').style.display = display;
1144 } else {
1145 debug("[incomingCurrent] tplCurrent N/A");
1146 }
1147
1148 } catch (e){}
1149
1150 isActive.getCurrent = false;
1151 }
1152}
1153function getCurrent(){
1154 if(!isActive.getCurrent){
1155 isActive.getCurrent = true;
1156 doRequest(URL.getcurrent, incomingCurrent, false);
1157 }
1158}
1159//Navigation and Content Helper Functions
1160
1161/*
1162 * Loads all Bouquets for the given enigma2 servicereference and sets the
1163 * according contentHeader @param sRef - the Servicereference for the bouquet to
1164 * load
1165 */
1166function getBouquets(sRef){
1167 var url = URL.getservices+encodeURIComponent(sRef);
1168
1169 doRequest(url, incomingBouquetList, true);
1170}
1171/*
1172 * Loads another navigation template and sets the navigation header
1173 * @param template - The name of the template
1174 * @param title - The title to set for the navigation
1175 */
1176function reloadNav(template, title){
1177 setAjaxLoad('navContent');
1178 processTpl(template, null, 'navContent');
1179 setNavHd(title);
1180}
1181function reloadNavDynamic(fnc, title){
1182 setAjaxLoad('navContent');
1183 setNavHd(title);
1184 fnc();
1185}
1186function getBouquetsTv(){
1187 getBouquets(bouquetsTv);
1188}
1189function getProviderTv(){
1190 getBouquets(providerTv);
1191}
1192function getSatellitesTv(){
1193 getBouquets(satellitesTv);
1194}
1195function getAllTv(){
1196 loadBouquet(allTv, "All (TV)");
1197}
1198function getBouquetsRadio(){
1199 getBouquets(bouquetsRadio);
1200}
1201function getProviderRadio(){
1202 getBouquets(providerRadio);
1203}
1204function getSatellitesRadio(){
1205 getBouquets(satellitesRadio);
1206}
1207function getAllRadio(){
1208 loadBouquet(allRadio, "All (Radio)");
1209}
1210/*
1211 * Loads dynamic content to $(contentMain) by calling a execution function
1212 * @param fnc - The function used to load the content
1213 * @param title - The Title to set on the contentpanel
1214 */
1215function loadContentDynamic(fnc, title, domid){
1216 if(typeof(domid) != "undefined" && $(domid) != null){
1217 setAjaxLoad(domid);
1218 } else {
1219 setAjaxLoad('contentMain');
1220 }
1221 setContentHd(title);
1222 stopUpdateBouquetItemsPoller();
1223
1224 fnc();
1225}
1226/*
1227 * like loadContentDynamic but without the AjaxLoaderAnimation being shown
1228 */
1229function reloadContentDynamic(fnc, title){
1230 setContentHd(title);
1231 fnc();
1232}
1233/*
1234 * Loads a static template to $(contentMain)
1235 * @param template - Name of the Template
1236 * @param title - The Title to set on the Content-Panel
1237 */
1238function loadContentStatic(template, title){
1239 setAjaxLoad('contentMain');
1240 setContentHd(title);
1241 stopUpdateBouquetItemsPoller();
1242 processTpl(template, null, 'contentMain');
1243}
1244/*
1245 * Opens the given Control
1246 * @param control - Control Page as String
1247 * Possible Values: power, extras, message, screenshot, videoshot, osdshot
1248 */
1249function loadControl(control){
1250 switch(control){
1251 case "power":
1252 loadContentStatic('tplPower', 'PowerControl');
1253 break;
1254
1255 case "softcam":
1256 loadContentStatic('tplSoftcam', 'SoftcamPanel');
1257 break;
1258
1259 case "videomode":
1260 loadContentStatic('tplVideomode', 'A/V Einstellungen');
1261 break;
1262
1263 case "pluginsipk":
1264 loadContentStatic('tplIPK', 'PluginPanel');
1265 break;
1266
1267 case "flashen":
1268 loadContentStatic('tplFlashen', 'UpdatePanel');
1269 break;
1270
1271 case "backuprestore":
1272 loadContentStatic('tplBackupRestore', 'Backup&Restore');
1273 break;
1274
1275 case "overclock":
1276 loadContentStatic('tplOverclock', 'OverClock');
1277 break;
1278
1279 case "message":
1280 loadContentStatic('tplSendMessage', 'Send a Message');
1281 break;
1282
1283 case "remote":
1284 loadAndOpenWebRemote();
1285 break;
1286
1287 case "screenshot":
1288 loadContentDynamic(getScreenShot, 'Screenshot');
1289 break;
1290
1291 case "videoshot":
1292 loadContentDynamic(getVideoShot, 'Videoshot');
1293 break;
1294
1295 case "osdshot":
1296 loadContentDynamic(getOsdShot, 'OSDshot');
1297 break;
1298
1299 default:
1300 break;
1301 }
1302}
1303function loadDeviceInfo(){
1304 loadContentDynamic(showDeviceInfo, 'Device Information');
1305}
1306function loadTools(){
1307 loadContentStatic('tplTools', 'Tools');
1308}
1309function loadAbout(){
1310 loadContentStatic('tplAbout', 'About');
1311}
1312function loadSettings(){
1313 loadContentDynamic(showSettings, 'Settings');
1314}
1315
1316var cachedServiceElements = null;
1317
1318function onServiceSearchFocus(event){
1319 event.element().value = '';
1320 cachedServiceElements = null;
1321 serviceSearch(event);
1322}
1323function serviceSearch(event){
1324 var needle = event.element().value.toLowerCase();
1325
1326 if(cachedServiceElements == null){
1327 cachedServiceElements = $$('.sListRow');
1328 }
1329
1330 for(var i = 0; i < cachedServiceElements.length; i++){
1331 var row = cachedServiceElements[i];
1332 var serviceName = row.readAttribute('data-servicename').toLowerCase();
1333
1334 if(serviceName.match(needle) != needle && serviceName != ""){
1335 row.hide();
1336 } else {
1337 row.show();
1338 }
1339 }
1340
1341 debug('serviceNames');
1342}
1343/*
1344 * Switches Navigation Modes
1345 * @param mode - The Navigation Mode you want to switch to
1346 * Possible Values: TV, Radio, Movies, Timer, Extras
1347 */
1348function switchMode(mode){
1349 switch(mode){
1350 case "TV":
1351 reloadNav('tplNavTv', 'TeleVision');
1352 break;
1353
1354 case "Radio":
1355 reloadNav('tplNavRadio', 'Radio');
1356 break;
1357
1358 case "Movies":
1359 //The Navigation
1360 reloadNavDynamic(loadMovieNav, 'Movies');
1361
1362 // The Movie list
1363 loadContentDynamic(loadMovieList, 'Movies');
1364 break;
1365
1366 case "Timer":
1367 //The Navigation
1368 reloadNav('tplNavTimer', 'Timer');
1369
1370 // The Timerlist
1371 loadContentDynamic(loadTimerList, 'Timer');
1372 break;
1373
1374 case "BoxControl":
1375 reloadNav('tplNavBoxControl', 'BoxControl');
1376 break;
1377
1378 case "AAF-Panel":
1379 reloadNav('tplNavExtras', 'AAF-Panel');
1380 break;
1381
1382 default:
1383 break;
1384 }
1385}
1386function openWebTV(){
1387 window.open('/web-data/streaminterface.html', 'WebTV', 'scrollbars=no, width=800, height=740');
1388}
1389function clearSearch(){
1390 $('epgSearch').value = "";
1391 $('epgSearch').focus();
1392}
1393function updateItems(){
1394 getCurrent();
1395 getPowerState();
1396}
1397function updateItemsLazy(bouquet){
1398 getSubServices();
1399 getBouquetEpg();
1400}
1401/*
1402 * Does the everything required on initial pageload
1403 */
1404function init(){
1405 var DBG = userprefs.data.debug || false;
1406
1407 if(DBG){
1408 openDebug();
1409 }
1410 if( parseNr(userprefs.data.updateCurrentInterval) < 10000){
1411 userprefs.data.updateCurrentInterval = 120000;
1412 userprefs.save();
1413 }
1414 if( parseNr(userprefs.data.updateBouquetInterval) < 60000 ){
1415 userprefs.data.updateBouquetInterval = 300000;
1416 userprefs.save();
1417 }
1418 if (typeof document.body.style.maxHeight == "undefined") {
1419 alert("Due to the tremendous amount of work needed to get everthing to " +
1420 "work properly, there is (for now) no support for Internet Explorer Versions below 7");
1421 }
1422 getBoxtype();
1423
1424 setAjaxLoad('navContent');
1425 setAjaxLoad('contentMain');
1426
1427 fetchTpl('tplServiceListEPGItem');
1428 fetchTpl('tplBouquetsAndServices');
1429 fetchTpl('tplCurrent');
1430 reloadNav('tplNavTv', 'TeleVision');
1431
1432 initChannelList();
1433 initVolumePanel();
1434 initMovieList();
1435
1436 updateItems();
1437 startUpdateCurrentPoller();
1438}
Note: See TracBrowser for help on using the repository browser.