diff --git a/redmine/app/helpers/application_helper.rb b/redmine/app/helpers/application_helper.rb index 9212a5952..d9bafdbcd 100644 --- a/redmine/app/helpers/application_helper.rb +++ b/redmine/app/helpers/application_helper.rb @@ -121,6 +121,11 @@ module ApplicationHelper " | " + link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)") end + + def calendar_for(field_id) + image_tag("calendar.gif", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) + + javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });") + end end class TabularFormBuilder < ActionView::Helpers::FormBuilder @@ -131,7 +136,7 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc end - (field_helpers - %w(radio_button) + %w(date_select)).each do |selector| + (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector| src = <<-END_SRC def #{selector}(field, options = {}) label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") diff --git a/redmine/app/helpers/custom_fields_helper.rb b/redmine/app/helpers/custom_fields_helper.rb index eb4d47a83..82ace311a 100644 --- a/redmine/app/helpers/custom_fields_helper.rb +++ b/redmine/app/helpers/custom_fields_helper.rb @@ -24,8 +24,11 @@ module CustomFieldsHelper field_id = "custom_fields_#{custom_field.id}" case custom_field.field_format - when "string", "int", "date" + when "string", "int" text_field 'custom_value', 'value', :name => field_name, :id => field_id + when "date" + text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) + + calendar_for(field_id) when "text" text_area 'custom_value', 'value', :name => field_name, :id => field_id, :cols => 60, :rows => 3 when "bool" diff --git a/redmine/app/models/custom_value.rb b/redmine/app/models/custom_value.rb index 6c1dd3aea..015ccd244 100644 --- a/redmine/app/models/custom_value.rb +++ b/redmine/app/models/custom_value.rb @@ -29,7 +29,7 @@ protected when "int" errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[0-9]*$/ when "date" - errors.add(:value, :activerecord_error_invalid) unless value =~ /^(\d+)\/(\d+)\/(\d+)$/ or value.empty? + errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ or value.empty? when "list" errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.split('|').include? value or value.empty? end diff --git a/redmine/app/models/issue.rb b/redmine/app/models/issue.rb index dc5b3fd84..7b48182c7 100644 --- a/redmine/app/models/issue.rb +++ b/redmine/app/models/issue.rb @@ -17,43 +17,48 @@ class Issue < ActiveRecord::Base - belongs_to :project - belongs_to :tracker - belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id' - belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' - belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id' - belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id' - belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id' - belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id' - - has_many :histories, :class_name => 'IssueHistory', :dependent => true, :order => "issue_histories.created_on DESC", :include => :status - has_many :attachments, :as => :container, :dependent => true - - has_many :custom_values, :dependent => true, :as => :customized - has_many :custom_fields, :through => :custom_values - + belongs_to :project + belongs_to :tracker + belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id' + belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' + belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id' + belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id' + belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id' + belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id' + + has_many :histories, :class_name => 'IssueHistory', :dependent => true, :order => "issue_histories.created_on DESC", :include => :status + has_many :attachments, :as => :container, :dependent => true + + has_many :custom_values, :dependent => true, :as => :customized + has_many :custom_fields, :through => :custom_values + validates_presence_of :subject, :description, :priority, :tracker, :author validates_associated :custom_values, :on => :update - - # set default status for new issues - def before_validation - self.status = IssueStatus.default if new_record? - end - - def before_create - build_history - end - - def long_id - "%05d" % self.id - end - + + # set default status for new issues + def before_validation + self.status = IssueStatus.default if new_record? + end + + def validate + if self.due_date.nil? && !@attributes['due_date'].empty? + errors.add :due_date, :activerecord_error_not_a_date + end + end + + def before_create + build_history + end + + def long_id + "%05d" % self.id + end + private - # Creates an history for the issue - def build_history - @history = self.histories.build - @history.status = self.status - @history.author = self.author - end - + # Creates an history for the issue + def build_history + @history = self.histories.build + @history.status = self.status + @history.author = self.author + end end diff --git a/redmine/app/models/version.rb b/redmine/app/models/version.rb index 70bd6e1c3..0ae1edda8 100644 --- a/redmine/app/models/version.rb +++ b/redmine/app/models/version.rb @@ -23,6 +23,7 @@ class Version < ActiveRecord::Base validates_presence_of :name validates_uniqueness_of :name, :scope => [:project_id] + validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :activerecord_error_not_a_date private def check_integrity diff --git a/redmine/app/views/issues/edit.rhtml b/redmine/app/views/issues/edit.rhtml index 13f9e4399..979dc6a47 100644 --- a/redmine/app/views/issues/edit.rhtml +++ b/redmine/app/views/issues/edit.rhtml @@ -11,7 +11,7 @@

<%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}) %>

<%= f.text_field :subject, :size => 80, :required => true %>

<%= f.text_area :description, :cols => 60, :rows => 10, :required => true %>

-

<%= f.date_select :due_date, :start_year => Date.today.year, :include_blank => true %>

+

<%= f.text_field :due_date, :size => 10 %><%= calendar_for('issue_due_date') %>

<% for @custom_value in @custom_values %>

<%= custom_field_tag_with_label @custom_value %>

diff --git a/redmine/app/views/layouts/base.rhtml b/redmine/app/views/layouts/base.rhtml index dd85ed5c3..33ddd8f99 100644 --- a/redmine/app/views/layouts/base.rhtml +++ b/redmine/app/views/layouts/base.rhtml @@ -10,7 +10,10 @@ <%= stylesheet_link_tag "rails" %> <%= javascript_include_tag :defaults %> <%= javascript_include_tag 'menu' %> - +<%= javascript_include_tag 'calendar/calendar' %> +<%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %> +<%= javascript_include_tag 'calendar/calendar-setup' %> +<%= stylesheet_link_tag 'calendar/calendar-blue' %>