Commit 4209b25ece1a6a1cfa651160ee37487dc45fe797
1 parent
0c3fd5c7
Exists in
master
and in
1 other branch
Refactored nested forms javascript and css.
Showing
3 changed files
with
15 additions
and
22 deletions
Show diff stats
app/views/apps/_fields.html.haml
| ... | ... | @@ -42,9 +42,9 @@ |
| 42 | 42 | = label_tag :watcher_type_user, 'User', :for => label_for_attr(w, 'watcher_type_user') |
| 43 | 43 | = w.radio_button :watcher_type, :email |
| 44 | 44 | = label_tag :watcher_type_email, 'Email Address', :for => label_for_attr(w, 'watcher_type_email') |
| 45 | - %div.user{:class => w.object.email.blank? ? 'choosen' : nil} | |
| 45 | + %div.watcher_params.user{:class => w.object.email.blank? ? 'chosen' : nil} | |
| 46 | 46 | = w.select :user_id, User.all.map{|u| [u.name,u.id.to_s]}, :include_blank => '-- Select a User --' |
| 47 | - %div.email{:class => w.object.email.present? ? 'choosen' : nil} | |
| 47 | + %div.watcher_params.email{:class => w.object.email.present? ? 'chosen' : nil} | |
| 48 | 48 | = w.text_field :email |
| 49 | 49 | |
| 50 | 50 | %fieldset | ... | ... |
public/javascripts/form.js
| ... | ... | @@ -2,10 +2,10 @@ $(function(){ |
| 2 | 2 | activateNestedForms(); |
| 3 | 3 | |
| 4 | 4 | if($('div.watcher.nested').length) |
| 5 | - activateWatcherTypeSelector(); | |
| 5 | + activateTypeSelector('watcher'); | |
| 6 | 6 | |
| 7 | 7 | if($('div.issue_tracker.nested').length) |
| 8 | - activateIssueTrackerTypeSelector(); | |
| 8 | + activateTypeSelector('issue_tracker', 'tracker_params'); | |
| 9 | 9 | }); |
| 10 | 10 | |
| 11 | 11 | function activateNestedForms() { |
| ... | ... | @@ -63,20 +63,14 @@ function removeNestedItem() { |
| 63 | 63 | nestedItem.hide(); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | -function activateWatcherTypeSelector() { | |
| 67 | - $('div.watcher input[name*=watcher_type]').live('click', function(){ | |
| 68 | - var choosen = $(this).val(); | |
| 69 | - var wrapper = $(this).closest('.nested'); | |
| 70 | - wrapper.find('div.choosen').removeClass('choosen'); | |
| 71 | - wrapper.find('div.'+choosen).addClass('choosen'); | |
| 72 | - }); | |
| 73 | -} | |
| 74 | 66 | |
| 75 | -function activateIssueTrackerTypeSelector() { | |
| 76 | - $('div.issue_tracker input[name*=issue_tracker_type]').live('click', function(){ | |
| 67 | +function activateTypeSelector(field_class, section_class) { | |
| 68 | + section_class = section_class || field_class+"_params"; // section_class can be deduced if not given | |
| 69 | + $('div.'+field_class+' input[name*='+field_class+'_type]').live('click', function(){ | |
| 77 | 70 | var chosen = $(this).val(); |
| 78 | 71 | var wrapper = $(this).closest('.nested'); |
| 79 | - wrapper.find('div.chosen').removeClass('chosen'); | |
| 80 | - wrapper.find('div.'+chosen).addClass('chosen'); | |
| 72 | + wrapper.find('div.chosen.'+section_class).removeClass('chosen'); | |
| 73 | + wrapper.find('div.'+section_class+'.'+chosen).addClass('chosen'); | |
| 81 | 74 | }); |
| 82 | -} | |
| 83 | 75 | \ No newline at end of file |
| 76 | +} | |
| 77 | + | ... | ... |
public/stylesheets/application.css
| ... | ... | @@ -525,14 +525,13 @@ a.button.active { |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | /* Watchers and Issue Tracker Forms */ |
| 528 | -div.nested.watcher .user, div.nested.watcher .email, div.issue_tracker.nested .tracker_params { | |
| 528 | +div.watcher.nested .watcher_params, div.issue_tracker.nested .tracker_params { | |
| 529 | 529 | display: none; |
| 530 | 530 | } |
| 531 | -div.nested.watcher .choosen, div.nested.issue_tracker .chosen { | |
| 532 | - display: block; | |
| 531 | +div.nested .chosen { | |
| 532 | + display: block !important; | |
| 533 | 533 | } |
| 534 | - | |
| 535 | -div.nested.watcher .choose, div.nested.issue_tracker .choose { | |
| 534 | +div.nested .choose { | |
| 536 | 535 | margin-bottom: 0.5em; |
| 537 | 536 | } |
| 538 | 537 | ... | ... |