############################################################################ # 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 . # ############################################################################ class PollHead def initialize @data = {} end def col_size @data.size end # iterates over each column # column should be the internal representation # column.to_s should deliver humanreadable form def each_column @data.sort.each{|k,v| yield(k) } end # column is in human readable form # returns true if deletion sucessfull def delete_column(column) @data.delete(column) != nil end # add new column if columnid = "" # returns parsed title or false if parsed title == "" def edit_column(column, newtitle, cgi) delete_column(column) if column != "" 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 = "" ret += "Name #{sortsymb(scols,"name")}\n" unless showeditbuttons @data.sort.each{|columntitle,columndescription| ret += "" unless showeditbuttons ret += "#{CGI.escapeHTML(columntitle)}" ret += " #{sortsymb(scols,columntitle)}" unless showeditbuttons if showeditbuttons ret += < #{EDIT} | #{DELETE} EDITDELETE end ret += "" } ret += "Last Edit #{sortsymb(scols,"timestamp")}\n" unless showeditbuttons ret += "\n" ret end def edit_column_htmlform(activecolumn, revision) if activecolumn != "" title = activecolumn description = @data[title] title = CGI.escapeHTML(title) hiddeninput = "" end return <
#{hiddeninput}

Preview

#{to_html([],true,activecolumn)}
END end end