diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-11-20 17:09:01 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-11-20 17:09:01 +0000 |
commit | 34c73c7573c3459620435e71470794f221a86b7b (patch) | |
tree | 7e635633e2555994fd5d769d3ea179f8ad2fa9d6 /app/controllers/issue_categories_controller.rb | |
parent | 6f4fb8b8920cc8bd414e98671b6025a4378d6c25 (diff) | |
download | redmine-34c73c7573c3459620435e71470794f221a86b7b.tar.gz redmine-34c73c7573c3459620435e71470794f221a86b7b.zip |
REST API for issue categories (#9553).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7882 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/issue_categories_controller.rb')
-rw-r--r-- | app/controllers/issue_categories_controller.rb | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/app/controllers/issue_categories_controller.rb b/app/controllers/issue_categories_controller.rb index b0d11dd8f..c83246f0b 100644 --- a/app/controllers/issue_categories_controller.rb +++ b/app/controllers/issue_categories_controller.rb @@ -18,18 +18,33 @@ class IssueCategoriesController < ApplicationController menu_item :settings model_object IssueCategory - before_filter :find_model_object, :except => [:new, :create] - before_filter :find_project_from_association, :except => [:new, :create] - before_filter :find_project, :only => [:new, :create] + before_filter :find_model_object, :except => [:index, :new, :create] + before_filter :find_project_from_association, :except => [:index, :new, :create] + before_filter :find_project, :only => [:index, :new, :create] before_filter :authorize + accept_api_auth :index, :show, :create, :update, :destroy + + def index + respond_to do |format| + format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project } + format.api { @categories = @project.issue_categories.all } + end + end + + def show + respond_to do |format| + format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project } + format.api + end + end def new - @category = @project.issue_categories.build(params[:category]) + @category = @project.issue_categories.build(params[:issue_category]) end verify :method => :post, :only => :create def create - @category = @project.issue_categories.build(params[:category]) + @category = @project.issue_categories.build(params[:issue_category]) if @category.save respond_to do |format| format.html do @@ -42,6 +57,7 @@ class IssueCategoriesController < ApplicationController 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 + format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) } end else respond_to do |format| @@ -49,6 +65,7 @@ class IssueCategoriesController < ApplicationController format.js do render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) } end + format.api { render_validation_errors(@category) } end end end @@ -58,26 +75,35 @@ class IssueCategoriesController < ApplicationController verify :method => :put, :only => :update def update - if @category.update_attributes(params[:category]) - flash[:notice] = l(:notice_successful_update) - redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project + if @category.update_attributes(params[:issue_category]) + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project + } + format.api { head :ok } + end else - render :action => 'edit' + respond_to do |format| + format.html { render :action => 'edit' } + format.api { render_validation_errors(@category) } + end end end verify :method => :delete, :only => :destroy def destroy @issue_count = @category.issues.size - if @issue_count == 0 - # No issue assigned to this category - @category.destroy - redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' - return - elsif params[:todo] - reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) if params[:todo] == 'reassign' + if @issue_count == 0 || params[:todo] || api_request? + reassign_to = nil + if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?) + reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) + end @category.destroy(reassign_to) - redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' + respond_to do |format| + format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' } + format.api { head :ok } + end return end @categories = @project.issue_categories - [@category] |