2016-11-23 09:34:21 -05:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.directive "reviewPanelToggle", () ->
|
|
|
|
restrict: "E"
|
|
|
|
scope:
|
2017-06-28 10:00:32 -04:00
|
|
|
onToggle: '&'
|
2017-01-10 10:11:12 -05:00
|
|
|
ngModel: '='
|
2017-07-04 06:15:24 -04:00
|
|
|
valWhenUndefined: '=?'
|
2017-02-02 07:08:17 -05:00
|
|
|
disabled: '=?'
|
2017-07-05 06:08:14 -04:00
|
|
|
onDisabledClick: '&?'
|
2017-01-10 10:11:12 -05:00
|
|
|
link: (scope) ->
|
2017-02-02 07:08:17 -05:00
|
|
|
if !scope.disabled?
|
|
|
|
scope.disabled = false
|
2017-01-10 10:11:12 -05:00
|
|
|
scope.onChange = (args...) ->
|
2017-06-28 10:00:32 -04:00
|
|
|
scope.onToggle({ isOn: scope.localModel })
|
2017-02-02 07:08:17 -05:00
|
|
|
scope.handleClick = () ->
|
2017-07-05 06:08:14 -04:00
|
|
|
if scope.disabled and scope.onDisabledClick?
|
2017-02-02 07:08:17 -05:00
|
|
|
scope.onDisabledClick()
|
2017-01-10 10:11:12 -05:00
|
|
|
scope.localModel = scope.ngModel
|
|
|
|
scope.$watch "ngModel", (value) ->
|
2017-07-04 06:15:24 -04:00
|
|
|
if scope.valWhenUndefined? and !value?
|
|
|
|
value = scope.valWhenUndefined
|
2017-01-10 10:11:12 -05:00
|
|
|
scope.localModel = value
|
|
|
|
|
2016-11-23 09:34:21 -05:00
|
|
|
template: """
|
2017-02-02 07:08:17 -05:00
|
|
|
<div class="rp-toggle" ng-click="handleClick();">
|
|
|
|
<input id="rp-toggle-{{$id}}" ng-disabled="disabled" type="checkbox" class="rp-toggle-hidden-input" ng-model="localModel" ng-change="onChange()" />
|
2016-11-23 09:34:21 -05:00
|
|
|
<label for="rp-toggle-{{$id}}" class="rp-toggle-btn"></label>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
|