Browse Source

[IMP] improve code in method clean_radio_in_records, using method write from dataset

pull/351/head
Cesar Lage 9 years ago
parent
commit
908f8afc19
  1. 54
      web_widget_radio_tree/static/src/js/widget.js

54
web_widget_radio_tree/static/src/js/widget.js

@ -20,22 +20,16 @@ openerp.web_widget_radio_tree = function (instance) {
instance.web.form.RadioTree = instance.web.form.FieldBoolean.extend({ instance.web.form.RadioTree = instance.web.form.FieldBoolean.extend({
template: 'RadioTree', template: 'RadioTree',
start: function() { start: function() {
var self = this;
this._super.apply(this, arguments);
this.$checkbox = $('input', this.$el); this.$checkbox = $('input', this.$el);
var radio_name = this.__parentedParent.model + '_' + this.$checkbox[0].name;
var radio_name = this.getParent().model + '_' + this.$checkbox[0].name;
this.$checkbox.attr('name', radio_name); this.$checkbox.attr('name', radio_name);
this.setupFocus(this.$checkbox);
var self = this;
this.$el.click(_.bind(function() { this.$el.click(_.bind(function() {
self.clean_radio_in_records(); self.clean_radio_in_records();
this.internal_set_value(true); this.internal_set_value(true);
}, this)); }, this));
var check_readonly = function() {
self.$checkbox.prop('disabled', self.get('effective_readonly'));
self.click_disabled_boolean();
};
this.on('change:effective_readonly', this, check_readonly);
check_readonly.call(this);
return this._super.apply(this, arguments);
}, },
click_disabled_boolean: function(){ click_disabled_boolean: function(){
var $disabled = this.$el.find('input[type=radio]:disabled'); var $disabled = this.$el.find('input[type=radio]:disabled');
@ -45,46 +39,14 @@ openerp.web_widget_radio_tree = function (instance) {
}); });
}, },
clean_radio_in_records: function() { clean_radio_in_records: function() {
var parent = this.getParent();
var name = (this.$checkbox[0].name).split('_')[1]; var name = (this.$checkbox[0].name).split('_')[1];
var ids = this.__parentedParent.dataset.ids;
var current_id = this.__parentedParent.datarecord.id;
// updating write hash
var already_added = [];
var to_write = this.__parentedParent.dataset.to_write;
for (var j=0; j<to_write.length; ++j) {
if (to_write[j]['id'] == current_id) {
to_write[j]['values'][name] = true;
}
else {
to_write[j]['values'][name] = false;
}
if (ids.includes(to_write[j]['id'])) {
already_added.push(to_write[j]['id']);
}
}
for (var j=0; j<ids.length; ++j) {
if (!already_added.includes(ids[j]) && ids[j] != current_id) {
values = {};
_.each(parent.dataset.ids, function(id) {
values = {}
values[name] = false; values[name] = false;
this.__parentedParent.dataset.to_write.push({
id: ids[j],
values: values
parent.dataset.write(id, values);
}); });
} }
}
// updating create hash
var to_create = this.__parentedParent.dataset.to_create;
for (var j=0; j<to_create.length; ++j) {
if (to_create[j]['id'] == current_id) {
to_create[j]['values'][name] = true;
}
else {
to_create[j]['values'][name] = false;
}
}
}
}); });
}; };
Loading…
Cancel
Save