[MOV] mail: move dedicated mobile file 'discuss_mobile.js' to mail_enterprise

These files are moved to be able to add some new responsive features
implemented in enterprise.

Task ID : 1895453
This commit is contained in:
Romain Estievenart
2019-08-19 13:01:30 +00:00
committed by Adrien Dieudonne
parent e631dbc182
commit dfa64cb7fe
3 changed files with 0 additions and 401 deletions
-287
View File
@@ -1,287 +0,0 @@
odoo.define('mail.DiscussMobile', function (require) {
"use strict";
var Discuss = require('mail.Discuss');
var config = require('web.config');
var core = require('web.core');
var QWeb = core.qweb;
if (!config.device.isMobile) {
return;
}
/**
* Overrides Discuss module in mobile
*/
Discuss.include({
contentTemplate: 'mail.discuss_mobile',
events: _.extend(Discuss.prototype.events, {
'click .o_mail_mobile_tab': '_onMobileTabClicked',
'click .o_mailbox_inbox_item': '_onMobileInboxButtonClicked',
'click .o_mail_preview': '_onMobileThreadClicked',
}),
/**
* @override
*/
init: function () {
this._super.apply(this, arguments);
this._currentState = this._defaultThreadID;
},
/**
* @override
*/
start: function () {
this._$mainContent = this.$('.o_mail_discuss_content');
return this._super.apply(this, arguments)
.then(this._updateControlPanel.bind(this));
},
/**
* @override
*/
on_attach_callback: function () {
if (this._thread && this._isInInboxTab()) {
this._threadWidget.scrollToPosition(this._threadsScrolltop[this._thread.getID()]);
}
},
/**
* @override
*/
on_detach_callback: function () {
if (this._isInInboxTab()) {
this._threadsScrolltop[this._thread.getID()] = this._threadWidget.getScrolltop();
}
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* @override
* @private
*/
_initThreads: function () {
return this._updateThreads();
},
/**
* @private
* @returns {Boolean} true iff we currently are in the Inbox tab
*/
_isInInboxTab: function () {
return _.contains(['mailbox_inbox', 'mailbox_starred', 'mailbox_history'], this._currentState);
},
/**
* @override
* @private
*/
_renderButtons: function () {
var self = this;
this._super.apply(this, arguments);
_.each(['dm_chat', 'multi_user_channel'], function (type) {
var selector = '.o_mail_discuss_button_' + type;
self.$buttons.on('click', selector, self._onAddThread.bind(self));
});
},
/**
* Overrides to only store the thread state if we are in the Inbox tab, as
* this is the only tab in which we actually have a displayed thread
*
* @override
* @private
*/
_restoreThreadState: function () {
if (this._isInInboxTab()) {
this._super.apply(this, arguments);
}
},
/**
* Overrides to toggle the visibility of the tabs when a message is selected
*
* @override
* @private
*/
_selectMessage: function () {
this._super.apply(this, arguments);
this.$('.o_mail_mobile_tabs').addClass('o_hidden');
},
/**
* @override
* @private
*/
_setThread: function (threadID) {
var thread = this.call('mail_service', 'getThread', threadID);
this._thread = thread;
if (thread.getType() !== 'mailbox') {
this.call('mail_service', 'openThreadWindow', threadID);
return Promise.resolve();
} else {
return this._super.apply(this, arguments);
}
},
/**
* Overrides to only store the thread state if we are in the Inbox tab, as
* this is the only tab in which we actually have a displayed thread
*
* @override
* @private
*/
_storeThreadState: function () {
if (this._thread && this._isInInboxTab()) {
this._super.apply(this, arguments);
}
},
/**
* Overrides to toggle the visibility of the tabs when a message is
* unselected
*
* @override
* @private
*/
_unselectMessage: function () {
this._super.apply(this, arguments);
this.$('.o_mail_mobile_tabs').removeClass('o_hidden');
},
/**
* @override
* @private
*/
_updateThreads: function () {
return this._updateContent(this._currentState);
},
/**
* Redraws the content of the client action according to its current state.
*
* @private
* @param {string} type the thread's type to display (e.g. 'mailbox_inbox',
* 'mailbox_starred', 'dm_chat'...).
*/
_updateContent: function (type) {
var self = this;
var inMailbox = _.contains(['mailbox_inbox', 'mailbox_starred', 'mailbox_history'], type);
if (!inMailbox && this._isInInboxTab()) {
// we're leaving the inbox, so store the thread scrolltop
this._storeThreadState();
}
var previouslyInInbox = this._isInInboxTab();
this._currentState = type;
// fetch content to display
var def;
if (inMailbox) {
def = this._fetchAndRenderThread();
} else {
var allChannels = this.call('mail_service', 'getChannels');
var channels = _.filter(allChannels, function (channel) {
return channel.getType() === type;
});
def = this.call('mail_service', 'getChannelPreviews', channels);
}
return Promise.resolve(def).then(function (previews) {
// update content
if (inMailbox) {
if (!previouslyInInbox) {
self.$('.o_mail_discuss_tab_pane').remove();
self._$mainContent.append(self._threadWidget.$el);
self._$mainContent.append(self._extendedComposer.$el);
}
self._restoreThreadState();
} else {
self._threadWidget.$el.detach();
self._extendedComposer.$el.detach();
var $content = $(QWeb.render('mail.discuss.MobileTabPane', {
previews: previews,
type: type,
}));
self._prepareAddThreadInput($content.find('.o_mail_add_thread input'), type);
self._$mainContent.html($content);
}
// update control panel
self.$buttons.find('button')
.removeClass('d-block')
.addClass('d-none');
self.$buttons.find('.o_mail_discuss_button_' + type)
.removeClass('d-none')
.addClass('d-block');
self.$buttons.find('.o_mail_discuss_button_mark_all_read')
.toggleClass('d-none', type !== 'mailbox_inbox')
.toggleClass('d-block', type === 'mailbox_inbox');
self.$buttons.find('.o_mail_discuss_button_unstar_all')
.toggleClass('d-none', type !== 'mailbox_starred')
.toggleClass('d-block', type === 'mailbox_starred');
// update Mailbox page buttons
if (inMailbox) {
self.$('.o_mail_discuss_mobile_mailboxes_buttons')
.removeClass('o_hidden');
self.$('.o_mailbox_inbox_item')
.removeClass('btn-primary')
.addClass('btn-secondary');
self.$('.o_mailbox_inbox_item[data-type=' + type + ']')
.removeClass('btn-secondary')
.addClass('btn-primary');
} else {
self.$('.o_mail_discuss_mobile_mailboxes_buttons')
.addClass('o_hidden');
}
// update bottom buttons
self.$('.o_mail_mobile_tab').removeClass('active');
// mailbox_inbox, mailbox_starred and mailbox_history share the same tab
type = _.contains(['mailbox_inbox', 'mailbox_starred', 'mailbox_history'], type) ? 'mailbox_inbox' : type;
self.$('.o_mail_mobile_tab[data-type=' + type + ']').addClass('active');
});
},
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* @override
* @private
*/
_onAddThread: function () {
this.$('.o_mail_add_thread').show().find('input').focus();
},
/**
* Switches to the clicked thread in the Inbox page (Inbox or Starred).
*
* @private
* @param {MouseEvent} ev
*/
_onMobileInboxButtonClicked: function (ev) {
var mailboxID = $(ev.currentTarget).data('type');
this._setThread(mailboxID);
this._updateContent(this._thread.getID());
},
/**
* Switches to another tab.
*
* @private
* @param {MouseEvent} ev
*/
_onMobileTabClicked: function (ev) {
var type = $(ev.currentTarget).data('type');
if (type === 'mailbox') {
var inbox = this.call('mail_service', 'getMailbox', 'inbox');
this._setThread(inbox);
}
this._updateContent(type);
},
/**
* Opens a thread in a chat window (full screen in mobile).
*
* @private
* @param {MouseEvent} ev
*/
_onMobileThreadClicked: function (ev) {
var threadID = $(ev.currentTarget).data('preview-id');
this.call('mail_service', 'openThreadWindow', threadID);
},
});
});
@@ -1,107 +0,0 @@
odoo.define('mail.discuss_mobile_tests', function (require) {
"use strict";
var mailTestUtils = require('mail.testUtils');
var testUtils = require('web.test_utils');
var createDiscuss = mailTestUtils.createDiscuss;
QUnit.module('mail', {}, function () {
QUnit.module('Discuss in mobile', {
beforeEach: function () {
this.services = mailTestUtils.getMailServices();
this.data = {
'mail.message': {
fields: {},
},
};
},
});
QUnit.test('mobile basic rendering', async function (assert) {
// This is a very basic first test for the client action. However, with
// the chat_service, it is hard to override RPCs (for instance, the
// /mail/client_action route is always called when the test suite is
// launched), and we must wait for this RPC to be done before starting to
// test the interface. This should be refactored to facilitate the testing.
assert.expect(16);
var discuss = await createDiscuss({
id: 1,
context: {},
params: {},
data: this.data,
services: this.services,
});
// test basic rendering in mobile
assert.containsOnce(discuss, '.o_mail_discuss_content .o_mail_no_content',
"should display the no content message");
assert.containsOnce(discuss, '.o_mail_mobile_tabs',
"should have rendered the tabs");
assert.hasClass(discuss.$('.o_mail_mobile_tab[data-type=mailbox_inbox]'),'active',
"should be in inbox tab");
assert.containsOnce(discuss, '.o_mail_discuss_mobile_mailboxes_buttons:visible',
"inbox/starred buttons should be visible");
assert.hasClass(discuss.$('.o_mail_discuss_mobile_mailboxes_buttons .o_mailbox_inbox_item[data-type=mailbox_inbox]'),'btn-primary',
"should be in inbox");
assert.hasClass($('.o_mail_discuss_button_dm_chat'),'d-none',
"should have invisible button 'New Message'");
assert.hasClass($('.o_mail_discuss_button_multi_user_channel'),'d-none',
"should have invisible button 'New Channel'");
// move to 'Chat' tab
await testUtils.dom.click(discuss.$('.o_mail_mobile_tab[data-type=dm_chat]'));
assert.hasClass(discuss.$('.o_mail_mobile_tab[data-type=dm_chat]'),'active',
"should be in 'Chat' tab");
assert.containsNone(discuss, '.o_mail_discuss_content .o_mail_no_content',
"should display the no content message");
assert.strictEqual($('.o_mail_discuss_button_dm_chat').length, 1,
"should have a button to open DM chat in 'Chat' tab");
assert.doesNotHaveClass($('.o_mail_discuss_button_dm_chat'), 'd-none',
"should be visible in 'Chat' tab");
assert.hasClass($('.o_mail_discuss_button_multi_user_channel'),'d-none',
"should have invisible button 'New Channel' in 'Chat' tab");
await testUtils.dom.click($('.o_mail_discuss_button_dm_chat'));
assert.containsOnce(discuss, '.o_mail_add_thread input:visible',
"should display the input to add a channel");
// move to 'Channels' tab
await testUtils.dom.click(discuss.$('.o_mail_mobile_tab[data-type=multi_user_channel]'));
assert.hasClass($('.o_mail_discuss_button_dm_chat'),'d-none',
"should have invisible button 'New Message' in 'Channels' tab");
assert.doesNotHaveClass($('.o_mail_discuss_button_multi_user_channel'), 'd-none',
"should have visible button 'New Channel' in 'Channels' tab");
await testUtils.dom.click($('.o_mail_discuss_button_multi_user_channel') );
assert.containsOnce(discuss, '.o_mail_add_thread input:visible',
"should display the input to add a channel");
discuss.destroy();
});
QUnit.test('on_{attach/detach}_callback', function (assert) {
assert.expect(2);
var done = assert.async();
createDiscuss({
id: 1,
context: {},
params: {},
data: this.data,
services: this.services,
}).then(function (discuss) {
try {
discuss.on_attach_callback();
assert.ok(true, 'should not crash on attach callback');
discuss.on_detach_callback();
assert.ok(true, 'should not crash on detach callback');
} finally {
discuss.destroy();
done();
}
});
});
});
});
-7
View File
@@ -46,7 +46,6 @@
<script type="text/javascript" src="/mail/static/src/js/thread_windows/abstract_thread_window.js"></script>
<script type="text/javascript" src="/mail/static/src/js/thread_windows/thread_window.js"></script>
<script type="text/javascript" src="/mail/static/src/js/discuss.js"></script>
<script type="text/javascript" src="/mail/static/src/js/discuss_mobile.js"></script>
<script type="text/javascript" src="/mail/static/src/js/document_viewer.js"></script>
<!-- composers -->
<script type="text/javascript" src="/mail/static/src/js/composers/basic_composer.js"></script>
@@ -141,12 +140,6 @@
</xpath>
</template>
<template id="qunit_mobile_suite" name="mail_mobile_tests" inherit_id="web.qunit_mobile_suite">
<xpath expr="//t[@t-set='head']" position="inside">
<script type="text/javascript" src="/mail/static/tests/discuss_mobile_tests.js"></script>
</xpath>
</template>
<template id="message_origin_link">
<p>This <t t-esc="self.env['ir.model']._get(self._name).name.lower()"/> has been <span t-if="edit">modified</span><span t-if="not edit">created</span> from:
<t t-foreach="origin" t-as="o">