Merge lp:~openerp-dev/openerp-web/6.1-opw-576512_CalendarEventDragAndDropIssue-msh into lp:openerp-web/6.1

Proposed by Mohammed Shekha(Open ERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openerp-web/6.1-opw-576512_CalendarEventDragAndDropIssue-msh
Merge into: lp:openerp-web/6.1
Diff against target: 108 lines (+62/-2)
1 file modified
addons/web_calendar/static/src/js/calendar.js (+62/-2)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/6.1-opw-576512_CalendarEventDragAndDropIssue-msh
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+116229@code.launchpad.net

Description of the change

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.

To post a comment you must log in.

Unmerged revisions

2415. By Mohammed Shekha(Open ERP)

[FIX]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.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web_calendar/static/src/js/calendar.js'
2--- addons/web_calendar/static/src/js/calendar.js 2012-06-29 10:35:12 +0000
3+++ addons/web_calendar/static/src/js/calendar.js 2012-07-23 10:03:19 +0000
4@@ -47,12 +47,14 @@
5 this._super();
6 },
7 on_loaded: function(data) {
8+ var self = this;
9 this.fields_view = data;
10 this.calendar_fields = {};
11 this.ids = this.dataset.ids;
12 this.color_values = [];
13 this.info_fields = [];
14
15+ this.modifier_fields = {};
16 this.name = this.fields_view.name || this.fields_view.arch.attrs.string;
17 this.view_id = this.fields_view.view_id;
18
19@@ -77,6 +79,14 @@
20 }
21 this.fields = this.fields_view.fields;
22
23+ _.chain([self.date_start, self.date_delay, self.date_stop])
24+ .filter(function(field){ return field != undefined })
25+ .each(function(field){
26+ self.modifier_fields[field] = self.fields[field];
27+ });
28+ if(this.fields['state']){
29+ this.transfer_field_to_modifiers();
30+ }
31 if (!this.date_start) {
32 throw new Error("Calendar view has not defined 'date_start' attribute.");
33 }
34@@ -95,7 +105,9 @@
35 }
36
37 for (var fld = 0; fld < this.fields_view.arch.children.length; fld++) {
38- this.info_fields.push(this.fields_view.arch.children[fld].attrs.name);
39+ if(!this.fields_view.arch.children[fld].attrs.invisible){
40+ this.info_fields.push(this.fields_view.arch.children[fld].attrs.name);
41+ }
42 }
43 this.$element.html(QWeb.render("CalendarView", {"fields_view": this.fields_view}));
44
45@@ -310,6 +322,35 @@
46 }
47 return r;
48 },
49+ transfer_field_to_modifiers: function(){
50+ var self = this;
51+ _.each(self.modifier_fields, function(field){
52+ var default_value = {};
53+ var state_value = {};
54+ var modifiers = {};
55+ state_value['readonly'] = [];
56+ default_value['readonly'] = py.bool(field['readonly']);
57+ _.each(field.states, function(expr, state){
58+ _.each(expr, function(val){
59+ if (val[0] == 'readonly' && default_value[val[0]] != val[1]){
60+ state_value[val[0]].push(state)
61+ }
62+ });
63+ });
64+ _.each(default_value, function(val, key){
65+ if(!_.isEmpty(state_value[key])){
66+ if(val){
67+ modifiers[key] = [["state", "not in", state_value[key]]]
68+ }else{
69+ modifiers[key] = [["state", "in", state_value[key]]]
70+ }
71+ }else{
72+ modifiers[key] = val;
73+ }
74+ });
75+ field['modifiers'] = modifiers
76+ });
77+ },
78 do_create_event: function(event_id, event_obj) {
79 var self = this,
80 data = this.get_event_data(event_obj);
81@@ -353,7 +394,26 @@
82 do_save_event: function(event_id, event_obj) {
83 var self = this,
84 data = this.get_event_data(event_obj),
85- index = this.dataset.get_id_index(event_id);
86+ index = this.dataset.get_id_index(event_id),
87+ check_readonly = false;
88+ event_id = parseInt(event_id);
89+ if(self.fields['state']){
90+ var compute_domain = openerp.web.form.compute_domain;
91+ var check_fields = {};
92+ var current_event = self.dataset_events[index];
93+ _.extend(check_fields,self.fields);
94+ _.map(check_fields, function(field, key){
95+ check_fields[key]['value'] = current_event[key]
96+ });
97+ check_readonly = _.any(self.modifier_fields, function(field){
98+ return compute_domain(field.modifiers['readonly'], check_fields);
99+ });
100+ if(check_readonly){
101+ self.reload_event(event_id);
102+ alert(_t("You can not change date of this event."));
103+ return;
104+ }
105+ }
106 if (index != null) {
107 event_id = this.dataset.ids[index];
108 this.dataset.write(event_id, data, {}, function() {