1
+ /**
2
+ * Copyright (C) 2010-2011 Share Extras contributors.
3
+ */
4
+
5
+ /**
6
+ * Extras root namespace.
7
+ *
8
+ * @namespace Extras
9
+ */
10
+ if ( typeof Extras == "undefined" || ! Extras )
11
+ {
12
+ var Extras = { } ;
13
+ }
14
+
15
+ /**
16
+ * Document geographic info component.
17
+ *
18
+ * @namespace Extras
19
+ * @class Extras.DocumentGeographicInfo
20
+ */
21
+ ( function ( )
22
+ {
23
+ /**
24
+ * YUI Library aliases
25
+ */
26
+ var Dom = YAHOO . util . Dom ;
27
+
28
+ /**
29
+ * Alfresco Slingshot aliases
30
+ */
31
+ var $html = Alfresco . util . encodeHTML ;
32
+
33
+ /**
34
+ * DocumentGeographicInfo constructor.
35
+ *
36
+ * @param {String } htmlId The HTML id of the parent element
37
+ * @return {Extras.DocumentGeographicInfo } The new DocumentGeographicInfo instance
38
+ * @constructor
39
+ */
40
+ Extras . DocumentGeographicInfo = function ( htmlId )
41
+ {
42
+ Extras . DocumentGeographicInfo . superclass . constructor . call ( this , "Extras.DocumentGeographicInfo" , htmlId ) ;
43
+
44
+ return this ;
45
+ } ;
46
+
47
+ YAHOO . extend ( Extras . DocumentGeographicInfo , Alfresco . component . Base ,
48
+ {
49
+ /**
50
+ * Object container for initialization options
51
+ *
52
+ * @property options
53
+ * @type object
54
+ */
55
+ options :
56
+ {
57
+ /**
58
+ * Reference to the current document
59
+ *
60
+ * @property nodeRef
61
+ * @type string
62
+ * @default ""
63
+ */
64
+ nodeRef : "" ,
65
+
66
+ /**
67
+ * Current siteId, if any.
68
+ *
69
+ * @property siteId
70
+ * @type string
71
+ * @default ""
72
+ */
73
+ siteId : "" ,
74
+
75
+ /**
76
+ * ContainerId representing root container
77
+ *
78
+ * @property containerId
79
+ * @type string
80
+ * @default "documentLibrary"
81
+ */
82
+ containerId : "documentLibrary" ,
83
+
84
+ /**
85
+ * JSON representation of document details
86
+ *
87
+ * @property documentDetails
88
+ * @type object
89
+ * @default null
90
+ */
91
+ documentDetails : null
92
+ } ,
93
+
94
+ /**
95
+ * GMap object
96
+ */
97
+ map : null ,
98
+
99
+ /**
100
+ * GMap marker
101
+ */
102
+ marker : null ,
103
+
104
+ /**
105
+ * Map container div
106
+ */
107
+ mapContainer : null ,
108
+
109
+ /**
110
+ * Event handler called when "onReady"
111
+ *
112
+ * @method : onReady
113
+ */
114
+ onReady : function DocumentGeographicInfo_onReady ( layer , args )
115
+ {
116
+ var docData = this . options . documentDetails ;
117
+ this . mapContainer = Dom . get ( this . id + "-map" ) ;
118
+
119
+ if ( typeof ( docData . item ) === "object" &&
120
+ typeof ( docData . item . node ) === "object" &&
121
+ typeof ( docData . item . node . properties ) === "object" &&
122
+ typeof ( docData . item . node . properties [ "cm:latitude" ] ) !== "undefined" )
123
+ {
124
+ Dom . removeClass ( this . id + "-body" , "hidden" ) ;
125
+
126
+ // Load maps API if not already loaded
127
+ if ( typeof google == "object" && typeof google . maps == "object" )
128
+ {
129
+ this . initializeMap ( this . options . documentDetails ) ;
130
+ }
131
+ else
132
+ {
133
+ // Async load the Google Maps API. Need to do this, as it breaks the YUI Loader otherwise
134
+ var script = document . createElement ( "script" ) ;
135
+ script . type = "text/javascript" ;
136
+ script . src = "http://maps.google.com/maps/api/js?sensor=false&callback=Extras.DocumentGeographicInfo.Callback" ;
137
+ document . body . appendChild ( script ) ;
138
+ }
139
+ }
140
+ else
141
+ {
142
+ Dom . addClass ( this . id + "-body" , "hidden" ) ;
143
+ }
144
+ } ,
145
+
146
+ /**
147
+ * Initialise the map itself
148
+ * @method initializeMap
149
+ */
150
+ initializeMap : function DocumentGeographicInfo_initializeMap ( doc )
151
+ {
152
+ var latLng = new google . maps . LatLng (
153
+ doc . item . node . properties [ "cm:latitude" ] ,
154
+ doc . item . node . properties [ "cm:longitude" ] ) ;
155
+ var myOptions =
156
+ {
157
+ zoom : 10 ,
158
+ center : latLng ,
159
+ mapTypeId : google . maps . MapTypeId . ROADMAP ,
160
+ useStaticMap : false
161
+ }
162
+ this . map = new google . maps . Map ( this . mapContainer , myOptions ) ;
163
+ this . marker = new google . maps . Marker (
164
+ {
165
+ position : latLng ,
166
+ map : this . map ,
167
+ title : this . msg ( "tooltip.gmaps" , doc . item . fileName )
168
+ } ) ;
169
+ google . maps . event . addListener ( this . marker , 'click' , function ( ) {
170
+ document . location . href = document . location . href . replace ( "/document-details" , "/geographic-map" ) ;
171
+ } ) ;
172
+
173
+ /* Decoupled event listener */
174
+ YAHOO . Bubbling . on ( "metadataRefresh" , this . doRefresh , this ) ;
175
+ } ,
176
+
177
+ /**
178
+ * Refresh component in response to metadataRefresh event
179
+ *
180
+ * @method doRefresh
181
+ */
182
+ doRefresh : function DocumentGeographicInfo_doRefresh ( )
183
+ {
184
+ YAHOO . Bubbling . unsubscribe ( "metadataRefresh" , this . doRefresh ) ;
185
+ this . refresh ( 'extras/components/document-details/document-geographic-info?nodeRef={nodeRef}' + ( this . options . siteId ? '&site={siteId}' : '' ) ) ;
186
+ } ,
187
+
188
+ /**
189
+ * Event handler called when the Google Maps API has loaded
190
+ *
191
+ * @method onGoogleAPIReady
192
+ */
193
+ onGoogleAPIReady : function DocumentGeographicInfo_onGoogleAPIReady ( )
194
+ {
195
+ this . initializeMap ( this . options . documentDetails ) ;
196
+ }
197
+
198
+ } ) ;
199
+ } ) ( ) ;
200
+
201
+ Extras . DocumentGeographicInfo . Callback = function ( )
202
+ {
203
+ var component = Alfresco . util . ComponentManager . findFirst ( "Extras.DocumentGeographicInfo" ) ;
204
+ if ( component )
205
+ {
206
+ component . onGoogleAPIReady ( ) ;
207
+ }
208
+ }
0 commit comments