[FIX] widgets client action handler: one action per widget

bzr revid: xmo@openerp.com-20110825123445-ayhaeipasl4imvqt
This commit is contained in:
Xavier Morel
2011-08-25 14:34:45 +02:00
parent b5a429d008
commit b8cd28fb35
2 changed files with 33 additions and 37 deletions
@@ -372,39 +372,36 @@ openerp.base_dashboard.ApplicationTiles = openerp.base.View.extend({
}
});
openerp.base.client_actions.add(
'board.home.widgets', 'openerp.base_dashboard.Widgets');
openerp.base_dashboard.Widgets = openerp.base.View.extend({
template: 'HomeWidgets',
start: function () {
return new openerp.base.DataSetSearch(
this, 'res.widget.user', null,
['|', ['user_id', '=', false],
['user_id', '=', parseInt(this.session.uid, 10)]])
.read_slice(['widget_id', 'user_id'], {}, this.on_widgets_list_loaded);
'board.home.widgets', 'openerp.base_dashboard.Widget');
openerp.base_dashboard.Widget = openerp.base.View.extend(/** @lends openerp.base_dashboard.Widgets# */{
template: 'HomeWidget',
/**
* Initializes a "HomeWidget" client widget: handles the display of a given
* res.widget objects in an OpenERP view (mainly a dashboard).
*
* @constructs
* @extends openerp.base.View
* @param {Object} parent
* @param {Object} options
* @param {Number} options.widget_id
*/
init: function (parent, options) {
this._super(parent);
this.widget_id = options.widget_id;
},
on_widgets_list_loaded: function (user_widgets) {
var self = this;
var widget_user = {};
_(user_widgets).each(function (widget) {
widget['widget_id'] = widget['widget_id'][0];
widget_user[widget['widget_id']] = {
removable: widget['user_id'] !== false,
user_widget_id: widget['id']
};
});
new openerp.base.DataSetSearch(this, 'res.widget')
.read_ids(_(user_widgets).pluck('widget_id'), ['title'], function (widgets) {
_(widgets).each(function (widget) {
_.extend(widget, widget_user[widget['id']]);
});
var url = _.sprintf(
'/base_dashboard/widgets/content?session_id=%s&widget_id=',
self.session.session_id);
self.$element.html(QWeb.render('HomeWidgets', {
widgets: widgets,
url: url
}));
});
start: function () {
return new openerp.base.DataSet(this, 'res.widget').read_ids(
[this.widget_id], ['title'], this.on_widget_loaded);
},
on_widget_loaded: function (widgets) {
var widget = widgets[0];
var url = _.sprintf(
'/base_dashboard/widgets/content?session_id=%s&widget_id=%d',
this.session.session_id, widget.id);
this.$element.html(QWeb.render('HomeWidget.content', {
widget: widget,
url: url
}));
}
});
};
@@ -107,10 +107,9 @@
</td>
</tr>
</table>
<div t-name="HomeWidgets" class="oe-dashboard-home-widgets"/>
<div t-name="HomeWidgets.content" class="oe-dashboard-home-widgets-widget"
t-foreach="widgets" t-as="widget">
<div t-name="HomeWidget" class="oe-dashboard-home-widget"/>
<t t-name="HomeWidget.content">
<h3><t t-esc="widget.title"/></h3>
<iframe width="100%" frameborder="0" t-att-src="url + widget.id"/>
</div>
<iframe width="100%" frameborder="0" t-att-src="url"/>
</t>
</template>