Use record and field properties of widget instead of method arguments
issue8020 review58491002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Use record and field properties of widget instead of method arguments
|
||||
* Reduce offset when no search result
|
||||
* Add support for plugins
|
||||
* Add support for expand, height and width attributes
|
||||
|
||||
+134
-100
@@ -352,10 +352,8 @@ function eval_pyson(value){
|
||||
promesses.push(record.load(name));
|
||||
});
|
||||
}
|
||||
var display = function(record, field) {
|
||||
return function(widget) {
|
||||
widget.display(record, field);
|
||||
};
|
||||
var display = function(widget) {
|
||||
widget.display();
|
||||
};
|
||||
return jQuery.when.apply(jQuery,promesses)
|
||||
.done(function() {
|
||||
@@ -369,7 +367,7 @@ function eval_pyson(value){
|
||||
if (field) {
|
||||
field.set_state(record);
|
||||
}
|
||||
widgets.forEach(display(record, field));
|
||||
widgets.forEach(display);
|
||||
}
|
||||
}.bind(this))
|
||||
.done(function() {
|
||||
@@ -1027,7 +1025,9 @@ function eval_pyson(value){
|
||||
this.visible = true;
|
||||
this.labelled = null; // Element which received the labelledby
|
||||
},
|
||||
display: function(record, field) {
|
||||
display: function() {
|
||||
var field = this.field();
|
||||
var record = this.record();
|
||||
var readonly = this.attributes.readonly;
|
||||
var invisible = this.attributes.invisible;
|
||||
var required = this.attributes.required;
|
||||
@@ -1083,7 +1083,7 @@ function eval_pyson(value){
|
||||
invalid_el.removeClass('has-error');
|
||||
}
|
||||
if (invisible === undefined) {
|
||||
invisible = field.get_state_attrs(record).invisible;
|
||||
invisible = field.get_state_attrs(this.record()).invisible;
|
||||
if (invisible === undefined) {
|
||||
invisible = false;
|
||||
}
|
||||
@@ -1114,9 +1114,9 @@ function eval_pyson(value){
|
||||
if (!this.visible) {
|
||||
return;
|
||||
}
|
||||
this.set_value(this.record(), this.field());
|
||||
this.set_value();
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
set_value: function() {
|
||||
},
|
||||
set_readonly: function(readonly) {
|
||||
this._readonly = readonly;
|
||||
@@ -1382,15 +1382,19 @@ function eval_pyson(value){
|
||||
.click(this.translate.bind(this));
|
||||
}
|
||||
},
|
||||
get_client_value: function(record, field) {
|
||||
get_client_value: function() {
|
||||
var field = this.field();
|
||||
var record = this.record();
|
||||
var value = '';
|
||||
if (field) {
|
||||
value = field.get_client(record);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.Char._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.Char._super.display.call(this);
|
||||
|
||||
var record = this.record();
|
||||
if (this.datalist) {
|
||||
this.datalist.children().remove();
|
||||
var set_autocompletion = function() {
|
||||
@@ -1420,13 +1424,13 @@ function eval_pyson(value){
|
||||
width = null;
|
||||
}
|
||||
}
|
||||
this.input.val(this.get_client_value(record, field));
|
||||
this.input.val(this.get_client_value());
|
||||
this.input.attr('maxlength', length);
|
||||
this.input.attr('size', length);
|
||||
this.group.css('width', width);
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
field.set_client(record, this.input.val());
|
||||
set_value: function() {
|
||||
this.field().set_client(this.record(), this.input.val());
|
||||
},
|
||||
set_readonly: function(readonly) {
|
||||
this.input.prop('readonly', readonly);
|
||||
@@ -1537,22 +1541,24 @@ function eval_pyson(value){
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
},
|
||||
get_format: function(record, field) {
|
||||
return field.date_format(record);
|
||||
get_format: function() {
|
||||
return this.field().date_format(this.record());
|
||||
},
|
||||
get_value: function(record, field) {
|
||||
get_value: function() {
|
||||
var value = this.date.data('DateTimePicker').date();
|
||||
if (value) {
|
||||
value.isDate = true;
|
||||
}
|
||||
return value;
|
||||
},
|
||||
display: function(record, field) {
|
||||
display: function() {
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
if (record && field) {
|
||||
this.date.data('DateTimePicker').format(
|
||||
Sao.common.moment_format(this.get_format(record, field)));
|
||||
Sao.common.moment_format(this.get_format()));
|
||||
}
|
||||
Sao.View.Form.Date._super.display.call(this, record, field);
|
||||
Sao.View.Form.Date._super.display.call(this);
|
||||
var value;
|
||||
if (record) {
|
||||
value = field.get_client(record);
|
||||
@@ -1569,8 +1575,8 @@ function eval_pyson(value){
|
||||
focus: function() {
|
||||
this.input.focus();
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
field.set_client(record, this.get_value(record, field));
|
||||
set_value: function() {
|
||||
this.field().set_client(this.record(), this.get_value());
|
||||
},
|
||||
set_readonly: function(readonly) {
|
||||
this.date.find('button').prop('disabled', readonly);
|
||||
@@ -1581,10 +1587,12 @@ function eval_pyson(value){
|
||||
Sao.View.Form.DateTime = Sao.class_(Sao.View.Form.Date, {
|
||||
class_: 'form-datetime',
|
||||
_width: '20em',
|
||||
get_format: function(record, field) {
|
||||
get_format: function() {
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
return field.date_format(record) + ' ' + field.time_format(record);
|
||||
},
|
||||
get_value: function(record, field) {
|
||||
get_value: function() {
|
||||
var value = this.date.data('DateTimePicker').date();
|
||||
if (value) {
|
||||
value.isDateTime = true;
|
||||
@@ -1596,10 +1604,10 @@ function eval_pyson(value){
|
||||
Sao.View.Form.Time = Sao.class_(Sao.View.Form.Date, {
|
||||
class_: 'form-time',
|
||||
_width: '10em',
|
||||
get_format: function(record, field) {
|
||||
return field.time_format(record);
|
||||
get_format: function() {
|
||||
return this.field().time_format(this.record());
|
||||
},
|
||||
get_value: function(record, field) {
|
||||
get_value: function() {
|
||||
var value = this.date.data('DateTimePicker').date();
|
||||
if (value) {
|
||||
value.isTime = true;
|
||||
@@ -1622,8 +1630,9 @@ function eval_pyson(value){
|
||||
}).appendTo(this.el);
|
||||
this.el.change(this.focus_out.bind(this));
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.TimeDelta._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.TimeDelta._super.display.call(this);
|
||||
var record = this.record();
|
||||
if (record) {
|
||||
var value = record.field_get_client(this.field_name);
|
||||
this.input.val(value || '');
|
||||
@@ -1634,8 +1643,8 @@ function eval_pyson(value){
|
||||
focus: function() {
|
||||
this.input.focus();
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
field.set_client(record, this.input.val());
|
||||
set_value: function() {
|
||||
this.field().set_client(this.record(), this.input.val());
|
||||
},
|
||||
set_readonly: function(readonly) {
|
||||
this.input.prop('readonly', readonly);
|
||||
@@ -1669,24 +1678,27 @@ function eval_pyson(value){
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
field.set_client(record, this.input.val(), undefined, this.factor);
|
||||
set_value: function() {
|
||||
this.field().set_client(
|
||||
this.record(), this.input.val(), undefined, this.factor);
|
||||
},
|
||||
get_client_value: function(record, field) {
|
||||
get_client_value: function() {
|
||||
var value = '';
|
||||
var field = this.field();
|
||||
if (field) {
|
||||
value = field.get(record);
|
||||
value = field.get(this.record());
|
||||
if (value !== null) {
|
||||
value *= this.factor;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.Integer._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.Integer._super.display.call(this);
|
||||
var field = this.field();
|
||||
var value = '';
|
||||
if (field) {
|
||||
value = field.get_client(record, this.factor);
|
||||
value = field.get_client(this.record(), this.factor);
|
||||
}
|
||||
this.input_text.val(value);
|
||||
this.input_text.attr('maxlength', this.input.attr('maxlength'));
|
||||
@@ -1708,7 +1720,9 @@ function eval_pyson(value){
|
||||
|
||||
Sao.View.Form.Float = Sao.class_(Sao.View.Form.Integer, {
|
||||
class_: 'form-float',
|
||||
display: function(record, field) {
|
||||
display: function() {
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
var step = 'any';
|
||||
if (record) {
|
||||
var digits = field.digits(record, this.factor);
|
||||
@@ -1720,7 +1734,7 @@ function eval_pyson(value){
|
||||
step = Math.pow(10, -step);
|
||||
}
|
||||
this.input.attr('step', step);
|
||||
Sao.View.Form.Float._super.display.call(this, record, field);
|
||||
Sao.View.Form.Float._super.display.call(this);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1763,7 +1777,9 @@ function eval_pyson(value){
|
||||
}));
|
||||
});
|
||||
},
|
||||
display_update_selection: function(record, field) {
|
||||
display_update_selection: function() {
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
this.update_selection(record, field, function() {
|
||||
if (!field) {
|
||||
this.select.val('');
|
||||
@@ -1795,9 +1811,9 @@ function eval_pyson(value){
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.Selection._super.display.call(this, record, field);
|
||||
this.display_update_selection(record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.Selection._super.display.call(this);
|
||||
this.display_update_selection();
|
||||
},
|
||||
focus: function() {
|
||||
this.select.focus();
|
||||
@@ -1805,9 +1821,9 @@ function eval_pyson(value){
|
||||
value_get: function() {
|
||||
return JSON.parse(this.select.val());
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
set_value: function() {
|
||||
var value = this.value_get();
|
||||
field.set_client(record, value);
|
||||
this.field().set_client(this.record(), value);
|
||||
},
|
||||
set_readonly: function(readonly) {
|
||||
this.select.prop('disabled', readonly);
|
||||
@@ -1833,8 +1849,9 @@ function eval_pyson(value){
|
||||
return !jQuery(this).prop('readonly');
|
||||
});
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.Boolean._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.Boolean._super.display.call(this);
|
||||
var record = this.record();
|
||||
if (record) {
|
||||
this.input.prop('checked', record.field_get(this.field_name));
|
||||
} else {
|
||||
@@ -1844,9 +1861,9 @@ function eval_pyson(value){
|
||||
focus: function() {
|
||||
this.input.focus();
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
set_value: function() {
|
||||
var value = this.input.prop('checked');
|
||||
field.set_client(record, value);
|
||||
this.field().set_client(this.record(), value);
|
||||
},
|
||||
set_readonly: function(readonly) {
|
||||
this.input.prop('readonly', readonly);
|
||||
@@ -1880,8 +1897,9 @@ function eval_pyson(value){
|
||||
button.click(this.translate.bind(this));
|
||||
}
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.Text._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.Text._super.display.call(this);
|
||||
var record = this.record();
|
||||
if (record) {
|
||||
var value = record.field_get_client(this.field_name);
|
||||
this.input.val(value);
|
||||
@@ -1897,9 +1915,9 @@ function eval_pyson(value){
|
||||
focus: function() {
|
||||
this.input.focus();
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
set_value: function() {
|
||||
var value = this.input.val() || '';
|
||||
field.set_client(record, value);
|
||||
this.field().set_client(this.record(), value);
|
||||
},
|
||||
set_readonly: function(readonly) {
|
||||
this.input.prop('readonly', readonly);
|
||||
@@ -2070,9 +2088,10 @@ function eval_pyson(value){
|
||||
}
|
||||
}.bind(this), 0);
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.RichText._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.RichText._super.display.call(this);
|
||||
var value = '';
|
||||
var record = this.record();
|
||||
if (record) {
|
||||
value = record.field_get_client(this.field_name);
|
||||
if(this.attributes.spell) {
|
||||
@@ -2086,17 +2105,17 @@ function eval_pyson(value){
|
||||
focus: function() {
|
||||
this.input.focus();
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
set_value: function() {
|
||||
// avoid modification of not normalized value
|
||||
this._normalize(this.input);
|
||||
var value = this.input.html() || '';
|
||||
var previous = field.get_client(record);
|
||||
var previous = this.field().get_client(this.record());
|
||||
var previous_el = jQuery('<div/>').html(previous || '');
|
||||
this._normalize(previous_el);
|
||||
if (value == previous_el.html()) {
|
||||
value = previous;
|
||||
}
|
||||
field.set_client(record, value);
|
||||
this.field().set_client(this.record(), value);
|
||||
},
|
||||
_normalize: function(el) {
|
||||
// TODO order attributes
|
||||
@@ -2237,20 +2256,19 @@ function eval_pyson(value){
|
||||
}
|
||||
Sao.View.Form.Many2One._super.focus_out.call(this);
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
set_value: function() {
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
if (field.get_client(record) != this.entry.val()) {
|
||||
field.set_client(record, this.value_from_id(null, ''));
|
||||
this.entry.val('');
|
||||
}
|
||||
},
|
||||
display: function(record, field) {
|
||||
var screen_record = this.record();
|
||||
if ((screen_record && record) && (screen_record.id != record.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
display: function() {
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
var text_value, value;
|
||||
Sao.View.Form.Many2One._super.display.call(this, record, field);
|
||||
Sao.View.Form.Many2One._super.display.call(this);
|
||||
|
||||
this._set_button_sensitive();
|
||||
this._set_completion();
|
||||
@@ -2672,8 +2690,10 @@ function eval_pyson(value){
|
||||
}
|
||||
this.record().field_set_client(this.field_name, value);
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
set_value: function() {
|
||||
var value;
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
if (!this.get_model()) {
|
||||
value = this.entry.val();
|
||||
if (jQuery.isEmptyObject(value)) {
|
||||
@@ -2714,9 +2734,9 @@ function eval_pyson(value){
|
||||
this.select.val('');
|
||||
}
|
||||
},
|
||||
display: function(record, field) {
|
||||
this.update_selection(record, field, function() {
|
||||
Sao.View.Form.Reference._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
this.update_selection(this.record(), this.field(), function() {
|
||||
Sao.View.Form.Reference._super.display.call(this);
|
||||
}.bind(this));
|
||||
},
|
||||
set_readonly: function(readonly) {
|
||||
@@ -2959,12 +2979,15 @@ function eval_pyson(value){
|
||||
!this.position || !access.write || !access.read);
|
||||
}
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.One2Many._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.One2Many._super.display.call(this);
|
||||
|
||||
this._set_button_sensitive();
|
||||
|
||||
this.prm.done(function() {
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
|
||||
if (field === undefined) {
|
||||
this.screen.new_group();
|
||||
this.screen.set_current_record(null);
|
||||
@@ -3237,7 +3260,7 @@ function eval_pyson(value){
|
||||
}
|
||||
return prm;
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
set_value: function() {
|
||||
this.screen.save_tree_state();
|
||||
}
|
||||
});
|
||||
@@ -3363,10 +3386,13 @@ function eval_pyson(value){
|
||||
this._position = data[0];
|
||||
this._set_button_sensitive();
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.Many2Many._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.Many2Many._super.display.call(this);
|
||||
|
||||
this.prm.done(function() {
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
|
||||
if (field === undefined) {
|
||||
this.screen.new_group();
|
||||
this.screen.set_current_record(null);
|
||||
@@ -3658,8 +3684,10 @@ function eval_pyson(value){
|
||||
|
||||
this.toolbar('input-group-btn').appendTo(group);
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.Binary._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.Binary._super.display.call(this);
|
||||
|
||||
var recor = this.record(), field = this.field();
|
||||
if (!field) {
|
||||
if (this.text) {
|
||||
this.text.val('');
|
||||
@@ -3696,9 +3724,9 @@ function eval_pyson(value){
|
||||
evt.preventDefault();
|
||||
}
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
set_value: function() {
|
||||
if (this.text) {
|
||||
this.filename_field().set_client(record,
|
||||
this.filename_field().set_client(this.record(),
|
||||
this.text.val() || '');
|
||||
}
|
||||
},
|
||||
@@ -3745,14 +3773,14 @@ function eval_pyson(value){
|
||||
this.select.val(value);
|
||||
}.bind(this));
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
set_value: function() {
|
||||
var value = this.select.val();
|
||||
if (value) {
|
||||
value = value.map(function(e) { return parseInt(e, 10); });
|
||||
} else {
|
||||
value = [];
|
||||
}
|
||||
field.set_client(record, value);
|
||||
this.field().set_client(this.record(), value);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3817,8 +3845,8 @@ function eval_pyson(value){
|
||||
this.update_buttons(Boolean(data));
|
||||
}.bind(this));
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.Image._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.Image._super.display.call(this);
|
||||
this.update_img();
|
||||
}
|
||||
});
|
||||
@@ -3837,9 +3865,11 @@ function eval_pyson(value){
|
||||
this.icon = jQuery('<img/>').appendTo(this.button);
|
||||
this.set_icon();
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.URL._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.URL._super.display.call(this);
|
||||
var url = '';
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
if (record) {
|
||||
url = record.field_get_client(this.field_name);
|
||||
}
|
||||
@@ -3915,10 +3945,11 @@ function eval_pyson(value){
|
||||
}).appendTo(this.el);
|
||||
this.progressbar.css('min-width: 2em');
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.ProgressBar._super.display.call(
|
||||
this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.ProgressBar._super.display.call(this);
|
||||
var value, text;
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
if (!field) {
|
||||
value = 0;
|
||||
text = '';
|
||||
@@ -4057,8 +4088,8 @@ function eval_pyson(value){
|
||||
this.set_value(this.record(), this.field());
|
||||
}
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
field.set_client(record, this.get_value());
|
||||
set_value: function() {
|
||||
this.field().set_client(this.record(), this.get_value());
|
||||
},
|
||||
get_value: function() {
|
||||
var value = {};
|
||||
@@ -4120,9 +4151,11 @@ function eval_pyson(value){
|
||||
|
||||
row.appendTo(this.container);
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.Dict._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.Dict._super.display.call(this);
|
||||
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
if (!field) {
|
||||
return;
|
||||
}
|
||||
@@ -4462,8 +4495,8 @@ function eval_pyson(value){
|
||||
}).appendTo(this.group);
|
||||
this.group.addClass('has-feedback');
|
||||
},
|
||||
display: function(record, field) {
|
||||
Sao.View.Form.PYSON._super.display.call(this, record, field);
|
||||
display: function() {
|
||||
Sao.View.Form.PYSON._super.display.call(this);
|
||||
this.validate_pyson();
|
||||
},
|
||||
get_encoded_value: function() {
|
||||
@@ -4478,9 +4511,11 @@ function eval_pyson(value){
|
||||
return null;
|
||||
}
|
||||
},
|
||||
set_value: function(record, field) {
|
||||
set_value: function() {
|
||||
// avoid modification because different encoding
|
||||
var value = this.get_encoded_value();
|
||||
var record = this.record();
|
||||
var field = this.field();
|
||||
var previous = field.get_client(record);
|
||||
if (previous && Sao.common.compare(
|
||||
value, this.encoder.encode(this.decoder.decode(previous)))) {
|
||||
@@ -4488,9 +4523,8 @@ function eval_pyson(value){
|
||||
}
|
||||
field.set_client(record, value);
|
||||
},
|
||||
get_client_value: function(record, field) {
|
||||
var value = Sao.View.Form.PYSON._super.get_client_value.call(
|
||||
this, record, field);
|
||||
get_client_value: function() {
|
||||
var value = Sao.View.Form.PYSON._super.get_client_value.call(this);
|
||||
if (value) {
|
||||
value = Sao.PYSON.toString(this.decoder.decode(value));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user