Collaborama About Help Contact Anonymous [login] Source: site.view [edit] Function name: mediaTimeStartStop Arguments: cmd,kind Description: Starts or stops the media timer Page type: webl Render function: Module: global Page source: var info = (WubCall("global.mediaTimeData", []) ? [. currentMedia = "tv", currentState = "STOP" .]); var html = ""; var dt = Str_Split(Wub_GetDateTimeStr(), " "); var timeLeft = info[dt[0]] ? [. tv = 1000 * 60 * 120, computer = 1000 * 60 * 120 .]; if cmd == "MODIFY TIME" then html = `<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;" />` + "\n" + `<meta name="apple-mobile-web-app-capable" content="yes" />` + "\n"; html = html + `<center><p><form action="/webl/WubHub_DoIt" method="post">` + `<input name="cmdline" value="mediaTimeChangeTime(cmd, day, amount)" type="hidden"/>` + "\n" + `<input name="day" value="` + dt[0] + `" size="10" />` + "\n" + `<input align=left name="cmd" type="submit" value="ZERO OUT HOURS FOR THIS DAY">` + "\n<p>\n" + `<input name="amount" value="30" size="10" />` + "\n" + `<input align=left name="cmd" type="submit" value="CONVERT TV MINS TO COMPUTER">` + "\n" + `</form><p><a href="/webl/WubHub_DoIt?cmdline=mediaTime">[Back]</a></center>` + "\n"; NewPage(html, "text/html"); else if cmd == "REFRESH" then html = "" elsif kind == "kind" then html = "Which type would you like to start or stop?" else var now = Wub_GetDateTime(); // Subtracts running time from timeLeft and updates currentState to STOP var stop = fun(mediaType) var running = now - info.lastClick; if (mediaType == "tv") then timeLeft.tv = timeLeft.tv - running; else // computer timeLeft.computer = timeLeft.computer - running; end; info[dt[0]] := timeLeft; info.lastClick := now; info.currentState := "STOP" end; // Sets currentState to START and remembers now as last time clicked var start = fun(mediaType) info.currentMedia := mediaType; info.currentState := "START"; info.lastClick := now; end; if (cmd == "START") then if info.currentState == "START" then if info.currentMedia == kind then html = kind + " already started." else stop(info.currentMedia); start(kind); html = "Timer started for " + kind + " (stopping previous timer)" end else // currently stopped start(kind); html = "Timer started for " + kind end else // cmd = stop if info.currentState == "START" then stop(info.currentMedia); html = "Timer stopped for " + info.currentMedia else // currently stopped html = "Timer was already stopped" end end; if (timeLeft.tv < 0) then timeLeft.tv := 0; info.currentState := "STOP" end; if (timeLeft.computer < 0) then timeLeft.computer := 0; info.currentState := "STOP" end; info[dt[0]] := timeLeft; var funcinfo = Wub_GetFunctionInfo("global.mediaTimeData"); funcinfo.exec := ToString(info); Wub_SaveFunctionInfo(funcinfo); end; var m = Markup(WubCall("mediaTime", [html])); m = Wub_ReplaceAll(m, `10"`, `4; URL=/webl/WubHub_DoIt?cmdline=global.mediaTime"`); NewPage(m, "text/html"); end;