[IMP] use Class.include() in editable listview, also in WebClient static home extension
[odoo/odoo.git] / addons / base_default_home / static / src / js / home.js
1 openerp.base_default_home = function (openerp) {
2     QWeb.add_template('/base_default_home/static/src/xml/base_default_home.xml');
3
4     openerp.base_default_home = {
5         applications: [
6             [
7                 {
8                     module: 'crm', name: 'CRM',
9                     help: "Acquire leads, follow opportunities, manage prospects and phone calls, \u2026"
10                 }, {
11                     module: 'sale', name: 'Sales',
12                     help: "Do quotations, follow sales orders, invoice and control deliveries"
13                 }, {
14                     module: 'account_voucher', name: 'Invoicing',
15                     help: "Send invoice, track payments and reminders"
16                 }, {
17                     module: 'project', name: 'Projects',
18                     help: "Manage projects, track tasks, invoice task works, follow issues, \u2026"
19                 }
20             ], [
21                 {
22                     module: 'purchase', name: 'Purchase',
23                     help: "Do purchase orders, control invoices and reception, follow your suppliers, \u2026"
24                 }, {
25                     module: 'stock', name: 'Warehouse',
26                     help: "Track your stocks, schedule product moves, manage incoming and outgoing shipments, \u2026"
27                 }, {
28                     module: 'hr', name: 'Human Resources',
29                     help: "Manage employees and their contracts, follow laves, recruit people, \u2026"
30                 }, {
31                     module: 'point_of_sale', name: 'Point of Sales',
32                     help: "Manage shop sales, use touch-screen POS"
33                 }
34             ], [
35                 {
36                     module: 'profile_tools', name: 'Extra Tools',
37                     help: "Track ideas, manage lunch, create surveys, share data"
38                 }, {
39                     module: 'mrp', name: 'Manufacturing',
40                     help: "Manage your manufacturing, control your supply chain, personalize master data, \u2026"
41                 }, {
42                     module: 'marketing', name: 'Marketing',
43                     help: "Manage campaigns, follow activities, automate emails, \u2026"
44                 }, {
45                     module: 'knowledge', name: 'Knowledge',
46                     help: "Track your documents, browse your files, \u2026"
47                 }
48             ]
49         ]
50     };
51
52     openerp.base.WebClient.include({
53         default_home: function () {
54             var self = this,
55                 // resig class can't handle _super in async contexts, by the
56                 // time async callback comes back, _super has already been
57                 // reset to a baseline value of this.prototype (or something
58                 // like that)
59                 old_home = this._super;
60             var Installer = new openerp.base.DataSet(
61                     this, 'base.setup.installer');
62             Installer.call('already_installed', [], function (installed_modules) {
63                 if (!_(installed_modules).isEmpty()) {
64                     return old_home.call(self);
65                 }
66                 self.$element.find('.oe-application').html(
67                     QWeb.render('StaticHome', {
68                         url: window.location.protocol + '//' + window.location.host + window.location.pathname,
69                         session: self.session,
70                         rows: openerp.base_default_home.applications
71                 })).delegate('.oe-static-home-tile-text button', 'click', function () {
72                     self.install_module($(this).val());
73                 })
74
75             }, function (err, event) {
76                 event.preventDefault();
77                 return old_home.call(self);
78             });
79         },
80         install_module: function (module_name) {
81             var Modules = new openerp.base.DataSetSearch(
82                 this, 'ir.module.module', null,
83                 [['name', '=', module_name], ['state', '=', 'uninstalled']]),
84                 Upgrade = new openerp.base.DataSet(this, 'base.module.upgrade');
85
86             $.blockUI({
87                 message: '<img src="/base_default_home/static/src/img/throbber.gif">'
88             });
89             Modules.read_slice(['id'], null, null, function (records) {
90                 if (!(records.length === 1)) { return; }
91                 Modules.call('state_update',
92                     [_.pluck(records, 'id'), 'to install', ['uninstalled']],
93                     function () {
94                         Upgrade.call('upgrade_module', [[]], function () {
95                             $.unblockUI();
96                             // TODO: less brutal reloading
97                             window.location.reload(true);
98                         });
99                     }
100                 )
101             });
102         }
103     });
104 };