simplify grid construction

move the html generation into a helper
pull/6827/head
Florian Kraft 10 years ago
parent 78edeaec37
commit 8f86411148
  1. 23
      app/helpers/my_projects_overviews_helper.rb
  2. 51
      app/views/my_projects_overviews/page_layout.html.erb

@ -1,7 +1,7 @@
#-- copyright
# OpenProject My Project Page Plugin
#
# Copyright (C) 2011-2014 the OpenProject Foundation (OPF)
# Copyright (C) 2011-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
@ -23,10 +23,10 @@ module MyProjectsOverviewsHelper
TOP = %w(top)
MIDDLE = %w(left right)
BOTTOM = %w(hidden)
HIDDEN = %w(hidden)
def field_list
TOP + MIDDLE + BOTTOM
TOP + MIDDLE + HIDDEN
end
def visible_fields
@ -41,6 +41,18 @@ module MyProjectsOverviewsHelper
raise NoMethodError
end
def grid_field(name)
content_tag :div, id: "list-#{name}", class: %w(block-receiver) + [name] do
ActiveSupport::SafeBuffer.new(blocks[name].map do |block|
if block_available? block
render partial: 'block', locals: { block_name: block }
elsif block.respond_to? :to_ary
render partial: 'block_textilizable', locals: { block_name: block }
end
end.join)
end
end
def sortable_box(field)
sortable_element "list-#{field}",
tag: 'div',
@ -51,4 +63,9 @@ module MyProjectsOverviewsHelper
constraint: false,
url: { action: 'order_blocks', group: field }
end
def block_available?(block)
controller.class.available_blocks.keys.include? block
end
end

@ -108,71 +108,42 @@ function addBlock() {
//]]>
</script>
<% content_for :action_menu_specific do %>
<% content_for :toolbar do %>
<li>
<%= form_tag({:action => "add_block"}, :id => "block-form") do %>
<%= select_tag 'block',
<%= styled_form_tag({:action => "add_block"}, :id => "block-form") do %>
<%= styled_select_tag 'block',
("<option>--#{t(:button_add)}--</option>" + options_for_select(block_options)).html_safe,
:id => "block-select",
:onChange => "addBlock();",
class: 'form--select -small'
class: 'form--select'
%>
<% end %>
</li>
<li><%= link_to l(:button_back), {:action => 'index'}, :class => 'icon icon-cancel' %></li>
<li><%= link_to l(:button_back), {:action => 'index'}, :class => 'button' %></li>
<% end %>
<h2><%=l(:label_overview)%></h2>
<%= render :partial => 'layouts/action_menu_specific' %>
<%= render :partial => 'layouts/toolbar' %>
<h4><%=l(:label_visible_elements) %></h4>
<div id="visible-grid">
<div class="grid-block">
<% top_fields.each do |f| %>
<div id="list-<%= f %>" class="grid-content block-receiver">
<% blocks[f].each do |b| %>
<% if MyProjectsOverviewsController.available_blocks.keys.include? b %>
<%= render(:partial => 'block', :locals => { :block_name => b }) %>
<% elsif b.respond_to? :to_ary %>
<%= render(:partial => 'block_textilizable',
:locals => {:block_name => b.first,
:block_title => b[1],
:textile => b.last}) %>
<% end %>
<% end %>
</div>
<%= grid_field f %>
<% end %>
</div>
<div class="grid-block">
<% middle_fields.each do |f| %>
<div id="list-<%= f %>" class="block-receiver <%= f %>">
<% blocks[f].each do |b| %>
<% if MyProjectsOverviewsController.available_blocks.keys.include? b %>
<%= render(:partial => 'block', :locals => { :block_name => b }) %>
<% elsif b.respond_to? :to_ary %>
<%= render(:partial => 'block_textilizable',
:locals => {:block_name => b.first,
:block_title => b[1],
:textile => b.last}) %>
<% end %>
<% end %>
</div>
<%= grid_field f %>
<% end %>
</div>
</div>
<h4><%=l(:label_hidden_elements) %></h4>
<div id="list-hidden" class="block-receiver">
<% blocks['hidden'].each do |b| %>
<% if MyProjectsOverviewsController.available_blocks.keys.include? b %>
<%= render(:partial => 'block', :locals => {:block_name => b}) %>
<% elsif b.respond_to? :to_ary %>
<%= render(:partial => 'block_textilizable',
:locals => {:block_name => b.first,
:block_title => b[1],
:textile => b.last}) %>
<% end %>
<div id="list-hidden">
<% hidden_fields.each do |f| %>
<%= grid_field f %>
<% end %>
</div>

Loading…
Cancel
Save