[FIX] web: BS4, restore slider checkboxes
Take advantage of the new BS4 checkbox structure to simplify the widget too.
This commit is contained in:
@@ -2006,32 +2006,10 @@ var FieldBooleanButton = AbstractField.extend({
|
||||
});
|
||||
|
||||
var BooleanToggle = FieldBoolean.extend({
|
||||
className: FieldBoolean.prototype.className + ' o_boolean_toggle',
|
||||
events: {
|
||||
'click': '_onClick'
|
||||
},
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_render: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this._renderToggleSwitch();
|
||||
},
|
||||
|
||||
/**
|
||||
* Display toggle switch
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_renderToggleSwitch: function () {
|
||||
this.$el.addClass("o_boolean_toggle");
|
||||
var $div = $('<div class="slider"></div>');
|
||||
$div.insertAfter(this.$("input[type=checkbox]"));
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
@@ -2048,7 +2026,6 @@ var BooleanToggle = FieldBoolean.extend({
|
||||
this._setValue(!this.value);
|
||||
this.$el.closest(".o_data_row").toggleClass('text-muted', this.value);
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
var StatInfo = AbstractField.extend({
|
||||
|
||||
@@ -73,43 +73,43 @@
|
||||
}
|
||||
|
||||
// Boolean Toggle widget
|
||||
div.o_boolean_toggle {
|
||||
position: relative;
|
||||
div.o_boolean_toggle.custom-control.custom-checkbox {
|
||||
$line-height-computed: $line-height-base * $font-size-base;
|
||||
$slider-width: $line-height-computed * 1.5;
|
||||
$circle-width: $line-height-computed * 0.6;
|
||||
|
||||
display: inline-block;
|
||||
width: 32px !important;
|
||||
height: 18px;
|
||||
padding-left: $slider-width + 0.25rem;
|
||||
|
||||
> input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #a0a0a0;
|
||||
border-radius: 24px;
|
||||
|
||||
&:before {
|
||||
position: absolute;
|
||||
> label.custom-control-label {
|
||||
&::before, &::after {
|
||||
content: "";
|
||||
height: 12px;
|
||||
width: 12px;
|
||||
left: 3px;
|
||||
bottom: 3px;
|
||||
background-color: white;
|
||||
border-radius: 50%;
|
||||
top: 0;
|
||||
left: -($slider-width + 0.25rem);
|
||||
}
|
||||
&::before {
|
||||
width: $slider-width;
|
||||
height: 100%;
|
||||
background-color: #a0a0a0 !important;
|
||||
border-radius: 100px;
|
||||
outline: none !important;
|
||||
}
|
||||
&::after {
|
||||
transform: translate($line-height-computed * 0.2, $line-height-computed * 0.2);
|
||||
width: ceil($circle-width / 1rem * $o-root-font-size);
|
||||
height: ceil($circle-width / 1rem * $o-root-font-size);
|
||||
border-radius: 100px;
|
||||
background-color: $white;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
> input:checked + .slider {
|
||||
background-color: $o-brand-primary;
|
||||
|
||||
&:before {
|
||||
transform: translate(14px, 0px);
|
||||
> input.custom-control-input:checked + label.custom-control-label {
|
||||
&::before {
|
||||
background-color: $o-brand-primary !important;
|
||||
}
|
||||
&::after {
|
||||
transform: translate($slider-width - $circle-width - $line-height-computed * 0.2, $line-height-computed * 0.2);
|
||||
background-image: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ QUnit.module('basic_fields', {
|
||||
QUnit.module('FieldBooleanToggle');
|
||||
|
||||
QUnit.test('use boolean toggle widget in form view', function (assert) {
|
||||
assert.expect(2);
|
||||
assert.expect(1);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
@@ -370,7 +370,6 @@ QUnit.module('basic_fields', {
|
||||
});
|
||||
|
||||
assert.strictEqual(form.$(".custom-checkbox.o_boolean_toggle").length, 1, "Boolean toggle widget applied to boolean field");
|
||||
assert.strictEqual(form.$(".custom-checkbox.o_boolean_toggle").find(".slider").length, 1, "Boolean toggle contains slider to toggle");
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user