Commit 1135aa99bc7c8d39cda566937069a7b3a599dd36
1 parent
4209b25e
Exists in
master
and in
1 other branch
Added unobtrusive javascript hooks for
hiding/showing content when a checkbox is clicked. Used this for 'notify_on_errs' checkbox.
Showing
2 changed files
with
19 additions
and
7 deletions
Show diff stats
app/views/apps/_fields.html.haml
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | %fieldset | 11 | %fieldset |
| 12 | %legend Notifications | 12 | %legend Notifications |
| 13 | %div.checkbox | 13 | %div.checkbox |
| 14 | - = f.check_box :notify_on_errs | 14 | + = f.check_box :notify_on_errs, 'data-show-when-checked' => '.email_at_notices_nested' |
| 15 | = f.label :notify_on_errs, 'Notify on errors' | 15 | = f.label :notify_on_errs, 'Notify on errors' |
| 16 | - if Errbit::Config.per_app_email_at_notices | 16 | - if Errbit::Config.per_app_email_at_notices |
| 17 | %div.email_at_notices_nested{:style => f.object.notify_on_errs ? '' : 'display: none;'} | 17 | %div.email_at_notices_nested{:style => f.object.notify_on_errs ? '' : 'display: none;'} |
| @@ -22,12 +22,6 @@ | @@ -22,12 +22,6 @@ | ||
| 22 | = f.check_box :notify_on_deploys | 22 | = f.check_box :notify_on_deploys |
| 23 | = f.label :notify_on_deploys, 'Notify on deploys' | 23 | = f.label :notify_on_deploys, 'Notify on deploys' |
| 24 | 24 | ||
| 25 | -:javascript | ||
| 26 | - $('#app_notify_on_errs').change(function(){ | ||
| 27 | - var el = $('.email_at_notices_nested'); | ||
| 28 | - this.checked ? el.show() : el.hide(); | ||
| 29 | - }); | ||
| 30 | - | ||
| 31 | %div.checkbox | 25 | %div.checkbox |
| 32 | = f.check_box :resolve_errs_on_deploy | 26 | = f.check_box :resolve_errs_on_deploy |
| 33 | = f.label :resolve_errs_on_deploy, 'Resolve errs on deploy' | 27 | = f.label :resolve_errs_on_deploy, 'Resolve errs on deploy' |
public/javascripts/form.js
| 1 | $(function(){ | 1 | $(function(){ |
| 2 | activateNestedForms(); | 2 | activateNestedForms(); |
| 3 | + activateCheckboxHooks(); | ||
| 3 | 4 | ||
| 4 | if($('div.watcher.nested').length) | 5 | if($('div.watcher.nested').length) |
| 5 | activateTypeSelector('watcher'); | 6 | activateTypeSelector('watcher'); |
| @@ -74,3 +75,20 @@ function activateTypeSelector(field_class, section_class) { | @@ -74,3 +75,20 @@ function activateTypeSelector(field_class, section_class) { | ||
| 74 | }); | 75 | }); |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 78 | + | ||
| 79 | +function activateCheckboxHooks() { | ||
| 80 | + // Hooks to hide/show content when a checkbox is clicked | ||
| 81 | + $('input[type="checkbox"][data-hide-when-checked]').each(function(){ | ||
| 82 | + $(this).change(function(){ | ||
| 83 | + el = $($(this).data('hide-when-checked')); | ||
| 84 | + $(this).attr('checked') ? el.hide() : el.show(); | ||
| 85 | + }); | ||
| 86 | + }); | ||
| 87 | + $('input[type="checkbox"][data-show-when-checked]').each(function(){ | ||
| 88 | + $(this).change(function(){ | ||
| 89 | + el = $($(this).data('show-when-checked')); | ||
| 90 | + $(this).attr('checked') ? el.show() : el.hide(); | ||
| 91 | + }); | ||
| 92 | + }); | ||
| 93 | +} | ||
| 94 | + |