summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2010-12-03 16:15:16 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2010-12-03 16:15:16 +0000
commit9284a32c9ac7b932feb72cf0d2d5fb1626ec7862 (patch)
treefff2301ee930a2324256ec1d3558b00a3c0ecf15 /app
parentf6c633212a4ee6a1d598b4c4c5c0027cfeb9d010 (diff)
downloadredmine-9284a32c9ac7b932feb72cf0d2d5fb1626ec7862.tar.gz
redmine-9284a32c9ac7b932feb72cf0d2d5fb1626ec7862.zip
Moves project attributes default assignments from ProjectsController#new to the model (#6064).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4460 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects_controller.rb7
-rw-r--r--app/models/project.rb25
-rw-r--r--app/views/projects/new.html.erb2
3 files changed, 27 insertions, 7 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index d94dec1c6..8ec947258 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -68,11 +68,6 @@ class ProjectsController < ApplicationController
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
@trackers = Tracker.all
@project = Project.new(params[:project])
-
- @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
- @project.trackers = Tracker.all
- @project.is_public = Setting.default_projects_public?
- @project.enabled_module_names = Setting.default_projects_modules
end
def create
@@ -80,7 +75,7 @@ class ProjectsController < ApplicationController
@trackers = Tracker.all
@project = Project.new(params[:project])
- @project.enabled_module_names = params[:enabled_modules]
+ @project.enabled_module_names = params[:enabled_modules] if params[:enabled_modules]
if validate_parent_id && @project.save
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
# Add current user as a project member if he is not admin
diff --git a/app/models/project.rb b/app/models/project.rb
index 6eb41cc84..d68958e27 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -84,6 +84,24 @@ class Project < ActiveRecord::Base
named_scope :all_public, { :conditions => { :is_public => true } }
named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } }
+ def initialize(attributes = nil)
+ super
+
+ initialized = (attributes || {}).stringify_keys
+ if !initialized.key?('identifier') && Setting.sequential_project_identifiers?
+ self.identifier = Project.next_identifier
+ end
+ if !initialized.key?('is_public')
+ self.is_public = Setting.default_projects_public?
+ end
+ if !initialized.key?('enabled_module_names')
+ self.enabled_module_names = Setting.default_projects_modules
+ end
+ if !initialized.key?('trackers') && !initialized.key?('tracker_ids')
+ self.trackers = Tracker.all
+ end
+ end
+
def identifier=(identifier)
super unless identifier_frozen?
end
@@ -492,7 +510,7 @@ class Project < ActiveRecord::Base
def enabled_module_names=(module_names)
if module_names && module_names.is_a?(Array)
- module_names = module_names.collect(&:to_s)
+ module_names = module_names.collect(&:to_s).reject(&:blank?)
# remove disabled modules
enabled_modules.each {|mod| mod.destroy unless module_names.include?(mod.name)}
# add new modules
@@ -501,6 +519,11 @@ class Project < ActiveRecord::Base
enabled_modules.clear
end
end
+
+ # Returns an array of the enabled modules names
+ def enabled_module_names
+ enabled_modules.collect(&:name)
+ end
# Returns an array of projects that are in this project's hierarchy
#
diff --git a/app/views/projects/new.html.erb b/app/views/projects/new.html.erb
index c8a9c7600..aad9c2c29 100644
--- a/app/views/projects/new.html.erb
+++ b/app/views/projects/new.html.erb
@@ -10,6 +10,8 @@
<%= l_or_humanize(m, :prefix => "project_module_") %>
</label>
<% end %>
+<%= hidden_field_tag 'enabled_modules[]', '' %>
+
</fieldset>
<%= submit_tag l(:button_save) %>