From 0a71d06be3909cfde8e3bd41752af2ba84dae023 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 12 Mar 2014 14:22:13 +0100 Subject: [PATCH] [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 --- addons/web/static/src/css/base.css | 17 ++++++++++++ addons/web/static/src/css/base.sass | 14 ++++++++++ addons/web/static/src/js/view_form.js | 37 +++++++++++++++++++++++++-- addons/web/static/src/xml/base.xml | 10 ++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index e43a2fb654e..263a867390e 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -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; diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index b19db9e4ebd..2d5ae82135e 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -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 diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index f1fc377fa94..a8973d760fa 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -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 = ""; + } + + }, + +}); + /** * 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({ diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 80b82c1f40b..fa96fe1ac8a 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1360,6 +1360,16 @@ + + +