diff options
-rw-r--r-- | poll.rb | 7 | ||||
-rw-r--r-- | pollhead.rb | 17 | ||||
-rw-r--r-- | timepollhead.rb | 13 |
3 files changed, 25 insertions, 12 deletions
@@ -62,9 +62,10 @@ class Poll def to_html(edituser = "", showparticipation = true) ret = "<table border='1' summary='Main Poll table'>\n" - - ret += @head.to_html - sort_data($cgi.include?("sort") ? $cgi.params["sort"] : ["timestamp"]).each{|participant,poll| + + sortcolumns = $cgi.include?("sort") ? $cgi.params["sort"] : ["timestamp"] + ret += @head.to_html(sortcolumns) + sort_data(sortcolumns).each{|participant,poll| if edituser == participant ret += participate_to_html(edituser) else diff --git a/pollhead.rb b/pollhead.rb index a4a6b8a..87d2cb3 100644 --- a/pollhead.rb +++ b/pollhead.rb @@ -78,12 +78,19 @@ class PollHead end end - def to_html(showeditbuttons = false,activecolumn = nil) - ret = "<tr><th><a href='?sort=name'>Name #{NOSORT}</a></th>\n" + def to_html(scols, showeditbuttons = false,activecolumn = nil) + def sortsymb(scols,col) + scols.include?(col) ? SORT : NOSORT + end + ret = "<tr>" + ret += "<th><a href='?sort=name'>Name #{sortsymb(scols,"name")}</a></th>\n" unless showeditbuttons @data.each{|columntitle,columndescription| ret += "<th" ret += " id='active' " if activecolumn == columntitle - ret += "><a title=\"#{columndescription}\" href=\"?sort=#{CGI.escapeHTML(CGI.escape(columntitle))}\">#{CGI.escapeHTML(columntitle)} #{NOSORT}</a>" + ret += ">" + ret += "<a title=\"#{columndescription}\" href=\"?sort=#{CGI.escapeHTML(CGI.escape(columntitle))}\">" unless showeditbuttons + ret += "#{CGI.escapeHTML(columntitle)}" + ret += " #{sortsymb(scols,columntitle)}</a>" unless showeditbuttons if showeditbuttons ret += <<EDITDELETE <div> @@ -100,7 +107,7 @@ EDITDELETE end ret += "</th>" } - ret += "<th><a href='.'>Last Edit #{NOSORT}</a></th>\n" + ret += "<th><a href='?'>Last Edit #{sortsymb(scols,"timestamp")}</a></th>\n" unless showeditbuttons ret += "</tr>\n" ret end @@ -126,7 +133,7 @@ EDITDELETE </form> <fieldset><legend>Preview</legend> <table summary='Preview poll head'> -#{to_html(true,activecolumn)} +#{to_html([],true,activecolumn)} </table> </fieldset> END diff --git a/timepollhead.rb b/timepollhead.rb index 4b4d619..4521f26 100644 --- a/timepollhead.rb +++ b/timepollhead.rb @@ -172,7 +172,7 @@ class TimePollHead } ret.sort end - def to_html(config = false,activecolumn = nil) + def to_html(scols,config = false,activecolumn = nil) ret = "<tr><td></td>" head_count("%Y-%m",false).each{|title,count| year, month = title.split("-").collect{|e| e.to_i} @@ -183,11 +183,16 @@ class TimePollHead head_count("%Y-%m-%d",false).each{|title,count| ret += "<th colspan='#{count}'>#{Date.parse(title).strftime("%a, %d")}</th>\n" } - ret += "</tr><tr><th><a href='?sort=name'>Name #{NOSORT}</a></th>" + + def sortsymb(scols,col) + scols.include?(col) ? SORT : NOSORT + end + + ret += "</tr><tr><th><a href='?sort=name'>Name #{sortsymb(scols,"name")}</a></th>" @data.sort.each{|date| - ret += "<th><a title='#{date}' href='?sort=#{CGI.escape(date.to_s + " ")}'>#{date.time_to_s} #{NOSORT}</a></th>\n" + ret += "<th><a title='#{date}' href='?sort=#{CGI.escape(date.to_s + " ")}'>#{date.time_to_s} #{sortsymb(scols,date.to_s + " ")}</a></th>\n" } - ret += "<th><a href='.'>Last Edit #{NOSORT}</a></th>\n</tr>\n" + ret += "<th><a href='?'>Last Edit #{sortsymb(scols,"timestamp")}</a></th>\n</tr>\n" ret end |