[IMP] Improved calendar's color handling
bzr revid: fme@openerp.com-20110818191826-e0le9cm6xnw38wc2
This commit is contained in:
parent
fa81a097f2
commit
ed11f76ec5
|
@ -26,6 +26,7 @@ openerp.base_calendar.CalendarView = openerp.base.View.extend({
|
|||
'#fcaf3e', '#ef2929', '#ff00c9', '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f',
|
||||
'#ff8e00', '#ff0000', '#b0008c', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00',
|
||||
'#905000', '#9b0000', '#840067', '#510090', '#0000c9', '#009b00', '#9abe00', '#ffc900' ];
|
||||
this.color_map = {};
|
||||
},
|
||||
start: function() {
|
||||
this.rpc("/base_calendar/calendarview/load", {"model": this.model, "view_id": this.view_id, 'toolbar': true}, this.on_loaded);
|
||||
|
@ -136,17 +137,21 @@ openerp.base_calendar.CalendarView = openerp.base.View.extend({
|
|||
reload_event: function(id) {
|
||||
this.dataset.read_ids([id], _.keys(this.fields), this.on_events_loaded);
|
||||
},
|
||||
get_color: function(index) {
|
||||
index = index % this.COLOR_PALETTE.length;
|
||||
return this.COLOR_PALETTE[index];
|
||||
get_color: function(key) {
|
||||
if (this.color_map[key]) {
|
||||
return this.color_map[key];
|
||||
}
|
||||
var index = _.keys(this.color_map).length % this.COLOR_PALETTE.length;
|
||||
var color = this.COLOR_PALETTE[index];
|
||||
this.color_map[key] = color;
|
||||
return color;
|
||||
},
|
||||
on_events_loaded: function(events, fn_filter, no_filter_reload) {
|
||||
var self = this;
|
||||
|
||||
//To parse Events we have to convert date Format
|
||||
var res_events = [],
|
||||
sidebar_items = [],
|
||||
sidebar_ids = [];
|
||||
sidebar_items = {};
|
||||
for (var e = 0; e < events.length; e++) {
|
||||
var evt = events[e];
|
||||
if (!evt[this.date_start]) {
|
||||
|
@ -157,21 +162,19 @@ openerp.base_calendar.CalendarView = openerp.base.View.extend({
|
|||
if (this.color_field) {
|
||||
var filter = evt[this.color_field];
|
||||
if (filter) {
|
||||
var filter_item = {
|
||||
value: (typeof filter === 'object') ? filter[0] : filter,
|
||||
label: (typeof filter === 'object') ? filter[1] : filter
|
||||
}
|
||||
if (typeof(fn_filter) === 'function' && !fn_filter(filter_item.value)) {
|
||||
var filter_value = (typeof filter === 'object') ? filter[0] : filter;
|
||||
if (typeof(fn_filter) === 'function' && !fn_filter(filter_value)) {
|
||||
continue;
|
||||
}
|
||||
var filter_index = _.indexOf(sidebar_ids, filter_item.value);
|
||||
if (filter_index === -1) {
|
||||
evt.color = filter_item.color = this.get_color(sidebar_ids.length);
|
||||
sidebar_items.push(filter_item);
|
||||
sidebar_ids.push(filter_item.value);
|
||||
} else {
|
||||
evt.color = this.get_color(filter_index);
|
||||
var filter_item = {
|
||||
value: filter_value,
|
||||
label: (typeof filter === 'object') ? filter[1] : filter,
|
||||
color: this.get_color(filter_value)
|
||||
}
|
||||
if (!sidebar_items[filter_value]) {
|
||||
sidebar_items[filter_value] = filter_item;
|
||||
}
|
||||
evt.color = filter_item.color;
|
||||
evt.textColor = '#ffffff';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
</div>
|
||||
</t>
|
||||
<t t-name="CalendarView.sidebar.responsible">
|
||||
<div t-foreach="filters" t-as="filter" class="oe_calendar_responsible" t-attf-style="background: #{filter.color}">
|
||||
<input type="checkbox" name="selection" t-att-value="filter.value"/>
|
||||
<span><t t-esc="filter.label"/></span>
|
||||
<div t-foreach="filters" class="oe_calendar_responsible" t-attf-style="background: #{filters_value.color}">
|
||||
<input type="checkbox" name="selection" t-att-value="filters_value.value"/>
|
||||
<span><t t-esc="filters_value.label"/></span>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
|
|
Loading…
Reference in New Issue