mirror of
https://github.com/redmine/redmine.git
synced 2025-11-13 00:36:01 +01:00
Adds custom fields to documents (#7249).
git-svn-id: http://svn.redmine.org/redmine/trunk@14004 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -24,6 +24,7 @@ class DocumentsController < ApplicationController
|
|||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
||||||
helper :attachments
|
helper :attachments
|
||||||
|
helper :custom_fields
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
|
@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},
|
:label => :label_project_plural},
|
||||||
{:name => 'VersionCustomField', :partial => 'custom_fields/index',
|
{:name => 'VersionCustomField', :partial => 'custom_fields/index',
|
||||||
:label => :label_version_plural},
|
:label => :label_version_plural},
|
||||||
|
{:name => 'DocumentCustomField', :partial => 'custom_fields/index',
|
||||||
|
:label => :label_document_plural},
|
||||||
{:name => 'UserCustomField', :partial => 'custom_fields/index',
|
{:name => 'UserCustomField', :partial => 'custom_fields/index',
|
||||||
:label => :label_user_plural},
|
:label => :label_user_plural},
|
||||||
{:name => 'GroupCustomField', :partial => 'custom_fields/index',
|
{:name => 'GroupCustomField', :partial => 'custom_fields/index',
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class Document < ActiveRecord::Base
|
|||||||
belongs_to :project
|
belongs_to :project
|
||||||
belongs_to :category, :class_name => "DocumentCategory"
|
belongs_to :category, :class_name => "DocumentCategory"
|
||||||
acts_as_attachable :delete_permission => :delete_documents
|
acts_as_attachable :delete_permission => :delete_documents
|
||||||
|
acts_as_customizable
|
||||||
|
|
||||||
acts_as_searchable :columns => ['title', "#{table_name}.description"],
|
acts_as_searchable :columns => ['title', "#{table_name}.description"],
|
||||||
:preload => :project
|
:preload => :project
|
||||||
@@ -39,7 +40,7 @@ class Document < ActiveRecord::Base
|
|||||||
where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args))
|
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)
|
def visible?(user=User.current)
|
||||||
!user.nil? && user.allowed_to?(:view_documents, project)
|
!user.nil? && user.allowed_to?(:view_documents, project)
|
||||||
|
|||||||
22
app/models/document_custom_field.rb
Normal file
22
app/models/document_custom_field.rb
Normal file
@@ -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
|
||||||
@@ -4,6 +4,10 @@
|
|||||||
<p><%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %></p>
|
<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_field :title, :required => true, :size => 60 %></p>
|
||||||
<p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit' %></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>
|
</div>
|
||||||
|
|
||||||
<%= wikitoolbar_for 'document_description' %>
|
<%= wikitoolbar_for 'document_description' %>
|
||||||
|
|||||||
@@ -11,6 +11,15 @@
|
|||||||
|
|
||||||
<p><em><%=h @document.category.name %><br />
|
<p><em><%=h @document.category.name %><br />
|
||||||
<%= format_date @document.created_on %></em></p>
|
<%= 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">
|
<div class="wiki">
|
||||||
<%= textilizable @document, :description, :attachments => @document.attachments %>
|
<%= textilizable @document, :description, :attachments => @document.attachments %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -592,7 +592,7 @@ module Redmine
|
|||||||
end
|
end
|
||||||
|
|
||||||
class RecordList < List
|
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)
|
def cast_single_value(custom_field, value, customized=nil)
|
||||||
target_class.find_by_id(value.to_i) if value.present?
|
target_class.find_by_id(value.to_i) if value.present?
|
||||||
|
|||||||
Reference in New Issue
Block a user