this.fields_view = data;
this.rendering_engine.set_fields_view(data);
- this.rendering_engine.render_to(this.$element.find('.oe_form_content'));
+ this.rendering_engine.render_to(this.$element.find('.oe_form_container'));
this.$form_header = this.$element.find('.oe_form_header:first');
this.$form_header.find('div.oe_form_pager button[data-pager-action]').click(function() {
}
// form field
if (self.fields[field]) {
- var value = self.fields[field].get_on_change_value();
+ var value = self.fields[field].get_value();
return value == null ? false : value;
}
// parent field
value = response.value[fieldname];
} else {
// otherwise get form value for field
- value = self.fields[fieldname].get_on_change_value();
+ value = self.fields[fieldname].get_value();
}
var condition = fieldname + '=' + value;
openerp.web.FormRenderingEngine = openerp.web.Class.extend({
init: function(view) {
this.view = view;
+ this.legacy_mode = false;
},
set_fields_view: function(fvg) {
this.fvg = fvg;
+ this.legacy_mode = (this.fvg.arch.tag === 'form');
},
set_registry: function(registry) {
this.registry = registry;
render_to: function($element) {
var self = this;
this.$element = $element;
-
- this.fields_prefix = this.view.dataset ? this.view.dataset.model : '';
-
+
// TODO: I know this will save the world and all the kitten for a moment,
// but one day, we will have to get rid of xml2json
var xml = openerp.web.json_node_to_xml(this.fvg.arch);
this.$form = $(xml);
this.process(this.$form);
-
- this.$form.children().appendTo(this.$element);
+
+ this.$form.appendTo(this.$element);
// OpenERP views spec :
// - @width is obsolete ?
- // TODO: modifiers invisible. Add a special attribute, eg: data-invisible that should be used in order to create openerp.form.InvisibleWidgetG
this.$element.find('field, button').each(function() {
var $elem = $(this),
w.replace($elem);
}
});
- $('<button>Debug layout</button>').appendTo(this.$element).click(this.do_toggle_layout_debugging);
+ $('<button>Debug layout</button>').appendTo(this.$element).click($.proxy(this.toggle_layout_debugging, this));
+ },
+ render_element: function(template, dict) {
+ dict = dict || {};
+ dict.legacy_mode = this.legacy_mode;
+ return $(QWeb.render(template, dict));
},
alter_field: function(field) {},
- do_toggle_layout_debugging: function() {
+ toggle_layout_debugging: function() {
if (!this.$element.has('.oe_layout_debug_cell:first').length) {
this.$element.find('.oe_form_group_cell').each(function() {
- var $span = $('<span class="oe_layout_debug_cell"/>').text($(this).attr('width'));
+ var text = 'W:' + ($(this).attr('width') || '') + ' - C:' + $(this).attr('colspan'),
+ $span = $('<span class="oe_layout_debug_cell"/>').text(text);
$span.prependTo($(this));
});
}
return $tag;
}
},
+ process_form: function($form) {
+ var $new_form = this.render_element('FormRenderingForm', $form.getAttributes());
+ $dst = this.legacy_mode ? $new_form.find('group:first') : $new_form;
+ $form.children().appendTo($dst);
+ if ($form[0] === this.$form[0]) {
+ // If root element, replace it
+ this.$form = $new_form;
+ } else {
+ $form.before($new_form).remove();
+ }
+ this.process($new_form);
+ },
preprocess_field: function($field) {
var name = $field.attr('name'),
field_orm = this.fvg.fields[name],
$table = $new_group.find('table:first');
}
$table.addClass('oe_form_group');
- var $tr,
+ var $tr, $td,
cols = parseInt($group.attr('col') || 4, 10),
row_cols = cols;
var children = [];
- $group.children().each(function() {
+ $group.children().each(function(a,b,c) {
var $child = $(this),
colspan = parseInt($child.attr('colspan') || 1, 10),
tagName = $child[0].tagName.toLowerCase();
row_cols = cols;
}
row_cols -= colspan;
- var $td = $('<td/>').addClass('oe_form_group_cell').attr('colspan', colspan);
+ $td = $('<td/>').addClass('oe_form_group_cell').attr('colspan', colspan);
$tr.append($td.append($child));
children.push($child[0]);
});
+ if (row_cols) {
+ $td.attr('colspan', parseInt($td.attr('colspan'), 10) + row_cols);
+ }
$group.before($new_group).remove();
// Now compute width of cells
},
process_notebook: function($notebook) {
var self = this;
- $notebook.children().each(function() {
- self.process($(this));
- });
var pages = [];
$notebook.find('> page').each(function() {
var $page = $(this),
page_attrs = $page.getAttributes();
page_attrs.id = _.uniqueId('notebook_page_');
pages.push(page_attrs);
- var $new_page = $(QWeb.render('FormRenderingNotebookPage', page_attrs));
- $page.children().appendTo($new_page);
+ var $new_page = self.render_element('FormRenderingNotebookPage', page_attrs),
+ $dst = self.legacy_mode ? $new_page.find('group:first') : $new_page;
+ $page.children().appendTo($dst);
$page.before($new_page).remove();
});
var $new_notebook = $(QWeb.render('FormRenderingNotebook', { pages : pages }));
$notebook.children().appendTo($new_notebook);
$notebook.before($new_notebook).remove();
+ $new_notebook.children().each(function() {
+ self.process($(this));
+ });
$new_notebook.tabs();
return $new_notebook;
},
init: function(field_manager, node) {
this._super(field_manager, node);
this.name = this.node.attrs.name;
- this.value = undefined;
+ this.value = false;
this.view.fields[this.name] = this;
this.view.fields_order.push(this.name);
this.type = this.node.attrs.widget;
this.on("change:force_readonly", this, test_effective_readonly);
_.bind(test_effective_readonly, this)();
+ // TODO: do something good about this
if (this.view) {
this.$label = this.view.$element.find('label[for="' + this.name + '"]');
if (this.$label.length) {
is_dirty: function() {
return this.dirty && !this.get("effective_readonly");
},
- get_on_change_value: function() {
- return this.get_value();
- },
update_dom: function(show_invalid) {
this._super.apply(this, arguments);
if (this.field.translate) {
this.render_value();
});
this.initialize_content();
+ this.render_value();
},
/**
* Called to destroy anything that could have been created previously, called before a
openerp.web.form.FieldFloat = openerp.web.form.FieldChar.extend({
init: function (view, node) {
this._super(view, node);
+ this.value = 0;
if (this.node.attrs.digits) {
- this.parse_digits(this.node.attrs.digits);
+ this.digits = py.eval(this.node.attrs.digits).toJSON();
} else {
this.digits = this.field.digits;
}
},
- parse_digits: function (digits_attr) {
- // could use a Python parser instead.
- var match = /^\s*[\(\[](\d+),\s*(\d+)/.exec(digits_attr);
- return [parseInt(match[1], 10), parseInt(match[2], 10)];
- },
set_value: function(value) {
if (value === false || value === undefined) {
// As in GTK client, floats default to 0
this.new_object();
}
},
+ stop: function () {
+ this.$element.dialog('close');
+ this._super();
+ },
setup_search_view: function(search_defaults) {
var self = this;
if (this.searchview) {
template: 'FieldBinaryImage',
initialize_content: function() {
this._super();
- this.$image = this.$element.find('img.oe-binary-image');
+ this.$placeholder = $(".oe_form_field-binary-image-placeholder", this.$element);
if (!this.get("effective_readonly"))
this.$element.find('.oe-binary').show();
else
this.render_value();
},
render_value: function() {
- this.set_image_maxwidth();
-
var url;
if (this.value && this.value.substr(0, 10).indexOf(' ') == -1) {
url = 'data:image/png;base64,' + this.value;
- } else {
+ } else if (this.value) {
url = '/web/binary/image?session_id=' + this.session.session_id + '&model=' +
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name + '&t=' + (new Date().getTime());
+ } else {
+ url = "/web/static/src/img/placeholder.png";
}
- this.$image.attr('src', url);
- },
- set_image_maxwidth: function() {
- this.$image.css('max-width', this.$element.width());
+ var rendered = QWeb.render("FieldBinaryImage-img", {widget: this, url: url});;
+ this.$placeholder.html(rendered);
},
on_file_change: function() {
- this.set_image_maxwidth();
+ this.render_value();
this._super.apply(this, arguments);
},
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
this.value = file_base64;
this.binary_value = true;
- this.$image.attr('src', 'data:' + (content_type || 'image/png') + ';base64,' + file_base64);
+ this.render_value();
},
on_clear: function() {
this._super.apply(this, arguments);
- this.$image.attr('src', '/web/static/src/img/placeholder.png');
+ this.render_value();
}
});