Skip to content

Commit

Permalink
this should have edition working
Browse files Browse the repository at this point in the history
  • Loading branch information
thegcat committed Aug 10, 2010
1 parent e9ca58b commit 4ec8c64
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 15 deletions.
25 changes: 19 additions & 6 deletions app/controllers/doodles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class DoodlesController < ApplicationController
unloadable

before_filter :find_project, :except => [:show, :destroy, :update, :lock]
before_filter :find_doodle, :only => [:show, :destroy, :update, :lock]
before_filter :find_project, :except => [:show, :destroy, :update, :lock, :edit, :answer]
before_filter :find_doodle, :only => [:show, :destroy, :update, :lock, :edit, :answer]
before_filter :authorize

verify :method => :post, :only => [:lock], :redirect_to => { :action => :show }
verify :method => :post, :only => [:lock, :answer], :redirect_to => { :action => :show }

helper :watchers
include WatchersHelper
Expand All @@ -15,7 +15,9 @@ def index
end

def new
@doodle = Doodle.new(:project => @project)
end

def edit
end

def show
Expand All @@ -38,7 +40,6 @@ def destroy
end

def create
@doodle = Doodle.new(:project => @project, :author => User.current)
@doodle.attributes = params[:doodle]
if @doodle.save
flash[:notice] = l(:notice_successful_create)
Expand All @@ -49,6 +50,17 @@ def create
end

def update
@doodle.attributes = params[:doodle]
if @doodle.save
flash[:notice] = l(:doodle_update_successful)
redirect_to :action => 'show', :id => @doodle
else
flash[:warning] = l(:doodle_update_unsuccessful)
redirect_to :action => 'edit', :id => @doodle
end
end

def answer
unless @doodle.active?
flash[:error] = l(:doodle_inactive)
redirect_to :action => 'show', :id => @doodle
Expand Down Expand Up @@ -76,7 +88,7 @@ def lock
def preview
if params[:doodle]
@doodle = Doodle.new(params[:doodle]).previewfy
unless @doodle.options.empty?
unless @doodle.options.nil? || @doodle.options.empty?
@winners = []
@responses = [DoodleAnswers.new(:author => User.current, :answers => Array.new(@doodle.options.size, false))]
end
Expand All @@ -88,6 +100,7 @@ def preview

def find_project
@project = Project.find(params[:project_id])
@doodle = Doodle.new(:project => @project, :author => User.current)
end

