summaryrefslogtreecommitdiff
path: root/addons/base/static/src
diff options
context:
space:
mode:
authorFabien Meghazi <fme@openerp.com>2011-08-31 14:45:38 +0200
committerFabien Meghazi <fme@openerp.com>2011-08-31 14:45:38 +0200
commitb44295bba90d1e853d0a73df3a42a6b64ba718fc (patch)
treeb36f50c005365dbc15072ff57318524544510350 /addons/base/static/src
parent5b8ad8068bac7f124071249899e91822f11f194f (diff)
[IMP] Many improvements to form frame rendering (with computation algorithm)
bzr revid: fme@openerp.com-20110831124538-xt3px1rv8ys181se
Diffstat (limited to 'addons/base/static/src')
-rw-r--r--addons/base/static/src/css/base.css3
-rw-r--r--addons/base/static/src/js/form.js56
-rw-r--r--addons/base/static/src/xml/base.xml13
3 files changed, 49 insertions, 23 deletions
diff --git a/addons/base/static/src/css/base.css b/addons/base/static/src/css/base.css
index 4133a9c8623..a33bdce973b 100644
--- a/addons/base/static/src/css/base.css
+++ b/addons/base/static/src/css/base.css
@@ -931,6 +931,9 @@ label.error {
margin: 3px 4px 3px 1px;
height: 15px;
}
+.openerp .oe_form_frame_cell.oe_form_separator_vertical {
+ border-left: 1px solid #666;
+}
.openerp td.required input, .openerp td.required select {
background-color: #D2D2FF !important;
}
diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js
index e2a99e9b8c5..11ddc1a3850 100644
--- a/addons/base/static/src/js/form.js
+++ b/addons/base/static/src/js/form.js
@@ -83,9 +83,11 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormVi
this.$form_header.find('button.oe_form_button_cancel').click(this.do_cancel);
this.$form_header.find('button.oe_form_button_new').click(this.on_button_new);
- this.$form_header.find('button.oe_get_xml_view').click(function() {
- $('<xmp>' + openerp.base.json_node_to_xml(self.fields_view.arch, true) + '</xmp>').dialog({ width: '95%', height: 600});
- });
+ if (this.session.debug) {
+ this.$form_header.find('button.oe_get_xml_view').click(function() {
+ $('<xmp>' + openerp.base.json_node_to_xml(self.fields_view.arch, true) + '</xmp>').dialog({ width: '95%', height: 600});
+ });
+ }
if (this.options.sidebar && this.options.sidebar_id) {
this.sidebar = new openerp.base.Sidebar(this, this.options.sidebar_id);
@@ -577,17 +579,23 @@ openerp.base.form.Widget = openerp.base.Widget.extend({
this.view.widgets[this.element_id] = this;
this.children = node.children;
- this.colspan = parseInt(node.attrs.colspan || 1);
+ this.colspan = parseInt(node.attrs.colspan || 1, 10);
+ this.decrease_max_width = 0;
this.string = this.string || node.attrs.string;
this.help = this.help || node.attrs.help;
this.invisible = this.modifiers['invisible'] === true;
+ this.classname = 'oe_form_' + this.type;
+
+ this.width = this.node.attrs.width;
},
start: function() {
this.$element = $('#' + this.element_id);
},
stop: function() {
- this.$element.remove();
+ if (this.$element) {
+ this.$element.remove();
+ }
},
process_modifiers: function() {
var compute_domain = openerp.base.form.compute_domain;
@@ -608,7 +616,7 @@ openerp.base.form.WidgetFrame = openerp.base.form.Widget.extend({
template: 'WidgetFrame',
init: function(view, node) {
this._super(view, node);
- this.columns = node.attrs.col || 4;
+ this.columns = parseInt(node.attrs.col || 4, 10);
this.x = 0;
this.y = 0;
this.table = [];
@@ -634,15 +642,21 @@ openerp.base.form.WidgetFrame = openerp.base.form.Widget.extend({
return row;
},
set_row_cells_with: function(row) {
+ var bypass = 0,
+ max_width = 100;
+ for (var i = 0; i < row.length; i++) {
+ bypass += row[i].width === undefined ? 0 : 1;
+ max_width -= row[i].decrease_max_width;
+ }
+ var size_unit = Math.round(max_width / (this.columns - bypass)),
+ colspan_sum = 0;
for (var i = 0; i < row.length; i++) {
var w = row[i];
- if (w.is_field_label) {
- w.width = "1%";
- if (row[i + 1]) {
- row[i + 1].width = Math.round((100 / this.columns) * (w.colspan + 1) - 1) + '%';
- }
- } else if (w.width === undefined) {
- w.width = Math.round((100 / this.columns) * w.colspan) + '%';
+ colspan_sum += w.colspan;
+ if (w.width === undefined) {
+ var width = (i === row.length - 1 && colspan_sum === this.columns) ? max_width : Math.round(size_unit * w.colspan);
+ max_width -= width;
+ w.width = width + '%';
}
}
},
@@ -732,6 +746,11 @@ openerp.base.form.WidgetSeparator = openerp.base.form.Widget.extend({
init: function(view, node) {
this._super(view, node);
this.template = "WidgetSeparator";
+ this.orientation = node.attrs.orientation || 'horizontal';
+ if (this.orientation === 'vertical') {
+ this.width = '1';
+ }
+ this.classname += '_' + this.orientation;
}
});
@@ -795,14 +814,15 @@ openerp.base.form.WidgetLabel = openerp.base.form.Widget.extend({
this._super(view, node);
// TODO fme: support for attrs.align
- if (this.node.tag == 'label' && this.node.attrs.colspan) {
- this.is_field_label = false;
+ if (this.node.tag == 'label' && (this.node.attrs.colspan || (this.string && this.string.length > 32))) {
this.template = "WidgetParagraph";
- this.colspan = this.node.attrs.colspan;
+ this.colspan = parseInt(this.node.attrs.colspan || 1, 10);
} else {
- this.is_field_label = true;
this.template = "WidgetLabel";
this.colspan = 1;
+ this.width = '1%';
+ this.decrease_max_width = 1;
+ this.nowrap = true;
}
},
render: function () {
@@ -844,6 +864,8 @@ openerp.base.form.Field = openerp.base.form.Widget.extend({
this.required = this.modifiers['required'] === true;
this.invalid = false;
this.dirty = false;
+
+ this.classname = 'oe_form_field_' + this.type;
},
start: function() {
this._super.apply(this, arguments);
diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml
index c6bd9a1ee19..b308d1c7856 100644
--- a/addons/base/static/src/xml/base.xml
+++ b/addons/base/static/src/xml/base.xml
@@ -622,7 +622,7 @@
</t>
<t t-name="FormView">
<div class="oe_form_header" t-att-id="view.element_id + '_header'">
- <h2 class="oe_view_title"><t t-esc="view.fields_view.arch.attrs.string"/> <button class="oe_get_xml_view">xml</button></h2>
+ <h2 class="oe_view_title"><t t-esc="view.fields_view.arch.attrs.string"/> <button t-if="view.session.debug" class="oe_get_xml_view">View#<t t-esc="view.fields_view.view_id"/></button></h2>
<div class="oe_form_buttons" t-if="view.options.action_buttons !== false">
<!--<button type="button" class="oe_form_button_save">
<span class="oe_form_on_update">Save</span>
@@ -690,11 +690,11 @@
<tr t-foreach="widget.table" t-as="row">
<t t-foreach="row" t-as="td">
<td t-att-colspan="td.colspan gt 1 ? td.colspan : undefined"
- t-att-width="td.width ? td.width : undefined"
- t-att-nowrap="td.is_field_label or td.is_field_m2o? 'true' : undefined"
+ t-att-width="td.width"
+ t-att-nowrap="td.nowrap or td.is_field_m2o? 'true' : undefined"
t-att-valign="td.table ? 'top' : undefined"
t-att-id="td.element_id"
- t-att-class="'oe_form_frame_cell oe_form_' + (td.is_field_label ? 'label' : (td.field ? 'field_' + td.type : td.type))"
+ t-attf-class="oe_form_frame_cell #{td.classname}"
>
<t t-raw="td.render()"/>
</td>
@@ -720,7 +720,7 @@
</div>
</t>
<t t-name="WidgetSeparator">
- <div t-att-class="'separator ' + (widget.node.attrs.orientation || 'horizontal')">
+ <div t-if="widget.orientation !== 'vertical'" t-att-class="'separator ' + widget.orientation">
<t t-esc="widget.string"/>
</div>
</t>
@@ -861,7 +861,8 @@
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center">
- <img src="/base/static/src/img/placeholder.png" class="oe-binary-image" border="1"
+ <img src="/base/static/src/img/placeholder.png" class="oe-binary-image"
+ t-att-border="widget.readonly ? 0 : 1"
t-att-id="widget.element_id + '_field'"
t-att-name="widget.name"
t-att-class="'field_' + widget.type"