summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/helpers/application_helper.rb2
-rw-r--r--app/helpers/issues_helper.rb9
-rw-r--r--app/models/custom_field.rb35
-rw-r--r--app/models/custom_field_value.rb4
-rw-r--r--app/models/custom_value.rb12
-rw-r--r--app/views/attachments/_form.html.erb66
-rw-r--r--app/views/attachments/destroy.js.erb1
-rw-r--r--app/views/attachments/upload.js.erb2
-rw-r--r--app/views/custom_fields/_form.html.erb12
-rw-r--r--app/views/custom_fields/formats/_attachment.html.erb0
10 files changed, 103 insertions, 40 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index d257894dd..c54858b6d 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -197,6 +197,8 @@ module ApplicationHelper
l(:general_text_No)
when 'Issue'
object.visible? && html ? link_to_issue(object) : "##{object.id}"
+ when 'Attachment'
+ html ? link_to_attachment(object, :download => true) : object.filename
when 'CustomValue', 'CustomFieldValue'
if object.custom_field
f = object.custom_field.format.formatted_custom_value(self, object, html)
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index a9286a2d2..08611c91e 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -329,6 +329,7 @@ module IssuesHelper
def show_detail(detail, no_html=false, options={})
multiple = false
show_diff = false
+ no_details = false
case detail.property
when 'attr'
@@ -364,7 +365,9 @@ module IssuesHelper
custom_field = detail.custom_field
if custom_field
label = custom_field.name
- if custom_field.format.class.change_as_diff
+ if custom_field.format.class.change_no_details
+ no_details = true
+ elsif custom_field.format.class.change_as_diff
show_diff = true
else
multiple = custom_field.multiple?
@@ -417,7 +420,9 @@ module IssuesHelper
end
end
- if show_diff
+ if no_details
+ s = l(:text_journal_changed_no_detail, :label => label).html_safe
+ elsif show_diff
s = l(:text_journal_changed_no_detail, :label => label)
unless no_html
diff_link = link_to 'diff',
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index cd217e766..7f37ec120 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -163,6 +163,10 @@ class CustomField < ActiveRecord::Base
end
end
+ def set_custom_field_value(custom_field_value, value)
+ format.set_custom_field_value(self, custom_field_value, value)
+ end
+
def cast_value(value)
format.cast_value(self, value)
end
@@ -254,20 +258,23 @@ class CustomField < ActiveRecord::Base
# or an empty array if value is a valid value for the custom field
def validate_custom_value(custom_value)
value = custom_value.value
- errs = []
- if value.is_a?(Array)
- if !multiple?
- errs << ::I18n.t('activerecord.errors.messages.invalid')
- end
- if is_required? && value.detect(&:present?).nil?
- errs << ::I18n.t('activerecord.errors.messages.blank')
- end
- else
- if is_required? && value.blank?
- errs << ::I18n.t('activerecord.errors.messages.blank')
+ errs = format.validate_custom_value(custom_value)
+
+ unless errs.any?
+ if value.is_a?(Array)
+ if !multiple?
+ errs << ::I18n.t('activerecord.errors.messages.invalid')
+ end
+ if is_required? && value.detect(&:present?).nil?
+ errs << ::I18n.t('activerecord.errors.messages.blank')
+ end
+ else
+ if is_required? && value.blank?
+ errs << ::I18n.t('activerecord.errors.messages.blank')
+ end
end
end
- errs += format.validate_custom_value(custom_value)
+
errs
end
@@ -281,6 +288,10 @@ class CustomField < ActiveRecord::Base
validate_field_value(value).empty?
end
+ def after_save_custom_value(custom_value)
+ format.after_save_custom_value(self, custom_value)
+ end
+
def format_in?(*args)
args.include?(field_format)
end
diff --git a/app/models/custom_field_value.rb b/app/models/custom_field_value.rb
index a816f0d11..38cffc0e6 100644
--- a/app/models/custom_field_value.rb
+++ b/app/models/custom_field_value.rb
@@ -48,6 +48,10 @@ class CustomFieldValue
value.to_s
end
+ def value=(v)
+ @value = custom_field.set_custom_field_value(self, v)
+ end
+
def validate_value
custom_field.validate_custom_value(self).each do |message|
customized.errors.add(:base, custom_field.name + ' ' + message)
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb
index 8026d5f65..1dfb49941 100644
--- a/app/models/custom_value.rb
+++ b/app/models/custom_value.rb
@@ -20,6 +20,8 @@ class CustomValue < ActiveRecord::Base
belongs_to :customized, :polymorphic => true
attr_protected :id
+ after_save :custom_field_after_save_custom_value
+
def initialize(attributes=nil, *args)
super
if new_record? && custom_field && !attributes.key?(:value)
@@ -40,6 +42,10 @@ class CustomValue < ActiveRecord::Base
custom_field.visible?
end
+ def attachments_visible?(user)
+ visible? && customized && customized.visible?(user)
+ end
+
def required?
custom_field.is_required?
end
@@ -47,4 +53,10 @@ class CustomValue < ActiveRecord::Base
def to_s
value.to_s
end
+
+ private
+
+ def custom_field_after_save_custom_value
+ custom_field.after_save_custom_value(self)
+ end
end
diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb
index 65ad8804a..6e19c230d 100644
--- a/app/views/attachments/_form.html.erb
+++ b/app/views/attachments/_form.html.erb
@@ -1,29 +1,45 @@
-<span id="attachments_fields">
-<% if defined?(container) && container && container.saved_attachments %>
- <% container.saved_attachments.each_with_index do |attachment, i| %>
- <span id="attachments_p<%= i %>">
- <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename') +
- text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description') +
- link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %>
- <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
- </span>
+<% attachment_param ||= 'attachments' %>
+<% saved_attachments ||= container.saved_attachments if defined?(container) && container %>
+<% multiple = true unless defined?(multiple) && multiple == false %>
+<% show_add = multiple || saved_attachments.blank? %>
+<% description = (defined?(description) && description == false ? false : true) %>
+<% css_class = (defined?(filedrop) && filedrop == false ? '' : 'filedrop') %>
+
+<span class="attachments_form">
+ <span class="attachments_fields">
+ <% if saved_attachments.present? %>
+ <% saved_attachments.each_with_index do |attachment, i| %>
+ <span id="attachments_p<%= i %>">
+ <%= text_field_tag("#{attachment_param}[p#{i}][filename]", attachment.filename, :class => 'filename') %>
+ <% if attachment.container_id.present? %>
+ <%= link_to l(:label_delete), "#", :onclick => "$(this).closest('.attachments_form').find('.add_attachment').show(); $(this).parent().remove(); return false;", :class => 'icon-only icon-del' %>
+ <%= hidden_field_tag "#{attachment_param}[p#{i}][id]", attachment.id %>
+ <% else %>
+ <%= text_field_tag("#{attachment_param}[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description') if description %>
+ <%= link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %>
+ <%= hidden_field_tag "#{attachment_param}[p#{i}][token]", attachment.token %>
+ <% end %>
+ </span>
+ <% end %>
<% end %>
-<% end %>
-</span>
-<span class="add_attachment">
-<%= file_field_tag 'attachments[dummy][file]',
- :id => nil,
- :class => 'file_selector',
- :multiple => true,
- :onchange => 'addInputFiles(this);',
- :data => {
- :max_file_size => Setting.attachment_max_size.to_i.kilobytes,
- :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
- :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i,
- :upload_path => uploads_path(:format => 'js'),
- :description_placeholder => l(:label_optional_description)
- } %>
-(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
+ </span>
+ <span class="add_attachment" style="<%= show_add ? nil : 'display:none;' %>">
+ <%= file_field_tag "#{attachment_param}[dummy][file]",
+ :id => nil,
+ :class => "file_selector #{css_class}",
+ :multiple => multiple,
+ :onchange => 'addInputFiles(this);',
+ :data => {
+ :max_file_size => Setting.attachment_max_size.to_i.kilobytes,
+ :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
+ :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i,
+ :upload_path => uploads_path(:format => 'js'),
+ :param => attachment_param,
+ :description => description,
+ :description_placeholder => l(:label_optional_description)
+ } %>
+ (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
+ </span>
</span>
<% content_for :header_tags do %>
diff --git a/app/views/attachments/destroy.js.erb b/app/views/attachments/destroy.js.erb
index 3cfb5845f..29b9a0c76 100644
--- a/app/views/attachments/destroy.js.erb
+++ b/app/views/attachments/destroy.js.erb
@@ -1 +1,2 @@
+$('#attachments_<%= j params[:attachment_id] %>').closest('.attachments_form').find('.add_attachment').show();
$('#attachments_<%= j params[:attachment_id] %>').remove();
diff --git a/app/views/attachments/upload.js.erb b/app/views/attachments/upload.js.erb
index acd8f83e1..6b804a62b 100644
--- a/app/views/attachments/upload.js.erb
+++ b/app/views/attachments/upload.js.erb
@@ -3,7 +3,7 @@ var fileSpan = $('#attachments_<%= j params[:attachment_id] %>');
fileSpan.hide();
alert("<%= escape_javascript @attachment.errors.full_messages.join(', ') %>");
<% else %>
-$('<input>', { type: 'hidden', name: 'attachments[<%= j params[:attachment_id] %>][token]' } ).val('<%= j @attachment.token %>').appendTo(fileSpan);
+fileSpan.find('input.token').val('<%= j @attachment.token %>');
fileSpan.find('a.remove-upload')
.attr({
"data-remote": true,
diff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erb
index 7c79189ac..2e50188a6 100644
--- a/app/views/custom_fields/_form.html.erb
+++ b/app/views/custom_fields/_form.html.erb
@@ -28,7 +28,9 @@
when "IssueCustomField" %>
<p><%= f.check_box :is_required %></p>
<p><%= f.check_box :is_for_all, :data => {:disables => '#custom_field_project_ids input'} %></p>
+ <% if @custom_field.format.is_filter_supported %>
<p><%= f.check_box :is_filter %></p>
+ <% end %>
<% if @custom_field.format.searchable_supported %>
<p><%= f.check_box :searchable %></p>
<% end %>
@@ -57,7 +59,9 @@ when "IssueCustomField" %>
<p><%= f.check_box :is_required %></p>
<p><%= f.check_box :visible %></p>
<p><%= f.check_box :editable %></p>
+ <% if @custom_field.format.is_filter_supported %>
<p><%= f.check_box :is_filter %></p>
+ <% end %>
<% when "ProjectCustomField" %>
<p><%= f.check_box :is_required %></p>
@@ -65,19 +69,27 @@ when "IssueCustomField" %>
<% if @custom_field.format.searchable_supported %>
<p><%= f.check_box :searchable %></p>
<% end %>
+ <% if @custom_field.format.is_filter_supported %>
<p><%= f.check_box :is_filter %></p>
+ <% end %>
<% when "VersionCustomField" %>
<p><%= f.check_box :is_required %></p>
+ <% if @custom_field.format.is_filter_supported %>
<p><%= f.check_box :is_filter %></p>
+ <% end %>
<% when "GroupCustomField" %>
<p><%= f.check_box :is_required %></p>
+ <% if @custom_field.format.is_filter_supported %>
<p><%= f.check_box :is_filter %></p>
+ <% end %>
<% when "TimeEntryCustomField" %>
<p><%= f.check_box :is_required %></p>
+ <% if @custom_field.format.is_filter_supported %>
<p><%= f.check_box :is_filter %></p>
+ <% end %>
<% else %>
<p><%= f.check_box :is_required %></p>
diff --git a/app/views/custom_fields/formats/_attachment.html.erb b/app/views/custom_fields/formats/_attachment.html.erb
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/app/views/custom_fields/formats/_attachment.html.erb