diff --git a/app/controllers/issue_categories_controller.rb b/app/controllers/issue_categories_controller.rb index ecb4bc906..e314856e1 100644 --- a/app/controllers/issue_categories_controller.rb +++ b/app/controllers/issue_categories_controller.rb @@ -44,13 +44,7 @@ class IssueCategoriesController < ApplicationController respond_to do |format| format.html - format.js do - render :update do |page| - page.replace_html 'ajax-modal', :partial => 'issue_categories/new_modal' - page << "showModal('ajax-modal', '600px');" - page << "Form.Element.focus('issue_category_name');" - end - end + format.js end end @@ -63,25 +57,13 @@ class IssueCategoriesController < ApplicationController flash[:notice] = l(:notice_successful_create) redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project end - format.js do - render(:update) {|page| - page << 'hideModal();' - # IE doesn't support the replace_html rjs method for select box options - page.replace "issue_category_id", - content_tag('select', content_tag('option') + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]') - } - end + format.js format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) } end else respond_to do |format| format.html { render :action => 'new'} - format.js do - render :update do |page| - page.replace_html 'ajax-modal', :partial => 'issue_categories/new_modal' - page << "Form.Element.focus('version_name');" - end - end + format.js { render :action => 'new'} format.api { render_validation_errors(@category) } end end diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index dcee97c85..8b9c0acd3 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -78,13 +78,7 @@ class VersionsController < ApplicationController respond_to do |format| format.html - format.js do - render :update do |page| - page.replace_html 'ajax-modal', :partial => 'versions/new_modal' - page << "showModal('ajax-modal', '600px');" - page << "Form.Element.focus('version_name');" - end - end + format.js end end @@ -103,14 +97,7 @@ class VersionsController < ApplicationController flash[:notice] = l(:notice_successful_create) redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project end - format.js do - render(:update) {|page| - page << 'hideModal();' - # IE doesn't support the replace_html rjs method for select box options - page.replace "issue_fixed_version_id", - content_tag('select', content_tag('option') + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]') - } - end + format.js format.api do render :action => 'show', :status => :created, :location => version_url(@version) end @@ -118,12 +105,7 @@ class VersionsController < ApplicationController else respond_to do |format| format.html { render :action => 'new' } - format.js do - render :update do |page| - page.replace_html 'ajax-modal', :partial => 'versions/new_modal' - page << "Form.Element.focus('version_name');" - end - end + format.js { render :action => 'new' } format.api { render_validation_errors(@version) } end end diff --git a/app/views/issue_categories/create.js.erb b/app/views/issue_categories/create.js.erb new file mode 100644 index 000000000..b9cc577aa --- /dev/null +++ b/app/views/issue_categories/create.js.erb @@ -0,0 +1,3 @@ +hideModal(); +<% select = content_tag('select', content_tag('option') + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]') %> +Element.replace('issue_category_id', '<%= escape_javascript(select) %>'); diff --git a/app/views/issue_categories/new.js.erb b/app/views/issue_categories/new.js.erb new file mode 100644 index 000000000..2a28e3863 --- /dev/null +++ b/app/views/issue_categories/new.js.erb @@ -0,0 +1,3 @@ +Element.update('ajax-modal', '<%= escape_javascript(render :partial => 'issue_categories/new_modal') %>'); +showModal('ajax-modal', '600px'); +Form.Element.focus('issue_category_name'); diff --git a/app/views/versions/create.js.erb b/app/views/versions/create.js.erb new file mode 100644 index 000000000..01720bf90 --- /dev/null +++ b/app/views/versions/create.js.erb @@ -0,0 +1,3 @@ +hideModal(); +<% select = content_tag('select', content_tag('option') + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]') %> +Element.replace('issue_fixed_version_id', '<%= escape_javascript(select) %>'); diff --git a/app/views/versions/new.js.erb b/app/views/versions/new.js.erb new file mode 100644 index 000000000..cce80e029 --- /dev/null +++ b/app/views/versions/new.js.erb @@ -0,0 +1,3 @@ +Element.update('ajax-modal', '<%= escape_javascript(render :partial => 'versions/new_modal') %>'); +showModal('ajax-modal', '600px'); +Form.Element.focus('version_name'); diff --git a/test/functional/issue_categories_controller_test.rb b/test/functional/issue_categories_controller_test.rb index 5c9e6c9dc..8364e11f1 100644 --- a/test/functional/issue_categories_controller_test.rb +++ b/test/functional/issue_categories_controller_test.rb @@ -40,6 +40,15 @@ class IssueCategoriesControllerTest < ActionController::TestCase assert_select 'input[name=?]', 'issue_category[name]' end + def test_new_from_issue_form + @request.session[:user_id] = 2 # manager + xhr :get, :new, :project_id => '1' + + assert_response :success + assert_template 'new' + assert_equal 'text/javascript', response.content_type + end + def test_create @request.session[:user_id] = 2 # manager assert_difference 'IssueCategory.count' do @@ -67,9 +76,8 @@ class IssueCategoriesControllerTest < ActionController::TestCase assert_equal 'New category', category.name assert_response :success - assert_select_rjs :replace, 'issue_category_id' do - assert_select "option[value=#{category.id}][selected=selected]" - end + assert_template 'create' + assert_equal 'text/javascript', response.content_type end def test_create_from_issue_form_with_failure @@ -79,9 +87,8 @@ class IssueCategoriesControllerTest < ActionController::TestCase end assert_response :success - assert_select_rjs :replace_html, "ajax-modal" do - assert_select "div#errorExplanation" - end + assert_template 'new' + assert_equal 'text/javascript', response.content_type end def test_edit diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb index 0aa490a66..66e4864c1 100644 --- a/test/functional/versions_controller_test.rb +++ b/test/functional/versions_controller_test.rb @@ -100,10 +100,8 @@ class VersionsControllerTest < ActionController::TestCase @request.session[:user_id] = 2 xhr :get, :new, :project_id => '1' assert_response :success - assert_select_rjs :replace_html, "ajax-modal" do - assert_select "form[action=/projects/ecookbook/versions]" - assert_select "input#version_name" - end + assert_template 'new' + assert_equal 'text/javascript', response.content_type end def test_create @@ -127,9 +125,8 @@ class VersionsControllerTest < ActionController::TestCase assert_equal 1, version.project_id assert_response :success - assert_select_rjs :replace, 'issue_fixed_version_id' do - assert_select "option[value=#{version.id}][selected=selected]" - end + assert_template 'create' + assert_equal 'text/javascript', response.content_type end def test_create_from_issue_form_with_failure @@ -138,9 +135,8 @@ class VersionsControllerTest < ActionController::TestCase xhr :post, :create, :project_id => '1', :version => {:name => ''} end assert_response :success - assert_select_rjs :replace_html, "ajax-modal" do - assert_select "div#errorExplanation" - end + assert_template 'new' + assert_equal 'text/javascript', response.content_type end def test_get_edit