Odoo10中calendar视图点击事件

有个需求,需要根据该条记录的状态字段来控制点击calendar时是否需要打开form视图,解决方案如下:重写了web_calendar的get_fc_init_options()方法中的eventClick()方法

对于Odoo10中calendar视图,底层用的是fullcalendar.js框架,odoo又对fullcalendar做了封装,也就是web_calendar.js。

我们可以根据自己的需要在web_calendar.js的基础上做修改。

web_calendar.js中对点击事件做了处理,代码如下:

 get_fc_init_options: function () {
//Documentation here : http://arshaw.com/fullcalendar/docs/
var self = this;
return $.extend({}, get_fc_defaultOptions(), {
defaultView: (this.mode == "month")? "month" : ((this.mode == "week")? "agendaWeek" : ((this.mode == "day")? "agendaDay" : "agendaWeek")),
header: false,
selectable: !this.options.read_only_mode && this.create_right,
selectHelper: true,
editable: this.editable,
droppable: true, // callbacks
viewRender: function(view) {
var mode = (view.name == "month")? "month" : ((view.name == "agendaWeek") ? "week" : "day");
if(self.$buttons !== undefined) {
self.$buttons.find('.active').removeClass('active');
self.$buttons.find('.o_calendar_button_' + mode).addClass('active');
} var title = self.title + ' (' + ((mode === "week")? _t("Week ") : "") + view.title + ")";
self.set({'title': title}); self.$calendar.fullCalendar('option', 'height', Math.max(290, parseInt(self.$('.o_calendar_view').height()))); setTimeout(function() {
var $fc_view = self.$calendar.find('.fc-view');
var width = $fc_view.find('> table').width();
$fc_view.find('> div').css('width', (width > $fc_view.width())? width : '100%'); // 100% = fullCalendar default
}, 0);
},
windowResize: function() {
self.$calendar.fullCalendar('render');
},
eventDrop: function (event, _day_delta, _minute_delta, _all_day, _revertFunc) {
var data = self.get_event_data(event);
self.proxy('update_record')(event._id, data); // we don't revert the event, but update it.
},
eventResize: function (event, _day_delta, _minute_delta, _revertFunc) {
var data = self.get_event_data(event);
self.proxy('update_record')(event._id, data);
},
eventRender: function (event, element, view) {
element.find('.fc-event-title').html(event.title + event.attendee_avatars);
},
eventAfterRender: function (event, element, view) {
if ((view.name !== 'month') && (((event.end-event.start)/60000)<=30)) {
//if duration is too small, we see the html code of img
var current_title = $(element.find('.fc-event-time')).text();
var new_title = current_title.substr(0,current_title.indexOf("<img")>0?current_title.indexOf("<img"):current_title.length);
element.find('.fc-event-time').html(new_title);
}
},
eventClick: function (event) { self.open_event(event._id,event.title); },
select: function (start_date, end_date, all_day, _js_event, _view) {
var data_template = self.get_event_data({
start: start_date,
end: end_date,
allDay: all_day,
});
self.open_quick_create(data_template);
}, unselectAuto: false,
});

其中的点击事件就是方法eventClick(event) {self.open_event(event._id, event.title);}

然后我们对该方法做修改,根据我们自己实际的业务需求来判断是否调用self.open_event()方法,来实现控制是否需要弹窗:

 get_fc_init_options: function () {
var self = this;
var res = this._super.apply(this, arguments); if (self.model == 'esw.working.hours.assign') {
// self.write_right = self.can_writable;
self.write_right = false;
return $.extend(
res,
{
selectable: self.creatable, eventClick: function (event) { self.dataset.read_ids([parseInt(event._id)], _.keys(this.fields)).done(function (incomplete_records) {
self.perform_necessary_name_gets(incomplete_records).then(function (records) { var need_open = false;
if (records.length > 0) {
if ('is_filled_in' in records[0]){
if (records[0].is_filled_in){
var fill_time = new Date(records[0].wh_filled_in_datetime);
// var fill_time = new Date('2019-03-01 16:02:06');
var d_val = (new Date() - fill_time) / (24*60*60*1000)
if (d_val < 30){
// Dialog.confirm(this, _t("工时已提报,是否重新提报?"), {
// confirm_callback: function () {
self.open_event(event._id, event.title);
// }
// }) } else {
Dialog.alert(this, _t("提报日期已超过30天,不允许修改"));
}
}else {
need_open = true;
}
} else {
need_open = true;
} if (need_open)
self.open_event(event._id, event.title);
} });
}); },
}
);
}else {
return self._super.apply(this, arguments);
} },

感觉这个方法有点笨,如果大家有什么更好的方法,可以留言说下,谢谢

希望可以帮到有需要的人,大家共同进步................................................................

上一篇:robot framework程序运行过程中,遇到点击事件之后,未出现点击之后的效果(求解)


下一篇:createElement()结合appendChild()的实例