hoodcms 6.0.4 → 6.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/ts/admin.ts CHANGED
@@ -13,11 +13,12 @@ import { ContentTypeController } from './admin/ContentTypeController';
13
13
  import { LogsController } from './admin/LogsController';
14
14
  import { PropertyImporter } from './admin/PropertyImporter';
15
15
  import { HoodApi } from './core/HoodApi';
16
- import { ColorPickers, Editors } from './index';
16
+ import { ColorPickers, Editors, MediaModal } from './index';
17
17
 
18
18
  class Admin extends HoodApi {
19
19
  editors: Editors = new Editors();
20
20
  colorPickers: ColorPickers = new ColorPickers();
21
+ mediaModal: MediaModal = new MediaModal();
21
22
 
22
23
  home: HomeController;
23
24
  media: MediaController;
@@ -4,199 +4,205 @@ import { Alerts } from "../core/Alerts";
4
4
  import { DataList } from "../core/DataList";
5
5
 
6
6
  declare global {
7
- namespace google.maps {
8
- interface Marker {
9
- info: string;
10
- }
11
- }
7
+ namespace google.maps {
8
+ interface Marker {
9
+ info: string;
10
+ }
11
+ }
12
12
  }
13
13
 
14
14
  export interface PropertyServiceOptions {
15
-
16
- listElementId?: string;
17
- mapListElementId?: string;
18
- mapElementId?: string;
19
-
20
- /**
21
- * Called before the data is fetched.
22
- */
23
- onListLoad?: (sender?: HTMLElement) => void;
24
-
25
- /**
26
- * Called before the fetched HTML is rendered to the list. Must return the data back to datalist to render.
27
- */
28
- onListRender?: (html: string, sender?: HTMLElement) => string;
29
- /**
30
- * Called before the data is fetched.
31
- */
32
- onMapLoad?: (data: string, sender?: HTMLElement) => void;
33
-
34
- /**
35
- * Called before the fetched HTML is rendered to the list. Must return the data back to datalist to render.
36
- */
37
- onMapRender?: (sender?: HTMLElement) => string;
38
-
15
+ listElementId?: string;
16
+ mapListElementId?: string;
17
+ mapElementId?: string;
18
+ mapLocationListId?: string;
19
+
20
+ /**
21
+ * Called before the data is fetched.
22
+ */
23
+ onListLoad?: (sender?: HTMLElement) => void;
24
+
25
+ /**
26
+ * Called before the fetched HTML is rendered to the list. Must return the data back to datalist to render.
27
+ */
28
+ onListRender?: (html: string, sender?: HTMLElement) => string;
29
+ /**
30
+ * Called before the data is fetched.
31
+ */
32
+ onMapLoad?: (data: string, sender?: HTMLElement) => void;
33
+
34
+ /**
35
+ * Called before the fetched HTML is rendered to the list. Must return the data back to datalist to render.
36
+ */
37
+ onMapRender?: (sender?: HTMLElement) => string;
38
+
39
+ /**
40
+ * Renders the popup on the property map, location is the property map marker object sent from the server for that property.
41
+ */
42
+ renderPropertyPopup?: (location?: any) => string;
39
43
  }
40
44
 
41
45
  export class PropertyService {
42
- options: PropertyServiceOptions = {
43
- listElementId: 'property-list',
44
- mapListElementId: 'property-map-list',
45
- mapElementId: 'property-map'
46
- };
47
-
48
- constructor(options?: PropertyServiceOptions) {
49
-
50
- this.options = { ...this.options, ...options };
51
-
52
- this.initList();
53
- }
54
-
55
- element: HTMLElement;
56
- list: DataList;
57
- mapListElement: HTMLElement;
58
- mapList: DataList;
59
- map: google.maps.Map = null;
60
- center: google.maps.LatLngLiteral = { lat: 30, lng: -110 };
61
- mapElement: HTMLElement;
62
- markers: any[];
63
-
64
- initList() {
65
-
66
- this.element = document.getElementById(this.options.listElementId);
67
- if (!this.element) {
68
- return;
46
+ options: PropertyServiceOptions = {
47
+ listElementId: "property-list",
48
+ mapListElementId: "property-map-list",
49
+ mapElementId: "property-map",
50
+ mapLocationListId: "property-map-locations",
51
+
52
+ renderPropertyPopup: function (location: any): string {
53
+ return `<div class="card border-0" style="max-width:300px">
54
+ <div style="background-image:url(${location.ImageUrl})" class="rounded img-full img img-wide"></div>
55
+ <div class="card-body border-0">
56
+ <p style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
57
+ <strong>${location.Address1}, ${location.Postcode}</strong>
58
+ </p>
59
+ <p>${location.Description}</p>
60
+ <a href="${location.MarkerUrl}" class="btn btn-block btn-primary">Find out more...</a>
61
+ </div>
62
+ </div>`;
63
+ },
64
+ };
65
+
66
+ constructor(options?: PropertyServiceOptions) {
67
+ this.options = { ...this.options, ...options };
68
+
69
+ this.initList();
70
+ }
71
+
72
+ element: HTMLElement;
73
+ list: DataList;
74
+ mapListElement: HTMLElement;
75
+ mapList: DataList;
76
+ map: google.maps.Map = null;
77
+ center: google.maps.LatLngLiteral = { lat: 30, lng: -110 };
78
+ mapElement: HTMLElement;
79
+ markers: any[];
80
+
81
+ initList() {
82
+ this.element = document.getElementById(this.options.listElementId);
83
+ if (!this.element) {
84
+ return;
85
+ }
86
+
87
+ this.list = new DataList(this.element, {
88
+ onLoad: function (this: PropertyService, sender: HTMLElement = null) {
89
+ if (this.options.onListLoad) {
90
+ this.options.onListLoad(sender);
91
+ }
92
+ }.bind(this),
93
+ onComplete: function (this: PropertyService, data: string, sender: HTMLElement = null) {
94
+ if (this.options.onListRender) {
95
+ this.options.onListRender(data, sender);
96
+ }
97
+ Alerts.log("Finished loading property list.", "info");
98
+ }.bind(this),
99
+ });
100
+ }
101
+
102
+ initMapList() {
103
+ this.mapListElement = document.getElementById(this.options.mapListElementId);
104
+ if (!this.mapElement) {
105
+ return;
106
+ }
107
+
108
+ this.mapList = new DataList(this.mapListElement, {
109
+ onComplete: function (this: PropertyService, data: string, sender: HTMLElement = null) {
110
+ if (this.options.onMapLoad) {
111
+ this.options.onMapLoad(data, sender);
112
+ }
113
+ Alerts.log("Finished loading map list.", "info");
114
+ this.reloadMarkers();
115
+ }.bind(this),
116
+ });
117
+ }
118
+
119
+ initMap() {
120
+ this.mapElement = document.getElementById(this.options.mapElementId);
121
+ if (!this.mapElement) {
122
+ return;
123
+ }
124
+
125
+ this.center = { lat: +this.mapElement.dataset.lat, lng: +this.mapElement.dataset.long };
126
+
127
+ let scrollwheel = false;
128
+ if (this.mapElement.dataset.scrollwheel === "true") {
129
+ scrollwheel = true;
69
130
  }
131
+ this.map = new google.maps.Map(this.mapElement, {
132
+ zoom: +this.mapElement.dataset.zoom || 15,
133
+ center: this.center,
134
+ scrollwheel: scrollwheel,
135
+ });
70
136
 
71
- this.list = new DataList(this.element, {
72
- onLoad: function (this: PropertyService, sender: HTMLElement = null) {
73
-
74
- if (this.options.onListLoad) {
75
- this.options.onListLoad(sender);
76
- }
77
-
78
- }.bind(this),
79
- onComplete: function (this: PropertyService, data: string, sender: HTMLElement = null) {
137
+ $(window).resize(
138
+ function (this: PropertyService) {
139
+ google.maps.event.trigger(this.map, "resize");
140
+ }.bind(this)
141
+ );
80
142
 
81
- if (this.options.onListRender) {
82
- this.options.onListRender(data, sender);
83
- }
84
- Alerts.log('Finished loading property list.', 'info');
143
+ google.maps.event.trigger(this.map, "resize");
85
144
 
86
- }.bind(this)
87
- });
145
+ this.initMapList();
146
+ }
88
147
 
89
- }
90
-
91
- initMapList() {
92
-
93
- this.mapListElement = document.getElementById(this.options.mapListElementId);
94
- if (!this.mapElement) {
95
- return;
96
- }
148
+ reloadMarkers() {
149
+ var infowindow: google.maps.InfoWindow = null;
97
150
 
98
- this.mapList = new DataList(this.mapListElement, {
99
- onComplete: function (this: PropertyService, data: string, sender: HTMLElement = null) {
151
+ if (!this.mapElement) {
152
+ return;
153
+ }
100
154
 
101
- if (this.options.onMapLoad) {
102
- this.options.onMapLoad(data, sender);
103
- }
104
- Alerts.log('Finished loading map list.', 'info');
105
- this.reloadMarkers();
155
+ var map = this.map;
106
156
 
107
- }.bind(this)
108
- });
109
- }
157
+ if (this.markers) {
158
+ for (var i = 0; i < this.markers.length; i++) {
159
+ this.markers[i].setMap(null);
160
+ }
161
+ }
110
162
 
111
- initMap() {
163
+ this.markers = [];
112
164
 
113
- this.mapElement = document.getElementById(this.options.mapElementId);
114
- if (!this.mapElement) {
165
+ var locationsElement = document.getElementById(this.options.mapLocationListId);
166
+ if (!locationsElement) {
115
167
  return;
116
168
  }
117
169
 
118
- this.center = { lat: +this.mapElement.dataset.lat, lng: +this.mapElement.dataset.long };
119
-
120
- this.map = new google.maps.Map(this.mapElement, {
121
- zoom: +this.mapElement.dataset.zoom || 15,
122
- center: this.center,
123
- scrollwheel: false
124
- });
125
-
126
- $(window).resize(function (this: PropertyService) {
127
- google.maps.event.trigger(this.map, 'resize');
128
- }.bind(this));
129
-
130
- google.maps.event.trigger(this.map, 'resize');
131
-
132
- this.initMapList();
133
-
134
- }
135
-
136
- reloadMarkers() {
137
-
138
- var infowindow: google.maps.InfoWindow = null;
139
-
140
- if (!this.mapElement) {
141
- return;
142
- }
143
-
144
- var map = this.map;
145
-
146
- if (this.markers) {
147
- for (var i = 0; i < this.markers.length; i++) {
148
- this.markers[i].setMap(null);
149
- }
150
- }
151
-
152
- this.markers = [];
153
-
154
- var locations = $("#property-map-locations").data('locations');
155
-
156
- locations.map(function (this: PropertyService, location: any, i: number) {
157
-
158
- let marker = new google.maps.Marker({
159
- position: new google.maps.LatLng(+location.Latitude, +location.Longitude),
160
- map: this.map,
161
- optimized: true // makes SVG icons work in IE
162
- });
163
-
164
- if (this.mapElement.dataset.marker) {
165
- marker.setIcon(this.mapElement.dataset.marker);
166
- }
167
-
168
- marker.info = `<div class="card border-0" style="max-width:300px">
169
- <div style="background-image:url(${location.ImageUrl})" class="rounded img-full img img-wide"></div>
170
- <div class="card-body border-0">
171
- <p style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
172
- <strong>${location.Address1}, ${location.Postcode}</strong>
173
- </p>
174
- <p>${location.Description}</p>
175
- <a href="${location.MarkerUrl}" class="btn btn-block btn-primary">Find out more...</a>
176
- </div>
177
- </div>`;
178
-
179
- marker.addListener("click", () => {
180
- if (infowindow) {
181
- infowindow.close();
182
- }
183
- infowindow = new google.maps.InfoWindow({
184
- content: marker.info
185
- });
186
- infowindow.open({
187
- anchor: marker,
188
- map,
189
- shouldFocus: false,
190
- });
191
- });
192
-
193
- this.markers.push(marker);
194
-
195
- }.bind(this));
196
-
197
-
198
- if (this.options.onMapRender) {
199
- this.options.onMapRender();
200
- }
201
- }
170
+ var locations = JSON.parse(locationsElement.dataset.locations);
171
+
172
+ locations.map(
173
+ function (this: PropertyService, location: any, i: number) {
174
+ let marker = new google.maps.Marker({
175
+ position: new google.maps.LatLng(+location.Latitude, +location.Longitude),
176
+ map: this.map,
177
+ optimized: true, // makes SVG icons work in IE
178
+ });
179
+
180
+ if (this.mapElement.dataset.marker) {
181
+ marker.setIcon(this.mapElement.dataset.marker);
182
+ }
183
+
184
+ marker.info = this.options.renderPropertyPopup(location);
185
+
186
+ marker.addListener("click", () => {
187
+ if (infowindow) {
188
+ infowindow.close();
189
+ }
190
+ infowindow = new google.maps.InfoWindow({
191
+ content: marker.info,
192
+ });
193
+ infowindow.open({
194
+ anchor: marker,
195
+ map,
196
+ shouldFocus: false,
197
+ });
198
+ });
199
+
200
+ this.markers.push(marker);
201
+ }.bind(this)
202
+ );
203
+
204
+ if (this.options.onMapRender) {
205
+ this.options.onMapRender();
206
+ }
207
+ }
202
208
  }