From f294d3cb3aa36e2a74e4e4c8542c48da78f54861 Mon Sep 17 00:00:00 2001 From: thlo Date: Sun, 29 Sep 2013 16:09:19 +0200 Subject: * Fixes in Comm handling. * Fixes in Timer menu. * Fixes in Image Viewer. * Widget Code Improvements (HTTP transaction handlings) --- smarttv-client/Javascript/Comm.js | 31 +-- smarttv-client/Javascript/Config.js | 1 + smarttv-client/Javascript/Display.js | 7 +- smarttv-client/Javascript/ImgViewer.js | 4 + smarttv-client/Javascript/Main.js | 5 +- smarttv-client/Javascript/Notify.js | 5 +- smarttv-client/Javascript/Options.js | 1 + smarttv-client/Javascript/Server.js | 456 ++++++++++++++++----------------- smarttv-client/Javascript/Timers.js | 71 ++--- 9 files changed, 273 insertions(+), 308 deletions(-) (limited to 'smarttv-client/Javascript') diff --git a/smarttv-client/Javascript/Comm.js b/smarttv-client/Javascript/Comm.js index d732fca..9ae9a44 100644 --- a/smarttv-client/Javascript/Comm.js +++ b/smarttv-client/Javascript/Comm.js @@ -61,19 +61,13 @@ Comm.onDeviceEvent = function(sParam) { switch(Number(sParam.infoType)) { case Comm.customMgr.DEV_EVENT_MESSAGE_RECEIVED: //CustomDeviceMessageInfo -// Main.log("#### onDeviceEvent -1- DEV_EVENT_MESSAGE_RECEIVED:" + sParam.data.message1); -// Main.logToServer("#### onDeviceEvent -1- DEV_EVENT_MESSAGE_RECEIVED:" + sParam.data.message1); Comm.onMessageReceived(sParam.data.message1, sParam.data.message2); break; case Comm.customMgr.DEV_EVENT_JOINED_GROUP: //CustomDeviceGroupInfo -// Main.log("#### onDeviceEvent -1- DEV_EVENT_JOINED_GROUP ####"); -// Main.logToServer("#### onDeviceEvent -1- DEV_EVENT_JOINED_GROUP ####"); break; case Comm.customMgr.DEV_EVENT_LEFT_GROUP: //CustomDeviceGroupInfo -// Main.log("#### onDeviceEvent -1- DEV_EVENT_LEFT_GROUP ####"); -// Main.logToServer("#### onDeviceEvent -1- DEV_EVENT_LEFT_GROUP ####"); break; default: Main.logToServer("onDeviceEvent -1- Unknown event infoType= " + Number(sParam.infoType)); @@ -114,14 +108,16 @@ Comm.onMessageReceived = function(message, context) { Main.logToServer("ERROR: msg.payload.id is not defined"); return; } + // TODO: I should change to the new server only if there is no other vdr server defined. + // Otherwise, check whether the new service is active. If active, add it to the list. Config.updateContext(msg.payload.serverAddr); - if (Config.firstLaunch == true) + if (Config.firstLaunch == true) { Main.state = 1; // ensure, that the cursor is on 1st position - Main.enableKeys(); - Options.hide(); - Main.changeState(0); - + Main.enableKeys(); + Options.hide(); + Main.changeState(0); + } break; case "INFO": Main.logToServer("INFO: type= " + msg.payload.type + " val= " + msg.payload.name); @@ -129,22 +125,27 @@ Comm.onMessageReceived = function(message, context) { case "RECSTART": Notify.showNotify("Recording started: '" + msg.payload.name +"'", true); if (Main.state == Main.eREC) { - Server.updateEntry(msg.payload.name); - } - // msg.payload.name is the guid. I should now run a query, then update the database and update the screen (if needed) - + Server.updateEntry(msg.payload.guid); + } break; case "RECSTOP": Notify.showNotify("Recording finished: " + msg.payload.name+"'", true); break; case "TCADD": Notify.showNotify("Timer added: '" + msg.payload.name+"'", true); + if (Main.state == Main.eTMR) { + Timers.resetView(); + } break; case "TCMOD": Notify.showNotify("Timer modified: '" + msg.payload.name+"'", true); + if (Main.state == Main.eTMR) { + Timers.resetView(); } break; case "TCDEL": Notify.showNotify("Timer deleted: '" + msg.payload.name+"'", true); + if (Main.state == Main.eTMR) { + Timers.resetView(); } break; } diff --git a/smarttv-client/Javascript/Config.js b/smarttv-client/Javascript/Config.js index 08c4cf5..7496cbc 100755 --- a/smarttv-client/Javascript/Config.js +++ b/smarttv-client/Javascript/Config.js @@ -249,6 +249,7 @@ Config.updateContext = function (addr) { if (found == true) { // don't overwrite, if the address is already there. Main.log("Config.updateContext: don't overwrite -> return"); + Main.logToServer("Config.updateContext: don't overwrite -> return"); Notify.showNotify("Server already included -> Ignoring", true); if ((Config.verboseStart == true) && (Config.firstLaunch == true)) Display.showPopup("Config.updateContext: don't overwrite -> return"); diff --git a/smarttv-client/Javascript/Display.js b/smarttv-client/Javascript/Display.js index 3d629f7..660a007 100755 --- a/smarttv-client/Javascript/Display.js +++ b/smarttv-client/Javascript/Display.js @@ -643,7 +643,9 @@ Display.getDisplayTitle = function(item) { Display.resetAtStop = function () { // this function should reset all overlay features to plan recordings. // Hide Recording bar - Notify.notifyOlHandler.cancel(); + +// TODO: Debugging purpose +// Notify.notifyOlHandler.cancel(); Player.resetAtStop(); // Needs to be done at beginning to reset parameters Display.resetStartStop(); @@ -909,6 +911,7 @@ Display.showPopup = function(text) { // var oldHTML = document.getElementById("popup").innerHTML; // Display.putInnerHTML(document.getElementById("popup"), oldHTML + "
" + text); + Main.log("Display.showPopup text= " + text); if (text == "") this.popupOlHandler.show(); @@ -920,6 +923,8 @@ Display.showPopup = function(text) { }; Display.scrollPopup = function () { + Main.log("Display.scrollPopup" ); + var t = $('#popup').children().last().position().top; var h = $('#popup').children().last().outerHeight(); if ((t + h) > $("#popup").height()) { diff --git a/smarttv-client/Javascript/ImgViewer.js b/smarttv-client/Javascript/ImgViewer.js index 9e076fb..431a1ee 100644 --- a/smarttv-client/Javascript/ImgViewer.js +++ b/smarttv-client/Javascript/ImgViewer.js @@ -227,6 +227,10 @@ ImgViewer.onInput = function () { break; case tvKey.KEY_YELLOW: Main.log("Delete YE Button"); + var img_name = Data.getCurrentItem().childs[this.imgList[this.curImg]].payload.link.split("/"); + Notify.showNotify( img_name[img_name.length -1], true); + + Buttons.ynHeadlineText ("Delete " + img_name[img_name.length -1]); Main.selectedVideo = this.imgList[this.curImg]; Buttons.ynShow(); // Server.deleteMedFile(Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); diff --git a/smarttv-client/Javascript/Main.js b/smarttv-client/Javascript/Main.js index d65ee70..48b4e44 100755 --- a/smarttv-client/Javascript/Main.js +++ b/smarttv-client/Javascript/Main.js @@ -283,6 +283,7 @@ Main.isTvSet = function () { Main.changeState = function (state) { Main.log("change state: OldState= " + this.state + " NewState= " + state); + Main.logToServer("change state: OldState= " + this.state + " NewState= " + state); var old_state = this.state; @@ -1069,10 +1070,10 @@ cLivePlayStateKeyHndl.prototype.handleKeyDown = function (keyCode) { case 73: Main.log("KEY_REC with guid= Data.getCurrentItem().childs[Main.selectedVideo].payload.guid"); - var timer_req = new addTimer(Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); +// var timer_req = new addTimer(Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); + Server.addTimer(Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); // use the guid and request the epg. // use the event id then issue the rec command -// Data.getCurrentItem().childs[Main.selectedVideo].payload.guid case tvKey.KEY_PAUSE: Main.log("REC / PAUSE"); diff --git a/smarttv-client/Javascript/Notify.js b/smarttv-client/Javascript/Notify.js index a980af5..dcb18ae 100644 --- a/smarttv-client/Javascript/Notify.js +++ b/smarttv-client/Javascript/Notify.js @@ -1,5 +1,5 @@ var Notify = { - notifyOlHandler : null + notifyOlHandler : null }; @@ -11,6 +11,7 @@ Notify.init = function () { Notify.showNotify = function (msg, timer) { + $("#notify").text(msg); if (timer == true) this.notifyOlHandler.show(); @@ -24,6 +25,6 @@ Notify.handlerShowNotify = function () { Notify.handlerHideNotify = function () { $("#notify").hide(); - $("#notify").text(""); + $("#notify").text(""); }; diff --git a/smarttv-client/Javascript/Options.js b/smarttv-client/Javascript/Options.js index cf44270..6364925 100755 --- a/smarttv-client/Javascript/Options.js +++ b/smarttv-client/Javascript/Options.js @@ -387,6 +387,7 @@ Options.onInput = function () { // Done // Options.cursorPos = Options.cursorPos +1; // Options.deleteChar(); // + Main.logToServer("Options.onInput: Enter Pressed - Val= " + document.getElementById(Options.inputElm).value); if (Config.verboseStart == true) Display.showPopup("Options.onInput: Enter Pressed - Val= " + document.getElementById(Options.inputElm).value); if (Options.state == Options.sSelect) { diff --git a/smarttv-client/Javascript/Server.js b/smarttv-client/Javascript/Server.js index 2d88fca..f976f9d 100755 --- a/smarttv-client/Javascript/Server.js +++ b/smarttv-client/Javascript/Server.js @@ -83,78 +83,6 @@ Server.fetchVideoList = function(url) { }); }; -Server.updateEntry = function(guid) { - - Server.curGuid = Data.getCurrentItem().childs[Main.selectedVideo].payload.guid; - - //url is sufficed with ?guid - var url = Config.serverUrl + "/recordings.xml?guid="+guid; - Main.logToServer(" Server.updateEntry: guid= " + guid); - - $.ajax({ - url: url, - type : "GET", - success : function(data, status, XHR ) { - Main.logToServer("Server.updateEntry Success Response - status= " + status + " mime= " + XHR.responseType + " data= "+ data); - - $(data).find("item").each(function () { - var title = $(this).find('title').text(); - var link = $(this).find('enclosure').attr('url'); - var guid = $(this).find('guid').text(); - var programme = $(this).find('programme').text(); - var description = $(this).find('description').text(); - var startVal = parseInt($(this).find('start').text()); - var durVal = parseInt($(this).find('duration').text()); - var fps = parseFloat($(this).find('fps').text()); - var ispes = $(this).find('ispes').text(); - var isnew = $(this).find('isnew').text(); - var num = parseInt($(this).find('number').text()); - Main.logToServer("Server.updateEntry: title= " + title + " start= " + startVal + " dur= " + durVal + " fps= " + fps); - - var title_list = title.split("~"); - Data.addItem( title_list, {link : link, prog: programme, desc: description, guid : guid, start: startVal, - dur: durVal, ispes : ispes, isnew : isnew, fps : fps, num : num}); - - }); // each - - Data.assets.sortPayload(Data.sortType); - - // check, whether Main.selectedVideo still points to the entry with guid - if (Data.getCurrentItem().childs[Main.selectedVideo].payload.guid != Server.curGuid) { - Main.logToServer("Server.updateEntry: curGuid has changed: curGuid= " + Server.curGuid); - Main.logToServer("Server.updateEntry: selVid= "+ Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); - Main.selectedVideo = Main.selectedVideo+1; - Main.logToServer("Server.updateEntry: curGuid has changed: selVid+1"+ Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); - } - - var first_item = Main.selectedVideo - Display.currentWindow; - if (first_item < 0 ) - first_item = 0; - - Display.setVideoList(Main.selectedVideo, first_item); - // Main.selectedVideo does not fit anymore!!!!! - // should do a general reset (jump to 0), when a new element is added - // should reset to zero - // plus update notif - Main.logToServer(" done"); - - }, - error : function (jqXHR, status, error) { - Main.logToServer("Server.updateEntry Error Response - status= " + status + " error= "+ error); - Display.showPopup("Error with XML File: " + status); - Server.retries ++; - }, - parsererror : function () { - Main.logToServer("Server.updateEntry parserError " ); - Display.showPopup("Error in XML File"); - Server.retries ++; - if (Server.errorCallback != null) { - Server.errorCallback("XmlError"); - } - - } - }); -}; //--------------------------------------------- @@ -206,53 +134,6 @@ Server.updateVdrStatus = function (){ }); }; -/* -Server.getResume = function (guid) { -// Main.log ("***** getResume *****"); - $.ajax({ - url: Config.serverUrl + "/getResume.xml", - type : "POST", - data : "filename:" + guid +"\n", - success : function(data, status, XHR ) { - Main.log("**** Resome Success Response - status= " + status + " mime= " + XHR.responseType + " data= "+ data); - - var resume_str = $(data).find("resume").text(); - if (resume_str != "") { - var resume_val = parseFloat(resume_str); - Main.log("resume val= " + resume_val ); - Main.logToServer("resume val= " + resume_val ); - Player.resumePos = resume_val; - Player.playVideo( resume_val); - } - else { - Display.hide(); - Display.showProgress(); - Player.playVideo(-1); - } - - }, - error : function (jqXHR, status, error) { - Main.log("**** Resome Error Response - status= " + status + " error= "+ error); - Display.hide(); - Display.showProgress(); - Player.playVideo(-1); - } - }); -}; -*/ -/* -Server.saveResume = function() { - var msg = ""; - msg += "filename:" + Data.getCurrentItem().childs[Main.selectedVideo].payload.guid + "\n"; - msg += "resume:"+ (Player.curPlayTime/1000) + "\n" ; - - $.post(Config.serverUrl + "/setResume.xml", msg, function(data, textStatus, XHR) { - Main.logToServer("SaveResume Status= " + XHR.status ); - }, "text"); - -}; - -*/ Server.notifyServer = function (state) { Main.log("Server.notifyServer state="+state +"&mac=" + Network.ownMac + "&ip=" + Network.ownIp); @@ -320,6 +201,12 @@ Server.getErrorText = function (status, input) { case 3: res = "Entry not found. Deletion failed"; break; + case 4: + res = "TV address field empty."; + break; + case 5: + res = "Mandatory TV address attribute not present."; + break; case 6: // set resume data res = "Failed to find the recording."; @@ -337,7 +224,18 @@ Server.getErrorText = function (status, input) { case 10: res = "No Timer found."; break; - + case 11: + res = "No id in query line"; + break; + case 12: + res = "Invalid Channel ID."; + break; + case 13: + res = "Time to large."; + break; + case 14: + res = "Timer already defined."; + break; case 15: res = "Mandatory cmd attribute not present."; break; @@ -382,9 +280,27 @@ Server.getErrorText = function (status, input) { }; case 500: // Internal Server Error switch (errno) { + case 1: + res = "Schedule is zero"; + break; + case 2: + res = "Event is zero"; + break; + case 3: + res = "Title is zero."; + break; + case 4: + res = "Description is zero."; + break; + case 5: + res = "writeXMLItem returned an error"; + break; case 6: res = "deletion failed!"; - break; + break; + case 7: + res = "Title is zero"; + break; default: res = "Unhandled Errno - Status= " + status + " Errno= "+ errno; break; @@ -407,40 +323,53 @@ Server.getErrorText = function (status, input) { return res; }; +Server.addTimer = function (guid) { + var obj = new execRestCmd(RestCmds.CMD_AddTimer, guid); +}; + +Server.actTimer = function (guid, act) { + // act : true = activate timer + // act : false = deactivate timer +// var obj = new execRestCmd(RestCmds.CMD_ActTimer, Timers.timerList[this.btnSelected].index, {setActive : false}); + var obj = new execRestCmd(RestCmds.CMD_ActTimer, guid, {setActive : act}); +}; + +Server.delTimer = function (guid) { + var obj = new execRestCmd(RestCmds.CMD_DelTimer, guid); +}; + Server.deleteRecording = function(guid) { var obj = new execRestCmd(RestCmds.CMD_DelRec, guid); - }; Server.deleteUrls = function (guid) { - var obj = new execRestCmd(RestCmds.CMD_DelYtUrl, guid); - }; - Server.getResume = function (guid) { Main.log ("***** getResume *****"); var obj = new execRestCmd(RestCmds.CMD_GetResume, guid); - }; Server.saveResume = function() { - var obj = new execRestCmd(RestCmds.CMD_SetResume, Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); - }; Server.execRecCmd = function (cmd, guid) { var obj = new execRestCmd(RestCmds.CMD_ExecRecCmd, guid, { cmd:cmd }); - }; Server.deleteMedFile = function(guid) { var obj = new execRestCmd(RestCmds.CMD_DelMedFile, guid); }; +Server.updateEntry = function(guid) { + var obj = new execRestCmd(RestCmds.CMD_UpdateEntry, guid); + +}; + + var RestCmds = { CMD_AddTimer : 0, CMD_DelMedFile : 1, @@ -451,7 +380,8 @@ var RestCmds = { CMD_GetRecCmds : 6, CMD_ExecRecCmd : 7, CMD_ActTimer : 8, - CMD_DelTimer : 9 + CMD_DelTimer : 9, + CMD_UpdateEntry : 10 }; @@ -460,25 +390,52 @@ var RestCmds = { //----------------- execRestCmd -------------------------------------- //-------------------------------------------------------------------- //-------------------------------------------------------------------- -function execRestCmd(cmd, guid, parms) { - this.successCallback = null; +function execRestCmd(cmd, guid, args) { +// this.successCallback = null; this.errorCallback = null; this.guid = guid; - this.parms = parms; - - this.url = ""; + this.args = args; this.cmd = -1; - this.method = ""; + + this.parms = { + context : this, + + error : function (XHR, status, error) { + this.statusCode = XHR.status; + this.status = status; + this.errno = Number(XHR.responseText.slice(0, 3)); + + Main.logToServer("ERROR received for guid= " + this.guid + " status= " + status); + if (status == "timeout") { + Notify.showNotify( "Timeout.", true); + + } + else { + Main.log("ERROR= " + XHR.status + " text= " + XHR.responseText); + var res = Server.getErrorText(XHR.status, XHR.responseText); + Main.log ("execRestCmd for Error Inst= " + this.guid+ " res= " + res); + Notify.showNotify( res, true); + + if (this.errorCallback != null) + this.errorCallback(); + + } + + } + }; + + switch(cmd) { case RestCmds.CMD_AddTimer: // add a timer - this.url =Config.serverUrl + "/addTimer.xml?guid="+this.guid; this.cmd = cmd; - this.method = "GET"; + this.parms.url =Config.serverUrl + "/addTimer.xml?guid="+this.guid; + this.parms.method = "GET"; +// this.parms.timeout = 500; - this.successCallback = function(data, status, XHR ) { + this.parms.success = function(data, status, XHR ) { Notify.showNotify("Timer added", true); Main.log ("addTimer for Inst= " + this.guid +" status: " + ((status != null) ? status : "null")); }; @@ -486,24 +443,29 @@ function execRestCmd(cmd, guid, parms) { case RestCmds.CMD_DelMedFile: // delete a file from media folder - Main.log("Server.deleteMedFile guid=" + guid); - Main.logToServer("Server.deleteMedFile guid=" + guid); + Main.log("Server.deleteMedFile guid=" + this.guid); + Main.logToServer("Server.deleteMedFile guid=" + this.guid); - this.url =Config.serverUrl + "/deleteFile?guid=" +guid; this.cmd = cmd; - this.method = "GET"; - - this.successCallback = function(data, status, XHR ) { + this.parms.url =Config.serverUrl + "/deleteFile?guid=" +this.guid; + this.parms.method = "GET"; +// this.parms.timeout = 500; + + var img_name = this.guid.split("/"); + Notify.showNotify("Deleting "+ img_name[img_name.length -1], true); + + this.parms.success = function(data, status, XHR ) { Notify.showNotify("Deleted", true); Data.deleteElm(Main.selectedVideo); if (Main.selectedVideo >= Data.getVideoCount()) Main.selectedVideo = Data.getVideoCount() -1; Display.setVideoList(Main.selectedVideo, (Main.selectedVideo - Display.currentWindow)); - if (ImgViewer.isActive == true) { ImgViewer.createImgArray(); + ImgViewer.curImg = 0; + ImgViewer.showImage(); ImgViewer.focus (); } @@ -523,11 +485,12 @@ function execRestCmd(cmd, guid, parms) { Main.logToServer("Server.deleteUrls guid=" + guid); Notify.handlerShowNotify("Deleting...", false); - this.url =Config.serverUrl + "/deleteYtUrl?guid=" +guid; this.cmd = cmd; - this.method = "POST"; + this.parms.url =Config.serverUrl + "/deleteYtUrl?guid=" +guid; + this.parms.method = "POST"; +// this.parms.timeout = 500; - this.successCallback = function(data, status, XHR ) { + this.parms.success = function(data, status, XHR ) { Notify.showNotify("Deleted", true); Data.deleteElm(Main.selectedVideo); if (Main.selectedVideo >= Data.getVideoCount()) @@ -535,8 +498,8 @@ function execRestCmd(cmd, guid, parms) { Server.updateVdrStatus(); Display.setVideoList(Main.selectedVideo, (Main.selectedVideo - Display.currentWindow)); Main.logToServer("Server.deleteUrls: Success" ); - }; + break; case RestCmds.CMD_DelRec: // Delete a Recording @@ -545,11 +508,12 @@ function execRestCmd(cmd, guid, parms) { Main.logToServer("Server.deleteRecording guid=" + guid); Notify.handlerShowNotify("Deleting...", false); - this.url =Config.serverUrl + "/deleteRecording.xml?id=" +guid; this.cmd = cmd; - this.method = "POST"; + this.parms.url =Config.serverUrl + "/deleteRecording.xml?id=" +guid; + this.parms.method = "POST"; +// this.parms.timeout = 500; - this.successCallback = function(data, status, XHR ) { + this.parms.success = function(data, status, XHR ) { Notify.showNotify("Deleted", true); Data.deleteElm(Main.selectedVideo); if (Main.selectedVideo >= Data.getVideoCount()) @@ -564,12 +528,17 @@ function execRestCmd(cmd, guid, parms) { case RestCmds.CMD_SetResume : // Send Resume Data - Main.log("Server.SetResume guid=" + guid); - Main.logToServer("Server.SetResume guid=" + guid + " resume= " + (Player.curPlayTime/1000) + "sec"); - this.url =Config.serverUrl + "/setResume.xml?guid=" +guid + "&resume=" + (Player.curPlayTime/1000); + Main.log ("Server.SetResume guid=" + guid + " resume= " + (Player.curPlayTime/1000) + "sec or " + Display.durationString(Player.curPlayTime/1000)); + Main.logToServer("Server.SetResume guid=" + guid + " resume= " + (Player.curPlayTime/1000) + "sec or " + Display.durationString(Player.curPlayTime/1000)); + this.cmd = cmd; - this.method = "POST"; - this.successCallback = function(data, status, XHR ) { + this.parms.url =Config.serverUrl + "/setResume.xml?guid=" +guid + "&resume=" + (Player.curPlayTime/1000); + this.parms.method = "POST"; +// this.parms.timeout = 1000; + + Notify.showNotify( "Set resume to " + Display.durationString(Player.curPlayTime/1000), true); + + this.parms.success = function(data, status, XHR ) { Main.logToServer("SaveResume Status= " + XHR.status ); }; @@ -580,11 +549,12 @@ function execRestCmd(cmd, guid, parms) { Main.log("Server.GetResume guid=" + guid); Main.logToServer("Server.GetResume guid=" + guid); - this.url =Config.serverUrl + "/getResume.xml?guid=" +guid; this.cmd = cmd; - this.method = "POST"; + this.parms.url =Config.serverUrl + "/getResume.xml?guid=" +guid; + this.parms.method = "POST"; + this.parms.timeout = 500; - this.successCallback = function(data, status, XHR ) { + this.parms.success = function(data, status, XHR ) { Main.log("**** Resome Success Response - status= " + status + " mime= " + XHR.responseType + " data= "+ data); var resume_str = $(data).find("resume").text(); @@ -592,6 +562,7 @@ function execRestCmd(cmd, guid, parms) { var resume_val = parseFloat(resume_str); Main.log("resume val= " + resume_val ); Main.logToServer("GetResume for" + this.guid + " resume val= " + resume_val + "sec"); + Notify.showNotify( "Resume from " + Display.durationString(resume_val), true); Player.resumePos = resume_val; Player.playVideo( resume_val); } @@ -608,21 +579,20 @@ function execRestCmd(cmd, guid, parms) { Display.hide(); Display.showProgress(); Player.playVideo(-1); - }; - - + }; break; case RestCmds.CMD_ExecRecCmd : // Execute a recording command - Main.logToServer("Server.execRecCmd cmd="+parms.cmd+" guid=" + guid ); + Main.logToServer("Server.execRecCmd cmd="+this.args.cmd+" guid=" + guid ); - this.url = Config.serverUrl + "/execreccmd?cmd="+parms.cmd+"&guid=" + guid; this.cmd = cmd; - this.method = "GET"; + this.parms.url = Config.serverUrl + "/execreccmd?cmd="+this.args.cmd+"&guid=" + guid; + this.parms.method = "GET"; +// this.parms.timeout = 500; - this.successCallback = function(data, status, XHR ) { + this.parms.success = function(data, status, XHR ) { Main.logToServer("Server.execRecCmd OK" ) ; Display.handleDescription(Main.selectedVideo); }; @@ -631,13 +601,14 @@ function execRestCmd(cmd, guid, parms) { case RestCmds.CMD_ActTimer : // Activate or Deactivate a timer - Main.logToServer("Server.ActTimer index=" + guid + " setActive= " + ((parms.setActive == true) ? "true" : "false" )); + Main.logToServer("Server.ActTimer index=" + guid + " setActive= " + ((this.args.setActive == true) ? "true" : "false" )); - this.url = Config.serverUrl + "/activateTimer?index=" +guid + "&activate=" + ((parms.setActive == true) ? "true" : "false"), this.cmd = cmd; - this.method = "GET"; + this.parms.url = Config.serverUrl + "/activateTimer?index=" +guid + "&activate=" + ((this.args.setActive == true) ? "true" : "false"), + this.parms.method = "GET"; + this.parms.timeout = 500; - this.successCallback = function(data, status, XHR ) { + this.parms.success = function(data, status, XHR ) { Main.logToServer("Timers.activateTimer: Success" ); Main.log("Timers.activateTimer: Success" ); @@ -650,11 +621,12 @@ function execRestCmd(cmd, guid, parms) { Main.logToServer("Server.DelTimer index=" + guid ); - this.url = Config.serverUrl + "/deleteTimer?index=" +guid, this.cmd = cmd; - this.method = "GET"; + this.parms.url = Config.serverUrl + "/deleteTimer?index=" +guid, + this.parms.method = "GET"; +// this.parms.timeout = 500; - this.successCallback = function(data, status, XHR ) { + this.parms.success = function(data, status, XHR ) { Main.logToServer("Timers.deleteTimer: Success" ); Main.log("Timers.deleteTimer: Success" ); @@ -662,7 +634,76 @@ function execRestCmd(cmd, guid, parms) { // remove index from database }; break; + + case RestCmds.CMD_UpdateEntry: + Server.curGuid = Data.getCurrentItem().childs[Main.selectedVideo].payload.guid; + + //url is sufficed with ?guid + Main.logToServer(" Server.updateEntry: guid= " + guid); + + this.cmd = cmd; + this.parms.url = Config.serverUrl + "/recordings.xml?guid="+guid, + this.parms.method = "GET"; + this.retries = 0; + + this.parms.success = function(data, status, XHR ) { + Main.logToServer("Server.updateEntry Success Response - status= " + status + " mime= " + XHR.responseType + " data= "+ data); + + $(data).find("item").each(function () { + var title = $(this).find('title').text(); + var link = $(this).find('enclosure').attr('url'); + var guid = $(this).find('guid').text(); + var programme = $(this).find('programme').text(); + var description = $(this).find('description').text(); + var startVal = parseInt($(this).find('start').text()); + var durVal = parseInt($(this).find('duration').text()); + var fps = parseFloat($(this).find('fps').text()); + var ispes = $(this).find('ispes').text(); + var isnew = $(this).find('isnew').text(); + var num = parseInt($(this).find('number').text()); + Main.logToServer("Server.updateEntry: title= " + title + " start= " + startVal + " dur= " + durVal + " fps= " + fps); + + var title_list = title.split("~"); + Data.addItem( title_list, {link : link, prog: programme, desc: description, guid : guid, start: startVal, + dur: durVal, ispes : ispes, isnew : isnew, fps : fps, num : num}); + + Display.showPopup("Server.updateEntry: addItem= " + title); + + }); // each + + Data.assets.sortPayload(Data.sortType); + + // check, whether Main.selectedVideo still points to the entry with guid + if (Data.getCurrentItem().childs[Main.selectedVideo].payload.guid != Server.curGuid) { + Main.logToServer("Server.updateEntry: curGuid has changed: curGuid= " + Server.curGuid); + Main.logToServer("Server.updateEntry: selVid= "+ Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); + Main.selectedVideo = Main.selectedVideo+1; + Main.logToServer("Server.updateEntry: curGuid has changed: selVid+1"+ Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); + } + + var first_item = Main.selectedVideo - Display.currentWindow; + if (first_item < 0 ) { + first_item = 0; + + } + Display.setVideoList(Main.selectedVideo, first_item); + Main.logToServer(" done"); + + }; + + this.errorCallback = function() { + Display.logToServer ("Server.updateEntry Error Response status= " + this.statusCode + " errno= " + this.errno+ " retries= " +this.retries); + + if ((this.statusCode== 400) && (this.errno == 7)) { + if (this.retires < 10) { + Server.updateEntry(this.guid) ; + } + this.retries ++; + + } + }; + break; default: Main.log("execRestCmd - ERROR: CMD= " + cmd + " is not supported"); Main.logToServer("execRestCmd - ERROR: CMD= " + cmd + " is not supported"); @@ -678,73 +719,12 @@ function execRestCmd(cmd, guid, parms) { }; execRestCmd.prototype.request = function () { - Main.log("execRestCmd request url= " + this.url); - - $.ajax({ - url: this.url, - type : this.method, - context : this, - timeout : 500, - success : this.successCallback, - - error : function (XHR, status, error) { - - Main.logToServer("ERROR received for guid= " + this.guid + " status= " + status); - if (status == "timeout") { - Notify.showNotify( "Timeout.", true); - - } - else { - Main.log("ERROR= " + XHR.status + " text= " + XHR.responseText); - var res = Server.getErrorText(XHR.status, XHR.responseText); - Main.log ("execRestCmd for Error Inst= " + this.guid+ " res= " + res); - Notify.showNotify( res, true); - - if (this.errorCallback != null) - this.errorCallback(); - - } - - } - }); + Main.log("execRestCmd request url= " + this.parms.url); + $.ajax(this.parms); }; - -function addTimer(guid) { - this.successCallback = null; - this.errorCallback = null; - this.guid = guid; - this.request(); -}; - -addTimer.prototype.request = function () { - var url =Config.serverUrl + "/addTimer.xml?guid="+this.guid; - Main.log("addTimer request url= " + url); - - $.ajax({ - url: url, - type : "GET", - context : this, - timeout : 400, - success : function(data, status, XHR ) { - Main.log ("addTimer for Inst= " + this.guid +" status: " + ((status != null) ? status : "null")); - }, - error : function (XHR, status, error) { - Main.log ("addTimer for Error Inst= " + this.guid+" status: " + ((status != null) ? status : "null")); - if (XHR.status == 400) { - - Display.showPopup("Timer creation failed channel= "+this.guid + " Text= " + XHR.responseText, true); - } - else - Display.showPopup("Timer creation failed channel= "+this.guid + " code= " + XHR.status, true); - - } - }); - -}; - var HeartbeatHandler = { timeoutObj : null, isActive : false diff --git a/smarttv-client/Javascript/Timers.js b/smarttv-client/Javascript/Timers.js index 8f38994..a90eedf 100644 --- a/smarttv-client/Javascript/Timers.js +++ b/smarttv-client/Javascript/Timers.js @@ -156,13 +156,22 @@ Timers.getWeekdays = function (wd) { var map = wd.toString(2); var res = ""; - res += ((map[0] == "1") ? "M" : "-"); - res += ((map[1] == "1") ? "D" : "-"); - res += ((map[2] == "1") ? "M" : "-"); - res += ((map[3] == "1") ? "D" : "-"); - res += ((map[4] == "1") ? "F" : "-"); - res += ((map[5] == "1") ? "S" : "-"); - res += ((map[6] == "1") ? "S" : "-"); + if (map.length <= 7) { + var suf = "0000000".slice(0, (7-map.length)); + map = suf + map; + } + else { + // take the last 7 digits + map = map.slice ((7-map.length)); + } + + res += ((map[6] == "1") ? "M" : "-"); + res += ((map[5] == "1") ? "T" : "-"); + res += ((map[4] == "1") ? "W" : "-"); + res += ((map[3] == "1") ? "T" : "-"); + res += ((map[2] == "1") ? "F" : "-"); + res += ((map[1] == "1") ? "S" : "-"); + res += ((map[0] == "1") ? "S" : "-"); return res; }; @@ -209,10 +218,9 @@ Timers.timerCallback = function () { // delete the current timer Main.log("****** Delete Timer: " + Timers.timerList[this.btnSelected].title); -// var del_req = new DeleteTimerReq (Timers.timerList[this.btnSelected].index); +// var obj = new execRestCmd(RestCmds.CMD_DelTimer, Timers.timerList[this.btnSelected].index); + Server.delTimer(Timers.timerList[this.btnSelected].index); - var obj = new execRestCmd(RestCmds.CMD_DelTimer, Timers.timerList[this.btnSelected].index); - // var del_req = new DeleteTimerReq (10); }; @@ -276,7 +284,6 @@ Timers.onInput = function () { break; case tvKey.KEY_ENTER: Buttons.ynShow(); -// Timers.hide(); break; case tvKey.KEY_YELLOW: @@ -284,12 +291,10 @@ Timers.onInput = function () { Timers.timerCallback = function () { // delete the current timer Main.log("Timers.timerCallback: " + Timers.timerList[this.btnSelected].title); - var obj = new execRestCmd(RestCmds.CMD_DelTimer, Timers.timerList[this.btnSelected].index); - // var del_req = new DeleteTimerReq (10); + Server.delTimer(Timers.timerList[this.btnSelected].index); }; Buttons.ynShow(); -// Timers.hide(); break; case tvKey.KEY_RED: @@ -298,7 +303,7 @@ Timers.onInput = function () { Buttons.ynHeadlineText ("Deactivate Timer ?"); Timers.timerCallback = function () { Main.log("Timers.timerCallback Deactivate Timer: " + Timers.timerList[this.btnSelected].title); - var obj = new execRestCmd(RestCmds.CMD_ActTimer, Timers.timerList[this.btnSelected].index, {setActive : false}); + Server.actTimer(Timers.timerList[this.btnSelected].index, false); }; } @@ -307,7 +312,7 @@ Timers.onInput = function () { Buttons.ynHeadlineText ("Activate Timer ?"); Timers.timerCallback = function () { Main.log("Timers.timerCallback Activate Timer: " + Timers.timerList[this.btnSelected].title); - var obj = new execRestCmd(RestCmds.CMD_ActTimer, Timers.timerList[this.btnSelected].index, {setActive : true}); + Server.actTimer(Timers.timerList[this.btnSelected].index, true); }; } @@ -336,37 +341,3 @@ Timers.onInput = function () { }; -/* -function DeleteTimerReq (idx) { - this.index = idx; - this.exec(); -}; - -DeleteTimerReq.prototype.exec = function () { - Main.log("Sending delete request for idx= " + this.index); - $.ajax({ - url: Config.serverUrl + "/deleteTimer?index=" +this.index, - type : "GET", - context : this, - success : function(data, status, XHR ) { - Main.logToServer("Timers.deleteTimer: Success" ); - Main.log("Timers.deleteTimer: Success" ); - - Timers.resetView(); - // remove index from database - }, - error : function (XHR, status, error) { - Main.logToServer("Timers.deleteTimer: ERROR " + XHR.status + ": " + XHR.responseText ); - Main.log("Timers.deleteTimer: ERROR (" + XHR.status + ": " + XHR.responseText +")"); - - var res = Server.getErrorText(XHR.status, XHR.responseText); -// var res = parseInt(XHR.responseText.slice(0, 3)); - Main.log("Timers.deleteTimer: res(" + res +") for idx= " + this.index); - - Notify.showNotify( res, true); - - } - }); - -}; -*/ \ No newline at end of file -- cgit v1.2.3