Skip to content
Permalink
Browse files

[IMP] calendar: Allow a user to accept/decline meeting from calendar …

…view popover
  • Loading branch information...
jat-odoo committed Mar 12, 2019
1 parent d01efce commit 20afa7bf9a06f50d1a99e1345d302af715cd0ca3
@@ -118,7 +118,7 @@ def _default_access_token(self):
return uuid.uuid4().hex

STATE_SELECTION = [
('needsAction', 'Needs Action'),
('needsAction', 'Your Answer?'),
('tentative', 'Uncertain'),
('declined', 'Declined'),
('accepted', 'Accepted'),
@@ -1808,3 +1808,12 @@ def _fix_rrule(self, values):
if 'UNTIL' not in rule_str and 'COUNT' not in rule_str:
rule_str += ';COUNT=100'
return rule_str

def change_attendee_status(self, status):
attendee = self.attendee_ids.filtered(lambda x: x.partner_id == self.env.user.partner_id)
if status == 'accepted':
return attendee.do_accept()
elif status == 'declined':
return attendee.do_decline()
else:
return attendee.do_tentative()
@@ -0,0 +1,73 @@
odoo.define('calendar.CalendarView', function (require) {
"use strict";

var CalendarPopover = require('web.CalendarPopover');
var CalendarRenderer = require('web.CalendarRenderer');
var CalendarModel = require('web.CalendarModel');
var CalendarView = require('web.CalendarView');
var viewRegistry = require('web.view_registry');

var AttendeeCalendarPopover = CalendarPopover.extend({
template: 'Calendar.attendee.status.popover',
events: _.extend({}, CalendarPopover.prototype.events, {
'click .o-calendar-attendee-status a': '_onClickAttendeeStatus'
}),
/**
* @constructor
*/
init: function () {
var self = this;
this._super.apply(this, arguments);
var session = this.getSession();
// Show status dropdown if user is in attendees list
this.showStatusDropdown = _.contains(this.event.record.partner_ids, session.partner_id);
if (this.showStatusDropdown) {
this.statusColors = {accepted: 'text-success', declined: 'text-danger', tentative: 'text-muted', needsAction: 'text-dark'};
this.statusInfo = {};
_.each(this.fields.attendee_status.selection, function (selection) {
self.statusInfo[selection[0]] = {text: selection[1], color: self.statusColors[selection[0]]};
});
this.selectedStatusInfo = this.statusInfo[this.event.record.attendee_status];
}
},

//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------

/**
* @private
* @param {MouseEvent} ev
*/
_onClickAttendeeStatus: function (ev) {
ev.preventDefault();
var self = this;
var selectedStatus = $(ev.currentTarget).attr('data-action');
this._rpc({
model: 'calendar.event',
method: 'change_attendee_status',
args: [this.event.id, selectedStatus],
}).then(function () {
self.event.record.attendee_status = selectedStatus; // FIXEME: Maybe we have to reload view
self.$('.o-calendar-attendee-status-text').text(self.statusInfo[selectedStatus].text);
self.$('.o-calendar-attendee-status-icon').removeClass(_.values(self.statusColors).join(' ')).addClass(self.statusInfo[selectedStatus].color);
});
},
});

var AttendeeCalendarRenderer = CalendarRenderer.extend({
config: _.extend({}, CalendarRenderer.prototype.config, {
CalendarPopover: AttendeeCalendarPopover,
}),
});


var AttendeeCalendarView = CalendarView.extend({
config: _.extend({}, CalendarView.prototype.config, {
Renderer: AttendeeCalendarRenderer,
}),
});

viewRegistry.add('attendee_calendar', AttendeeCalendarView);

});
@@ -45,4 +45,19 @@
</t>
</t>

<t t-name="Calendar.attendee.status.popover" t-extend="CalendarView.event.popover">
<t t-jquery=".o_cw_popover_delete" t-operation="after">
<div t-if="widget.showStatusDropdown" class="btn-group o-calendar-attendee-status ml-2">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i t-attf-class="fa fa-circle o-calendar-attendee-status-icon #{widget.selectedStatusInfo.color}"/> <span class="o-calendar-attendee-status-text" t-esc="widget.selectedStatusInfo.text"></span>
</button>
<div class="dropdown-menu overflow-hidden">
<a class="dropdown-item" href="#" data-action="accepted"><i class="fa fa-circle text-success"/> Accept</a>
<a class="dropdown-item" href="#" data-action="declined"><i class="fa fa-circle text-danger"/> Decline</a>
<a class="dropdown-item" href="#" data-action="tentative"><i class="fa fa-circle text-muted"/> Uncertain</a>
</div>
</div>
</t>
</t>

</template>
@@ -4,6 +4,7 @@
<xpath expr="." position="inside">
<link rel="stylesheet" type="text/scss" href="/calendar/static/src/scss/calendar.scss"/>
<script type="text/javascript" src="/calendar/static/src/js/base_calendar.js"></script>
<script type="text/javascript" src="/calendar/static/src/js/calendar_view.js"></script>
<script type="text/javascript" src="/calendar/static/src/js/mail_activity.js"></script>
<script type="text/javascript" src="/calendar/static/src/js/systray_activity_menu.js"></script>
</xpath>
@@ -234,10 +234,11 @@
<field name="model">calendar.event</field>
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<calendar string="Meetings" date_start="start" date_stop="stop" date_delay="duration" all_day="allday"
<calendar js_class="attendee_calendar" string="Meetings" date_start="start" date_stop="stop" date_delay="duration" all_day="allday"
event_open_popup="true"
event_limit="5"
color="partner_id">
<field name="attendee_status" invisible="1"/>
<field name="partner_id"/>
<field name="partner_ids" widget="many2many_tags_avatar" write_model="calendar.contacts" write_field="partner_id" avatar_field="image_small"/>
<field name="description"/>

0 comments on commit 20afa7b

Please sign in to comment.
You can’t perform that action at this time.