[IMP] mail, *: remove legacy code from activity systray
* = calendar, crm, im_livechat, mass_mailing_sms, note, test_discuss_full,
test_mail
task-2920645
closes odoo/odoo#96114
Related: odoo/enterprise#29794
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { useRefToModel } from '@mail/component_hooks/use_ref_to_model';
|
||||
import { useUpdateToModel } from '@mail/component_hooks/use_update_to_model';
|
||||
import '@mail/components/activity_menu_view/activity_menu_view'; // ensure components are registered beforehand.
|
||||
import { getMessagingComponent } from "@mail/utils/messaging_component";
|
||||
|
||||
import { DatePicker } from '@web/core/datepicker/datepicker';
|
||||
import { patch } from 'web.utils';
|
||||
|
||||
const ActivityMenuView = getMessagingComponent('ActivityMenuView');
|
||||
|
||||
patch(ActivityMenuView.prototype, 'note', {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
setup() {
|
||||
this._super();
|
||||
useRefToModel({ fieldName: 'noteInputRef', refName: 'noteInput', });
|
||||
useUpdateToModel({ methodName: 'onComponentUpdate' });
|
||||
},
|
||||
});
|
||||
|
||||
Object.assign(ActivityMenuView.components, {
|
||||
DatePicker,
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-inherit="mail.ActivityMenuView" t-inherit-mode="extension">
|
||||
<xpath expr="//*[@name='activityGroupLoop']" position="after">
|
||||
<div t-if="!activityMenuView.isAddingNote" class="o_note_show d-grid" t-on-click="activityMenuView.onClickAddNote">
|
||||
<a role="button" class="btn text-center">Add new note</a>
|
||||
</div>
|
||||
<div t-if="activityMenuView.isAddingNote" class="o_note o_ActivityMenuView_activityGroup">
|
||||
<div class="o_ActivityMenuView_activityGroupIconContainer">
|
||||
<img src="/note/static/description/icon.svg" alt="Channel"/>
|
||||
</div>
|
||||
<div class="o_ActivityMenuView_activityGroupInfo">
|
||||
<div class="o_ActivityMenuView_activityGroupTitle">
|
||||
<span class="o_ActivityMenuView_activityGroupName"><strong>Add a note</strong></span>
|
||||
<DatePicker
|
||||
date="activityMenuView.addingNoteDate"
|
||||
onDateTimeChanged="activityMenuView.onDateTimeChanged"
|
||||
placeholder="activityMenuView.addingNoteDatePlaceholder"
|
||||
/>
|
||||
</div>
|
||||
<div class="o_note_input_box">
|
||||
<p><input class="o_note_input" type="text" placeholder="Remember..." t-on-keydown="activityMenuView.onKeydownNoteInput" t-ref="noteInput"/></p>
|
||||
<span class="ml8 mr4">
|
||||
<a class="o_note_save" t-on-click="activityMenuView.onClickSaveNote">SAVE</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -1,133 +0,0 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import ActivityMenu from '@mail/js/systray/systray_activity_menu';
|
||||
|
||||
import { _t } from 'web.core';
|
||||
import datepicker from 'web.datepicker';
|
||||
|
||||
ActivityMenu.include({
|
||||
events: _.extend({}, ActivityMenu.prototype.events, {
|
||||
'click .o_note_show': '_onAddNoteClick',
|
||||
'click .o_note_save': '_onNoteSaveClick',
|
||||
'click .o_note_set_datetime': '_onNoteDateTimeSetClick',
|
||||
'keydown input.o_note_input': '_onNoteInputKeyDown',
|
||||
'click .o_note': '_onNewNoteClick',
|
||||
}),
|
||||
//--------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------
|
||||
/**
|
||||
* Moving notes at first place
|
||||
* @override
|
||||
*/
|
||||
_getActivityData: function () {
|
||||
var self = this;
|
||||
return this._super.apply(this, arguments).then(function () {
|
||||
var reminderIndex = _.findIndex(self.activities, function (val) {
|
||||
return val.model === 'note.note';
|
||||
});
|
||||
if (reminderIndex > 0) {
|
||||
self.activities.splice(0, 0, self.activities.splice(reminderIndex, 1)[0]);
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Save the note to database using datepicker date and field as note
|
||||
* By default, when no datetime is set, it uses the current datetime.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_saveNote: function () {
|
||||
var note = this.$('.o_note_input').val().trim();
|
||||
if (! note) {
|
||||
return;
|
||||
}
|
||||
var params = {'note': note};
|
||||
var noteDateTime = this.noteDateTimeWidget.getValue();
|
||||
if (noteDateTime) {
|
||||
params = _.extend(params, {'date_deadline': noteDateTime});
|
||||
} else {
|
||||
params = _.extend(params, {'date_deadline': moment()});
|
||||
}
|
||||
this.$('.o_note_show').removeClass('d-none');
|
||||
this.$('.o_note').addClass('d-none');
|
||||
this._rpc({
|
||||
route: '/note/new',
|
||||
params: params,
|
||||
}).then(this._updateActivityPreview.bind(this));
|
||||
},
|
||||
//-----------------------------------------
|
||||
// Handlers
|
||||
//-----------------------------------------
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_onActivityFilterClick: function (ev) {
|
||||
var $el = $(ev.currentTarget);
|
||||
if (!$el.hasClass("o_note")) {
|
||||
this._super.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* When add new note button clicked, toggling quick note create view inside
|
||||
* Systray activity view
|
||||
*
|
||||
* @private
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
_onAddNoteClick: function (ev) {
|
||||
var self = this;
|
||||
ev.stopPropagation();
|
||||
if (!this.noteDateTimeWidget){
|
||||
this.noteDateTimeWidget = new datepicker.DateWidget(this, {useCurrent: true});
|
||||
}
|
||||
this.noteDateTimeWidget.appendTo(this.$('.o_note_datetime')).then(function() {
|
||||
self.noteDateTimeWidget.$input.attr('placeholder', _t("Today"));
|
||||
self.noteDateTimeWidget.setValue(false);
|
||||
self.$('.o_note_show, .o_note').toggleClass('d-none');
|
||||
self.$('.o_note_input').val('').focus();
|
||||
});
|
||||
},
|
||||
/**
|
||||
* When focusing on input for new quick note systerm tray must be open.
|
||||
* Preventing to close
|
||||
*
|
||||
* @private
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
_onNewNoteClick: function (ev) {
|
||||
ev.stopPropagation();
|
||||
},
|
||||
/**
|
||||
* Opens datetime picker for note.
|
||||
* Quick FIX due to no option for set custom icon instead of caret in datepicker.
|
||||
*
|
||||
* @private
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
_onNoteDateTimeSetClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
this.noteDateTimeWidget.$input.click();
|
||||
},
|
||||
/**
|
||||
* Saving note (quick create) and updating activity preview
|
||||
*
|
||||
* @private
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
_onNoteSaveClick: function (ev) {
|
||||
this._saveNote();
|
||||
},
|
||||
/**
|
||||
* Handling Enter key for quick create note.
|
||||
*
|
||||
* @private
|
||||
* @param {KeyboardEvent} ev
|
||||
*/
|
||||
_onNoteInputKeyDown: function (ev) {
|
||||
if (ev.which === $.ui.keyCode.ENTER) {
|
||||
this._saveNote();
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { addFields, addRecordMethods } from '@mail/model/model_core';
|
||||
import { attr } from '@mail/model/model_field';
|
||||
import '@mail/models/activity_group'; // ensure the model definition is loaded before the patch
|
||||
|
||||
addRecordMethods('ActivityGroup', {
|
||||
_computeIsNote() {
|
||||
return this.irModel.model === 'note.note';
|
||||
},
|
||||
});
|
||||
|
||||
addFields('ActivityGroup', {
|
||||
isNote: attr({
|
||||
compute: '_computeIsNote',
|
||||
}),
|
||||
});
|
||||
@@ -0,0 +1,112 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { addFields, addRecordMethods, patchRecordMethods } from '@mail/model/model_core';
|
||||
import { attr } from '@mail/model/model_field';
|
||||
import { clear } from '@mail/model/model_field_command';
|
||||
import '@mail/models/activity_menu_view'; // ensure the model definition is loaded before the patch
|
||||
|
||||
const { DateTime } = luxon;
|
||||
|
||||
addRecordMethods('ActivityMenuView', {
|
||||
/**
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
onClickAddNote(ev) {
|
||||
this.update({
|
||||
addingNoteDoFocus: true,
|
||||
isAddingNote: true,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
onClickSaveNote(ev) {
|
||||
this.saveNote();
|
||||
},
|
||||
onComponentUpdate() {
|
||||
if (this.addingNoteDoFocus && this.noteInputRef.el) {
|
||||
this.noteInputRef.el.focus();
|
||||
this.update({ addingNoteDoFocus: clear() });
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @param {DateTime|string} date
|
||||
*/
|
||||
onDateTimeChanged(date) {
|
||||
this.update({ addingNoteDate: date ? date : clear() });
|
||||
},
|
||||
/**
|
||||
* @param {KeyboardEvent} ev
|
||||
*/
|
||||
onKeydownNoteInput(ev) {
|
||||
if (ev.key === 'Enter') {
|
||||
this.saveNote();
|
||||
}
|
||||
},
|
||||
async saveNote() {
|
||||
const note = this.noteInputRef.el.value.trim();
|
||||
if (!note) {
|
||||
return;
|
||||
}
|
||||
this.update({ isAddingNote: false });
|
||||
await this.messaging.rpc({
|
||||
route: '/note/new',
|
||||
params: {
|
||||
'note': note,
|
||||
'date_deadline': this.addingNoteDate ? this.addingNoteDate : new DateTime.local(),
|
||||
},
|
||||
});
|
||||
this.fetchData();
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @returns {string}
|
||||
*/
|
||||
_computeAddingNoteDatePlaceholder() {
|
||||
return this.env._t("Today");
|
||||
},
|
||||
});
|
||||
|
||||
patchRecordMethods('ActivityMenuView', {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
close() {
|
||||
this.update({
|
||||
addingNoteDoFocus: clear(),
|
||||
isAddingNote: false,
|
||||
});
|
||||
this._super();
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_onClickCaptureGlobal(ev) {
|
||||
if (ev.target.closest('.bootstrap-datetimepicker-widget')) {
|
||||
return;
|
||||
}
|
||||
this._super(ev);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_sortActivityGroups(ev) {
|
||||
const res = this._super();
|
||||
res.unshift(['truthy-first', 'isNote']);
|
||||
return res;
|
||||
},
|
||||
});
|
||||
|
||||
addFields('ActivityMenuView', {
|
||||
addingNoteDate: attr(),
|
||||
addingNoteDoFocus: attr({
|
||||
default: false,
|
||||
}),
|
||||
addingNoteDatePlaceholder: attr({
|
||||
compute: '_computeAddingNoteDatePlaceholder',
|
||||
}),
|
||||
isAddingNote: attr({
|
||||
default: false,
|
||||
}),
|
||||
noteInputRef: attr(),
|
||||
});
|
||||
@@ -51,11 +51,11 @@
|
||||
}
|
||||
|
||||
// Quick create notes from systray
|
||||
.o_note.o_mail_preview {
|
||||
.o_note.o_ActivityMenuView_activityGroup {
|
||||
background-color: white;
|
||||
.o_preview_info {
|
||||
.o_preview_title {
|
||||
.o_preview_name {
|
||||
.o_ActivityMenuView_activityGroupInfo {
|
||||
.o_ActivityMenuView_activityGroupTitle {
|
||||
.o_ActivityMenuView_activityGroupName {
|
||||
flex: 1 1 100%;
|
||||
}
|
||||
}
|
||||
@@ -74,20 +74,4 @@
|
||||
.o_note_input {
|
||||
border: none;
|
||||
}
|
||||
.o_note_datetime {
|
||||
.o_datepicker {
|
||||
.o_datepicker_input {
|
||||
float: right;
|
||||
text-align: right;
|
||||
border: none;
|
||||
font-size: 11px;
|
||||
}
|
||||
.o_datepicker_button {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
.o_note_set_datetime {
|
||||
color: $text-muted;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
<t t-extend="mail.systray.ActivityMenu.Previews">
|
||||
<t t-jquery="t[t-foreach*='activities'][t-as*='activity']" t-operation="after">
|
||||
<div class="o_note_show d-grid">
|
||||
<a role="button" class="btn text-center">Add new note</a>
|
||||
</div>
|
||||
<div class="o_note o_mail_preview d-none">
|
||||
<div class="o_mail_preview_image o_mail_preview_app">
|
||||
<img src="/note/static/description/icon.svg" alt="Channel"/>
|
||||
</div>
|
||||
<div class="o_preview_info">
|
||||
<div class="o_preview_title">
|
||||
<span class="o_preview_name"><strong>Add a note</strong></span>
|
||||
<div class="o_note_datetime"/>
|
||||
<span class="ml4">
|
||||
<a class="o_note_set_datetime">
|
||||
<span class="fa fa-calendar" role="img" aria-label="Set date and time" title="Set date and time"/>
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="o_note_input_box">
|
||||
<p><input class="o_note_input" type="text" placeholder="Remember..." /></p>
|
||||
<span class="ml8 mr4">
|
||||
<a class="o_note_save">SAVE</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
||||
Reference in New Issue
Block a user