From a704c8433931c83494460cb7d448092ea39e7625 Mon Sep 17 00:00:00 2001 From: jke-openerp Date: Tue, 26 Nov 2013 19:02:12 +0100 Subject: [PATCH] [IMP] Add picture on event, manage name on tooltip, ... bzr revid: jke@openerp.com-20131126180212-gsmsgjlsqa7yq0u1 --- addons/web_calendar/contacts_view.xml | 10 +- .../static/src/css/web_fullcalendar.css | 32 --- .../static/src/css/web_fullcalendar.sass | 33 --- .../static/src/js/fullcalendar.js | 234 +++++++++++------- .../static/src/xml/web_fullcalendar.xml | 9 +- 5 files changed, 164 insertions(+), 154 deletions(-) diff --git a/addons/web_calendar/contacts_view.xml b/addons/web_calendar/contacts_view.xml index 6f59193be2b..e168ba08fe1 100644 --- a/addons/web_calendar/contacts_view.xml +++ b/addons/web_calendar/contacts_view.xml @@ -16,7 +16,15 @@ web_calendar.contacts form tree - + + +

+ Click to add your first contact. +

+ Add your contacts here to see the events which are created by them.
+ Each contact will have it own color on calendar, to see easily who is busy... +

+
diff --git a/addons/web_calendar/static/src/css/web_fullcalendar.css b/addons/web_calendar/static/src/css/web_fullcalendar.css index d117d2504a4..bda17c32bca 100644 --- a/addons/web_calendar/static/src/css/web_fullcalendar.css +++ b/addons/web_calendar/static/src/css/web_fullcalendar.css @@ -7,42 +7,10 @@ z-index: 10; } -.openerp .oe_fullcalendar_widget .fc-content .fc-event .close-btn { - color: white; - float: right; - display: none; - line-height: 6px; - height: 8px; - width: 8px; - border: 1px solid white; - border-radius: 3px; - text-align: center; - padding: 1px; - background-color: #b40000; - box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.5); - z-index: 9; -} -.openerp .oe_fullcalendar_widget .fc-content .fc-event:hover .close-btn { - display: inline; - opacity: 0.5; -} -.openerp .oe_fullcalendar_widget .fc-content .fc-event:hover .close-btn:hover { - display: inline; - opacity: 1; -} - .openerp td.oe_calendar_sidebar_container { padding: 10px; } -.bgDark { - background-color: rgba(55, 55, 55, 0.5); -} - -.bgLight { - background-color: rgba(255, 255, 255, 0.5); -} - .attendee_head { float: right; margin-left: 1px; diff --git a/addons/web_calendar/static/src/css/web_fullcalendar.sass b/addons/web_calendar/static/src/css/web_fullcalendar.sass index 8ac427cb429..a93ae0652b6 100644 --- a/addons/web_calendar/static/src/css/web_fullcalendar.sass +++ b/addons/web_calendar/static/src/css/web_fullcalendar.sass @@ -9,43 +9,10 @@ .oe_searchview_drawer z-index: 10 -.openerp - .oe_fullcalendar_widget - .fc-content - .fc-event - .close-btn - color: white - float: right - display: none - line-height: 6px - height: 8px - width: 8px - border: 1px solid white - border-radius: 3px - text-align: center - padding: 1px - background-color: rgba(180, 0, 0, 1) - box-shadow: 0px 0px 2px rgba(0, 0, 0, .5) - z-index: 9 - .fc-event:hover - .close-btn - display: inline - opacity: 0.5 - .fc-event:hover - .close-btn:hover - display: inline - opacity: 1.0 - .openerp td.oe_calendar_sidebar_container padding: 10px -.bgDark - background-color: rgba(55, 55, 55, 0.5) - -.bgLight - background-color: rgba(255, 255, 255, 0.5) - .attendee_head float: right margin-left: 1px diff --git a/addons/web_calendar/static/src/js/fullcalendar.js b/addons/web_calendar/static/src/js/fullcalendar.js index 7d292469f43..cd96b838799 100644 --- a/addons/web_calendar/static/src/js/fullcalendar.js +++ b/addons/web_calendar/static/src/js/fullcalendar.js @@ -113,7 +113,7 @@ openerp.web_calendar = function(instance) { this.date_start = attrs.date_start; // Field name of starting date field this.date_delay = attrs.date_delay; // duration this.date_stop = attrs.date_stop; - this.all_day = attrs.all_day; // boolean + this.all_day = attrs.all_day; this.attendee_people = attrs.attendee; this.how_display_event = ''; @@ -130,18 +130,28 @@ openerp.web_calendar = function(instance) { if (typeof attrs.display !== "undefined") this.how_display_event = attrs.display; // String with [FIELD] - // If this field is set ot true, we don't add itself as an attendee when we use attendee_people to add each attendee icon on an event - // The color is the color of the attendee, so don't need to show again that it will be present - if (typeof attrs.color_is_attendee !== "undefined" && attrs.color_is_attendee == "True") - this.colorIsAttendee = true; - else - this.colorIsAttendee = false; + // If this field is set ot true, we don't open the event in form view, but in a popup with the xml_view_id passed by this parameter + if (attrs.event_open_popup == null || attrs.event_open_popup == "False") + this.open_popup_action = false; + else { + this.open_popup_action = attrs.event_open_popup; + } + // If this field is set to true, we will use de calendar_friends model as filter and not the color field. if (typeof attrs.use_contacts !== "undefined" && attrs.use_contacts == "True") this.useContacts = true; else this.useContacts = false; + + // If this field is set ot true, we don't add itself as an attendee when we use attendee_people to add each attendee icon on an event + // The color is the color of the attendee, so don't need to show again that it will be present + if (typeof attrs.color_is_attendee == null || attrs.color_is_attendee == "False") + this.colorIsAttendee = false; + else + this.colorIsAttendee = true; + + this.color_field = attrs.color; @@ -199,10 +209,10 @@ openerp.web_calendar = function(instance) { eventRender: function (event, element, view) { element.find('.fc-event-title').html(event.title); if (!self.options.read_only_mode) { - self.append_deletion_handle(event, element, view); + //self.append_deletion_handle(event, element, view); } }, - eventClick: function (event) { self.open_event(event._id); }, + eventClick: function (event) { console.log(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, @@ -214,6 +224,9 @@ openerp.web_calendar = function(instance) { }, drop: function(start_date, all_day) { + if (this.classList.contains("ui-dialog")) { + return; //don't look click event on calendar if popup hover ! + } var data_template = self.get_event_data({ start: start_date, allDay: all_day, @@ -231,6 +244,17 @@ openerp.web_calendar = function(instance) { weekNumbers: true, snapMinutes: 15, + timeFormat : { + // for agendaWeek and agendaDay + agenda: 'h:mm{ - h:mm}', // 5:00 - 6:30 + + // for all other views + '': 'h(:mm)tt' // 7pm + }, + firstHour: 8, + weekMode : 'liquid', + + }); }, @@ -420,17 +444,7 @@ openerp.web_calendar = function(instance) { }); return def; }, - - - hexToRgb : function(hex) { - var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); - return result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } : null; - }, - + isInArray: function(array_is, array_in) { for(var z=0; z/g,'>'); + if (typeof this.attendee_people !== "undefined") { - if (temp_ret[this.attendee_people]) - the_title += " "; - _.each(temp_ret[this.attendee_people], function (the_attendee_people) { attendees.push(the_attendee_people); - if (the_attendee_people in self.allFilters && (!self.colorIsAttendee || temp_ret[self.color_field]!=the_attendee_people)) { //&& the_attendee_people != this.colorIsAttendee - /* - var color = self.get_color(the_attendee_people); - var bgcolor = 'bgLight'; - var rgbColor = self.hexToRgb(color); - if ((0.2126 * rgbColor.r + 0.7152 * rgbColor.g + 0.0722 * rgbColor.b) > 127) { - bgcolor = 'bgDark'; - } - - the_title += '+' - */ - the_title += ''; - - } + + style = 'style="border:2px solid '+self.get_color((the_attendee_people in self.allFilters) ? the_attendee_people : '-1')+'"'; + + // if (the_attendee_people in self.allFilters && (!self.colorIsAttendee || temp_ret[self.color_field]!=the_attendee_people)) { //&& the_attendee_people != this.colorIsAttendee + the_title += ''; } ); } @@ -601,10 +605,28 @@ openerp.web_calendar = function(instance) { console.log("Consecutive ``do_search`` called. Cancelling."); return; } - // We should make sure that *2many used in title of event have - // their extended form [ID, NAME]... + // We should make sure that *2many used in title of event have their extended form [ID, NAME]... - if (!self.useContacts) { + events = $.map(events, function (e) { + + if (self.attendee_people != undefined) { //If we filter on contacts... + if (self.isInArray(self.selected_filters,e[self.attendee_people]) || (self.selected_filters.indexOf(-1) > -1)) { + return e; + } + else { + return null; + } + } + else { //We adds all events # TO TEST ? if (self.isInArray(self.selected_filters,e[self.color_field])){ + + return e; + } + return null; + }); + + + + if (!self.useContacts) { // If we use all peoples as filter in sidebars var now_filters = {}; var filter_value; var filter_item; @@ -621,36 +643,30 @@ openerp.web_calendar = function(instance) { }); self.allFilters = now_filters; - self.sidebar.filter.events_loaded(now_filters); + self.sidebar.filter.events_loaded(now_filters); + return self.perform_necessary_name_gets(events).then(callback); + } + else { + var all_attendees = []; + + _.each(events, function (e) { + all_attendees.push(e[self.attendee_people]); + }); + + self.all_attendees = {} + + all_attendees = _.chain(all_attendees).flatten().uniq().value(); + new instance.web.Model("res.partner").query(["name"]).filter([["id", "in",all_attendees]]).all().then(function(result) { + _.each(result, function(item) { + self.all_attendees[item.id] = item.name; + }); + }).done(function() { + return self.perform_necessary_name_gets(events).then(callback); + }); } - events = $.map(events, function (e) { - - if (self.attendee_people != undefined) { - if (self.isInArray(self.selected_filters,e[self.attendee_people]) - || (self.selected_filters.indexOf(-1) > -1)) { - console.log(e.name + 'is show'); - console.log(self.isInArray(self.selected_filters,e[self.attendee_people])); - console.log(self.selected_filters.indexOf(-1) > -1); - - return e; - } - else { - console.log(e.name + 'is hidden'); - console.log(self.isInArray(self.selected_filters,e[self.attendee_people])); - console.log(self.selected_filters.indexOf(-1) > -1); - console.log(self.selected_filters); - return null; - } - } - else if (self.isInArray(self.selected_filters,e[self.color_field])){ - return e; - } - return null; - }); - - return self.perform_necessary_name_gets(events).then(callback); + }); }, eventDataTransform: function (event) { @@ -697,11 +713,63 @@ openerp.web_calendar = function(instance) { } return false; }, - open_event: function(id) { - var index = this.dataset.get_id_index(id); - this.dataset.index = index; - this.do_switch_view('form'); - return false; + open_event: function(id,title) { + if (! this.open_popup_action) { + var index = this.dataset.get_id_index(id); + this.dataset.index = index; + this.do_switch_view('form'); + } + else { + + var self = this; + + var pop = new instance.web.form.FormOpenPopup(this); + pop.show_element(this.dataset.model, id, this.dataset.get_context(), { + title: _.str.sprintf(_t("View: %s"),title), + view_id: this.open_popup_action, + res_id: id, + target: 'new', + readonly:true + }); + + var form_controller = pop.view_form; + form_controller.on("load_record", self, function(){ + button_delete = _.str.sprintf("",_t("Delete")); + button_edit = _.str.sprintf("",_t("Edit event >>")); + + + pop.$el.closest(".ui-dialog").find(".ui-dialog-buttonpane").prepend(button_delete) + pop.$el.closest(".ui-dialog").find(".ui-dialog-buttonpane").prepend(button_edit) + + $('.delme').click( + function() { + $('.oe_form_button_cancel').trigger('click'); + self.remove_event(id); + } + ); + $('.editme').click( + function() { + var action = { + type: 'ir.actions.act_window', + res_model: 'crm.meeting', + view_mode: 'form', + view_type: 'form', + views: [[false, 'form']], + res_id: id, + context: {}, + }; + $('.oe_form_button_cancel').trigger('click'); + self.do_action(action); + } + ); + + + }); + + } + + return false; + }, do_show: function() { @@ -748,17 +816,6 @@ openerp.web_calendar = function(instance) { self.$calendar.fullCalendar('refetchEvents'); }, - append_deletion_handle: function (event, element, view) { - var self = this; - var $x = $("
x
") - .on('click', function(ev) { - self.remove_event(event.id); - ev.preventDefault(); - return false; - }); - element.find('.deleteMe').html($x);//prepend($x); - }, - remove_event: function(id) { var self = this; function do_it() { @@ -886,6 +943,11 @@ openerp.web_calendar = function(instance) { _.each($.extend({}, this.data_template, data), function(val, field_name) { defaults['default_' + field_name] = val; }); + + if (defaults['default_allday'] && (defaults['default_date_deadline'] || defaults['default_duration'])) { + delete defaults['default_date_deadline']; + delete defaults['default_duration']; + } var pop = new instance.web.form.FormOpenPopup(this); var context = new instance.web.CompoundContext(this.dataset.context, defaults) @@ -900,7 +962,7 @@ openerp.web_calendar = function(instance) { // XXXvlab: why ``create`` does not call dataset_changed AND adds id in dataset.ids // is a mystery for me ATM. }).fail(function (r, event) { - if (!r.data.message) //els emanage by openerp + if (!r.data.message) //else manage by openerp throw new Error(r); }); }, @@ -965,7 +1027,7 @@ openerp.web_calendar = function(instance) { var self = this; return $.when(this._super.apply(this, arguments)).then(function() { self.on('event_rendered', this, function (event, element, view) { - self.append_deletion_handle(event, element, view); + }); }); }, diff --git a/addons/web_calendar/static/src/xml/web_fullcalendar.xml b/addons/web_calendar/static/src/xml/web_fullcalendar.xml index e2d0c9ccde0..d844a8d17e6 100644 --- a/addons/web_calendar/static/src/xml/web_fullcalendar.xml +++ b/addons/web_calendar/static/src/xml/web_fullcalendar.xml @@ -28,9 +28,14 @@
- - , + + , + + + + +