Added a link to add a new category when creating or editing an issue.

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
This commit is contained in:
Jean-Philippe Lang 2007-08-16 16:45:06 +00:00
parent 1f991c6a79
commit 4cedecad4d
5 changed files with 35 additions and 4 deletions

View File

@ -169,9 +169,19 @@ class ProjectsController < ApplicationController
def add_issue_category
@category = @project.issue_categories.build(params[:category])
if request.post? and @category.save
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
# Add a new version to @project

View 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

View 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">

View File

@ -10,7 +10,11 @@
<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>

View 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(){