[REM] homepage support, trigger first menu item instead

bzr revid: al@openerp.com-20120419215344-vn1yyk70oztpn2mw
This commit is contained in:
Antony Lesuisse
2012-04-19 23:53:44 +02:00
parent fc58572201
commit 5522c5e100
3 changed files with 7 additions and 218 deletions
+7 -1
View File
@@ -638,6 +638,7 @@ instance.web.Menu = instance.web.Widget.extend({
}
},
on_menu_click: function(ev, id) {
// TODO If first level menu doesnt have action trigger first leaf
this.do_hide_more();
id = id || 0;
var $clicked_menu, manual = false;
@@ -984,13 +985,18 @@ instance.web.WebClient = instance.web.Widget.extend({
});
},
bind_hashchange: function() {
var self = this;
$(window).bind('hashchange', this.on_hashchange);
var state = $.bbq.getState(true);
if (! _.isEmpty(state)) {
$(window).trigger('hashchange');
} else {
this.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'});
self.menu.has_been_loaded.then(function() {
var first_menu_id = self.menu.$element.find("a:first").data("menu");
if(first_menu_id)
self.menu.on_menu_click(null,first_menu_id);
});
}
},
on_hashchange: function(event) {
@@ -277,87 +277,6 @@ instance.web.form.tags.add('hpaned', 'instance.web.form.DashBoardLegacy');
instance.web.form.tags.add('vpaned', 'instance.web.form.DashBoardLegacy');
instance.web.form.tags.add('board', 'instance.web.form.DashBoard');
/*
* ConfigOverview
* This client action designed to be used as a dashboard widget display
* ir.actions.todo in a fancy way
*/
instance.web.client_actions.add( 'board.config.overview', 'instance.web_dashboard.ConfigOverview');
instance.web_dashboard.ConfigOverview = instance.web.View.extend({
template: 'ConfigOverview',
init: function (parent) {
this._super(parent);
this.user = _.extend(new instance.web.DataSet(this, 'res.users'), {
index: 0,
ids: [this.session.uid]
});
this.dataset = new instance.web.DataSetSearch(this, 'ir.actions.todo');
},
start: function () {
var self = this;
return this.user.read_index(['groups_id']).pipe(function(record) {
var todos_filter = [
['type', '!=', 'automatic'],
'|', ['groups_id', '=', false],
['groups_id', 'in', record['groups_id']]];
return $.when(
self.dataset.read_slice(
['state', 'action_id', 'category_id'],
{ domain: todos_filter }
),
self.dataset.call('progress').pipe(
function (arg) { return arg; }, null))
}, null).then(this.on_records_loaded);
},
on_records_loaded: function (records, progress) {
var grouped_todos = _(records).chain()
.map(function (record) {
return {
id: record.id,
name: record.action_id[1],
done: record.state !== 'open',
to_do: record.state === 'open',
category: record['category_id'][1] || _t("Uncategorized")
}
})
.groupBy(function (record) {return record.category})
.value();
this.$element.html(QWeb.render('ConfigOverview.content', {
completion: 100 * progress.done / progress.total,
groups: grouped_todos,
task_title: _t("Execute task \"%s\""),
checkbox_title: _t("Mark this task as done"),
_: _
}));
var $progress = this.$element.find('div.oe-config-progress-bar');
$progress.progressbar({value: $progress.data('completion')});
var self = this;
this.$element.find('dl')
.delegate('input', 'click', function (e) {
// switch todo status
e.stopImmediatePropagation();
var new_state = this.checked ? 'done' : 'open',
todo_id = parseInt($(this).val(), 10);
self.dataset.write(todo_id, {state: new_state}, {}, function () {
self.start();
});
})
.delegate('li:not(.oe-done)', 'click', function () {
self.getParent().getParent().getParent().do_execute_action({
type: 'object',
name: 'action_launch'
}, self.dataset,
$(this).data('id'), function () {
// after action popup closed, refresh configuration
// thingie
self.start();
});
});
}
});
/*
* Widgets
* This client action designed to be used as a dashboard widget display
@@ -397,79 +316,5 @@ instance.web_dashboard.Widget = instance.web.View.extend(/** @lends instance.web
}
});
/*
* HomeTiles this client action display either the list of application to
* install (if none is installed yet) or a list of root menu items
*/
instance.web.client_actions.add('default_home', 'session.web_dashboard.ApplicationTiles');
instance.web_dashboard.ApplicationTiles = instance.web.OldWidget.extend({
template: 'web_dashboard.ApplicationTiles',
init: function(parent) {
this._super(parent);
},
start: function() {
var self = this;
var domain = [['application','=',true], ['state','=','installed'], ['name', '!=', 'base']];
var ds = new instance.web.DataSetSearch(this, 'ir.module.module',{},domain);
ds.read_slice(['id']).then(function(result) {
if(result.length) {
self.on_installed_database();
} else {
self.on_uninstalled_database();
}
});
},
on_uninstalled_database: function() {
installer = new instance.web_dashboard.ApplicationInstaller(this);
installer.appendTo(this.$element);
},
on_installed_database: function() {
var self = this;
self.rpc('/web/menu/get_user_roots', {}).then(function (menu_ids) {
var menuds = new instance.web.DataSet(this, 'ir.ui.menu',{})
.read_ids(menu_ids, ['name', 'web_icon_data', 'web_icon_hover_data', 'module']).then(function (applications) {
var tiles = QWeb.render('ApplicationTiles.content', {applications: applications});
$(tiles).appendTo(self.$element).find('.oe_install-module-link').click(function () {
instance.webclient.menu.on_menu_click(null, $(this).data('menu'))
});
});
});
}
});
/**
* ApplicationInstaller
* This client action display a list of applications to install.
*/
instance.web.client_actions.add( 'board.application.installer', 'instance.web_dashboard.ApplicationInstaller');
instance.web_dashboard.ApplicationInstaller = instance.web.OldWidget.extend({
template: 'web_dashboard.ApplicationInstaller',
start: function () {
// TODO menu hide
var r = this._super();
this.action_manager = new instance.web.ActionManager(this);
this.action_manager.appendTo(this.$element.find('.oe_installer'));
this.action_manager.do_action({
type: 'ir.actions.act_window',
res_model: 'ir.module.module',
domain: [['application','=',true]],
views: [[false, 'kanban']],
flags: {
display_title:false,
search_view: false,
views_switcher: false,
action_buttons: false,
sidebar: false,
pager: false
}
});
return r;
},
destroy: function() {
this.action_manager.destroy();
return this._super();
}
});
};
@@ -56,71 +56,9 @@
</board>
</form>
</t>
<div t-name="ConfigOverview" class="oe-dashboard-config-overview"/>
<t t-name="ConfigOverview.content">
<div class="oe-config-progress">
<h6 class="oe-config-progress-title">
progress: <t t-esc="Math.round(completion)"/>%
</h6>
<div class="oe-config-progress-bar" t-att-data-completion="completion"/>
</div>
<p class="oe-config-tip">Click on the functionalites listed below to launch them and configure your system</p>
<dl>
<t t-foreach="groups" t-as="category">
<dt><t t-esc="category"/></dt>
<dd><ul>
<li t-foreach="category_value" t-as="todo"
t-att-class="todo.done ? 'oe-done' : undefined"
t-att-data-id="todo.id"
t-att-title="!todo.done ? _.str.sprintf(task_title, todo.name) : undefined">
<span style="text-decoration: underline;"><t t-esc="todo.name"/></span>
<input type="checkbox" t-att-value="todo.id"
t-att-title="!todo.done ? checkbox_title : undefined"
t-att-checked="todo.done ? 'checked' : undefined"/>
</li>
</ul></dd>
</t>
</dl>
</t>
<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"/>
</t>
<t t-name="ApplicationTiles.content">
<ul class="oe_app_tiles">
<t t-foreach="applications" t-as="application" >
<li>
<a href="#" class="oe_install-module-link" t-att-data-module="application.module" t-att-data-menu="application.id" >
<img t-if="application.web_icon_data" t-att-src="'data:image/png;base64,' + application.web_icon_data"
/><img t-if="application.web_icon_hover_data" class="hover" t-att-src="'data:image/png;base64,' + application.web_icon_hover_data"/>
<span><t t-esc="application.name"/></span>
</a>
</li>
</t>
</ul>
</t>
<t t-name="web_dashboard.ApplicationTiles">
<div>
<div class="oe_applications_tiles">
<h1 class="oe_welcome_message">Welcome to OpenERP</h1>
</div>
</div>
</t>
<div t-name="web_dashboard.ApplicationInstaller">
<div class="oe_initial_welcome_message">
<ul>
<li>Remember to bookmark
<a class="oe_welcome_url" t-att-href="widget.session.origin">This url</a>
</li>
<li>Your login: <t t-esc="widget.session.username"/></li>
</ul>
</div>
<div class="oe_installer" />
</div>
</template>