##// END OF EJS Templates
Adds custom fields to documents (#7249)....
Jean-Philippe Lang -
r13622:ae4eb4788132
parent child
Show More
@@ -0,0 +1,22
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 class DocumentCustomField < CustomField
19 def type_name
20 :label_document_plural
21 end
22 end
@@ -24,6 +24,7 class DocumentsController < ApplicationController
24 before_filter :authorize
24 before_filter :authorize
25
25
26 helper :attachments
26 helper :attachments
27 helper :custom_fields
27
28
28 def index
29 def index
29 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
30 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
@@ -28,6 +28,8 module CustomFieldsHelper
28 :label => :label_project_plural},
28 :label => :label_project_plural},
29 {:name => 'VersionCustomField', :partial => 'custom_fields/index',
29 {:name => 'VersionCustomField', :partial => 'custom_fields/index',
30 :label => :label_version_plural},
30 :label => :label_version_plural},
31 {:name => 'DocumentCustomField', :partial => 'custom_fields/index',
32 :label => :label_document_plural},
31 {:name => 'UserCustomField', :partial => 'custom_fields/index',
33 {:name => 'UserCustomField', :partial => 'custom_fields/index',
32 :label => :label_user_plural},
34 :label => :label_user_plural},
33 {:name => 'GroupCustomField', :partial => 'custom_fields/index',
35 {:name => 'GroupCustomField', :partial => 'custom_fields/index',
@@ -20,6 +20,7 class Document < ActiveRecord::Base
20 belongs_to :project
20 belongs_to :project
21 belongs_to :category, :class_name => "DocumentCategory"
21 belongs_to :category, :class_name => "DocumentCategory"
22 acts_as_attachable :delete_permission => :delete_documents
22 acts_as_attachable :delete_permission => :delete_documents
23 acts_as_customizable
23
24
24 acts_as_searchable :columns => ['title', "#{table_name}.description"],
25 acts_as_searchable :columns => ['title', "#{table_name}.description"],
25 :preload => :project
26 :preload => :project
@@ -39,7 +40,7 class Document < ActiveRecord::Base
39 where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args))
40 where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args))
40 }
41 }
41
42
42 safe_attributes 'category_id', 'title', 'description'
43 safe_attributes 'category_id', 'title', 'description', 'custom_fields', 'custom_field_values'
43
44
44 def visible?(user=User.current)
45 def visible?(user=User.current)
45 !user.nil? && user.allowed_to?(:view_documents, project)
46 !user.nil? && user.allowed_to?(:view_documents, project)
@@ -4,6 +4,10
4 <p><%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %></p>
4 <p><%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %></p>
5 <p><%= f.text_field :title, :required => true, :size => 60 %></p>
5 <p><%= f.text_field :title, :required => true, :size => 60 %></p>
6 <p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
6 <p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
7
8 <% @document.custom_field_values.each do |value| %>
9 <p><%= custom_field_tag_with_label :document, value %></p>
10 <% end %>
7 </div>
11 </div>
8
12
9 <%= wikitoolbar_for 'document_description' %>
13 <%= wikitoolbar_for 'document_description' %>
@@ -11,6 +11,15
11
11
12 <p><em><%=h @document.category.name %><br />
12 <p><em><%=h @document.category.name %><br />
13 <%= format_date @document.created_on %></em></p>
13 <%= format_date @document.created_on %></em></p>
14
15 <% if @document.custom_field_values.any? %>
16 <ul>
17 <% render_custom_field_values(@document) do |custom_field, formatted| %>
18 <li><span class="label"><%= custom_field.name %>:</span> <%= formatted %></li>
19 <% end %>
20 </ul>
21 <% end %>
22
14 <div class="wiki">
23 <div class="wiki">
15 <%= textilizable @document, :description, :attachments => @document.attachments %>
24 <%= textilizable @document, :description, :attachments => @document.attachments %>
16 </div>
25 </div>
@@ -592,7 +592,7 module Redmine
592 end
592 end
593
593
594 class RecordList < List
594 class RecordList < List
595 self.customized_class_names = %w(Issue TimeEntry Version Project)
595 self.customized_class_names = %w(Issue TimeEntry Version Document Project)
596
596
597 def cast_single_value(custom_field, value, customized=nil)
597 def cast_single_value(custom_field, value, customized=nil)
598 target_class.find_by_id(value.to_i) if value.present?
598 target_class.find_by_id(value.to_i) if value.present?
General Comments 0
You need to be logged in to leave comments. Login now