[ADD] web: add dynamic widget to toggle boolean button
This commit is contained in:
committed by
Raphael Collet
parent
40cbf2bea1
commit
95cb54b80b
@@ -301,6 +301,12 @@
|
||||
.openerp .oe_button_box .oe_stat_button {
|
||||
display: inline-table;
|
||||
}
|
||||
.openerp .oe_button_box .oe_stat_button .o_stat_info:not(.is_true) > .o_stat_text.oe_true {
|
||||
display: none;
|
||||
}
|
||||
.openerp .oe_button_box .oe_stat_button .o_stat_info.is_true > .o_stat_text.oe_false {
|
||||
display: none;
|
||||
}
|
||||
.openerp button.oe_toggle_button {
|
||||
box-shadow: none;
|
||||
white-space: nowrap;
|
||||
|
||||
@@ -359,6 +359,10 @@ $sheet-padding: 16px
|
||||
text-align: right
|
||||
.oe_stat_button
|
||||
display: inline-table
|
||||
.o_stat_info:not(.is_true) > .o_stat_text.oe_true
|
||||
display: none
|
||||
.o_stat_info.is_true > .o_stat_text.oe_false
|
||||
display: none
|
||||
button.oe_toggle_button
|
||||
box-shadow: none
|
||||
white-space: nowrap
|
||||
|
||||
@@ -629,6 +629,29 @@ var FieldBoolean = common.AbstractField.extend({
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
This widget is intended to be used on stat button boolean fields.
|
||||
It is a read-only field that will display a simple string "<label of value>".
|
||||
*/
|
||||
var FieldBooleanButton = common.AbstractField.extend({
|
||||
template: 'BooleanButton',
|
||||
init: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.true_string = this.options['true'] || _t('True');
|
||||
this.false_string = this.options['false'] || _t('False');
|
||||
},
|
||||
render_value: function() {
|
||||
this._super();
|
||||
this.$el.toggleClass("is_true", this.get_value());
|
||||
if (this.node.attrs.class) {
|
||||
this.$el.addClass(this.node.attrs.class);
|
||||
}
|
||||
},
|
||||
is_false: function() {
|
||||
return false;
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
The progressbar field expect a float from 0 to 100.
|
||||
*/
|
||||
@@ -1597,6 +1620,7 @@ core.form_widget_registry
|
||||
.add('radio', FieldRadio)
|
||||
.add('reference', FieldReference)
|
||||
.add('boolean', FieldBoolean)
|
||||
.add('boolean_button', FieldBooleanButton)
|
||||
.add('toggle_button', FieldToggleBoolean)
|
||||
.add('float', FieldFloat)
|
||||
.add('percentpie', FieldPercentPie)
|
||||
|
||||
@@ -1436,4 +1436,9 @@
|
||||
<img t-attf-src="#{_s}/web/static/src/img/icons/#{widget.icon}" t-att-alt="widget.string"/>
|
||||
</button>
|
||||
|
||||
<div t-name="BooleanButton" class="o_stat_info is_true">
|
||||
<span class="o_stat_text oe_true text-success"><t t-esc="widget.true_string"/></span>
|
||||
<span class="o_stat_text oe_false text-danger"><t t-esc="widget.false_string"/></span>
|
||||
</div>
|
||||
|
||||
</templates>
|
||||
|
||||
@@ -572,6 +572,11 @@ class res_users(osv.osv):
|
||||
def _is_admin(self):
|
||||
return self.id == openerp.SUPERUSER_ID or self.sudo(self).has_group('base.group_erp_manager')
|
||||
|
||||
@api.multi
|
||||
def toggle_active(self):
|
||||
for user in self:
|
||||
user.active = not user.active
|
||||
|
||||
def get_company_currency_id(self, cr, uid, context=None):
|
||||
return self.browse(cr, uid, uid, context=context).company_id.currency_id.id
|
||||
|
||||
|
||||
@@ -171,7 +171,12 @@
|
||||
</header>
|
||||
<sheet>
|
||||
<field name="id" invisible="1"/>
|
||||
<div class="oe_button_box" name="button_box"/>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-check">
|
||||
<field name="active" widget="boolean_button"
|
||||
options='{"true": "Active User", "false": "Inactive User"}'/>
|
||||
</button>
|
||||
</div>
|
||||
<field name="image" widget='image' class="oe_avatar" options='{"preview_image": "image_medium"}'/>
|
||||
<div class="oe_title">
|
||||
<label for="name" class="oe_edit_only"/>
|
||||
@@ -182,7 +187,6 @@
|
||||
<group>
|
||||
<field name="partner_id" readonly="1" required="0" groups="base.group_no_one"
|
||||
attrs="{'invisible': [('id', '=', False)]}"/>
|
||||
<field name="active"/>
|
||||
</group>
|
||||
</div>
|
||||
<notebook colspan="4">
|
||||
@@ -235,6 +239,7 @@
|
||||
<field name="company_ids" string="Company" groups="base.group_light_multi_company"/>
|
||||
<field name="share"/>
|
||||
<filter name="no_share" string="Internal Users" domain="[('share','=',False)]"/>
|
||||
<filter name="Inactive" string="Inactive Users" domain="[('active','=',False)]"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user