bzr revid: nicolas.vanhoren@openerp.com-20110822091110-xflm02no7auscyxx
This commit is contained in:
niv-openerp 2011-08-22 11:11:10 +02:00
commit 0f296d6a9c
4 changed files with 61 additions and 39 deletions

View File

@ -30,11 +30,15 @@ openerp.base.ActionManager = openerp.base.Widget.extend({
this.dialog = null;
}
},
inner_stop: function () {
content_stop: function () {
if (this.inner_viewmanager) {
this.inner_viewmanager.stop();
this.inner_viewmanager = null;
}
if (this.client_widget) {
this.client_widget.stop();
this.client_widget = null;
}
},
url_update: function(action) {
// this.url = {
@ -89,7 +93,7 @@ openerp.base.ActionManager = openerp.base.Widget.extend({
this.dialog.open();
} else {
this.dialog_stop();
this.inner_stop();
this.content_stop();
this.inner_viewmanager = new openerp.base.ViewManagerAction(this, action);
this.inner_viewmanager.appendTo(this.$element);
this.url_update(action);
@ -114,8 +118,9 @@ openerp.base.ActionManager = openerp.base.Widget.extend({
});
},
ir_actions_client: function (action) {
this.client_widget = openerp.base.client_actions.get_object(action.tag);
new this.client_widget(this, this.element_id, action.params).start();
this.content_stop();
var ClientWidget = openerp.base.client_actions.get_object(action.tag);
(this.client_widget = new ClientWidget(this, action.params)).appendTo(this);
}
});

View File

@ -345,14 +345,11 @@ openerp.base_dashboard.ConfigOverview = openerp.base.View.extend({
openerp.base.client_actions.add(
'board.home.applications', 'openerp.base_dashboard.ApplicationTiles');
openerp.base_dashboard.ApplicationTiles = openerp.base.View.extend({
init: function (parent, element_id) {
this._super(parent, element_id);
this.dataset = new openerp.base.DataSetSearch(
this, 'ir.ui.menu', null, [['parent_id', '=', false]]);
},
start: function () {
var self = this;
this.dataset.read_slice( ['name', 'web_icon_data', 'web_icon_hover_data'], {}, function (applications) {
return new openerp.base.DataSetSearch(
this, 'ir.ui.menu', null, [['parent_id', '=', false]])
.read_slice( ['name', 'web_icon_data', 'web_icon_hover_data'], {}, function (applications) {
// Create a matrix of 3*x applications
var rows = [];
while (applications.length) {
@ -367,22 +364,18 @@ openerp.base_dashboard.ApplicationTiles = openerp.base.View.extend({
$this.closest('.openerp')
.find('.menu a[data-menu=' + $this.data('menuid') + ']')
.click();});
});
});
}
});
openerp.base.client_actions.add(
'board.home.widgets', 'openerp.base_dashboard.Widgets');
openerp.base_dashboard.Widgets = openerp.base.View.extend({
init: function (parent, element_id) {
this._super(parent, element_id);
this.user_widgets = new openerp.base.DataSetSearch(
start: function () {
return new openerp.base.DataSetSearch(
this, 'res.widget.user', null,
['|', ['user_id', '=', false],
['user_id', '=', parseInt(this.session.uid, 10)]]);
this.widgets = new openerp.base.DataSetSearch(this, 'res.widget');
},
start: function () {
this.user_widgets.read_slice(['widget_id', 'user_id'], {}, this.on_widgets_list_loaded);
['user_id', '=', parseInt(this.session.uid, 10)]])
.read_slice(['widget_id', 'user_id'], {}, this.on_widgets_list_loaded);
},
on_widgets_list_loaded: function (user_widgets) {
var self = this;
@ -394,18 +387,19 @@ openerp.base_dashboard.Widgets = openerp.base.View.extend({
user_widget_id: widget['id']
};
});
this.widgets.read_ids(_(user_widgets).pluck('widget_id'), ['title'], function (widgets) {
_(widgets).each(function (widget) {
_.extend(widget, widget_user[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
}));
});
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
}));
})
}
});
};

View File

@ -63,22 +63,38 @@ openerp.base_default_home = function (openerp) {
if (!_(installed_modules).isEmpty()) {
return old_home.call(self);
}
self.$element.find('.oe-application').html(
QWeb.render('StaticHome', {
url: window.location.protocol + '//' + window.location.host + window.location.pathname,
session: self.session,
rows: openerp.base_default_home.applications
})).delegate('.oe-static-home-tile-text button', 'click', function () {
self.install_module($(this).val());
self.action_manager.do_action({
type: 'ir.actions.client',
tag: 'home.default'
})
}, function (err, event) {
event.preventDefault();
return old_home.call(self);
});
}
});
openerp.base.client_actions.add(
'home.default', 'openerp.base_default_home.DefaultHome');
openerp.base_default_home.DefaultHome = openerp.base.View.extend({
template: 'StaticHome',
start: function () {
var r = this._super(), self = this;
this.$element.delegate('.oe-static-home-tile-text button', 'click', function () {
self.install_module($(this).val());
});
return r;
},
render: function () {
return this._super({
url: window.location.protocol + '//' + window.location.host + window.location.pathname,
session: this.session,
rows: openerp.base_default_home.applications
})
},
install_module: function (module_name) {
var Modules = new openerp.base.DataSetSearch( this, 'ir.module.module', null, [['name', '=', module_name], ['state', '=', 'uninstalled']]);
var Modules = new openerp.base.DataSetSearch(
this, 'ir.module.module', null, [['name', '=', module_name], ['state', '=', 'uninstalled']]);
var Upgrade = new openerp.base.DataSet(this, 'base.module.upgrade');
$.blockUI({

View File

@ -195,6 +195,13 @@ The new class can then be used in the following manner:
After these two lines have executed (and any promise returned by ``appendTo``
has been resolved if needed), the widget is ready to be used.
.. note:: the insertion methods will start the widget themselves, and will
return the result of :js:func:`~openerp.base.Widget.start()`.
If for some reason you do not want to call these methods, you will
have to first call :js:func:`~openerp.base.Widget.render()` on the
widget, then insert it into your DOM and start it.
If the widget is not needed anymore (because it's transient), simply terminate
it: