aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-10-07 13:20:11 +0200
committerBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-10-07 13:20:11 +0200
commit85f02b2ebb0e6aa6f3ecea043e8bca84bbad1490 (patch)
tree17591eb1fb852e5fb928d2778fd0439bdcbc9706
parentf16a7d352e52e78abca952142dacb93a58540301 (diff)
new feature: one can change a column name in one step
-rwxr-xr-xconfig_poll.rb15
-rw-r--r--datepoll.rb35
-rwxr-xr-xparticipate.rb4
-rw-r--r--poll.rb85
-rw-r--r--print.css2
-rw-r--r--timepoll.rb46
6 files changed, 105 insertions, 82 deletions
diff --git a/config_poll.rb b/config_poll.rb
index c88b0e9..201893b 100755
--- a/config_poll.rb
+++ b/config_poll.rb
@@ -58,7 +58,7 @@ else
}
table.invite_delete($cgi["invite_delete"]) if $cgi.include?("invite_delete") and $cgi["invite_delete"] != ""
- table.add_remove_column($cgi["add_remove_column"],$cgi["columndescription"]) if $cgi.include?("add_remove_column")
+ table.edit_column($cgi["edit_column"],$cgi["columndescription"],$cgi["editcolumn"]) if $cgi.include?("edit_column")
table.toggle_hidden if $cgi.include?("toggle_hidden")
def writehtaccess(acusers)
@@ -132,9 +132,10 @@ $htmlout += <<HTMLHEAD
</div>
HTMLHEAD
+activecolumn = $cgi.include?("edit_column") ? $cgi["edit_column"] : $cgi["editcolumn"]
$htmlout += <<TABLE
<h1>#{table.name}</h1>
-#{table.to_html(config = true)}
+#{table.to_html(config = true,activecolumn = activecolumn)}
TABLE
$htmlout += <<INVITEDELETE
@@ -152,13 +153,11 @@ $htmlout += <<INVITEDELETE
INVITEDELETE
# ADD/REMOVE COLUMN
-$htmlout +=<<ADD_REMOVE
-<div id='add_remove_column'>
-<fieldset><legend>add/remove column</legend>
-#{table.add_remove_column_htmlform}
-</fieldset>
+$htmlout +=<<ADD_EDIT
+<div id='edit_column'>
+#{table.edit_column_htmlform(activecolumn)}
</div>
-ADD_REMOVE
+ADD_EDIT
$htmlout +=<<ACL
<div id='access_control'>
diff --git a/datepoll.rb b/datepoll.rb
index 1060886..e323c30 100644
--- a/datepoll.rb
+++ b/datepoll.rb
@@ -14,7 +14,7 @@ class DatePoll < Poll
}
super datefields
end
- def head_to_html(config = false)
+ def head_to_html(config = false, activecolumn = nil)
ret = "<tr><td></td>\n"
monthhead = Hash.new(0)
@head.sort.each{|curdate,curdescription|
@@ -28,15 +28,15 @@ class DatePoll < Poll
@head.sort.each{|curdate,curdescription|
ret += "<th><a href='?sort=#{curdate.to_s}'>#{Date::ABBR_DAYNAMES[curdate.wday]}, #{curdate.day}</a></th>\n"
}
- ret += "<th><a href='.'>Last Edit</a></th>\n"
- ret += "</tr>\n"
- ret
+ ret += "<th><a href='.'>Last Edit</a></th>\n</tr>\n"
+ ret
end
- def add_remove_column_htmlform
+
+ def edit_column_htmlform(activecolumn)
if $cgi.include?("add_remove_column_month")
- begin
+ if $cgi.params["add_remove_column_month"].size == 1
startdate = Date.parse("#{$cgi["add_remove_column_month"]}-1")
- rescue ArgumentError
+ else
olddate = $cgi.params["add_remove_column_month"][1]
case $cgi["add_remove_column_month"]
when CGI.unescapeHTML(YEARBACK)
@@ -56,6 +56,7 @@ class DatePoll < Poll
startdate = Date.parse("#{Date.today.year}-#{Date.today.month}-1")
end
ret = <<END
+<fieldset><legend>add/remove column</legend>
<form method='post' action=''>
<div>
<table><tr>
@@ -82,7 +83,7 @@ END
klasse = "notchoosen"
klasse = "disabled" if d < Date.today
klasse = "choosen" if @head.include?(d)
- ret += "<td class='calendarday'><input class='#{klasse}' type='submit' name='add_remove_column' value='#{d.day}' /></td>\n"
+ ret += "<td class='calendarday'><input class='#{klasse}' type='submit' name='edit_column' value='#{d.day}' /></td>\n"
ret += "</tr><tr>\n" if d.wday == 0
d = d.next
end
@@ -91,16 +92,22 @@ END
<input type='hidden' name='add_remove_column_month' value='#{startdate.strftime("%Y-%m")}' />
</div>
</form>
+</fieldset>
END
ret
end
- def add_remove_column name,description
- begin
- parsed_name = Date.parse("#{$cgi["add_remove_column_month"]}-#{name}")
- rescue ArgumentError
- return false
+ def parsecolumntitle(title)
+ Date.parse("#{$cgi["add_remove_column_month"]}-#{title}")
+ end
+ def edit_column(newtitle, description, oldtitle = nil)
+ parsed_date = parsecolumntitle(newtitle)
+ if @head.include?(parsed_date)
+ delete_column(newtitle)
+ else
+ @head[parsed_date] = ""
+ store "Column #{parsed_date} added"
end
- add_remove_parsed_column(parsed_name,CGI.escapeHTML(description))
+ true
end
end
diff --git a/participate.rb b/participate.rb
index 2c52b6a..7d6039b 100755
--- a/participate.rb
+++ b/participate.rb
@@ -33,9 +33,7 @@ load "charset.rb"
load "config.rb"
Dir.chdir(olddir)
-if $cgi.include?("edituser")
- $edituser = $cgi["edituser"]
-end
+$edituser = $cgi["edituser"] if $cgi.include?("edituser")
if $cgi.include?("revision")
REVISION=$cgi["revision"].to_i
diff --git a/poll.rb b/poll.rb
index 7774afc..f02835a 100644
--- a/poll.rb
+++ b/poll.rb
@@ -35,23 +35,23 @@ class Poll
@data.sort{|x,y| x[1].compare_by_values(y[1],fields) }
end
end
- def head_to_html(config = false)
+ def head_to_html(config = false,activecolumn = nil)
ret = "<tr><th><a href='?sort=name'>Name</a></th>\n"
@head.sort.each{|columntitle,columndescription|
ret += "<th"
- ret += " id='active' " if $cgi["editcolumn"] == columntitle
+ ret += " id='active' " if activecolumn == columntitle
ret += "><a title=\"#{columndescription}\" href=\"?sort=#{CGI.escapeHTML(CGI.escape(columntitle))}\">#{CGI.escapeHTML(columntitle)}</a>"
- ret += "<br/>\n<small><a href=\"?editcolumn=#{CGI.escapeHTML(CGI.escape(columntitle))}#add_remove_column\">#{EDIT}</a></small>" if config
+ ret += "<br/>\n<small><a href=\"?editcolumn=#{CGI.escapeHTML(CGI.escape(columntitle))}#edit_column\">#{EDIT}</a></small>" if config
ret += "</th>"
}
ret += "<th><a href='.'>Last Edit</a></th>\n"
ret += "</tr>\n"
ret
end
- def to_html(config = false)
+ def to_html(config = false,activecolumn = nil)
ret = "<table border='1'>\n"
- ret += head_to_html(config)
+ ret += head_to_html(config, activecolumn)
sort_data($cgi.include?("sort") ? $cgi.params["sort"] : ["timestamp"]).each{|participant,poll|
ret += "<tr class='participantrow'>\n"
ret += "<td class='name' #{$edituser == participant ? "id='active'":""}>"
@@ -227,27 +227,6 @@ ADDCOMMENT
ret += " <a href='.' >last</a>" if defined?(REVISION)
ret
end
- def add_remove_column_htmlform
- if $cgi.include?("editcolumn")
- title = $cgi["editcolumn"]
- description = @head[title]
- title = CGI.escapeHTML(title)
- else
- title = CGI.escapeHTML($cgi["add_remove_column"])
- description = CGI.escapeHTML($cgi["columndescription"])
- end
- return <<END
-<form method='post' action=''>
- <div>
- <label for='columntitle'>Columntitle: </label>
- <input id='columntitle' size='16' type='text' value="#{title}" name='add_remove_column' />
- <label for='columndescription'>Description: </label>
- <input id='columndescription' size='30' type='text' value="#{description}" name='columndescription' />
- <input type='submit' value='add/remove column' />
- </div>
-</form>
-END
- end
def add_participant(name, agreed)
name.strip!
if name == ""
@@ -281,6 +260,10 @@ END
end
VCS.commit(CGI.escapeHTML(comment))
end
+
+ ###############################
+ # comment related functions
+ ###############################
def add_comment name, comment
@comment << [Time.now, CGI.escapeHTML(name.strip), CGI.escapeHTML(comment.strip).gsub("\r\n","<br />")]
store "Comment added by #{name}"
@@ -288,20 +271,52 @@ END
def delete_comment index
store "Comment from #{@comment.delete_at(index)[1]} deleted"
end
- def add_remove_column name, description
- add_remove_parsed_column name.strip, CGI.escapeHTML(description.strip)
+
+ ###############################
+ # column related functions
+ ###############################
+ def parsecolumntitle title
+ title.strip
end
- def add_remove_parsed_column columntitle, description
- if @head.include?(columntitle)
- @head.delete(columntitle)
- action = "deleted"
+ def delete_column title
+ parsedtitle = parsecolumntitle(title)
+ if @head.include?(parsedtitle)
+ @head.delete(parsedtitle)
+ store "Column #{parsedtitle} deleted"
+ return true
else
- @head[columntitle] = description
- action = "added"
+ return false
end
- store "Column #{columntitle} #{action}"
+ end
+ def edit_column(newtitle, description, oldtitle = nil)
+ @head.delete(oldtitle) if oldtitle
+ parsedtitle = parsecolumntitle(newtitle)
+
+ @head[parsedtitle] = CGI.escapeHTML(description.strip)
+ store "Column #{parsedtitle} edited"
true
end
+ def edit_column_htmlform(activecolumn)
+ if activecolumn
+ title = activecolumn
+ description = @head[title]
+ title = CGI.escapeHTML(title)
+ end
+ return <<END
+<fieldset><legend>add/edit column</legend>
+<form method='post' action='?'>
+ <div>
+ <label for='columntitle'>Columntitle: </label>
+ <input id='columntitle' size='16' type='text' value="#{title}" name='edit_column' />
+ <label for='columndescription'>Description: </label>
+ <input id='columndescription' size='30' type='text' value="#{description}" name='columndescription' />
+ <input type='hidden' name='editcolumn' value="#{title}" />
+ <input type='submit' value='add/edit column' />
+ </div>
+</form>
+</fieldset>
+END
+ end
def toggle_hidden
@hidden = !@hidden
diff --git a/print.css b/print.css
index c9e09c4..07c6052 100644
--- a/print.css
+++ b/print.css
@@ -42,7 +42,7 @@ td {
td.sum, td.date, td.name, td.checkboxes {
background-color:Silver;
}
-div#add_comment,div#add_remove_column, div#invite_delete, div#history, div#backlink, input.delete_comment_button, tr#add_participant, div#configlink{
+div#add_comment,div#edit_column, div#invite_delete, div#history, div#backlink, input.delete_comment_button, tr#add_participant, div#configlink{
visibility: collapse;
}
th {
diff --git a/timepoll.rb b/timepoll.rb
index 4068156..fc69097 100644
--- a/timepoll.rb
+++ b/timepoll.rb
@@ -28,7 +28,7 @@ class TimePoll < Poll
ret.sort
end
- def head_to_html(config = false)
+ def head_to_html(config = false, activecolumn = nil)
ret = "<tr><td></td>"
head_count("%Y-%m","-%d %H:%M%Z").each{|title,count|
year, month = title.split("-").collect{|e| e.to_i}
@@ -42,17 +42,17 @@ class TimePoll < Poll
@head.keys.sort.each{|curdate|
ret += "<th><a title='#{curdate}' href='?sort=#{CGI.escapeHTML(CGI.escape(curdate.to_s))}'>#{curdate.strftime("%H:%M")}</a></th>\n"
}
- ret += "<th><a href='.'>Last Edit</a></th></tr>\n"
+ ret += "<th><a href='.'>Last Edit</a></th>\n</tr>\n"
ret
end
- def add_remove_column_htmlform
+ def edit_column_htmlform(activecolumn)
if $cgi.include?("add_remove_column_month")
if $cgi.params["add_remove_column_month"].size == 1
startdate = Date.parse("#{$cgi["add_remove_column_month"]}-1")
else
olddate = $cgi.params["add_remove_column_month"][1]
- case $cgi.params["add_remove_column_month"][0]
+ case $cgi["add_remove_column_month"]
when CGI.unescapeHTML(YEARBACK)
startdate = Date.parse("#{olddate}-1")-365
when CGI.unescapeHTML(MONTHBACK)
@@ -70,6 +70,7 @@ class TimePoll < Poll
startdate = Date.parse("#{Date.today.year}-#{Date.today.month}-1")
end
ret = <<END
+<fieldset><legend>add/remove column</legend>
<form method='post' action=''>
<div style="float: left; margin-right: 20px">
<table><tr>
@@ -96,7 +97,7 @@ END
klasse = "notchoosen"
klasse = "disabled" if d < Date.today
klasse = "choosen" if @head.keys.collect{|t|t.strftime("%Y-%m-%d")}.include?(d.strftime("%Y-%m-%d"))
- ret += "<td class='calendarday'><input class='#{klasse}' type='submit' name='add_remove_column' value='#{d.day}' /></td>\n"
+ ret += "<td class='calendarday'><input class='#{klasse}' type='submit' name='edit_column' value='#{d.day}' /></td>\n"
ret += "</tr><tr>\n" if d.wday == 0
d = d.next
end
@@ -141,7 +142,7 @@ END
<form method='post' action="config.cgi">
<div>
<!--Timestamp: #{timestamp} -->
- <input title='#{timestamp}' class='#{klasse}' type='submit' name='add_remove_column' value='#{time}' />
+ <input title='#{timestamp}' class='#{klasse}' type='submit' name='edit_column' value='#{time}' />
<input type='hidden' name='add_remove_column_day' value='#{timestamp.day}' />
<input type='hidden' name='add_remove_column_month' value='#{timestamp.strftime("%Y-%m")}' />
</div>
@@ -160,8 +161,8 @@ END
<div>
<input type='hidden' name='add_remove_column_day' value='#{d.day}' />
<input type='hidden' name='add_remove_column_month' value='#{d.strftime("%Y-%m")}' />
- <input name='add_remove_column' type="text" maxlength="7" style="width: 5ex" /><br />
- <input name="add_remove_column" type="submit" value="Add" style="width: 100%" />
+ <input name='edit_column' type="text" maxlength="7" style="width: 7ex" /><br />
+ <input type="submit" value="Add" style="width: 100%" />
</div>
</form>
</td>
@@ -172,25 +173,28 @@ END
</tr>
</table>
</div>
+</fieldset>
END
ret
end
- def add_remove_column col,description
+ def parsecolumntitle(title)
if $cgi.include?("add_remove_column_day")
- begin
- parsed_date = YAML::load(Time.parse("#{$cgi["add_remove_column_month"]}-#{$cgi["add_remove_column_day"]} #{col}").to_yaml)
- rescue ArgumentError
- return false
- end
+ parsed_date = YAML::load(Time.parse("#{$cgi["add_remove_column_month"]}-#{$cgi["add_remove_column_day"]} #{title}").to_yaml)
else
- begin
- earlytime = @head.keys.collect{|t|t.strftime("%H:%M")}.sort[0]
- parsed_date = YAML::load(Time.parse("#{$cgi["add_remove_column_month"]}-#{col} #{earlytime}").to_yaml)
- rescue ArgumentError
- return false
- end
+ earlytime = @head.keys.collect{|t|t.strftime("%H:%M")}.sort[0]
+ parsed_date = YAML::load(Time.parse("#{$cgi["add_remove_column_month"]}-#{title} #{earlytime}").to_yaml)
+ end
+ parsed_date
+ end
+ def edit_column(newtitle, description, oldtitle = nil)
+ parsed_date = parsecolumntitle(newtitle)
+ if @head.include?(parsed_date)
+ delete_column(newtitle)
+ else
+ @head[parsed_date] = ""
+ store "Column #{parsed_date} added"
end
- add_remove_parsed_column(parsed_date,CGI.escapeHTML(description))
+ true
end
end