[IMP] work in progress on stats buttons. The goal is to allow buttons with dynamic/statistical informations in form views (addon web)

bzr revid: ged@openerp.com-20140312132213-hclaw6jc87u220zq
This commit is contained in:
Gery Debongnie 2014-03-12 14:22:13 +01:00
parent 36f2ff879a
commit 0a71d06be3
4 changed files with 76 additions and 2 deletions

View File

@ -462,6 +462,23 @@
.openerp .oe_button_box button {
margin: 4px;
}
.openerp .oe_button_box .oe_stat_button {
font-weight: normal;
display: inline-table;
width: 48% !important;
height: 45px;
margin: 1px;
}
.openerp .oe_button_box .oe_stat_button > div {
display: table-cell;
vertical-align: middle;
padding: 0;
}
.openerp .oe_button_box .oe_stat_button .stat_button_icon {
color: #7c7bad;
font-size: 24px;
padding: 4px;
}
.openerp .oe_avatar > img {
max-height: 90px;
max-width: 90px;

View File

@ -433,6 +433,20 @@ $sheet-padding: 16px
text-align: right
button
margin: 4px
.oe_stat_button
font-weight: normal
display: inline-table
width: 48% !important
height: 45px
margin: 1px
> div
display: table-cell
vertical-align: middle
padding: 0
.stat_button_icon
color: #7C7BAD
font-size: 24px
padding: 4px
.oe_avatar
> img
max-height: 90px

View File

@ -1218,6 +1218,9 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt
$('button', doc).each(function() {
$(this).attr('data-button-type', $(this).attr('type')).attr('type', 'button');
});
$('statbutton', doc).each(function() {
$(this).attr('data-button-type', $(this).attr('type')).attr('type', 'button');
});
// IE's html parser is also a css parser. How convenient...
$('board', doc).each(function() {
$(this).attr('layout', $(this).attr('style'));
@ -1277,6 +1280,9 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt
var defs = [];
_.each(this.to_replace, function(el) {
defs.push(el[0].replace(el[1]));
if (el[1].children().length) {
el[0].$el.append(el[1].children());
}
});
this.to_replace = [];
return $.when.apply($, defs);
@ -1304,7 +1310,7 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt
var tagname = $tag[0].nodeName.toLowerCase();
if (this.tags_registry.contains(tagname)) {
this.tags_to_init.push($tag);
return $tag;
return (tagname === 'statbutton') ? this.process_statbutton($tag) : $tag;
}
var fn = self['process_' + tagname];
if (fn) {
@ -1321,6 +1327,17 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt
return $tag;
}
},
process_statbutton: function ($button) {
var self = this;
console.log('yenrst');
if ($button.children().length) {
$button.children().each(function() {
self.process($(this));
});
}
return $button;
},
process_widget: function($widget) {
this.widgets_to_init.push($widget);
return $widget;
@ -1976,7 +1993,6 @@ instance.web.form.WidgetButton = instance.web.form.FormWidget.extend({
var self = this;
var context = this.build_context();
return this.view.do_execute_action(
_.extend({}, this.node.attrs, {context: context}),
this.view.dataset, this.view.datarecord.id, function () {
@ -1990,6 +2006,22 @@ instance.web.form.WidgetButton = instance.web.form.FormWidget.extend({
}
});
instance.web.form.StatButton = instance.web.form.WidgetButton.extend({
template: 'StatButton',
init: function(field_manager, node) {
var icon = node.attrs.icon;
this._super(field_manager, node);
// debugger;
if (icon) {
this.icon = "<span class=\"fa " + icon + "\"></span>";
}
},
});
/**
* Interface to be implemented by fields.
*
@ -5899,6 +5931,7 @@ instance.web.form.widgets = new instance.web.Registry({
*/
instance.web.form.tags = new instance.web.Registry({
'button' : 'instance.web.form.WidgetButton',
'statbutton' : 'instance.web.form.StatButton',
});
instance.web.form.custom_widgets = new instance.web.Registry({

View File

@ -1360,6 +1360,16 @@
<span t-if="widget.string"><t t-esc="widget.string"/></span>
</button>
</t>
<t t-name="StatButton">
<label type="button" class="oe_stat_button btn btn-default"
t-att-style="widget.node.attrs.style"
t-att-tabindex="widget.node.attrs.tabindex"
t-att-autofocus="widget.node.attrs.autofocus"
t-att-accesskey="widget.node.attrs.accesskey">
<t t-if="widget.icon"><div class="stat_button_icon"><t t-raw="widget.icon"/></div></t>
<span t-if="widget.string"><t t-esc="widget.string"/></span>
</label>
</t>
<t t-name="WidgetButton.tooltip" t-extend="WidgetLabel.tooltip">
<t t-jquery="div.oe_tooltip_string" t-operation="replace">
<div class="oe_tooltip_string" t-if="debug || widget.string">