[IMP] mail: add view icon on all app (activity systray)

Before this commit, you could only access the activity view of the
Contacts app via the activity icon in activity systray menu.

With this commit, all apps in the activity systray menu that support
the activity view now have this icon that redirects to the
corresponding activity view.

Also, the icon in the activity systray menu has been changed in order
to match the icon of the activity view in the view switcher.

Task-ID 1894900

closes odoo/odoo#28066
This commit is contained in:
Geoffroy Larue
2018-11-08 23:28:13 +00:00
committed by Alexandre Kühn
parent e9e864802f
commit 8e15a23ca6
5 changed files with 92 additions and 24 deletions
-5
View File
@@ -17,9 +17,4 @@ class Users(models.Model):
if activity['model'] != 'res.partner':
continue
activity['icon'] = modules.module.get_module_icon('contacts')
activity['actions'] = [{
'icon': 'fa-th',
'name': 'Summary',
'action_xmlid': 'contacts.action_contacts_summary'
}]
return activities
-15
View File
@@ -34,21 +34,6 @@
<field name="act_window_id" ref="action_contacts"/>
</record>
<record id="action_contacts_summary" model="ir.actions.act_window">
<field name="name">Contacts</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name="view_type">form</field>
<field name="view_mode">activity,kanban,tree,form</field>
<field name="search_view_id" ref="base.view_res_partner_filter"/>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a contact in your address book
</p><p>
Odoo helps you to easily track all activities related to a customer.
</p>
</field>
</record>
<menuitem name="Contacts"
id="menu_contacts"
+4
View File
@@ -140,6 +140,10 @@ GROUP BY channel_moderator.res_users_id""", [tuple(self.ids)])
if activity['states'] in ('today', 'overdue'):
user_activities[activity['model']]['total_count'] += activity['count']
user_activities[activity['model']]['actions'] = [{
'icon': 'fa-clock-o',
'name': 'Summary',
}]
return list(user_activities.values())
@@ -100,14 +100,27 @@ var ActivityMenu = Widget.extend({
//------------------------------------------------------------
/**
* Redirect to specific action given its xml id
* Redirect to specific action given its xml id or to the activity
* view of the current model if no xml id is provided
*
* @private
* @param {MouseEvent} ev
*/
_onActivityActionClick: function (ev) {
ev.stopPropagation();
var actionXmlid = $(ev.currentTarget).data('action_xmlid');
this.do_action(actionXmlid);
var targetAction = $(ev.currentTarget);
var actionXmlid = targetAction.data('action_xmlid');
if (actionXmlid) {
this.do_action(actionXmlid);
} else {
this.do_action({
type: 'ir.actions.act_window',
name: targetAction.data('model_name'),
views: [[false, 'activity'], [false, 'kanban'], [false, 'list']],
view_mode: 'activity',
res_model: targetAction.data('res_model')
});
}
},
/**
@@ -20,6 +20,11 @@ QUnit.module('ActivityMenu', {
today_count: { type: "integer"},
overdue_count: { type: "integer"},
total_count: { type: "integer"},
actions: [{
icon: { type: "char" },
name: { type: "char" },
action_xmlid: { type: "char" },
}],
},
records: [{
name: "Contact",
@@ -47,6 +52,24 @@ QUnit.module('ActivityMenu', {
today_count: 1,
overdue_count: 1,
total_count: 3,
actions : [{
icon: "fa-clock-o",
name: "summary",
}],
},
{
name: "Note",
type: "activity",
model: "partner",
planned_count: 1,
today_count: 1,
overdue_count: 1,
total_count: 3,
actions: [{
icon: "fa-clock-o",
name: "summary",
action_xmlid: "mail.mail_activity_type_view_tree",
}],
}],
},
};
@@ -88,7 +111,7 @@ QUnit.test('activity menu widget: activity menu with 3 records', function (asser
assert.ok(activityMenu.$el.hasClass('o_mail_systray_item'), 'should be the instance of widget');
assert.ok(activityMenu.$('.o_mail_preview').hasClass('o_mail_preview'), "should instance of widget");
assert.ok(activityMenu.$('.o_notification_counter').hasClass('o_notification_counter'), "widget should have notification counter");
assert.strictEqual(parseInt(activityMenu.el.innerText), 5, "widget should have 5 notification counter");
assert.strictEqual(parseInt(activityMenu.el.innerText), 8, "widget should have 8 notification counter");
var context = {};
testUtils.intercept(activityMenu, 'do_action', function (event) {
@@ -125,5 +148,53 @@ QUnit.test('activity menu widget: activity menu with 3 records', function (asser
activityMenu.destroy();
});
QUnit.test('activity menu widget: activity view icon', function (assert) {
assert.expect(8);
var self = this;
var activityMenu = new ActivityMenu();
testUtils.addMockEnvironment(activityMenu, {
services: this.services,
mockRPC: function (route, args) {
if (args.method === 'systray_get_activities') {
return $.when(self.data['mail.activity.menu'].records);
}
return this._super(route, args);
},
});
activityMenu.appendTo($('#qunit-fixture'));
assert.strictEqual(activityMenu.$('.o_mail_activity_action').length, 2,
"widget should have 2 activity view icons");
var $first = activityMenu.$('.o_mail_activity_action').eq(0);
var $second = activityMenu.$('.o_mail_activity_action').eq(1);
assert.strictEqual($first.data('model_name'), "Issue",
"first activity action should link to 'Issue'");
assert.ok($first.hasClass('fa-clock-o'), "should display the activity action icon");
assert.strictEqual($second.data('model_name'), "Note",
"Second activity action should link to 'Note'");
assert.ok($second.hasClass('fa-clock-o'), "should display the activity action icon");
testUtils.intercept(activityMenu, 'do_action', function (event) {
assert.step('do_action:' +
(event.data.action.name ? event.data.action.name : event.data.action));
}, true);
// click on the "Issue" activity icon
activityMenu.$('.dropdown-toggle').click();
activityMenu.$(".o_mail_activity_action[data-model_name='Issue']").click();
// click on the "Note" activity icon
activityMenu.$('.dropdown-toggle').click();
activityMenu.$(".o_mail_activity_action[data-model_name='Note']").click();
assert.verifySteps([
'do_action:Issue',
'do_action:mail.mail_activity_type_view_tree'
]);
activityMenu.destroy();
});
});
});