Mohammed Shekha(Open ERP) has proposed merging
lp:~openerp-dev/openerp-web/6.1-opw-576512_CalendarEventDragAndDropIssue-msh
into lp:openerp-web/6.1.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/6.1-opw-576512_CalendarEventDragAndDropIssue-msh/+merge/116229
Hello,
Fixed the issue of calendar view, here the events are dragged which has field
readonly based on some state, chekced the modifiers and based on it allow drag
and drop of the events so that unwanted write is not called, this is a serious
issue that we can not change the date from the form but allowed from calendar
view due to drag and drop feature.
Demo :- Open any calendar view and drag any event which is already in some
state based on which the date fields are going to readonly, say for example
Sale -> Meetings -> Meetings -> drag the event which is in "done" state.
Issue :- You will be allowed to drag and drop the events.
Expected :- Event should not be drag and drop which are satisfying some state
based conditions.
This branch will fix this issue, but to evaluate the states we obviously need
to pass state field from the addons in calendar view, here I have changed the
info_field also so that if someone have kept invisible=1 for state field in
calendar view, so that state field will not be shown on event title.
Thanks.
--
https://code.launchpad.net/~openerp-dev/openerp-web/6.1-opw-576512_CalendarEventDragAndDropIssue-msh/+merge/116229
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openerp-web/6.1-opw-576512_CalendarEventDragAndDropIssue-msh.
=== modified file 'addons/web_calendar/static/src/js/calendar.js'
--- addons/web_calendar/static/src/js/calendar.js 2012-06-29 10:35:12 +0000
+++ addons/web_calendar/static/src/js/calendar.js 2012-07-23 10:03:19 +0000
@@ -47,12 +47,14 @@
this._super();
},
on_loaded: function(data) {
+ var self = this;
this.fields_view = data;
this.calendar_fields = {};
this.ids = this.dataset.ids;
this.color_values = [];
this.info_fields = [];
+ this.modifier_fields = {};
this.name = this.fields_view.name || this.fields_view.arch.attrs.string;
this.view_id = this.fields_view.view_id;
@@ -77,6 +79,14 @@
}
this.fields = this.fields_view.fields;
+ _.chain([self.date_start, self.date_delay, self.date_stop])
+ .filter(function(field){ return field != undefined })
+ .each(function(field){
+ self.modifier_fields[field] = self.fields[field];
+ });
+ if(this.fields['state']){
+ this.transfer_field_to_modifiers();
+ }
if (!this.date_start) {
throw new Error("Calendar view has not defined 'date_start' attribute.");
}
@@ -95,7 +105,9 @@
}
for (var fld = 0; fld < this.fields_view.arch.children.length; fld++) {
- this.info_fields.push(this.fields_view.arch.children[fld].attrs.name);
+ if(!this.fields_view.arch.children[fld].attrs.invisible){
+ this.info_fields.push(this.fields_view.arch.children[fld].attrs.name);
+ }
}
this.$element.html(QWeb.render("CalendarView", {"fields_view": this.fields_view}));
@@ -310,6 +322,35 @@
}
return r;
},
+ transfer_field_to_modifiers: function(){
+ var self = this;
+ _.each(self.modifier_fields, function(field){
+ var default_value = {};
+ var state_value = {};
+ var modifiers = {};
+ state_value['readonly'] = [];
+ default_value['readonly'] = py.bool(field['readonly']);
+ _.each(field.states, function(expr, state){
+ _.each(expr, function(val){
+ if (val[0] == 'readonly' && default_value[val[0]] != val[1]){
+ state_value[val[0]].push(state)
+ }
+ });
+ });
+ _.each(default_value, function(val, key){
+ if(!_.isEmpty(state_value[key])){
+ if(val){
+ modifiers[key] = [["state", "not in", state_value[key]]]
+ }else{
+ modifiers[key] = [["state", "in", state_value[key]]]
+ }
+ }else{
+ modifiers[key] = val;
+ }
+ });
+ field['modifiers'] = modifiers
+ });
+ },
do_create_event: function(event_id, event_obj) {
var self = this,
data = this.get_event_data(event_obj);
@@ -353,7 +394,26 @@
do_save_event: function(event_id, event_obj) {
var self = this,
data = this.get_event_data(event_obj),
- index = this.dataset.get_id_index(event_id);
+ index = this.dataset.get_id_index(event_id),
+ check_readonly = false;
+ event_id = parseInt(event_id);
+ if(self.fields['state']){
+ var compute_domain = openerp.web.form.compute_domain;
+ var check_fields = {};
+ var current_event = self.dataset_events[index];
+ _.extend(check_fields,self.fields);
+ _.map(check_fields, function(field, key){
+ check_fields[key]['value'] = current_event[key]
+ });
+ check_readonly = _.any(self.modifier_fields, function(field){
+ return compute_domain(field.modifiers['readonly'], check_fields);
+ });
+ if(check_readonly){
+ self.reload_event(event_id);
+ alert(_t("You can not change date of this event."));
+ return;
+ }
+ }
if (index != null) {
event_id = this.dataset.ids[index];
this.dataset.write(event_id, data, {}, function() {
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp