Permalink
Browse files

this should have edition working

  • Loading branch information...
1 parent e9ca58b commit 4ec8c6429154dc6486ddaf1753155f78e5898237 @thegcat committed Aug 10, 2010
@@ -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
@@ -15,7 +15,9 @@ def index
end
def new
- @doodle = Doodle.new(:project => @project)
+ end
+
+ def edit
end
def show
@@ -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)
@@ -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
@@ -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
@@ -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
@@ -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>
@@ -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 },
@@ -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>
@@ -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">
@@ -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) %>
@@ -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; }
View
@@ -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
View
@@ -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

0 comments on commit 4ec8c64

Please sign in to comment.