From 6e367354e9e15104128ed74fab305416e0729987 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 14 Oct 2006 07:44:00 +0000 Subject: [PATCH] date picker git-svn-id: http://redmine.rubyforge.org/svn/trunk@29 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- redmine/app/helpers/application_helper.rb | 7 +- redmine/app/helpers/custom_fields_helper.rb | 5 +- redmine/app/models/custom_value.rb | 2 +- redmine/app/models/issue.rb | 77 +- redmine/app/models/version.rb | 1 + redmine/app/views/issues/edit.rhtml | 2 +- redmine/app/views/layouts/base.rhtml | 5 +- redmine/app/views/projects/add_issue.rhtml | 2 +- redmine/app/views/versions/_form.rhtml | 3 +- redmine/lang/de.yml | 1 + redmine/lang/en.yml | 1 + redmine/lang/es.yml | 1 + redmine/lang/fr.yml | 1 + .../javascripts/calendar/calendar-setup.js | 200 ++ .../public/javascripts/calendar/calendar.js | 1806 +++++++++++++++++ .../javascripts/calendar/lang/calendar-de.js | 128 ++ .../javascripts/calendar/lang/calendar-en.js | 127 ++ .../javascripts/calendar/lang/calendar-es.js | 129 ++ .../javascripts/calendar/lang/calendar-fr.js | 129 ++ redmine/public/stylesheets/application.css | 6 + .../stylesheets/calendar/calendar-blue.css | 232 +++ 21 files changed, 2822 insertions(+), 43 deletions(-) create mode 100644 redmine/public/javascripts/calendar/calendar-setup.js create mode 100644 redmine/public/javascripts/calendar/calendar.js create mode 100644 redmine/public/javascripts/calendar/lang/calendar-de.js create mode 100644 redmine/public/javascripts/calendar/lang/calendar-en.js create mode 100644 redmine/public/javascripts/calendar/lang/calendar-es.js create mode 100644 redmine/public/javascripts/calendar/lang/calendar-fr.js create mode 100644 redmine/public/stylesheets/calendar/calendar-blue.css diff --git a/redmine/app/helpers/application_helper.rb b/redmine/app/helpers/application_helper.rb index 9212a5952e..d9bafdbcd6 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 eb4d47a83a..82ace311a0 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 6c1dd3aeae..015ccd2444 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 dc5b3fd84f..7b48182c78 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 70bd6e1c39..0ae1edda8b 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 13f9e43998..979dc6a478 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 dd85ed5c32..33ddd8f99d 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' %>