]> source.dussan.org Git - redmine.git/commitdiff
Displays the full form when creating a version from the issue form so that required...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 11 Feb 2012 13:05:41 +0000 (13:05 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 11 Feb 2012 13:05:41 +0000 (13:05 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8845 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/versions_controller.rb
app/views/issues/_attributes.html.erb
app/views/versions/_new_modal.html.erb [new file with mode: 0644]
public/javascripts/application.js
test/functional/versions_controller_test.rb

index 54cd9d7c2c16190fadd4d8ccbf783d984c231f0e..f04388c78da3682ef327a3c46dd73409a84cc4dd 100644 (file)
@@ -75,6 +75,17 @@ class VersionsController < ApplicationController
 
   def new
     @version = @project.versions.build(params[:version])
+
+    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
+    end
   end
 
   def create
@@ -93,9 +104,11 @@ class VersionsController < ApplicationController
             redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
           end
           format.js do
-            # IE doesn't support the replace_html rjs method for select box options
-            render(:update) {|page| page.replace "issue_fixed_version_id",
-              content_tag('select', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
+            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', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
             }
           end
           format.api do
@@ -106,7 +119,10 @@ class VersionsController < ApplicationController
         respond_to do |format|
           format.html { render :action => 'new' }
           format.js do
-            render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
+            render :update do |page|
+              page.replace_html 'ajax-modal', :partial => 'versions/new_modal'
+              page << "Form.Element.focus('version_name');"
+            end
           end
           format.api  { render_validation_errors(@version) }
         end
index fed949e24086bad849355440e0c1ff2f03f609bc..90d47a20c8d932441cd1ef182b4cbf91ec4346b4 100644 (file)
 
 <% if @issue.safe_attribute?('fixed_version_id') && @issue.assignable_versions.any? %>
 <p><%= f.select :fixed_version_id, version_options_for_select(@issue.assignable_versions, @issue.fixed_version), :include_blank => true %>
-<%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'),
-                     l(:label_version_new),
-                     'version[name]',
-                     {:controller => 'versions', :action => 'create', :project_id => @issue.project},
-                     :title => l(:label_version_new),
-                     :tabindex => 200) if User.current.allowed_to?(:manage_versions, @issue.project) %>
+<%= link_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'),
+                   {:url => new_project_version_path(@issue.project), :method => 'get'},
+                   :title => l(:label_version_new),
+                   :tabindex => 200) if User.current.allowed_to?(:manage_versions, @issue.project) %>
 </p>
 <% end %>
 </div>
diff --git a/app/views/versions/_new_modal.html.erb b/app/views/versions/_new_modal.html.erb
new file mode 100644 (file)
index 0000000..8b58883
--- /dev/null
@@ -0,0 +1,9 @@
+<h3 class="title"><%=l(:label_version_new)%></h3>
+
+<% labelled_remote_form_for @version, :url => project_versions_path(@project) do |f| %>
+<%= render :partial => 'versions/form', :locals => { :f => f } %>
+  <p class="buttons">
+    <%= submit_tag l(:button_create), :name => nil %>
+    <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
+  </p>
+<% end %>
index f0b493c3964519f86ae771310d66fb5f0db59652..2c4910c441e32e8021da81d94156721241ba1f3e 100644 (file)
@@ -321,7 +321,12 @@ function showModal(id, width) {
 }
 
 function hideModal(el) {
-  var modal = Element.up(el, 'div.modal');
+  var modal;
+       if (el) {
+               modal = Element.up(el, 'div.modal');
+       } else {
+               modal = $('ajax-modal');
+       }
   if (modal) {
     modal.hide();
   }
index 9ba301bc585f35f34e36a5aef6cb114aea556917..fe5d3f895062d8bd5795075b82dfd94065aa6765 100644 (file)
@@ -96,6 +96,16 @@ class VersionsControllerTest < ActionController::TestCase
     assert_template 'new'
   end
 
+  def test_new_from_issue_form
+    @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
+  end
+
   def test_create
     @request.session[:user_id] = 2 # manager
     assert_difference 'Version.count' do
@@ -108,15 +118,29 @@ class VersionsControllerTest < ActionController::TestCase
   end
 
   def test_create_from_issue_form
-    @request.session[:user_id] = 2 # manager
+    @request.session[:user_id] = 2
     assert_difference 'Version.count' do
       xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
     end
-    assert_response :success
-    assert_select_rjs :replace, 'issue_fixed_version_id'
     version = Version.find_by_name('test_add_version_from_issue_form')
     assert_not_nil version
     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
+  end
+
+  def test_create_from_issue_form_with_failure
+    @request.session[:user_id] = 2
+    assert_no_difference 'Version.count' do
+      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
   end
 
   def test_get_edit