OSDN Git Service

Added a link to add a new category when creating or editing an issue.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 16 Aug 2007 16:45:06 +0000 (16:45 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 16 Aug 2007 16:45:06 +0000 (16:45 +0000)
The user is prompted for the category name. The new category is created and the drop-down list updated using an ajax call.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@648 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/projects_controller.rb
app/helpers/application_helper.rb
app/views/issues/edit.rhtml
app/views/projects/add_issue.rhtml
public/javascripts/application.js

index 582ff33..920dbd5 100644 (file)
@@ -169,8 +169,18 @@ class ProjectsController < ApplicationController
   def add_issue_category
     @category = @project.issue_categories.build(params[:category])
     if request.post? and @category.save
-      flash[:notice] = l(:notice_successful_create)
-      redirect_to :action => 'settings', :tab => 'categories', :id => @project
+         respond_to do |format|
+        format.html do
+          flash[:notice] = l(:notice_successful_create)
+          redirect_to :action => 'settings', :tab => 'categories', :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_category_id",
+            content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
+          }
+        end
+      end
     end
   end
        
index 1563106..0719044 100644 (file)
@@ -77,6 +77,11 @@ module ApplicationHelper
         }))
   end
   
+  def prompt_to_remote(name, text, param, url, html_options = {})
+    html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
+    link_to name, {}, html_options
+  end
+  
   def format_date(date)
     return nil unless date
     @date_format_setting ||= Setting.date_format.to_i
index 05017ac..18d6e01 100644 (file)
@@ -8,7 +8,11 @@
 <p><label><%=l(:field_status)%></label> <%= @issue.status.name %></p>
 <p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), :required => true %></p>
 <p><%= f.select :assigned_to_id, (@issue.project.members.collect {|m| [m.name, m.user_id]}), :include_blank => true %></p>
-<p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %></p>
+<p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %>
+<%= prompt_to_remote(l(:label_issue_category_new),
+                     l(:label_issue_category_new), 'category[name]', 
+                     {:controller => 'projects', :action => 'add_issue_category', :id => @project},
+                     :class => 'small') if authorize_for('projects', 'add_issue_category') %></p>
 </div>
 
 <div class="splitcontentright">
index b250232..d35f7f4 100644 (file)
 <p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p>
 <p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), :required => true %></p>
 <p><%= f.select :assigned_to_id, (@issue.project.members.collect {|m| [m.name, m.user_id]}), :include_blank => true %></p>
-<p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %></p>
+<p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %>
+<%= prompt_to_remote(l(:label_issue_category_new),
+                     l(:label_issue_category_new), 'category[name]', 
+                     {:controller => 'projects', :action => 'add_issue_category', :id => @project},
+                     :class => 'small') if authorize_for('projects', 'add_issue_category') %></p>
 </div>
 <div class="splitcontentright">
 <p><%= f.text_field :start_date, :size => 10 %><%= calendar_for('issue_start_date') %></p>
index 7ca0cc4..6a30e42 100644 (file)
@@ -41,6 +41,14 @@ function setPredecessorFieldsVisibility() {
     }
 }
 
+function promptToRemote(text, param, url) {
+    value = prompt(text + ':');
+    if (value) {
+        new Ajax.Request(url + '?' + param + '=' + value, {asynchronous:true, evalScripts:true});
+        return false;
+    }
+}
+
 /* shows and hides ajax indicator */
 Ajax.Responders.register({
     onCreate: function(){