##// END OF EJS Templates
Disable children when checking parent notifiable....
Jean-Philippe Lang -
r12721:d50ec43dffcd
parent child
Show More
@@ -1,106 +1,118
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2014 Jean-Philippe Lang
4 # Copyright (C) 2006-2014 Jean-Philippe Lang
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 module SettingsHelper
20 module SettingsHelper
21 def administration_settings_tabs
21 def administration_settings_tabs
22 tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general},
22 tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general},
23 {:name => 'display', :partial => 'settings/display', :label => :label_display},
23 {:name => 'display', :partial => 'settings/display', :label => :label_display},
24 {:name => 'authentication', :partial => 'settings/authentication', :label => :label_authentication},
24 {:name => 'authentication', :partial => 'settings/authentication', :label => :label_authentication},
25 {:name => 'projects', :partial => 'settings/projects', :label => :label_project_plural},
25 {:name => 'projects', :partial => 'settings/projects', :label => :label_project_plural},
26 {:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
26 {:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
27 {:name => 'notifications', :partial => 'settings/notifications', :label => :field_mail_notification},
27 {:name => 'notifications', :partial => 'settings/notifications', :label => :field_mail_notification},
28 {:name => 'mail_handler', :partial => 'settings/mail_handler', :label => :label_incoming_emails},
28 {:name => 'mail_handler', :partial => 'settings/mail_handler', :label => :label_incoming_emails},
29 {:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural}
29 {:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural}
30 ]
30 ]
31 end
31 end
32
32
33 def setting_select(setting, choices, options={})
33 def setting_select(setting, choices, options={})
34 if blank_text = options.delete(:blank)
34 if blank_text = options.delete(:blank)
35 choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices
35 choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices
36 end
36 end
37 setting_label(setting, options).html_safe +
37 setting_label(setting, options).html_safe +
38 select_tag("settings[#{setting}]",
38 select_tag("settings[#{setting}]",
39 options_for_select(choices, Setting.send(setting).to_s),
39 options_for_select(choices, Setting.send(setting).to_s),
40 options).html_safe
40 options).html_safe
41 end
41 end
42
42
43 def setting_multiselect(setting, choices, options={})
43 def setting_multiselect(setting, choices, options={})
44 setting_values = Setting.send(setting)
44 setting_values = Setting.send(setting)
45 setting_values = [] unless setting_values.is_a?(Array)
45 setting_values = [] unless setting_values.is_a?(Array)
46
46
47 content_tag("label", l(options[:label] || "setting_#{setting}")) +
47 content_tag("label", l(options[:label] || "setting_#{setting}")) +
48 hidden_field_tag("settings[#{setting}][]", '').html_safe +
48 hidden_field_tag("settings[#{setting}][]", '').html_safe +
49 choices.collect do |choice|
49 choices.collect do |choice|
50 text, value = (choice.is_a?(Array) ? choice : [choice, choice])
50 text, value = (choice.is_a?(Array) ? choice : [choice, choice])
51 content_tag(
51 content_tag(
52 'label',
52 'label',
53 check_box_tag(
53 check_box_tag(
54 "settings[#{setting}][]",
54 "settings[#{setting}][]",
55 value,
55 value,
56 setting_values.include?(value),
56 setting_values.include?(value),
57 :id => nil
57 :id => nil
58 ) + text.to_s,
58 ) + text.to_s,
59 :class => (options[:inline] ? 'inline' : 'block')
59 :class => (options[:inline] ? 'inline' : 'block')
60 )
60 )
61 end.join.html_safe
61 end.join.html_safe
62 end
62 end
63
63
64 def setting_text_field(setting, options={})
64 def setting_text_field(setting, options={})
65 setting_label(setting, options).html_safe +
65 setting_label(setting, options).html_safe +
66 text_field_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
66 text_field_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
67 end
67 end
68
68
69 def setting_text_area(setting, options={})
69 def setting_text_area(setting, options={})
70 setting_label(setting, options).html_safe +
70 setting_label(setting, options).html_safe +
71 text_area_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
71 text_area_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
72 end
72 end
73
73
74 def setting_check_box(setting, options={})
74 def setting_check_box(setting, options={})
75 setting_label(setting, options).html_safe +
75 setting_label(setting, options).html_safe +
76 hidden_field_tag("settings[#{setting}]", 0, :id => nil).html_safe +
76 hidden_field_tag("settings[#{setting}]", 0, :id => nil).html_safe +
77 check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options).html_safe
77 check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options).html_safe
78 end
78 end
79
79
80 def setting_label(setting, options={})
80 def setting_label(setting, options={})
81 label = options.delete(:label)
81 label = options.delete(:label)
82 label != false ? label_tag("settings_#{setting}", l(label || "setting_#{setting}"), options[:label_options]).html_safe : ''
82 label != false ? label_tag("settings_#{setting}", l(label || "setting_#{setting}"), options[:label_options]).html_safe : ''
83 end
83 end
84
84
85 # Renders a notification field for a Redmine::Notifiable option
85 # Renders a notification field for a Redmine::Notifiable option
86 def notification_field(notifiable)
86 def notification_field(notifiable)
87 return content_tag(:label,
87 tag_data = notifiable.parent.present? ?
88 check_box_tag('settings[notified_events][]',
88 {:parent_notifiable => notifiable.parent} :
89 notifiable.name,
89 {:disables => "input[data-parent-notifiable=#{notifiable.name}]"}
90 Setting.notified_events.include?(notifiable.name), :id => nil).html_safe +
90
91 l_or_humanize(notifiable.name, :prefix => 'label_').html_safe,
91 tag = check_box_tag('settings[notified_events][]',
92 :class => notifiable.parent.present? ? "parent" : '').html_safe
92 notifiable.name,
93 Setting.notified_events.include?(notifiable.name),
94 :id => nil,
95 :data => tag_data)
96
97 text = l_or_humanize(notifiable.name, :prefix => 'label_')
98
99 options = {}
100 if notifiable.parent.present?
101 options[:class] = "parent"
102 end
103
104 content_tag(:label, tag + text, options)
93 end
105 end
94
106
95 def cross_project_subtasks_options
107 def cross_project_subtasks_options
96 options = [
108 options = [
97 [:label_disabled, ''],
109 [:label_disabled, ''],
98 [:label_cross_project_system, 'system'],
110 [:label_cross_project_system, 'system'],
99 [:label_cross_project_tree, 'tree'],
111 [:label_cross_project_tree, 'tree'],
100 [:label_cross_project_hierarchy, 'hierarchy'],
112 [:label_cross_project_hierarchy, 'hierarchy'],
101 [:label_cross_project_descendants, 'descendants']
113 [:label_cross_project_descendants, 'descendants']
102 ]
114 ]
103
115
104 options.map {|label, value| [l(label), value.to_s]}
116 options.map {|label, value| [l(label), value.to_s]}
105 end
117 end
106 end
118 end
General Comments 0
You need to be logged in to leave comments. Login now