2017-12-20 05:33:33 -06:00
|
|
|
import coreModule from 'app/core/core_module';
|
2016-03-21 15:24:06 -05:00
|
|
|
|
2018-08-29 07:26:50 -05:00
|
|
|
const template = `
|
2017-06-06 04:03:56 -05:00
|
|
|
<label for="check-{{ctrl.id}}" class="gf-form-label {{ctrl.labelClass}} pointer" ng-show="ctrl.label">
|
2016-04-15 18:56:39 -05:00
|
|
|
{{ctrl.label}}
|
2017-04-12 10:28:32 -05:00
|
|
|
<info-popover mode="right-normal" ng-if="ctrl.tooltip" position="top center">
|
2016-04-15 18:56:39 -05:00
|
|
|
{{ctrl.tooltip}}
|
|
|
|
</info-popover>
|
|
|
|
</label>
|
2016-03-28 10:08:31 -05:00
|
|
|
<div class="gf-form-switch {{ctrl.switchClass}}" ng-if="ctrl.show">
|
2016-03-29 08:53:41 -05:00
|
|
|
<input id="check-{{ctrl.id}}" type="checkbox" ng-model="ctrl.checked" ng-change="ctrl.internalOnChange()">
|
|
|
|
<label for="check-{{ctrl.id}}" data-on="Yes" data-off="No"></label>
|
2016-03-21 15:24:06 -05:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
export class SwitchCtrl {
|
|
|
|
onChange: any;
|
2016-03-28 06:10:42 -05:00
|
|
|
checked: any;
|
2016-03-28 10:08:31 -05:00
|
|
|
show: any;
|
2016-03-29 08:53:41 -05:00
|
|
|
id: any;
|
2017-06-06 04:03:56 -05:00
|
|
|
label: string;
|
2016-03-28 06:10:42 -05:00
|
|
|
|
2016-03-28 14:45:31 -05:00
|
|
|
/** @ngInject */
|
2016-04-10 13:58:52 -05:00
|
|
|
constructor($scope, private $timeout) {
|
2016-03-28 10:08:31 -05:00
|
|
|
this.show = true;
|
2016-03-29 08:53:41 -05:00
|
|
|
this.id = $scope.$id;
|
2016-03-28 06:10:42 -05:00
|
|
|
}
|
2016-03-21 15:24:06 -05:00
|
|
|
|
|
|
|
internalOnChange() {
|
2016-04-11 15:21:25 -05:00
|
|
|
return this.$timeout(() => {
|
|
|
|
return this.onChange();
|
2016-03-21 15:24:06 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function switchDirective() {
|
|
|
|
return {
|
2017-12-20 05:33:33 -06:00
|
|
|
restrict: 'E',
|
2016-03-21 15:24:06 -05:00
|
|
|
controller: SwitchCtrl,
|
2017-12-20 05:33:33 -06:00
|
|
|
controllerAs: 'ctrl',
|
2016-03-21 15:24:06 -05:00
|
|
|
bindToController: true,
|
|
|
|
scope: {
|
2017-12-20 05:33:33 -06:00
|
|
|
checked: '=',
|
|
|
|
label: '@',
|
|
|
|
labelClass: '@',
|
|
|
|
tooltip: '@',
|
|
|
|
switchClass: '@',
|
|
|
|
onChange: '&',
|
2016-03-21 15:24:06 -05:00
|
|
|
},
|
2017-12-20 05:33:33 -06:00
|
|
|
template: template,
|
2016-03-21 15:24:06 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.directive('gfFormSwitch', switchDirective);
|