forked from Techsystech/web
manage states (readonly/disabled) on form view
parent
af3d1ac503
commit
9ce5e96ad8
|
@ -13,63 +13,64 @@ openerp.web_widget_boolean_switch = function(instance){
|
||||||
var options = options ? options : {};
|
var options = options ? options : {};
|
||||||
this.checkboxes = checkboxes;
|
this.checkboxes = checkboxes;
|
||||||
var switchOptions = {
|
var switchOptions = {
|
||||||
'readonly': options.hasOwnProperty('readonly') ? options.readonly : true,
|
'readonly': options.hasOwnProperty('readonly') ? options.readonly : false,
|
||||||
|
'disabled': options.hasOwnProperty('disabled') ? options.disabled : false,
|
||||||
};
|
};
|
||||||
if(options.hasOwnProperty('readonly')){
|
if(options.hasOwnProperty('onSwitchChange')){
|
||||||
switchOptions.onSwitchChange = options.onSwitchChange
|
switchOptions.onSwitchChange = options.onSwitchChange
|
||||||
}
|
}
|
||||||
'onSwitchChange'
|
|
||||||
this.checkboxes.bootstrapSwitch(switchOptions);
|
this.checkboxes.bootstrapSwitch(switchOptions);
|
||||||
},
|
},
|
||||||
start: function(){
|
|
||||||
debugger;
|
|
||||||
},
|
|
||||||
set_value: function(value){
|
set_value: function(value){
|
||||||
// the third parameter tell if we should skip to fire evnets
|
// the third parameter tell if we should skip to fire evnets
|
||||||
this.checkboxes.bootstrapSwitch('state', value, false);
|
this.checkboxes.bootstrapSwitch('state', value, true);
|
||||||
|
},
|
||||||
|
set_readonly: function(value){
|
||||||
|
this.checkboxes.bootstrapSwitch('readonly', value);
|
||||||
|
},
|
||||||
|
set_disabled: function(value){
|
||||||
|
this.checkboxes.bootstrapSwitch('disabled', value);
|
||||||
},
|
},
|
||||||
// set_readonly: function(value){
|
|
||||||
// // the third parameter tell if we should skip to fire evnets
|
|
||||||
// this.checkboxes.bootstrapSwitch({'readonly': value});
|
|
||||||
// },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Form view
|
// Form view
|
||||||
|
|
||||||
instance.web.form.FieldBooleanSwitch = instance.web.form.AbstractField.extend(
|
instance.web.form.FieldBooleanSwitch = instance.web.form.AbstractField.extend({
|
||||||
instance.web.form.ReinitializeFieldMixin, {
|
|
||||||
|
|
||||||
template: 'FieldBooleanSwitch',
|
template: 'FieldBooleanSwitch',
|
||||||
|
|
||||||
start: function() {
|
init: function(field_manager, node){
|
||||||
var self = this;
|
this._super(field_manager, node);
|
||||||
//TODO: Get options from xmlview to init widget
|
},
|
||||||
|
start: function(){
|
||||||
this.$checkbox = $("input", this.$el);
|
this.$checkbox = $("input", this.$el);
|
||||||
this.widget = new openerp.instances.instance0.web.BooleanSwitchWidget(
|
var readonly = this.modifiers &&
|
||||||
|
this.modifiers.hasOwnProperty('readonly') ?
|
||||||
|
this.modifiers.readonly : false;
|
||||||
|
this.quick_edit = this.options &&
|
||||||
|
this.options.hasOwnProperty('quick_edit') ?
|
||||||
|
this.options.quick_edit : false;
|
||||||
|
var disabled = !this.quick_edit;
|
||||||
|
this.switcher = new openerp.instances.instance0.web.BooleanSwitchWidget(
|
||||||
this.$checkbox, {
|
this.$checkbox, {
|
||||||
|
'readonly': readonly,
|
||||||
|
'disabled': disabled,
|
||||||
onSwitchChange: _.bind(function(event, state) {
|
onSwitchChange: _.bind(function(event, state) {
|
||||||
this.internal_set_value(this.$checkbox.is(':checked'));
|
this.internal_set_value(this.$checkbox.is(':checked'));
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}, this)
|
}, this)
|
||||||
});
|
});
|
||||||
|
this.on("change:effective_readonly", this, this.switcher_states);
|
||||||
this.setupFocus(this.$checkbox);
|
this._super();
|
||||||
//TODO: use initialize_content to change
|
},
|
||||||
// var check_readonly = function() {
|
switcher_states: function () {
|
||||||
// self.$checkbox.prop('disabled', self.get("effective_readonly"));
|
if (this.quick_edit)
|
||||||
// };
|
return;
|
||||||
// this.on("change:effective_readonly", this, check_readonly);
|
this.switcher.set_disabled(this.get('effective_readonly'))
|
||||||
// check_readonly.call(this);
|
|
||||||
this._super.apply(this, arguments);
|
|
||||||
},
|
},
|
||||||
render_value: function() {
|
render_value: function() {
|
||||||
this.widget.set_value(this.get('value'));
|
this.switcher.set_value(this.get('value'));
|
||||||
//this.$checkbox.bootstrapSwitch('state', this.get('value'), true);
|
|
||||||
},
|
},
|
||||||
focus: function() {
|
|
||||||
var input = this.$checkbox && this.$checkbox[0];
|
|
||||||
return input ? input.focus() : false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// List view
|
// List view
|
||||||
|
|
Loading…
Reference in New Issue