GitLab wurde erfolgreich aktualisiert. Durch regelmäßige Updates bleibt das THM GitLab sicher. Danke für Ihre Geduld.

Commit f911e315 authored by jplang's avatar jplang

Added default value for custom fields. Fixed javascript on custom field form...

Added default value for custom fields. Fixed javascript on custom field form for project and user custom fields.

git-svn-id: https://svn.redmine.org/redmine/trunk@1090 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent d88f7d85
......@@ -53,6 +53,11 @@ class CustomField < ActiveRecord::Base
errors.add(:possible_values, :activerecord_error_blank) if self.possible_values.nil? || self.possible_values.empty?
errors.add(:possible_values, :activerecord_error_invalid) unless self.possible_values.is_a? Array
end
# validate default value
v = CustomValue.new(:custom_field => self.dup, :value => default_value, :customized => nil)
v.custom_field.is_required = false
errors.add(:default_value, :activerecord_error_invalid) unless v.valid?
end
def <=>(field)
......
......@@ -19,6 +19,12 @@ class CustomValue < ActiveRecord::Base
belongs_to :custom_field
belongs_to :customized, :polymorphic => true
def after_initialize
if custom_field && new_record? && (customized_type.blank? || (customized && customized.new_record?))
self.value ||= custom_field.default_value
end
end
protected
def validate
errors.add(:value, :activerecord_error_blank) and return if custom_field.is_required? and value.blank?
......
......@@ -8,31 +8,42 @@ function toggle_custom_field_format() {
p_regexp = $("custom_field_regexp");
p_values = $("custom_field_possible_values");
p_searchable = $("custom_field_searchable");
p_default = $("custom_field_default_value");
p_default.setAttribute('type','text');
Element.show(p_default.parentNode);
switch (format.value) {
case "list":
Element.hide(p_length.parentNode);
Element.hide(p_regexp.parentNode);
Element.show(p_searchable.parentNode);
if (p_searchable) Element.show(p_searchable.parentNode);
Element.show(p_values);
break;
case "date":
case "bool":
p_default.setAttribute('type','checkbox');
Element.hide(p_length.parentNode);
Element.hide(p_regexp.parentNode);
if (p_searchable) Element.hide(p_searchable.parentNode);
Element.hide(p_values);
break;
case "date":
Element.hide(p_length.parentNode);
Element.hide(p_regexp.parentNode);
Element.hide(p_searchable.parentNode);
if (p_searchable) Element.hide(p_searchable.parentNode);
Element.hide(p_values);
break;
case "float":
case "int":
Element.show(p_length.parentNode);
Element.show(p_regexp.parentNode);
Element.hide(p_searchable.parentNode);
if (p_searchable) Element.hide(p_searchable.parentNode);
Element.hide(p_values);
break;
default:
Element.show(p_length.parentNode);
Element.show(p_regexp.parentNode);
Element.show(p_searchable.parentNode);
if (p_searchable) Element.show(p_searchable.parentNode);
Element.hide(p_values);
break;
}
......@@ -70,6 +81,7 @@ function deleteValueField(e) {
<span><%= text_field_tag 'custom_field[possible_values][]', value, :size => 30 %> <%= image_to_function "delete.png", "deleteValueField(this);return false" %><br /></span>
<% end %>
</p>
<p><%= @custom_field.field_format == 'bool' ? f.check_box(:default_value) : f.text_field(:default_value) %></p>
</div>
<div class="box">
......
......@@ -161,6 +161,7 @@ field_delay: Отместване
field_assignable: Възможно е възлагане на задачи за тази роля
field_redirect_existing_links: Пренасочване на съществуващи линкове
field_estimated_hours: Изчислено време
field_default_value: Статус по подразбиране
setting_app_title: Заглавие
setting_app_subtitle: Описание
......
......@@ -159,6 +159,7 @@ field_is_filter: Used as a filter
field_issue_to_id: Vztažený požadavek
field_delay: Zpoždění
field_assignable: Požadavky mohou být přiřazeny této roli
field_default_value: Výchozí stav
setting_app_title: Titulek aplikace
setting_app_subtitle: Podtitulek aplikace
......
......@@ -161,6 +161,7 @@ field_delay: Pufferzeit
field_assignable: Tickets können dieser Rolle zugewiesen werden
field_redirect_existing_links: Existierende Links umleiten
field_estimated_hours: Geschätzter Aufwand
field_default_value: Default
setting_app_title: Applikations-Titel
setting_app_subtitle: Applikations-Untertitel
......
......@@ -174,6 +174,7 @@ field_estimated_hours: Estimated time
field_column_names: Columns
field_time_zone: Time zone
field_searchable: Searchable
field_default_value: Default value
setting_app_title: Application title
setting_app_subtitle: Application subtitle
......
......@@ -155,6 +155,7 @@ field_identifier: Identificador
field_is_filter: Usado como filtro
field_issue_to_id: Petición Relacionada
field_delay: Retraso
field_default_value: Estado por defecto
setting_app_title: Título de la aplicación
setting_app_subtitle: Subtítulo de la aplicación
......
......@@ -174,6 +174,7 @@ field_estimated_hours: Arvioitu aika
field_column_names: Saraketta
field_time_zone: Aikavyöhyke
field_searchable: Haettava
field_default_value: Vakio arvo
setting_app_title: Ohjelman otsikko
setting_app_subtitle: Ohjelman alaotsikko
......
......@@ -174,6 +174,7 @@ field_estimated_hours: Temps estimé
field_column_names: Colonnes
field_time_zone: Fuseau horaire
field_searchable: Utilisé pour les recherches
field_default_value: Valeur par défaut
setting_app_title: Titre de l'application
setting_app_subtitle: Sous-titre de l'application
......
......@@ -164,6 +164,7 @@ field_assignable: ניתן להקצות נושאים לתפקיד זה
field_redirect_existing_links: העבר קישורים קיימים
field_estimated_hours: זמן משוער
field_column_names: עמודות
field_default_value: ערך ברירת מחדל
setting_app_title: כותרת ישום
setting_app_subtitle: תת-כותרת ישום
......
......@@ -161,6 +161,7 @@ field_delay: Delay
field_assignable: Issues can be assigned to this role
field_redirect_existing_links: Redirect existing links
field_estimated_hours: Estimated time
field_default_value: Stato predefinito
setting_app_title: Titolo applicazione
setting_app_subtitle: Sottotitolo applicazione
......
......@@ -162,6 +162,7 @@ field_delay: 遅延
field_assignable: 問題はこのロールに割り当てることができます
field_redirect_existing_links: 既存のリンクをリダイレクトする
field_estimated_hours: 予定工数
field_default_value: デフォルトのステータス
setting_app_title: アプリケーションのタイトル
setting_app_subtitle: アプリケーションのサブタイトル
......
......@@ -164,6 +164,7 @@ field_assignable: 이 역할에 할당될수 있는 티켓
field_redirect_existing_links: Redirect existing links
field_estimated_hours: 추정시간
field_column_names: 컬럼
field_default_value: 기본값
setting_app_title: 레드마인 제목
setting_app_subtitle: 레드마인 부제목
......
......@@ -171,7 +171,8 @@ field_estimated_hours: Apskaičiuotas laikas
field_column_names: Skiltys
field_time_zone: Laiko juosta
field_searchable: Randamas
field_default_value: Numatytoji vertė
setting_app_title: Programos pavadinimas
setting_app_subtitle: Programos paantraštė
setting_welcome_text: Pasveikinimas
......
......@@ -109,7 +109,7 @@ field_issue: Issue
field_status: Status
field_notes: Notities
field_is_closed: Issue gesloten
field_is_default: Default status
field_is_default: Default
field_tracker: Tracker
field_subject: Onderwerp
field_due_date: Verwachte datum gereed
......@@ -161,6 +161,7 @@ field_delay: Vertraging
field_assignable: Issues can be assigned to this role
field_redirect_existing_links: Redirect existing links
field_estimated_hours: Estimated time
field_default_value: Default value
setting_app_title: Applicatie titel
setting_app_subtitle: Applicatie ondertitel
......
......@@ -155,6 +155,7 @@ field_identifier: Identifikator
field_is_filter: Atrybut filtrowania
field_issue_to_id: Powiązania zagadnienia
field_delay: Opóźnienie
field_default_value: Domyślny
setting_app_title: Tytuł aplikacji
setting_app_subtitle: Podtytuł aplikacji
......
......@@ -161,6 +161,7 @@ field_delay: Delay
field_assignable: Issues can be assigned to this role
field_redirect_existing_links: Redirect existing links
field_estimated_hours: Estimated time
field_default_value: Padrao
setting_app_title: Titulo da aplicacao
setting_app_subtitle: Sub-titulo da aplicacao
......
......@@ -161,6 +161,7 @@ field_delay: Atraso
field_assignable: Issues can be assigned to this role
field_redirect_existing_links: Redirect existing links
field_estimated_hours: Estimated time
field_default_value: Padrão
setting_app_title: Título da aplicação
setting_app_subtitle: Sub-título da aplicação
......
......@@ -161,6 +161,7 @@ field_delay: Intarziere
field_assignable: La acest rol se poate atribui tichete
field_redirect_existing_links: Redirectare linkuri existente
field_estimated_hours: Timpul estimat
field_default_value: Default value
setting_app_title: Titlul aplicatiei
setting_app_subtitle: Subtitlul aplicatiei
......
......@@ -166,6 +166,7 @@ field_assignable: Задача может быть назначена этой
field_redirect_existing_links: Перенаправить существующие ссылки
field_estimated_hours: Оцененное время
field_column_names: Колонки
field_default_value: Default value
setting_app_title: Название приложения
setting_app_subtitle: Подзаголовок приложения
......
......@@ -166,6 +166,7 @@ field_assignable: Kartice mogu biti dodeljene ovoj ulozi
field_redirect_existing_links: Redirekcija postojećih linkova
field_estimated_hours: Procenjeno vreme
field_column_names: Kolone
field_default_value: Default value
setting_app_title: Naziv aplikacije
setting_app_subtitle: Podnaslov aplikacije
......
......@@ -161,6 +161,7 @@ field_delay: Delay
field_assignable: Issues can be assigned to this role
field_redirect_existing_links: Redirect existing links
field_estimated_hours: Estimated time
field_default_value: Default value
setting_app_title: Applikationstitel
setting_app_subtitle: Applicationsunderrubrik
......
......@@ -174,6 +174,7 @@ field_estimated_hours: 預估工時
field_column_names: Columns
field_time_zone: 時區
field_searchable: 可用做搜尋條件
field_default_value: Default value
setting_app_title: 標題
setting_app_subtitle: 副標題
......
......@@ -164,6 +164,7 @@ field_delay: Delay
field_assignable: Issues can be assigned to this role
field_redirect_existing_links: Redirect existing links
field_estimated_hours: Estimated time
field_default_value: Default value
setting_app_title: 应用程序标题
setting_app_subtitle: 应用程序子标题
......
......@@ -10,6 +10,7 @@ custom_fields_001:
id: 1
is_required: false
field_format: list
default_value: ""
custom_fields_002:
name: Searchable field
min_length: 1
......@@ -22,6 +23,7 @@ custom_fields_002:
is_required: false
field_format: string
searchable: true
default_value: "Default string"
custom_fields_003:
name: Development status
min_length: 0
......@@ -33,6 +35,7 @@ custom_fields_003:
id: 3
is_required: true
field_format: list
default_value: ""
custom_fields_004:
name: Phone number
min_length: 0
......@@ -44,6 +47,7 @@ custom_fields_004:
id: 4
is_required: false
field_format: string
default_value: ""
custom_fields_005:
name: Money
min_length: 0
......@@ -55,4 +59,5 @@ custom_fields_005:
id: 5
is_required: false
field_format: float
default_value: ""
\ No newline at end of file
......@@ -34,7 +34,10 @@ class IssuesControllerTest < Test::Unit::TestCase
:enabled_modules,
:enumerations,
:attachments,
:workflows
:workflows,
:custom_fields,
:custom_values,
:custom_fields_trackers
def setup
@controller = IssuesController.new
......@@ -132,6 +135,9 @@ class IssuesControllerTest < Test::Unit::TestCase
get :new, :project_id => 1, :tracker_id => 1
assert_response :success
assert_template 'new'
assert_tag :tag => 'input', :attributes => { :name => 'custom_fields[2]',
:value => 'Default string' }
end
def test_get_new_without_tracker_id
......@@ -162,9 +168,16 @@ class IssuesControllerTest < Test::Unit::TestCase
:issue => {:tracker_id => 1,
:subject => 'This is the test_new issue',
:description => 'This is the description',
:priority_id => 5}
:priority_id => 5},
:custom_fields => {'2' => 'Value for field 2'}
assert_redirected_to 'projects/ecookbook/issues'
assert Issue.find_by_subject('This is the test_new issue')
issue = Issue.find_by_subject('This is the test_new issue')
assert_not_nil issue
assert_equal 2, issue.author_id
v = issue.custom_values.find_by_custom_field_id(2)
assert_not_nil v
assert_equal 'Value for field 2', v.value
end
def test_copy_issue
......
require "#{File.dirname(__FILE__)}/../test_helper"
class IssuesTest < ActionController::IntegrationTest
fixtures :projects, :users, :trackers, :issue_statuses, :issues, :enumerations
fixtures :projects,
:users,
:trackers,
:projects_trackers,
:issue_statuses,
:issues,
:enumerations,
:custom_fields,
:custom_values,
:custom_fields_trackers
# create an issue
def test_add_issue
......@@ -18,7 +27,8 @@ class IssuesTest < ActionController::IntegrationTest
:description => "new issue",
:done_ratio => "0",
:due_date => "",
:assigned_to_id => "" }
:assigned_to_id => "" },
:custom_fields => {'2' => 'Value for field 2'}
# find created issue
issue = Issue.find_by_subject("new test issue")
assert_kind_of Issue, issue
......
......@@ -31,4 +31,15 @@ class CustomValueTest < Test::Unit::TestCase
v.value = '6a'
assert !v.save
end
def test_default_value
field = CustomField.find_by_default_value('Default string')
assert_not_nil field
v = CustomValue.new(:custom_field => field)
assert_equal 'Default string', v.value
v = CustomValue.new(:custom_field => field, :value => 'Not empty')
assert_equal 'Not empty', v.value
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment