############################################################################ # Copyright 2009-2019 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 # returns a sorted array of all columns # column should be the internal representation # column.to_s should deliver humanreadable form def columns @data.keys.sort end # column is in human readable form # returns true if deletion successful 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["columndescription"].strip return parsedtitle else return false end end def to_html(scols, showeditbuttons = false,activecolumn = nil) def sortsymb(scols,col) return < #{scols.include?(col) ? SORT : NOSORT} SORTSYMBOL 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 editstr = _("Edit option") deletestr = _("Delete option") ret += < 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 columntitlestr = _("Option") descriptionstr = _("Description (optional)") addeditstr = _("Add/Edit option") previewstr = _("Preview") hint = _("Enter all the options (columns) which you want the participants of the poll to choose among. For each option you give here, the participants will choose a vote.") ret = <
#{hint}
#{hiddeninput}
END if col_size > 0 ret += <#{previewstr} #{to_html([],true,activecolumn)}
END end ret end end