2016-03-21 15:24:06 -05:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import config from 'app/core/config';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import $ from 'jquery';
|
|
|
|
import coreModule from 'app/core/core_module';
|
2016-03-29 04:01:00 -05:00
|
|
|
import Drop from 'tether-drop';
|
2016-03-21 15:24:06 -05:00
|
|
|
|
|
|
|
var template = `
|
2016-03-29 08:53:41 -05:00
|
|
|
<label for="check-{{ctrl.id}}" class="gf-form-label {{ctrl.labelClass}} pointer">{{ctrl.label}}</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;
|
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() {
|
|
|
|
return new Promise(resolve => {
|
2016-04-10 13:58:52 -05:00
|
|
|
this.$timeout(() => {
|
2016-03-21 15:24:06 -05:00
|
|
|
this.onChange();
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export function switchDirective() {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
controller: SwitchCtrl,
|
|
|
|
controllerAs: 'ctrl',
|
|
|
|
bindToController: true,
|
|
|
|
scope: {
|
|
|
|
checked: "=",
|
|
|
|
label: "@",
|
|
|
|
labelClass: "@",
|
2016-03-29 04:01:00 -05:00
|
|
|
tooltip: "@",
|
2016-03-21 15:24:06 -05:00
|
|
|
switchClass: "@",
|
|
|
|
onChange: "&",
|
|
|
|
},
|
|
|
|
template: template,
|
2016-03-29 04:01:00 -05:00
|
|
|
link: (scope, elem) => {
|
|
|
|
if (scope.ctrl.tooltip) {
|
|
|
|
var drop = new Drop({
|
|
|
|
target: elem[0],
|
|
|
|
content: scope.ctrl.tooltip,
|
|
|
|
position: "right middle",
|
|
|
|
classes: 'drop-help',
|
|
|
|
openOn: 'hover',
|
|
|
|
hoverOpenDelay: 400,
|
|
|
|
});
|
|
|
|
|
|
|
|
scope.$on('$destroy', function() {
|
|
|
|
drop.destroy();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2016-03-21 15:24:06 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
coreModule.directive('gfFormSwitch', switchDirective);
|