#encoding: utf-8 #-- copyright # OpenProject is a project management system. # # Copyright (C) 2012-2013 the OpenProject Team # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License version 3. # # See doc/COPYRIGHT.rdoc for more details. #++ module TimelinesHelper unloadable def icon_for_color(color, options = {}) return unless color options = options.merge(:class => "timelines-phase " + options[:class].to_s, :style => "background-color: #{color.hexcode};" + options[:style].to_s) content_tag(:span, " ", options) end def icon_for_planning_element_type(type) return unless type if type.is_milestone? css_class = 'timelines-milestone' else css_class = 'timelines-phase' end if type.color.present? color = type.color.hexcode else color = "#CCC" end content_tag(:span, " ", :class => css_class, :style => "background-color: #{color}") end def parent_id_select_tag(form, planning_element) available_parents = planning_element.project.timelines_planning_elements.without_deleted.find(:all, :order => "COALESCE(parent_id, id), parent_id") available_parents -= [planning_element] available_options = available_parents.map do |pe| texts = (pe.ancestors.reverse << pe).map { |a| "*#{a.id} #{a.name}" } [texts.join(right_pointing_arrow), pe.id] end available_options.unshift(['','']) form.select :parent_id, available_options end def right_pointing_arrow " ▸ " end def format_date(date, options = nil) text = super(date) if options.present? content_tag(:span, text, options) else text end end def options_for_colors(colored_thing) s = content_tag(:option, '') colored_thing.available_colors.each do |c| options = {} options[:value] = c.id options[:selected] = 'selected' if c.id == colored_thing.color_id options[:style] = "background-color: #{c.hexcode}; color: #{c.text_hexcode}" s << content_tag(:option, h(c.name), options) end s end def options_for_project_types Timelines::ProjectType.all.map { |t| [t.name, t.id] } end def options_for_responsible(project) project.users.map { |u| [u.name, u.id] } end def visible_parent_project(project) parent = project.parent while parent.present? && !parent.timelines_visible? parent = parent.parent end parent end def timelines_header_tags %Q{ }.html_safe end def none_option result = [[l('timelines.filter.none'), -1]] end def filter_select_i18n_array_with_index_and_none(array, i18n_prefix) result = self.none_option index = -1 result += array.map do |t| index += 1 [l(i18n_prefix + t), index] end end def filter_select_with_none(collection, text, value) result = self.none_option result += filter_select(collection, text, value) end def filter_select(collection, text, value) collection.map do |t| [t.send(text), t.send(value)] end end def resolve_with_none_option(const, collection) collection end def internationalized_columns_select(collection) collection.map do |t| [l("timelines.filter.column." + t), t] end end end