From fb39d841a720d74b6fd4d5e82d80e5426d6770c2 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Sun, 24 Oct 2010 22:31:57 +0200 Subject: [PATCH] migrate editing a context and refactor project with it --- app/controllers/contexts_controller.rb | 16 +++++--- app/controllers/projects_controller.rb | 3 ++ app/helpers/application_helper.rb | 6 +++ app/views/contexts/_context_form.rhtml | 20 +++++++--- app/views/contexts/_context_listing.rhtml | 22 ++++++----- app/views/contexts/edit.js.erb | 21 ++++++++++ app/views/contexts/edit.js.rjs | 4 -- app/views/contexts/update.js.erb | 47 +++++++++++++++++++++++ app/views/contexts/update.js.rjs | 9 ----- app/views/projects/_project_form.rhtml | 2 +- app/views/projects/edit.js.erb | 22 ++++++++--- app/views/projects/update.js.erb | 6 +-- public/javascripts/application.js | 28 +++++++++++++- 13 files changed, 163 insertions(+), 43 deletions(-) create mode 100644 app/views/contexts/edit.js.erb delete mode 100644 app/views/contexts/edit.js.rjs create mode 100644 app/views/contexts/update.js.erb delete mode 100644 app/views/contexts/update.js.rjs diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index 63985245..025d7493 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -91,13 +91,18 @@ class ContextsController < ApplicationController @original_context_hidden = @context.hidden? @context.attributes = params["context"] - if @context.save + @saved = @context.save + + if @saved if boolean_param('wants_render') - @context_state_changed = (@original_context_hidden != @context.hidden?) - @new_state = (@context.hidden? ? "hidden" : "active") if @context_state_changed + @state_changed = (@original_context_hidden != @context.hidden?) + @new_state = (@context.hidden? ? "hidden" : "active") if @state_changed respond_to do |format| format.js end + + # TODO is this param ever used? is this dead code? + elsif boolean_param('update_context_name') @contexts = current_user.projects render :template => 'contexts/update_context_name.js.rjs' @@ -106,8 +111,9 @@ class ContextsController < ApplicationController render :text => success_text || 'Success' end else - notify :warning, "Couldn't update new context" - render :text => "" + respond_to do |format| + format.js + end end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 338935b5..d1a8c9e2 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -134,6 +134,9 @@ class ProjectsController < ApplicationController init_data_for_sidebar render :template => 'projects/update.js.erb' return + + # TODO: are these params ever set? or is this dead code? + elsif boolean_param('update_status') render :template => 'projects/update_status.js.rjs' return diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 95b5e468..46377fa1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -116,6 +116,12 @@ module ApplicationHelper url_for({:controller => 'projects', :action => 'edit', :id => project.id}), {:id => "link_edit_#{dom_id(project)}", :class => "project_edit_settings"}) end + + def link_to_edit_context (context, descriptor = sanitize(context.name)) + link_to(descriptor, + url_for({:controller => 'contexts', :action => 'edit', :id => context.id}), + {:id => "link_edit_#{dom_id(context)}", :class => "context_edit_settings"}) + end def link_to_delete_project(project, descriptor = sanitize(project.name)) link_to( diff --git a/app/views/contexts/_context_form.rhtml b/app/views/contexts/_context_form.rhtml index e22414f4..952e8a44 100644 --- a/app/views/contexts/_context_form.rhtml +++ b/app/views/contexts/_context_form.rhtml @@ -1,14 +1,22 @@ <% context = context_form - @context = context-%> -<% form_remote_tag(:url => context_path(context), :html => {:id => dom_id(context, 'edit_form'), :class => "inline-form "+dom_id(context, 'edit_form')+"-edit-context-form edit-context-form", :method => :put}) do -%> - <%= error_messages_for 'context' %> +@context = context +-%> + +<% form_for(context, :html => { + :id => dom_id(context, 'edit_form'), + :class => "inline-form edit-project-form", + :method => :put }) do + -%> + +
<%= error_messages_for("project") %>
+
<%= text_field('context', 'name', :class => 'context-name') %>
- + <%= check_box('context', 'hide', :class => 'context-hide') %> - +
@@ -24,5 +32,5 @@


- <% end %> +<% end %> diff --git a/app/views/contexts/_context_listing.rhtml b/app/views/contexts/_context_listing.rhtml index 79036bcd..cde76c9a 100644 --- a/app/views/contexts/_context_listing.rhtml +++ b/app/views/contexts/_context_listing.rhtml @@ -21,16 +21,20 @@ suppress_edit_button ||= false <% end %> <%= link_to_delete_context(context, image_tag( "blank.png", :title => t('contexts.delete_context'), :class=>"delete_item")) %> + <%= suppress_edit_button ? "" : link_to_edit_context(context, image_tag( "blank.png", :title => t('contexts.edit_context'), :class=>"edit_item")) %> + + <% # = # link_to_remote( + #image_tag( "blank.png", :title => "Delete context", :class=>"delete_item"), + #:url => {:controller => 'contexts', :action => 'destroy', :id => context.id}, + #:method => 'delete', + #:with => "'_source_view=#{@source_view}'", + #:before => "$('#{dom_id(context)}').block({message:null});", + #:complete => "$('#{dom_id(context)}').unblock();", + #:confirm => "Are you sure that you want to delete the context '#{context.name}'? Be aware that this will also delete all (repeating) actions in this context!", + #:html => { :id => dom_id(context, 'delete') } + #) + %> - <%= link_to_remote( - image_tag( "blank.png", :title => t('contexts.edit_context'), :class=>"edit_item"), - :url => {:controller => 'contexts', :action => 'edit', :id => context.id}, - :method => 'get', - :with => "'_source_view=#{@source_view}'", - :before => "$('#{dom_id(context)}').block({message:null});", - :complete => "$('#{dom_id(context)}').unblock();", - :html => {:id => "edit_context_#{context.id}_link"} - ) %>