Mercurial > hg > soundsoftware-site
comparison app/controllers/.svn/text-base/versions_controller.rb.svn-base @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | cca12e1c1fd4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 # redMine - project management software | |
2 # Copyright (C) 2006 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 VersionsController < ApplicationController | |
19 menu_item :roadmap | |
20 model_object Version | |
21 before_filter :find_model_object, :except => [:new, :close_completed] | |
22 before_filter :find_project_from_association, :except => [:new, :close_completed] | |
23 before_filter :find_project, :only => [:new, :close_completed] | |
24 before_filter :authorize | |
25 | |
26 helper :custom_fields | |
27 helper :projects | |
28 | |
29 def show | |
30 end | |
31 | |
32 def new | |
33 @version = @project.versions.build | |
34 if params[:version] | |
35 attributes = params[:version].dup | |
36 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing']) | |
37 @version.attributes = attributes | |
38 end | |
39 if request.post? | |
40 if @version.save | |
41 respond_to do |format| | |
42 format.html do | |
43 flash[:notice] = l(:notice_successful_create) | |
44 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
45 end | |
46 format.js do | |
47 # IE doesn't support the replace_html rjs method for select box options | |
48 render(:update) {|page| page.replace "issue_fixed_version_id", | |
49 content_tag('select', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]') | |
50 } | |
51 end | |
52 end | |
53 else | |
54 respond_to do |format| | |
55 format.html | |
56 format.js do | |
57 render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) } | |
58 end | |
59 end | |
60 end | |
61 end | |
62 end | |
63 | |
64 def edit | |
65 if request.post? && params[:version] | |
66 attributes = params[:version].dup | |
67 attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) | |
68 if @version.update_attributes(attributes) | |
69 flash[:notice] = l(:notice_successful_update) | |
70 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
71 end | |
72 end | |
73 end | |
74 | |
75 def close_completed | |
76 if request.post? | |
77 @project.close_completed_versions | |
78 end | |
79 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
80 end | |
81 | |
82 def destroy | |
83 if @version.fixed_issues.empty? | |
84 @version.destroy | |
85 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
86 else | |
87 flash[:error] = l(:notice_unable_delete_version) | |
88 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
89 end | |
90 end | |
91 | |
92 def status_by | |
93 respond_to do |format| | |
94 format.html { render :action => 'show' } | |
95 format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} } | |
96 end | |
97 end | |
98 | |
99 private | |
100 def find_project | |
101 @project = Project.find(params[:project_id]) | |
102 rescue ActiveRecord::RecordNotFound | |
103 render_404 | |
104 end | |
105 end |