############################################################################
# Copyright 2009 Benjamin Kellermann #
# #
# This file is part of dudle. #
# #
# Dudle is free software: you can redistribute it and/or modify it under #
# the terms of the GNU Affero General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# Dudle is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public #
# License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with dudle. If not, see . #
############################################################################
require "digest/sha2"
class PollHead
def initialize
@data = {}
end
def col_size
@data.size
end
def get_id(columntitle)
if @data.include?(columntitle)
return Digest::SHA2.hexdigest("#{columntitle}#{@data[columntitle]}" + columntitle)
else
raise("no such column found: #{columntitle}")
end
end
def get_title(columnid)
@data.each_key{|k| return k if get_id(k) == columnid}
raise("no such id found: #{columnid}")
end
def each_columntitle
@data.sort.each{|k,v|
yield(k)
}
end
def each_columnid
@data.sort.each{|k,v|
yield(get_id(k))
}
end
def each_column
@data.sort.each{|k,v|
yield(get_id(k),k)
}
end
# returns internal representation of cgi-string
def cgi_to_id(field)
field
end
# returns true if deletion sucessfull
def delete_column(columnid)
@data.delete(get_title(columnid)) != nil
end
# add new column if columnid = ""
# returns parsed title or false if parsed title == ""
def edit_column(columnid, newtitle, cgi)
delete_column(columnid) if columnid != ""
parsedtitle = newtitle.strip
if parsedtitle != ""
@data[parsedtitle] = CGI.escapeHTML(cgi["columndescription"].strip)
return parsedtitle
else
return false
end
end
def to_html(scols, showeditbuttons = false,activecolumn = nil)
def sortsymb(scols,col)
scols.include?(col) ? SORT : NOSORT
end
ret = "
\n"
ret
end
def edit_column_htmlform(activecolumn, revision)
if activecolumn != ""
title = activecolumn
description = @data[title]
title = CGI.escapeHTML(title)
hiddeninput = ""
end
return <