def find_doodle
Expand Down
2 changes: 2 additions & 0 deletions app/views/doodles/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
<p><%= f.text_field :title, :required => true, :size => 60 %></p>
<p><%= f.text_field :expiry_date, :size => 10 %><%= calendar_for('doodle_expiry_date') %></p>
<p><%= f.text_area :description, :cols => 60, :rows => 3 %>
<% if @doodle.new_record? %>
<div id="options">
<%= render :partial => 'option' %>
</div>
<p><%= link_to_function l(:label_add_options) do |page|
page.insert_html :bottom, :options, :partial => 'option'
end %></p>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/views/doodles/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div id="add-doodle" style="display:none;">
<h2><%= l(:label_doodle_new) %></h2>
<% labelled_tabular_form_for :doodle, @doodle, :url => { :controller => 'doodles', :action => 'create', :project_id => @project }, :html => { :id => 'doodle-form' } do |f| %>
<%= render :partial => 'doodles/form', :locals => { :f => f } %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),
{ :url => { :controller => 'doodles', :action => 'preview', :project_id => @project },
Expand Down
2 changes: 1 addition & 1 deletion app/views/doodles/preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</fieldset>
<% end %>

<% unless @doodle.options.empty? %>
<% unless @doodle.options.nil? || @doodle.options.empty? %>
<fieldset class="preview"><legend><%= l(:label_doodle) %></legend>
<%= render :partial => 'doodle' %>
</fieldset>
Expand Down
30 changes: 26 additions & 4 deletions app/views/doodles/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
<div class="contextual">
<%= watcher_tag(@doodle, User.current) %>
<%= link_to_if_authorized(l(:button_lock), {:action => 'lock', :id => @doodle.id, :locked => 1}, :method => :post, :class => 'icon icon-lock') if !@doodle.locked? %>
<%= link_to_if_authorized(l(:button_unlock), {:action => 'lock', :id => @doodle.id, :locked => 0}, :method => :post, :class => 'icon icon-unlock') if @doodle.locked? %>
<%= link_to_if_authorized(l(:button_lock), {:action => 'lock', :id => @doodle, :locked => 1}, :method => :post, :class => 'icon icon-lock') if !@doodle.locked? %>
<%= link_to_if_authorized(l(:button_unlock), {:action => 'lock', :id => @doodle, :locked => 0}, :method => :post, :class => 'icon icon-unlock') if @doodle.locked? %>
<%= link_to_if_authorized l(:button_edit),
{:action => 'edit', :id => @doodle},
:class => 'icon icon-edit',
:accesskey => accesskey(:edit),
:onclick => 'Element.show("edit-doodle"); return false;' %>
</div>

<h2>Doodle #<%= @doodle.id %></h2>

<div class="issue details">
<% if authorize_for('doodles', 'edit') %>
<div id="edit-doodle" style="display:none;">
<% labelled_tabular_form_for :doodle, @doodle, :url => { :controller => 'doodles', :action => 'update', :id => @doodle}, :html => { :id => 'doodle-form', :method => :put } do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
{ :url => { :controller => 'doodles', :action => 'preview', :project_id => @project },
:method => 'post',
:update => 'preview',
:with => "Form.serialize('doodle-form')"
}, :accesskey => accesskey(:preview) %>
<% end %>
<div id="preview" class="doodle"></div>
</div>
<% end %>


<div class="doodle details">
<%= avatar(@author, :size => "64") %>
<h3><%=h @doodle.title %></h3>
<p class="author">
Expand All @@ -20,7 +42,7 @@
</div>
</div>
<div class="doodle">
<% form_tag({:action => 'update', :id => @doodle}, {:method => :put}) do %>
<% form_tag({:action => 'answer', :id => @doodle}, {:method => :post}) do %>
<%= render :partial => 'doodle' %>
</div>
<%= submit_tag l(:button_save) if @doodle.active? && User.current.allowed_to?(:answer_doodles, @project) %>
Expand Down
12 changes: 12 additions & 0 deletions assets/stylesheets/redmine_doodles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/* Doodle details */

div.doodle.details { background: #ffffdd; padding: 6px; margin: 1em 0px; border: 1px solid #d7d7d7; }
div.doodle.details div.subject div div { padding-left: 16px; }
div.doodle.details div.subject p {margin: 0; margin-bottom: 0.1em; font-size: 90%; color: #999;}
div.doodle.details div.subject>div>p { margin-top: 0.5em; }
div.doodle.details div.subject h3 {margin: 0; margin-bottom: 0.1em;}
div.doodle.details img.gravatar { float: right; margin: 0 0 0 1em; padding: 5px; }
div.doodle.details table img.gravatar { height: 14px; width: 14px; padding: 2px; float: left; margin: 0 0.5em 0 0; }



/* Doodles view: */
table.doodle { border: none; width: auto; }
table.doodle th { white-space: normal; }
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
doodles_routes.connect "projects/:project_id/doodles", :conditions => { :method => :get }, :action => 'index'
doodles_routes.connect "projects/:project_id/doodles", :conditions => { :method => :post }, :action => 'create'
doodles_routes.connect "projects/:project_id/doodles/new", :conditions => { :method => :get }, :action => 'new'
doodles_routes.connect "projects/:project_id/doodles/preview", :conditions => { :method => :post }, :action => 'preview'
doodles_routes.connect "projects/:project_id/doodles/preview", :conditions => { :method => [:post, :put] }, :action => 'preview'
doodles_routes.connect "doodles/:id", :conditions => { :method => :get }, :action => 'show', :id => /\d+/
doodles_routes.connect "doodles/:id", :conditions => { :method => :put }, :action => 'update', :id => /\d+/
doodles_routes.connect "doodles/:id", :conditions => { :method => :delete }, :action => 'destroy', :id => /\d+/
doodles_routes.connect "doodles/:id/edit", :conditions => { :method => :get }, :action => 'edit', :id => /\d+/
doodles_routes.connect "doodles/:id/lock", :conditions => { :method => :post }, :action => 'lock', :id => /\d+/
doodles_routes.connect "doodles/:id/answer", :conditions => { :method => :post }, :action => 'answer', :id => /\d+/
end
end
4 changes: 2 additions & 2 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
version 'trunk'

project_module :doodles do
permission :manage_doodles, {:doodles => [:lock]}, :require => :member
permission :manage_doodles, {:doodles => [:lock, :edit, :update]}, :require => :member
permission :create_doodles, {:doodles => [:new, :create, :preview]}, :require => :member
permission :answer_doodles, {:doodles => [:update]}, :require => :loggedin
permission :answer_doodles, {:doodles => [:answer]}, :require => :loggedin
permission :view_doodles, {:doodles => [:index, :show]}
end

Expand Down

0 comments on commit 4ec8c64

Please sign in to comment.