Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

2.2 KB
Raw Blame
<%= form_tag update_design_colors_path, method: :post, class: "form", data: { turbo: false } do %>
  <section class="form--section">
    <fieldset class="form--fieldset">
      <legend class="form--fieldset-legend"><%= I18n.t(:label_interface_colors) %></legend>
      <p> <%= t("label_interface_colors_description") %> </p>
      <% DesignColor.setables.each do |design_color| %>
        <div class="form--field -required">
          <label class="form--label"><%= I18n.t("admin.custom_styles.colors.#{design_color.variable}") %>:</label>
          <span class="form--field-container">
            <div class="form--field-affix">
              <%= icon_for_color(
                    Color.new(
                      hexcode: design_color.hexcode
                    ),
                    data: { target: "#design_colors_" + design_color.variable }
                  ) %>
            </div>
            <span class="form--text-field-container">
              <%= styled_text_field_tag "design_colors[]" + design_color.variable,
                                        design_color.hexcode,
                                        class: "design-color--variable-input",
                                        data: { "variable-name": design_color.variable } %>
            </span>
          </span>
          <div class="form--field-instructions">
            <% instruction_key = "admin.custom_styles.instructions.#{design_color.variable}" %>
            <% if I18n.exists?(instruction_key, :en) %>
              <%= I18n.t(instruction_key) %>
            <% end %>
          </div>
        </div>
      <% end %>
      <button type="submit" class="button -hide-when-collapsed" data-test-selector="interface-colors-button"><%= I18n.t(:button_save) %></button>
    </fieldset>
  </section>
  <%# Fill in the computed css variables in the inputs as their defaults %>
  <%= nonced_javascript_tag do %>
    var computedStyle = getComputedStyle(document.documentElement);

    document
        .querySelectorAll('.design-color--variable-input')
        .forEach(function(el) {
            if (!el.value || el.value === '') {
                el.placeholder = computedStyle.getPropertyValue('--' + el.dataset.variableName).trim();
            }
        });
  <% end %>
<% end %>