Merge lp:~camptocamp/geospatial-addons/6.1-fix-geo_edit_map-tabs-20121221 into lp:~geospatial-addons-core-editors/geospatial-addons/6.1

Proposed by Yannick Vaucher @ Camptocamp
Status: Merged
Merged at revision: 87
Proposed branch: lp:~camptocamp/geospatial-addons/6.1-fix-geo_edit_map-tabs-20121221
Merge into: lp:~geospatial-addons-core-editors/geospatial-addons/6.1
Diff against target: 84 lines (+51/-7)
1 file modified
base_geoengine/static/src/js/geoengine_view.js (+51/-7)
To merge this branch: bzr merge lp:~camptocamp/geospatial-addons/6.1-fix-geo_edit_map-tabs-20121221
Reviewer Review Type Date Requested Status
Nicolas Bessi - Camptocamp (community) Approve
Review via email: mp+141076@code.launchpad.net

Description of the change

Add a listener on tabs to force the rendering of geo_edit_map widget to ensure it is displayed correctly

To post a comment you must log in.
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'base_geoengine/static/src/js/geoengine_view.js'
2--- base_geoengine/static/src/js/geoengine_view.js 2012-12-21 08:38:57 +0000
3+++ base_geoengine/static/src/js/geoengine_view.js 2012-12-21 14:34:33 +0000
4@@ -594,12 +594,49 @@
5 return [rl, vl];
6 },
7
8+ find_parent_tabs: function() {
9+ var obj_id = this.element_id;
10+ var current_obj = $('#' + obj_id);
11+ var results = new Array();
12+ while (current_obj.length != 0) {
13+ class_name = current_obj.attr('class');
14+ if (class_name && class_name.match(/ui-tabs-panel/) !== null) {
15+ results.push(current_obj);
16+ }
17+ current_obj = current_obj.parent();
18+ }
19+ return results;
20+ },
21+
22+ add_tab_listener: function() {
23+
24+ var self = this;
25+ var parent_tabs = this.find_parent_tabs();
26+ self.parent_tabs = parent_tabs;
27+ for (var i = 0; i < parent_tabs.length; i++) {
28+ tab = parent_tabs[i];
29+ tab.parent().bind('tabsshow', function(event, ui) {
30+ var ui_id = ui.tab.href.match(/notebook-.*/)[0];
31+ // update the render only if the ui_id match with one of the parent_tab id
32+ for (var i = 0; i < self.parent_tabs.length; i++) {
33+ tab_id = self.parent_tabs[i][0].id;
34+ if (ui_id == tab_id){
35+ self.render_map(self);
36+ return;
37+ }
38+ }
39+ });
40+ }
41+ },
42+
43 start: function() {
44 this._super.apply(this, arguments);
45 if (this.map) {
46 return;
47 }
48 var self = this;
49+ // add a listener on parent tab if it exists in order to refresh geoengine view
50+ self.add_tab_listener();
51 // We blacklist all other fields in order to avoid calling get_value inside the build_context on field widget which aren't started yet
52 var blacklist = this.view.fields_order.slice();
53 delete blacklist[this.name];
54@@ -666,16 +703,23 @@
55 this.invalid = false;
56 },
57
58+ render_map: function(self) {
59+ if (self.map) {
60+ self.map.render(self.element_id);
61+ if (self.readonly || self.force_readonly) {
62+ self.modify_control.deactivate();
63+ } else {
64+ self.modify_control.activate();
65+ self.value === false ? self.draw_control.activate() : self.draw_control.deactivate();
66+ }
67+ }
68+ },
69+
70 update_dom: function() {
71 this._super.apply(this, arguments);
72+ var self = this
73 if (this.map) {
74- this.map.render(this.element_id);
75- if (this.readonly || this.force_readonly) {
76- this.modify_control.deactivate();
77- } else {
78- this.modify_control.activate();
79- this.value === false ? this.draw_control.activate() : this.draw_control.deactivate();
80- }
81+ this.render_map(self);
82 }
83 this.$element.toggle(!this.invisible);
84 }

Subscribers

People subscribed via source and target branches