Просмотр исходного кода

Adds custom fields to documents (#7249).

git-svn-id: http://svn.redmine.org/redmine/trunk@14004 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/3.0.0
Jean-Philippe Lang 9 лет назад
Родитель
Сommit
ae4eb47881

+ 1
- 0
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'

+ 2
- 0
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',

+ 2
- 1
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)

+ 22
- 0
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

+ 4
- 0
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' %>

+ 9
- 0
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>

+ 1
- 1
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?

Загрузка…
Отмена
Сохранить