Created
August 22, 2016 09:37
-
-
Save timurvafin/cff2b3431d2adfb149a57bd9d4191674 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/assets/javascripts/exclude_options.coffee | |
class @ExcludeOptions | |
constructor: (el) -> | |
$el = $(el) | |
trigger_id = "#" + $el.data("exclude-options") | |
@$trigger = $el.find(trigger_id) | |
@$options = $el.find("input[type=checkbox]").not(trigger_id) | |
@_bindEvents() | |
_bindEvents: -> | |
@$trigger.on "click", @_resetOptions | |
@$options.on "click", @_resetTrigger | |
_resetOptions: => | |
@_reset(@$options) | |
_resetTrigger: => | |
@_reset(@$trigger) | |
_reset: (checkboxes) -> | |
checkboxes.prop "checked", false | |
new ExcludeOptions(el) for el in $("[data-exclude-options]") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- spec/javascripts/fixtures/exclude_options.html --> | |
<div data-exclude-options="report_team_rotation_no_rotations"> | |
<input type="checkbox" id="report_team_rotation_no_rotations"> | |
<label for="report_team_rotation_no_rotations">No Rotations</label> | |
<input type="checkbox" id="report_team_rotation_team_member_rotation"> | |
<label for="report_team_rotation_team_member_rotation">Team Member Rotation</label> | |
<input type="checkbox" id="report_team_rotation_team_member_vacation"> | |
<label for="report_team_rotation_team_member_vacation">Team Member Vacation</label> | |
<input type="checkbox" id="report_team_rotation_manager_rotation"> | |
<label for="report_team_rotation_manager_rotation">Manager Rotation</label> | |
<input type="checkbox" id="report_team_rotation_manager_vacation"> | |
<label for="report_team_rotation_manager_vacation">Manager Vacation</label> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/javascripts/exclude_options_spec.coffee | |
describe "ExcludeOptions", -> | |
beforeAll -> | |
loadFixtures("exclude_options.html") | |
new ExcludeOptions(el) for el in $("[data-exclude-options]") | |
it "unchecks trigger option", -> | |
$("#report_team_rotation_no_rotations").click() | |
$("#report_team_rotation_team_member_rotation").click() | |
expect($("#report_team_rotation_no_rotations")).not.toBeChecked() | |
it "unchecks other options", -> | |
$("#report_team_rotation_team_member_rotation").click() | |
$("#report_team_rotation_team_member_vacation").click() | |
$("#report_team_rotation_no_rotations").click() | |
expect($("#report_team_rotation_team_member_rotation")).not.toBeChecked() | |
expect($("#report_team_rotation_team_member_vacation")).not.toBeChecked() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment