Commit fc245282 authored by jplang's avatar jplang

Adds custom fields to documents (#7249).

git-svn-id: https://svn.redmine.org/redmine/trunk@14004 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 84dba027
......@@ -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'
......
......@@ -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',
......
......@@ -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)
......
# 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
......@@ -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' %>
......
......@@ -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>
......
......@@ -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?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment