File: app/controllers/issue_relations_controller.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  class: IssueRelationsController#18
inherits from
  ApplicationController   
has properties
method: index #24
method: show #33
method: create #42
method: destroy #72
method: find_issue #84
method: find_relation #90

Class Hierarchy

Code

   1  # Redmine - project management software
   2  # Copyright (C) 2006-2011  Jean-Philippe Lang
   3  #
   4  # This program is free software; you can redistribute it and/or
   5  # modify it under the terms of the GNU General Public License
   6  # as published by the Free Software Foundation; either version 2
   7  # of the License, or (at your option) any later version.
   8  #
   9  # This program is distributed in the hope that it will be useful,
  10  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  # GNU General Public License for more details.
  13  #
  14  # You should have received a copy of the GNU General Public License
  15  # along with this program; if not, write to the Free Software
  16  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  17 
  18  class IssueRelationsController < ApplicationController
  19    before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create]
  20    before_filter :find_relation, :except => [:index, :create]
  21 
  22    accept_api_auth :index, :show, :create, :destroy
  23 
  24    def index
  25      @relations = @issue.relations
  26 
  27      respond_to do |format|
  28        format.html { render :nothing => true }
  29        format.api
  30      end
  31    end
  32 
  33    def show
  34      raise Unauthorized unless @relation.visible?
  35 
  36      respond_to do |format|
  37        format.html { render :nothing => true }
  38        format.api
  39      end
  40    end
  41 
  42    def create
  43      @relation = IssueRelation.new(params[:relation])
  44      @relation.issue_from = @issue
  45      if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/)
  46        @relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
  47      end
  48      saved = @relation.save
  49 
  50      respond_to do |format|
  51        format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
  52        format.js do
  53          @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
  54          render :update do |page|
  55            page.replace_html "relations", :partial => 'issues/relations'
  56            if @relation.errors.empty?
  57              page << "$('relation_delay').value = ''"
  58              page << "$('relation_issue_to_id').value = ''"
  59            end
  60          end
  61        end
  62        format.api {
  63          if saved
  64            render :action => 'show', :status => :created, :location => relation_url(@relation)
  65          else
  66            render_validation_errors(@relation)
  67          end
  68        }
  69      end
  70    end
  71 
  72    def destroy
  73      raise Unauthorized unless @relation.deletable?
  74      @relation.destroy
  75 
  76      respond_to do |format|
  77        format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to?
  78        format.js   { render(:update) {|page| page.remove "relation-#{@relation.id}"} }
  79        format.api  { head :ok }
  80      end
  81    end
  82 
  83  private
  84    def find_issue
  85      @issue = @object = Issue.find(params[:issue_id])
  86    rescue ActiveRecord::RecordNotFound
  87      render_404
  88    end
  89 
  90    def find_relation
  91      @relation = IssueRelation.find(params[:id])
  92    rescue ActiveRecord::RecordNotFound
  93      render_404
  94    end
  95  end