Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Re-implemented editing functionality to be more fully featured

  • Loading branch information...
commit e981add4a7ca858b115318d0f50091546b860a80 1 parent 14be91d
@dalyons authored
View
5 README.rdoc
@@ -8,8 +8,9 @@ Currently has translations for Russian, Chinese, Spanish, Italian, French, Germa
Please check the issues page(thanks Mischa!) for current known bugs.
== Release 0.0.3.9
-* Merging in of nowhereman's changes
-* Massive refactoring of the todo associations to make them simpler and more generic.
+* Merging in of nowhereman's changes(thanks for all the features!)
+* Re-implementation of todo editing functionality - now you can edit everything, not just text.
+* Massive refactoring of the todo associations to make them simpler and more generic, and to prepare for templates.
* Russian translations added
== Release 0.0.3.8
View
68 app/controllers/todos_controller.rb
@@ -13,7 +13,7 @@ class TodosController < ApplicationController
#end
#before_filter :find_project #, :only => [:index]
- before_filter :find_todo, :only => [:destroy, :show, :toggle_complete, :edit]
+ before_filter :find_todo, :only => [:destroy, :show, :toggle_complete, :edit, :update]
before_filter :authorize
helper :todos
@@ -52,18 +52,15 @@ def show
# raise ex, l(:todo_not_found_error)
#end
- if @todo
- respond_to do |format|
- format.html { render }
- #format.js { render :action => 'show' }
- end
- else
- flash.now[:error] = @todo.errors.collect{|k,m| m}.join
- respond_to do |format|
- format.html { redirect_to :action => 'index' }
- #format.js { render :action => 'edit' }
- end
+ respond_to do |format|
+ format.html { render }
+ format.js {
+ @element_html = render_to_string :partial => 'todos/todo',
+ :locals => {:todo => @todo, :editable => true}
+ render :template => "todos/todo.rjs"
+ }
end
+
end
def new
@@ -129,24 +126,43 @@ def sort
#render :action => "sort.rjs"
end
+ def update
+ if @todo.update_attributes(params[:todo])
+ if request.xhr?
+ show
+ else
+ flash[:notice] = "Todo updated!"
+ redirect_to :action => :index
+ end
+ else
+ render :text => "Error in update"
+ end
+ end
def edit
- if request.post?
- #@todo = Todo.for_project(@project.id).find(params[:id])
- if @todo.update_attributes(:text => params[:text])
- @allowed_to_edit = User.current.allowed_to?(:edit_todos, parent_object)
- respond_to do |format|
- format.html { redirect_to :action => 'index' }
- format.js { render :action => 'update', :controller => :todos }
- end
- else
- flash.now[:error] = @todo.errors.collect{|k,m| m}.join
- respond_to do |format|
- format.html { redirect_to :action => 'index' }
- format.js { render :action => 'edit', :controller => :todos }
- end
+ if request.xhr?
+ respond_to do |format|
+ format.html { render :partial => "todos/inline_edit.html", :locals => {:todo => @todo} }
end
+ else
+ raise "Non-ajax editing not supported..."
end
+
+ #if @todo.update_attributes(:text => params[:text])
+ # @allowed_to_edit = User.current.allowed_to?(:edit_todos, parent_object)
+ # respond_to do |format|
+ # format.html { render :partial => "todos/inline_edit.html", :locals => {:todo => @todo} }
+ #format.js { render :action => 'update', :controller => :todos }
+ #format.js { render :partial => "todos/inline_edit.html", :locals => {:todo => @todo} }
+ # end
+ #else
+ # flash.now[:error] = @todo.errors.collect{|k,m| m}.join
+ # respond_to do |format|
+ #format.html { redirect_to :action => 'index' }
+ # format.js { render :action => 'edit', :controller => :todos }
+ # end
+ #end
+
end
protected
View
33 app/views/todos/_inline_edit.html.erb
@@ -0,0 +1,33 @@
+<% raise unless todo %>
+
+<div>
+ <div class='todos-edit'>
+ <% remote_form_for([todo.todoable,todo], :html => {:class => 'inline'}) do |f| %>
+ <%= f.text_field :text %>
+ Due:
+ <%= f.text_field :due, :size => 8 %>
+ <%= calendar_for :todo_due %>
+ <% if todo.todoable.is_a? Project %>
+ <%= f.select :assigned_to_id, todo.todoable.users.collect{|m| [m.name,m.id]},
+ {:prompt=> l(:todo_new_assign_to_tooltip) },
+ {:title => l(:todo_new_assign_to_tooltip) }
+ %>
+ <%= f.select :issue_id, todo.possible_issues.collect{ |i|
+ subject = i.subject[0..40].scan(/([\x00-\x7f]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3})/on).join
+ ["##{i.id} #{subject}... #{i.tracker.name}" , i.id]
+ },
+ {:prompt=> l(:todo_new_issue_tooltip), :selected => (todo.issue_id)? todo.issue_id.to_i : nil}
+ %>
+ <% end %>
+ <br />
+ <%= f.submit %>
+ <%= link_to_remote("cancel", :url => polymorphic_path([todo.todoable,todo]), :method => :get) %>
+
+
+ <% end %>
+
+
+ </div>
+ <div style='clear:both;' />
+</div>
+
View
5 app/views/todos/_todo.html.erb
@@ -28,6 +28,11 @@
:html => {:class => 'icon-new'},
:update => "todo#{todo.id}-new-box" )
+ %><%= link_to_remote( image_tag('edit.png', :title => 'Edit'),
+ :url => edit_polymorphic_url( [parent_object,todo]), :method => :get,
+ :html => {:class => 'icon-edit'},
+ :update => "todo_#{todo.id}" )
+
%><%= link_to_remote( image_tag('delete.png', :title => l(:todo_delete_tooltip)),
:url => polymorphic_url([ parent_object,todo]), :method => :delete,
:confirm => l(:text_are_you_sure), :html => {:class => 'icon-delete'},
View
12 assets/stylesheets/todos.css
@@ -94,3 +94,15 @@ dt.todo {
background-image:url(../images/todo.png);
}
+.todos-edit {
+ border: 1px solid #e4e4e4;
+ padding: 0.7em;
+ margin:0.4em;
+ background-color:#f6f6f6;
+ float: left;
+}
+.clearer {}
+.todos-edit form { display: inline; }
+
+
+
View
18 config/routes.rb
@@ -1,14 +1,6 @@
#custom routes for this plugin
ActionController::Routing::Routes.draw do |map|
- #map.with_options :controller => 'todos' do |todos_routes|
- #todos_routes.new_issue_todo 'projects/:project_id/issues/:issue_id/todos/:parent_id/new', :action => 'new'
- #todos_routes.new_project_todo 'projects/:project_id/todos/:parent_id/new', :action => 'new'
- #todos_routes.connect 'projects/:project_id/issues/:issue_id/todos/:parent_id/new(.:format)', :action => 'new'
- #todos_routes.connect "projects/:project_id/todos/:action/:id"
- #todos_routes.connect "projects/:project_id/todos/:action/:id.:format"
-
- #end
map.resources :todos, :name_prefix => 'project_', :path_prefix => '/projects/:project_id',
:member => {:toggle_complete => :post }, :collection => {:sort => :post}
@@ -26,4 +18,14 @@
# map.resources :comments, :path_prefix => '/articles/:article_id'
+ #map.with_options :controller => 'todos' do |todos_routes|
+
+ #todos_routes.new_issue_todo 'projects/:project_id/issues/:issue_id/todos/:parent_id/new', :action => 'new'
+ #todos_routes.new_project_todo 'projects/:project_id/todos/:parent_id/new', :action => 'new'
+ #todos_routes.connect 'projects/:project_id/issues/:issue_id/todos/:parent_id/new(.:format)', :action => 'new'
+ #todos_routes.connect "projects/:project_id/todos/:action/:id"
+ #todos_routes.connect "projects/:project_id/todos/:action/:id.:format"
+
+ #end
+
end
View
8 init.rb
@@ -27,7 +27,7 @@
name 'Redmine Todo Lists plugin'
author 'David Lyons'
description 'A plugin to create and manage agile-esque todo lists on a per project basis.'
- version '0.0.3.8'
+ version '0.0.3.9'
settings :default => {
@@ -39,11 +39,11 @@
permission :view_todos, {:todos => [:index, :show] }
permission :edit_todos,
- {:todos => [:create, :destroy, :new, :toggle_complete, :sort, :edit],
- :issues => [:create, :destroy, :new, :toggle_complete, :sort, :edit]}
+ {:todos => [:create, :destroy, :new, :toggle_complete, :sort, :edit, :update],
+ :issues => [:create, :destroy, :new, :toggle_complete, :sort, :edit, :update]}
permission :use_personal_todos,
- {:mytodos => [:index,:destroy, :new, :create, :toggle_complete, :index, :sort, :edit]}
+ {:mytodos => [:index,:destroy, :new, :create, :toggle_complete, :index, :sort, :edit, :update]}
end
Please sign in to comment.
Something went wrong with that request. Please try again.