[REM] web: Remove toggle_button widget

This widget is not used anymore, as all the stat buttons have been removed
from the views.
This commit is contained in:
Yannick Tivisse
2019-07-12 13:01:36 +02:00
parent f896afcc8a
commit 52fc9a24a6
7 changed files with 49 additions and 150 deletions
+35 -14
View File
@@ -49,21 +49,40 @@
<form string="Carrier">
<sheet>
<div class="oe_button_box" name="button_box">
<button name="toggle_prod_environment" type="object" class="oe_stat_button" icon="fa-check-square" attrs="{'invisible': ['|', ('delivery_type', '=', 'fixed'), ('delivery_type', '=', 'base_on_rule')]}">
<field name="prod_environment" widget="boolean_button" options='{"terminology": {
"string_true": "Production Environment",
"hover_true": "Switch to test environment",
"string_false": "Test Environment",
"hover_false": "Switch to production environment"
}}'/>
<button name="toggle_prod_environment"
attrs="{'invisible': ['|', '|', ('prod_environment', '=', False), ('delivery_type', '=', 'fixed'), ('delivery_type', '=', 'base_on_rule')]}"
class="oe_stat_button"
type="object" icon="fa-play">
<div class="o_stat_info o_field_widget">
<span class="text-success">Production</span>
<span class="o_stat_text">Environment</span>
</div>
</button>
<button name="toggle_debug" type="object" class="oe_stat_button" icon="fa-code" groups="base.group_no_one" attrs="{'invisible': ['|', ('delivery_type', '=', 'fixed'), ('delivery_type', '=', 'base_on_rule')]}">
<field name="debug_logging" widget="boolean_button" options='{"terminology": {
"string_true": "Debug requests",
"hover_true": "Disable debug",
"string_false": "No debug",
"hover_false": "Enable debug"
}}'/>
<!-- transfer referenced here due to view inheritance issue in current master (post-saas-16) -->
<button name="toggle_prod_environment"
attrs="{'invisible': ['|', '|', ('prod_environment', '=', True), ('delivery_type', '=', 'fixed'), ('delivery_type', '=', 'base_on_rule')]}"
class="oe_stat_button"
type="object" icon="fa-stop">
<div class="o_stat_info o_field_widget">
<span class="o_warning_text">Test</span>
<span class="o_stat_text">Environment</span>
</div>
</button>
<button name="toggle_debug"
attrs="{'invisible': ['|', '|', ('delivery_type', '=', 'fixed'), ('delivery_type', '=', 'base_on_rule'), ('debug_logging', '=', True)]}"
class="oe_stat_button"
type="object" icon="fa-code">
<div class="o_stat_info o_field_widget">
<span class="text-danger">No debug</span>
</div>
</button>
<button name="toggle_debug"
attrs="{'invisible': ['|', '|', ('delivery_type', '=', 'fixed'), ('delivery_type', '=', 'base_on_rule'), ('debug_logging', '=', False)]}"
class="oe_stat_button"
type="object" icon="fa-code">
<div class="o_stat_info o_field_widget">
<span class="text-success">Debug requests</span>
</div>
</button>
</div>
<div class="oe_title" name="title">
@@ -75,6 +94,8 @@
<group>
<group name="provider_details">
<field name="active" invisible="1"/>
<field name="prod_environment" invisible="1"/>
<field name="debug_logging" invisible="1"/>
<label for="delivery_type"/>
<div>
<field name="delivery_type" widget="radio"/>
+13 -2
View File
@@ -18,6 +18,7 @@
<field name="fees_implemented" invisible='1'/>
<field name="token_implemented" invisible='1'/>
<field name="authorize_implemented" invisible="1"/>
<field name="website_published" invisible="1"/>
<sheet>
<field name="module_id" invisible="1"/>
<field name="module_state" invisible="1"/>
@@ -44,10 +45,20 @@
</div>
</button>
<button name="toggle_website_published"
attrs="{'invisible': [('website_published', '=', True)]}"
class="oe_stat_button"
type="object" icon="fa-globe">
<field name="website_published" widget="boolean_button"
options='{"terminology": {"string_true": "Published", "hover_false": "Publish"}}'/>
<div class="o_stat_info o_field_widget">
<span class="text-danger">Unpublished</span>
</div>
</button>
<button name="toggle_website_published"
attrs="{'invisible': [('website_published', '=', False)]}"
class="oe_stat_button"
type="object" icon="fa-globe">
<div class="o_stat_info o_field_widget">
<span class="text-success">Published</span>
</div>
</button>
</div>
<field name="image" widget='image' class="oe_avatar" options='{"preview_image": "image_medium"}'/>
@@ -2251,68 +2251,6 @@ var LabelSelection = AbstractField.extend({
},
});
var FieldBooleanButton = AbstractField.extend({
className: 'o_stat_info',
supportedFieldTypes: ['boolean'],
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/**
* A boolean field is always set since false is a valid value.
*
* @override
*/
isSet: function () {
return true;
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* This widget is supposed to be used inside a stat button and, as such, is
* rendered the same way in edit and readonly mode.
*
* @override
* @private
*/
_render: function () {
this.$el.empty();
var text, hover;
switch (this.nodeOptions.terminology) {
case "active":
text = this.value ? _t("Active") : _t("Inactive");
hover = this.value ? _t("Deactivate") : _t("Activate");
break;
case "archive":
text = this.value ? _t("Active") : _t("Archived");
hover = this.value ? _t("Archive") : _t("Restore");
break;
case "close":
text = this.value ? _t("Active") : _t("Closed");
hover = this.value ? _t("Close") : _t("Open");
break;
default:
var opt_terms = this.nodeOptions.terminology || {};
if (typeof opt_terms === 'string') {
opt_terms = {}; //unsupported terminology
}
text = this.value ? _t(opt_terms.string_true) || _t("On")
: _t(opt_terms.string_false) || _t("Off");
hover = this.value ? _t(opt_terms.hover_true) || _t("Switch Off")
: _t(opt_terms.hover_false) || _t("Switch On");
}
var val_color = this.value ? 'text-success' : 'text-danger';
var hover_color = this.value ? 'text-danger' : 'text-success';
var $val = $('<span>').addClass('o_stat_text o_not_hover ' + val_color).text(text);
var $hover = $('<span>').addClass('o_stat_text o_hover ' + hover_color).text(hover);
this.$el.append($val).append($hover);
},
});
var BooleanToggle = FieldBoolean.extend({
description: _lt("Toggle"),
className: FieldBoolean.prototype.className + ' o_boolean_toggle',
@@ -3158,7 +3096,6 @@ return {
AbstractFieldBinary: AbstractFieldBinary,
FieldBinaryImage: FieldBinaryImage,
FieldBoolean: FieldBoolean,
FieldBooleanButton: FieldBooleanButton,
BooleanToggle: BooleanToggle,
FieldChar: FieldChar,
LinkButton: LinkButton,
@@ -49,7 +49,6 @@ registry
.add('state_selection', basic_fields.StateSelectionWidget)
.add('kanban_state_selection', basic_fields.StateSelectionWidget) // deprecated, use state_selection
.add('boolean_favorite', basic_fields.FavoriteWidget)
.add('boolean_button', basic_fields.FieldBooleanButton)
.add('boolean_toggle', basic_fields.BooleanToggle)
.add('statinfo', basic_fields.StatInfo)
.add('percentpie', basic_fields.FieldPercentPie)
@@ -320,39 +320,6 @@ QUnit.module('basic_fields', {
list.destroy();
});
QUnit.module('FieldBooleanButton');
QUnit.test('use custom terminology in form view', async function (assert) {
assert.expect(2);
var terminology = {
string_true: "Production Environment",
hover_true: "Switch to test environment",
string_false: "Test Environment",
hover_false: "Switch to production environment"
};
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<div name="button_box" class="oe_button_box">' +
'<button type="object" class="oe_stat_button" icon="fa-check-square">' +
'<field name="bar" widget="boolean_button" options=\'{"terminology": ' +
JSON.stringify(terminology) + '}\'/>' +
'</button>' +
'</div>' +
'</form>',
res_id: 2,
});
assert.containsOnce(form, ".o_stat_text.o_not_hover:contains(Production Environment)",
"button should contain correct string");
assert.containsOnce(form, ".o_stat_text.o_hover:contains(Switch to test environment)",
"button should display correct string when hovering");
form.destroy();
});
QUnit.module('FieldBooleanToggle');
QUnit.test('use boolean toggle widget in form view', async function (assert) {
@@ -3140,42 +3140,6 @@ QUnit.module('Views', {
form.destroy();
});
QUnit.test('attrs are properly transmitted to new records', async function (assert) {
assert.expect(2);
// this test checks that the fieldsInfo have been transmitted to the
// load function when creating a new record
var terminology = {
string_true: "Production Environment",
hover_true: "Switch to test environment",
string_false: "Test Environment",
hover_false: "Switch to production environment"
};
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<group>' +
'<field name="bar" widget="boolean_button" options=\'{"terminology": ' +
JSON.stringify(terminology) + '}\'/>' +
'</group>' +
'</form>',
res_id: 2,
});
assert.strictEqual(form.$('.o_stat_text.o_not_hover:contains(Production Environment)').length, 1,
"button should contain correct string");
await testUtils.form.clickCreate(form);
assert.strictEqual(form.$('.o_stat_text.o_not_hover:contains(Test Environment)').length, 1,
"button should contain correct string");
form.destroy();
});
QUnit.test('button box is rendered in create mode', async function (assert) {
assert.expect(3);
@@ -14,7 +14,7 @@
<field name="website_description" placeholder="Description displayed on the eCommerce and on online quotations."/>
</page>
</xpath>
<xpath expr="//button[@name='toggle_active']" position='before'>
<xpath expr="//button[@name='toggle_prod_environment']" position='before'>
<button class="oe_stat_button" name="website_publish_button" type="object" icon="fa-globe">
<field name="is_published" widget="website_button"/>
</button>