From 78ffd15e485fe3ba341bf7d5e7479ff9a5a6de4b Mon Sep 17 00:00:00 2001 From: Dieter Hametner Date: Sun, 23 Mar 2008 01:01:32 +0100 Subject: Some clean up in the timer editing call. Prepeared timer edititing to be a popup like the epg-data. This is not finished yet and seems to have some problems with the form and the popup. So the overall functionality is disabled. Never the less some of the changes for this are of general interrest, so current work was commited. Changes in the styles for this. --- epg_events.cpp | 10 ++++++---- live/js/live/pageenhance.js | 28 ++++++++++++++++++++++++++++ pages/edit_timer.ecpp | 23 ++++++++++++++++++++--- pages/timers.ecpp | 10 ++++++---- timers.cpp | 18 ++++++++++++++++++ timers.h | 11 ++++++++--- tools.cpp | 18 ++++++++++++++++++ tools.h | 7 +++---- 8 files changed, 107 insertions(+), 18 deletions(-) diff --git a/epg_events.cpp b/epg_events.cpp index 7d22cdf..962fcfc 100644 --- a/epg_events.cpp +++ b/epg_events.cpp @@ -214,8 +214,9 @@ namespace vdrlive string channelId(chanId.ToString()); string eventId("event_"); - replace(channelId.begin(), channelId.end(), '.', 'p'); - replace(channelId.begin(), channelId.end(), '-', 'm'); + channelId = vdrlive::EncodeDomId(channelId, ".-", "pm"); + // replace(channelId.begin(), channelId.end(), '.', 'p'); + // replace(channelId.begin(), channelId.end(), '-', 'm'); eventId += channelId; eventId += '_'; @@ -230,8 +231,9 @@ namespace vdrlive size_t delimPos = epgid.find_last_of('_'); string cIdStr = epgid.substr(eventStr.length(), delimPos - eventStr.length()); - replace(cIdStr.begin(), cIdStr.end(), 'm', '-'); - replace(cIdStr.begin(), cIdStr.end(), 'p', '.'); + cIdStr = vdrlive::DecodeDomId(cIdStr, "mp", "-."); + // replace(cIdStr.begin(), cIdStr.end(), 'm', '-'); + // replace(cIdStr.begin(), cIdStr.end(), 'p', '.'); string const eIdStr = epgid.substr(delimPos+1); diff --git a/live/js/live/pageenhance.js b/live/js/live/pageenhance.js index d98b374..5ca90c0 100644 --- a/live/js/live/pageenhance.js +++ b/live/js/live/pageenhance.js @@ -16,6 +16,7 @@ var PageEnhance = new Class({ vlcWinOptions: { size: { width: 720, height: 640 } }, + editTimerSelector: 'a[href^="edit_timer.html?timerid"]', hintTipSelector: '*[title]', hintClassName: 'hint', infoWinOptions: { @@ -46,6 +47,9 @@ var PageEnhance = new Class({ $$(this.options.actionLinkSelector).each(this.vdrRequest.bind(this)); $$(this.options.vlcLinkSelector).each(this.vlcRequest.bind(this)); $$(this.options.datePickerSelector).each(this.datePicker.bind(this)); + // the following line activates timer editing in popup window. + // but it does not yet work like expected. So we leave it deactivated currently. + // $$(this.options.editTimerSelector).each(this.editTimer.bind(this)); }, // actions applied on mouse down. @@ -85,6 +89,30 @@ var PageEnhance = new Class({ } }, + // Edit Timer Popup function. Apply to all elements that should + // pop up a timer edit windows based on InfoWin window. + editTimer: function(el){ + var href = el.href; + var timerid = $pick(href, ""); + if (timerid != "") { + var extractId = /timerid=(.+)/; + var found = extractId.exec(timerid); + if ($defined(found) && found.length > 1) { + timerid = found[1]; + el.addEvent('click', function(event){ + var event = new Event(event); + new InfoWin.Ajax(timerid, href, $merge(this.options.infoWinOptions, { + bodyselect: '', + modal: true, + onDomExtend: this.domExtend.bind(this) + })).show(event); + event.stop(); + return false; + }.bind(this)); + } + } + }, + // function that requests an action from the server vdr. vdrRequest: function(el){ el.addEvent('click', function(event, element){ diff --git a/pages/edit_timer.ecpp b/pages/edit_timer.ecpp index 7b92551..f1c6ca2 100644 --- a/pages/edit_timer.ecpp +++ b/pages/edit_timer.ecpp @@ -20,6 +20,7 @@ using namespace vdrlive; // input parameters string timerid; string epgid; + string async; // form parameters tChannelID channel; bool active = true; @@ -53,6 +54,8 @@ cTimer* timer; <%cpp> if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); + bool ajaxReq = !async.empty() && (lexical_cast(async) != 0); + tChannelID channelid = tChannelID(); tEventID eventid = tEventID(); @@ -62,7 +65,9 @@ cTimer* timer; timer = 0; if ( !timerid.empty() ) { - timer = timers.GetByTimerId( timerid ); + string tId = SortedTimers::DecodeDomId(timerid); + dsyslog("DEBUG: TIMER: tId = %s", tId.c_str()); + timer = timers.GetByTimerId(tId); if ( timer == 0 ) throw HtmlError( tr("Couldn't find timer. Maybe you mistyped your request?") ); } @@ -134,19 +139,31 @@ cTimer* timer; VDR Live - <$ timer ? tr("Edit timer") : tr("New timer") $> +<%cpp> + if (!ajaxReq) { + <& pageelems.stylesheets &> <& pageelems.ajax_js &> +<%cpp> + } + +<%cpp> + if (!ajaxReq) { + <& pageelems.logo &> <& menu active=("timers") &> +<%cpp> + } +
-
+ - + diff --git a/pages/timers.ecpp b/pages/timers.ecpp index 9af9425..654484f 100644 --- a/pages/timers.ecpp +++ b/pages/timers.ecpp @@ -38,7 +38,9 @@ static const size_t maximumDescriptionLength = 300; timer = 0; if ( !timerid.empty() ) { - timer = timers.GetByTimerId( timerid ); + string tId = SortedTimers::DecodeDomId(timerid); + dsyslog("DEBUG: TIMER: tId = %s", tId.c_str()); + timer = timers.GetByTimerId(tId); if ( timer == 0 ) throw HtmlError( tr("Couldn't find timer. Maybe you mistyped your request?") ); if (action == "delete") { @@ -143,9 +145,9 @@ static const size_t maximumDescriptionLength = 300; % } ><$ timer->File() $> - - - + + + <%cpp> } diff --git a/timers.cpp b/timers.cpp index b5a82ed..4ceb60d 100644 --- a/timers.cpp +++ b/timers.cpp @@ -65,6 +65,24 @@ namespace vdrlive { return 0; } + + string SortedTimers::EncodeDomId(string const& timerid) + { + string tId("timer_"); + tId += vdrlive::EncodeDomId(timerid, ".-:", "pmc"); + return tId; + } + + string SortedTimers::DecodeDomId(string const &timerDomId) + { + string const timerStr("timer_"); + + string tId = timerDomId.substr(timerStr.length()); + + return vdrlive::DecodeDomId(tId, "pmc", ".-:"); + } + + void SortedTimers::ReloadTimers( bool initial ) { dsyslog("live reloading timers"); diff --git a/timers.h b/timers.h index 9bd7e6e..4ad8a7f 100644 --- a/timers.h +++ b/timers.h @@ -16,10 +16,15 @@ namespace vdrlive { friend class TimerManager; public: - std::string GetTimerId( cTimer const& timer ); - cTimer* GetByTimerId( std::string const& timerid ); + static std::string GetTimerId(cTimer const& timer); + cTimer* GetByTimerId(std::string const& timerid); + + // en- or decodes a timer into an id usable for DOM Ids. + static std::string EncodeDomId(std::string const& timerid); + static std::string DecodeDomId(std::string const &timerDomId); + + bool Modified() { return Timers.Modified(m_state); } - bool Modified() { return Timers.Modified( m_state ); } static std::string GetTimerDays(cTimer const& timer); static std::string GetTimerInfo(cTimer const& timer); diff --git a/tools.cpp b/tools.cpp index 5fee00b..8b6006e 100644 --- a/tools.cpp +++ b/tools.cpp @@ -293,5 +293,23 @@ namespace vdrlive { return FormatDateTime(cformat.c_str(), date); } + std::string EncodeDomId(std::string const & toEncode, char const * from, char const * to) + { + std::string encoded = toEncode; + for (; *from && *to; from++, to++) { + replace(encoded.begin(), encoded.end(), *from, *to); + } + return encoded; + } + + std::string DecodeDomId(std::string const & toDecode, char const * from, char const * to) + { + std::string decoded = toDecode; + for (; *from && *to; from++, to++) { + replace(decoded.begin(), decoded.end(), *from, *to); + } + return decoded; + } + } // namespace vdrlive diff --git a/tools.h b/tools.h index 23142da..f4020ac 100644 --- a/tools.h +++ b/tools.h @@ -33,7 +33,6 @@ namespace vdrlive { std::string StringRepeat(int times, const std::string& input); std::string StringWordTruncate(const std::string& input, size_t maxLen, bool& truncated); - inline std::string StringWordTruncate(const std::string& input, size_t maxLen) { bool dummy; return StringWordTruncate(input, maxLen, dummy); } std::string StringEscapeAndBreak( std::string const& input ); @@ -41,13 +40,11 @@ namespace vdrlive { std::string StringFormatBreak(std::string const& input); std::string StringTrim(const std::string& str); - std::string ZeroPad(int number); std::string MD5Hash(std::string const& str); time_t GetTimeT(std::string timestring); - std::string ExpandTimeString(std::string timestring); std::string StringUrlEncode( std::string const& input ); @@ -55,9 +52,11 @@ namespace vdrlive { std::string GetXMLValue( std::string const& xml, std::string const& element ); time_t GetDateFromDatePicker(std::string const& datestring, std::string const& format); - std::string DatePickerToC(time_t date, std::string const& format); + std::string EncodeDomId(std::string const & toEncode, char const * from = ".-:", char const * to = "pmc"); + std::string DecodeDomId(std::string const & toDecode, char const * from = "pmc", char const * to = ".-:"); + struct bad_lexical_cast: std::runtime_error { bad_lexical_cast(): std::runtime_error( "bad lexical cast" ) {} -- cgit v1.2.3
<$ timer ? tr("Edit timer") : tr("New timer") $>
<$ timer ? tr("Edit timer") : tr("New timer") $>
">Flags() & tfActive) ? "active.png" : "inactive.png") $>" alt="" <& tooltip.hint text=(tr("Toggle timer active/inactive")) &>>">" alt="" <& tooltip.hint text=(tr("Edit timer")) &>>">" alt="" <& tooltip.hint text=(tr("Delete timer")) &>>">Flags() & tfActive) ? "active.png" : "inactive.png") $>" alt="" <& tooltip.hint text=(tr("Toggle timer active/inactive")) &>>">" alt="" <& tooltip.hint text=(tr("Edit timer")) &>>">" alt="" <& tooltip.hint text=(tr("Delete timer")) &>>