Skip to content

Commit 0d42fd7

Browse files
committed
- (Bug Fix) Fixed an issue that would cause Craft to break when editing entries inline with Google Maps fields
1 parent e17b40b commit 0d42fd7

File tree

5 files changed

+63
-61
lines changed

5 files changed

+63
-61
lines changed

fieldtypes/GoogleMaps_GoogleMapFieldType.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,24 @@ public function getInputHtml($name, $value)
214214

215215
craft()->templates->includeJsResource('googlemaps/js/app.compiled.js');
216216
craft()->templates->includeCssResource('googlemaps/css/app.css');
217-
craft()->templates->includeJsFile('//maps.googleapis.com/maps/api/js?key=&sensor=false');
217+
craft()->templates->includeJsResource('googlemaps/js/callback.js');
218+
craft()->templates->includeJsFile('//maps.googleapis.com/maps/api/js?key=&sensor=false&callback=GoogleMaps.init');
218219

219220
$addressFields = $this->getSettings()->addressFields;
220221

221222
craft()->templates->includeJs("
223+
GoogleMaps.data.push(['#$namespacedId-field .oh-google-map-wrapper', {
224+
fieldname: '$name',
225+
savedData: ".(!empty($value) ? $value->toJson() : "false").",
226+
width: '".$this->getSettings()->defaultMapWidth."',
227+
height: '".$this->getSettings()->defaultMapHeight."',
228+
center: '".$this->getSettings()->defaultMapCenter."',
229+
zoom: ".$this->getSettings()->defaultMapZoom.",
230+
showButtons: ".json_encode($this->getSettings()->displayButtons).",
231+
addressFields: ".($addressFields ? json_encode(explode("\r\n", $this->getSettings()->addressFields)) : 'false')."
232+
}]);
233+
234+
/*
222235
new GoogleMaps.Fieldtype('#$namespacedId-field .oh-google-map-wrapper', {
223236
fieldname: '$name',
224237
savedData: ".(!empty($value) ? $value->toJson() : "false").",
@@ -228,7 +241,8 @@ public function getInputHtml($name, $value)
228241
zoom: ".$this->getSettings()->defaultMapZoom.",
229242
showButtons: ".json_encode($this->getSettings()->displayButtons).",
230243
addressFields: ".($addressFields ? json_encode(explode("\r\n", $this->getSettings()->addressFields)) : 'false')."
231-
});");
244+
});
245+
*/");
232246

233247
return craft()->templates->render('googlemaps/fieldtype', array(
234248
'name' => $name

resources/js/app.compiled.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11033,7 +11033,16 @@ function program2(depth0,data) {
1103311033
}());
1103411034
var GoogleMaps = {
1103511035
Views: {},
11036-
Models: {}
11036+
Models: {},
11037+
data: [],
11038+
instances: [],
11039+
init: function() {
11040+
var t = this;
11041+
11042+
_.each(this.data, function(data) {
11043+
t.instances.push(new GoogleMaps.Fieldtype(data[0], data[1]));
11044+
});
11045+
}
1103711046
};
1103811047

1103911048
(function() {
@@ -11077,6 +11086,8 @@ var GoogleMaps = {
1107711086

1107811087
var App = new Backbone.Marionette.Application();
1107911088

11089+
this.App = App;
11090+
1108011091
App.options = options;
1108111092

1108211093
App.addRegions({
@@ -11098,6 +11109,8 @@ var GoogleMaps = {
1109811109
addressFields: options.addressFields
1109911110
});
1110011111

11112+
this.map = map;
11113+
1110111114
App.addInitializer(function() {
1110211115

1110311116
setTimeout(function() {
@@ -11125,23 +11138,6 @@ var GoogleMaps = {
1112511138

1112611139

1112711140
}());
11128-
11129-
/*
11130-
11131-
(function() {
11132-
11133-
11134-
11135-
GoogleMaps.App = new Backbone.Marionette.Application();
11136-
11137-
GoogleMaps.App.addRegions({
11138-
content: ".oh-google-maps-wrapper"
11139-
});
11140-
11141-
GoogleMaps.App.start();
11142-
11143-
}());
11144-
*/
1114511141
(function() {
1114611142

1114711143
"use strict";

resources/js/app.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
var GoogleMaps = {
22
Views: {},
3-
Models: {}
3+
Models: {},
4+
data: [],
5+
instances: [],
6+
init: function() {
7+
var t = this;
8+
9+
_.each(this.data, function(data) {
10+
t.instances.push(new GoogleMaps.Fieldtype(data[0], data[1]));
11+
});
12+
}
413
};
514

615
(function() {
@@ -44,6 +53,8 @@ var GoogleMaps = {
4453

4554
var App = new Backbone.Marionette.Application();
4655

56+
this.App = App;
57+
4758
App.options = options;
4859

4960
App.addRegions({
@@ -65,6 +76,8 @@ var GoogleMaps = {
6576
addressFields: options.addressFields
6677
});
6778

79+
this.map = map;
80+
6881
App.addInitializer(function() {
6982

7083
setTimeout(function() {
@@ -92,23 +105,6 @@ var GoogleMaps = {
92105

93106

94107
}());
95-
96-
/*
97-
98-
(function() {
99-
100-
101-
102-
GoogleMaps.App = new Backbone.Marionette.Application();
103-
104-
GoogleMaps.App.addRegions({
105-
content: ".oh-google-maps-wrapper"
106-
});
107-
108-
GoogleMaps.App.start();
109-
110-
}());
111-
*/
112108
(function() {
113109

114110
"use strict";

resources/js/app.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/app/main.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
var GoogleMaps = {
22
Views: {},
3-
Models: {}
3+
Models: {},
4+
data: [],
5+
instances: [],
6+
init: function() {
7+
var t = this;
8+
9+
_.each(this.data, function(data) {
10+
t.instances.push(new GoogleMaps.Fieldtype(data[0], data[1]));
11+
});
12+
}
413
};
514

615
(function() {
@@ -44,6 +53,8 @@ var GoogleMaps = {
4453

4554
var App = new Backbone.Marionette.Application();
4655

56+
this.App = App;
57+
4758
App.options = options;
4859

4960
App.addRegions({
@@ -65,6 +76,8 @@ var GoogleMaps = {
6576
addressFields: options.addressFields
6677
});
6778

79+
this.map = map;
80+
6881
App.addInitializer(function() {
6982

7083
setTimeout(function() {
@@ -91,21 +104,4 @@ var GoogleMaps = {
91104
});
92105

93106

94-
}());
95-
96-
/*
97-
98-
(function() {
99-
100-
101-
102-
GoogleMaps.App = new Backbone.Marionette.Application();
103-
104-
GoogleMaps.App.addRegions({
105-
content: ".oh-google-maps-wrapper"
106-
});
107-
108-
GoogleMaps.App.start();
109-
110-
}());
111-
*/
107+
}());

0 commit comments

Comments
 (0)