Skip to content

Commit

Permalink
Merge pull request #111 from fsek/FixPostdescriptionElection
Browse files Browse the repository at this point in the history
Fixing post expand for Election
  • Loading branch information
davidwessman committed Mar 24, 2015
2 parents d97a079 + aeb45cb commit 62cc3b4
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 24 deletions.
6 changes: 2 additions & 4 deletions app/controllers/admin/elections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ def create
@election = Election.new(election_params)
respond_to do |format|
if @election.save
format.html { redirect_to @election, :notice => 'Eventet skapades!' }
format.json { render :json => @election, :status => :created, :location => @election }
format.html { redirect_to [:admin,@election], notice: 'Valet skapades!' }
else
format.html { render :action => "new" }
format.json { render :json => @election.errors, :status => :unprocessable_entity }
format.html { render action: "new" }
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class PostsController < ApplicationController
before_filter :authenticate
before_action :set_council
before_action :set_edit
before_action :set_post, only: [:show, :edit, :update, :destroy, :remove_profile,:add_profile_username]
before_action :set_post, only: [:show, :edit, :update, :destroy, :remove_profile,:add_profile_username, :display]

def remove_profile
@profile = Profile.find_by_id(params[:profile_id])
Expand Down Expand Up @@ -104,6 +104,12 @@ def destroy
end
end

def display
end

def collapse
end

private
def post_params
params.require(:post).permit(:title, :limit,:recLimit,:description,:elected_by,:elected_at,:styrelse,:car_rent,:council_id)
Expand Down
6 changes: 2 additions & 4 deletions app/views/elections/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
<%= render "posttab", grid: @grid_termins %>
<p>Orangefärgade fält innebär att posten sitter i styrelsen.</p>
<%end%>
<div class="panel collapsing" id="views">
<%= render @election.posts %>
</div>
<div class="display-post" id="views"></div>

<p>Ser något konstigt ut eller blir det fel? Hör av dig
till <%= render partial: "contacts/kontakt", locals: {name: 'Spindelmän'} %></p>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/elections/_posttab.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
end
end
g.column name: "Titel",attribute: "title",filter: false do |post|
link_to(post.title,%(##{dom_id(post)}),data: {toggle: "collapse", target: ""})
link_to(post.title,display_post_path(post),remote: true)
end
g.column name: "Rekommenderat antal",attribute: "limit",filter: false do |post|
post.printLimit
Expand All @@ -21,4 +21,4 @@
@election.candidate_count(post)
end
end
end -%>
end -%>
37 changes: 25 additions & 12 deletions app/views/posts/_post.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
<div id="<%=dom_id(post)%>" class="collapsed">
<div id="<%= dom_id(post) %>" class="collapsed">
<div class="funny-boxes funny-boxes-left-orange left-text-align">
<%=link_to("Dölj",%(##{dom_id(post)}),class: "btn btn-u pull-right margin-left-20", data: {toggle: "collapse"})%>
<%= link_to("Dölj", collapse_posts_path, remote: true, class: "btn btn-u pull-right margin-left-20") %>
<% if @election && @election.can_candidate?(post) %>
<%=link_to("Kandidera",new_election_candidate_path(post: post.id.to_s),class: "btn btn-u pull-right margin-left-20")%>
<%=link_to("Nominera",new_election_nominations_path(post: post.id.to_s),class: "btn btn-u pull-right")%>
<%end%>
<h2><%=post.title%></h2>
<%if post.description%><p><%=simple_format(post.description)%></p><%end%>
<%= link_to("Kandidera", new_election_candidate_path(post: post.id.to_s), class: "btn btn-u pull-right margin-left-20") %>
<%= link_to("Nominera", new_election_nominations_path(post: post.id.to_s), class: "btn btn-u pull-right") %>
<% end %>
<h2><%= post.title %></h2>
<% if post.description %><p><%= simple_format(post.description) %></p>
<% end %>
<ul class="list-unstyled">
<%if (post.limit) || (post.styrelse)%><li><i class="fa fa-briefcase"></i><%if post.limit%>Antal: <%=post.printLimit%> <%end%><%if post.styrelse%>, styrelsepost<%end%></li><%end%>
<%if post.council%><li><i class="fa fa-users"></i>Utskott: <%=link_to(post.council.title,post.council)%></li><%end%>
<%if post.elected_by%><li><i class="fa fa-cog"></i>Väljs av: <%=post.elected_by%></li><%end%>
<%if (current_user) && (current_user.moderator?(:poster))%><li><%=link_to("Redigera",edit_council_post_path(post.council,post))%></li> <%end%>
<% if (post.limit) || (post.styrelse) %>
<li><i class="fa fa-briefcase"></i>
<% if post.limit %>Antal: <%= post.printLimit %>
<% end %>
<% if post.styrelse %>, styrelsepost
<% end %></li>
<% end %>
<% if post.council %>
<li><i class="fa fa-users"></i>Utskott: <%= link_to(post.council.title, post.council) %></li>
<% end %>
<% if post.elected_by %>
<li><i class="fa fa-cog"></i>Väljs av: <%= post.elected_by %></li>
<% end %>
<% if (current_user) && (current_user.moderator?(:poster)) %>
<li><%= link_to("Redigera", edit_council_post_path(post.council, post)) %></li>
<% end %>
</ul>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions app/views/posts/collapse.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$('.display-post').hide();
$('.display-post').html("");
7 changes: 7 additions & 0 deletions app/views/posts/display.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if @post.present? %>
$('.display-post').hide();
$('.display-post').html("<%= escape_javascript( render @post)%>").show();
$('html, body').animate({
scrollTop: $('.display-post').offset().top
}, 1000);
<%end%>
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
end
resources :menus, path: :meny, except: :show

resources :posts, path: :poster, only: :index
resources :posts, path: :poster, only: :index do
get :display, on: :member
get :collapse, on: :collection
end

resources :councils, path: :utskott do
resources :posts, path: :poster do
Expand Down

0 comments on commit 62cc3b4

Please sign in to comment.