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