summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-02-14 10:44:59 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-02-14 10:44:59 +0000
commitae4eb4788132caf495eb7b180f9104e4aa0ac42a (patch)
tree74a0bd1faedc646b7a17e9ce14ac11f350864b95
parent1c078a7081e83839a7689c9a8c5e4d49b9b75e4c (diff)
downloadredmine-ae4eb4788132caf495eb7b180f9104e4aa0ac42a.tar.gz
redmine-ae4eb4788132caf495eb7b180f9104e4aa0ac42a.zip
Adds custom fields to documents (#7249).
git-svn-id: http://svn.redmine.org/redmine/trunk@14004 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/documents_controller.rb1
-rw-r--r--app/helpers/custom_fields_helper.rb2
-rw-r--r--app/models/document.rb3
-rw-r--r--app/models/document_custom_field.rb22
-rw-r--r--app/views/documents/_form.html.erb4
-rw-r--r--app/views/documents/show.html.erb9
-rw-r--r--lib/redmine/field_format.rb2
7 files changed, 41 insertions, 2 deletions
diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb
index a90da410a..fef3a7d6e 100644
--- a/app/controllers/documents_controller.rb
+++ b/app/controllers/documents_controller.rb
@@ -24,6 +24,7 @@ class DocumentsController < ApplicationController
before_filter :authorize
helper :attachments
+ helper :custom_fields
def index
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb
index c431d9827..e0f3fa7d2 100644
--- a/app/helpers/custom_fields_helper.rb
+++ b/app/helpers/custom_fields_helper.rb
@@ -28,6 +28,8 @@ module CustomFieldsHelper
:label => :label_project_plural},
{:name => 'VersionCustomField', :partial => 'custom_fields/index',
:label => :label_version_plural},
+ {:name => 'DocumentCustomField', :partial => 'custom_fields/index',
+ :label => :label_document_plural},
{:name => 'UserCustomField', :partial => 'custom_fields/index',
:label => :label_user_plural},
{:name => 'GroupCustomField', :partial => 'custom_fields/index',
diff --git a/app/models/document.rb b/app/models/document.rb
index 29f9031fc..d6b96ac98 100644
--- a/app/models/document.rb
+++ b/app/models/document.rb
@@ -20,6 +20,7 @@ class Document < ActiveRecord::Base
belongs_to :project
belongs_to :category, :class_name => "DocumentCategory"
acts_as_attachable :delete_permission => :delete_documents
+ acts_as_customizable
acts_as_searchable :columns => ['title', "#{table_name}.description"],
:preload => :project
@@ -39,7 +40,7 @@ class Document < ActiveRecord::Base
where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args))
}
- safe_attributes 'category_id', 'title', 'description'
+ safe_attributes 'category_id', 'title', 'description', 'custom_fields', 'custom_field_values'
def visible?(user=User.current)
!user.nil? && user.allowed_to?(:view_documents, project)
diff --git a/app/models/document_custom_field.rb b/app/models/document_custom_field.rb
new file mode 100644
index 000000000..3ea9d10b5
--- /dev/null
+++ b/app/models/document_custom_field.rb
@@ -0,0 +1,22 @@
+# Redmine - project management software
+# Copyright (C) 2006-2015 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+class DocumentCustomField < CustomField
+ def type_name
+ :label_document_plural
+ end
+end
diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb
index 53d8fc3bb..bd3b7cd9f 100644
--- a/app/views/documents/_form.html.erb
+++ b/app/views/documents/_form.html.erb
@@ -4,6 +4,10 @@
<p><%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %></p>
<p><%= f.text_field :title, :required => true, :size => 60 %></p>
<p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
+
+<% @document.custom_field_values.each do |value| %>
+ <p><%= custom_field_tag_with_label :document, value %></p>
+<% end %>
</div>
<%= wikitoolbar_for 'document_description' %>
diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb
index a8aea63da..8b1f0067b 100644
--- a/app/views/documents/show.html.erb
+++ b/app/views/documents/show.html.erb
@@ -11,6 +11,15 @@
<p><em><%=h @document.category.name %><br />
<%= format_date @document.created_on %></em></p>
+
+<% if @document.custom_field_values.any? %>
+<ul>
+ <% render_custom_field_values(@document) do |custom_field, formatted| %>
+ <li><span class="label"><%= custom_field.name %>:</span> <%= formatted %></li>
+ <% end %>
+</ul>
+<% end %>
+
<div class="wiki">
<%= textilizable @document, :description, :attachments => @document.attachments %>
</div>
diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb
index 68e59ffa5..8cb3bc45d 100644
--- a/lib/redmine/field_format.rb
+++ b/lib/redmine/field_format.rb
@@ -592,7 +592,7 @@ module Redmine
end
class RecordList < List
- self.customized_class_names = %w(Issue TimeEntry Version Project)
+ self.customized_class_names = %w(Issue TimeEntry Version Document Project)
def cast_single_value(custom_field, value, customized=nil)
target_class.find_by_id(value.to_i) if value.present?