1
- function gmaps_init ( ) {
2
- // Do nothing
1
+ /**
2
+ * Extras root namespace.
3
+ *
4
+ * @namespace Extras
5
+ */
6
+ if ( typeof Extras == "undefined" || ! Extras )
7
+ {
8
+ var Extras = { } ;
3
9
}
4
10
5
11
/**
@@ -21,14 +27,6 @@ function gmaps_init() {
21
27
*/
22
28
var $html = Alfresco . util . encodeHTML ,
23
29
$combine = Alfresco . util . combinePaths ;
24
-
25
- // Async handler to bring in Google Maps scripts
26
- Event . onDOMReady ( function geotag_gmapsInit ( ) {
27
- var script = document . createElement ( "script" ) ;
28
- script . type = "text/javascript" ;
29
- script . src = "http://maps.google.com/maps/api/js?sensor=false&callback=gmaps_init" ;
30
- document . body . appendChild ( script ) ;
31
- } ) ;
32
30
33
31
/**
34
32
* Geotag a document.
@@ -39,120 +37,145 @@ function gmaps_init() {
39
37
YAHOO . Bubbling . fire ( "registerAction" ,
40
38
{
41
39
actionName : "onActionGeotag" ,
42
- fn : function DL_onActionGeotag ( asset )
43
- {
44
- var nodeRef = asset . nodeRef ,
45
- lat = "" , lon = "" ,
46
- displayName = asset . displayName ,
47
- actionUrl = Alfresco . constants . PROXY_URI + $combine ( "slingshot/doclib/action/geotag/node" , nodeRef . replace ( ":/" , "" ) ) ;
48
-
49
- if ( typeof ( asset . node ) === "object" &&
50
- typeof ( asset . node . properties ) === "object" &&
51
- typeof ( asset . node . properties [ "cm:latitude" ] ) !== "undefined" &&
52
- typeof ( asset . node . properties [ "cm:longitude" ] ) !== "undefined" )
53
- {
54
- lat = asset . node . properties [ "cm:latitude" ] ;
55
- lon = asset . node . properties [ "cm:longitude" ] ;
56
- }
57
-
58
- // Validation
59
- var fnValidate = function fnValidate ( field , args , event , form , silent , message )
60
- {
61
- return field . value !== "" ;
62
- } ;
63
-
64
- // Always create a new instance
65
- this . modules . geotag = new Alfresco . module . SimpleDialog ( this . id + "-geotag" ) . setOptions (
66
- {
67
- width : "50em" ,
68
- templateUrl : Alfresco . constants . URL_SERVICECONTEXT + "extras/modules/documentlibrary/geotag" ,
69
- actionUrl : actionUrl ,
70
- onSuccess :
71
- {
72
- fn : function dlA_onActionChangeType_success ( response )
73
- {
74
- YAHOO . Bubbling . fire ( "metadataRefresh" ,
75
- {
76
- highlightFile : displayName
77
- } ) ;
78
- Alfresco . util . PopupManager . displayMessage (
79
- {
80
- text : this . msg ( "message.geotag.success" , displayName )
81
- } ) ;
82
- } ,
83
- scope : this
84
- } ,
85
- onFailure :
86
- {
87
- fn : function dlA_onActionChangeType_failure ( response )
88
- {
89
- Alfresco . util . PopupManager . displayMessage (
90
- {
91
- text : this . msg ( "message.geotag.failure" , displayName )
92
- } ) ;
93
- } ,
94
- scope : this
95
- } ,
96
- doSetupFormsValidation :
97
- {
98
- fn : function dlA_onActionChangeType_doSetupFormsValidation ( p_form )
99
- {
100
- // Add validation
101
- p_form . addValidation ( this . id + "-geotag-lat" , fnValidate , null , "change" ) ;
102
- p_form . addValidation ( this . id + "-geotag-lon" , fnValidate , null , "change" ) ;
103
- p_form . setShowSubmitStateDynamically ( true , false ) ;
104
-
105
- var me = this , marker = null ;
106
- // Set up the GMap
107
- var latLng = new google . maps . LatLng ( lat !== "" ? lat : 0.0 , lon !== "" ? lon : 0.0 ) ;
108
- var myOptions =
109
- {
110
- zoom : 1 ,
111
- center : latLng ,
112
- mapTypeId : google . maps . MapTypeId . ROADMAP ,
113
- draggableCursor : "crosshair"
114
- }
115
- var map = new google . maps . Map ( Dom . get ( this . modules . geotag . id + "-map" ) , myOptions ) ;
116
- if ( lat !== "" && lon !== "" )
117
- {
118
- marker = new google . maps . Marker (
119
- {
120
- position : latLng ,
121
- map : map ,
122
- title : displayName
123
- } ) ;
124
- map . setZoom ( 10 ) ;
125
- }
126
- // Add click listener to the map to update coordinates
127
- google . maps . event . addListener ( map , "click" , function ( e ) {
128
- // Update the coordiates stored in the form
129
- Dom . get ( me . modules . geotag . id + "-lat" ) . value = e . latLng . lat ( ) ;
130
- Dom . get ( me . modules . geotag . id + "-lon" ) . value = e . latLng . lng ( ) ;
131
-
132
- // Trigger re-validation of the form
133
- p_form . updateSubmitElements ( ) ;
134
-
135
- // Remove the old marker if present
136
- if ( marker !== null )
137
- {
138
- marker . setMap ( null )
139
- marker = null ;
140
- }
141
-
142
- // Centre the map on the new coordinates and add a new marker
143
- map . panTo ( e . latLng ) ;
144
- marker = new google . maps . Marker (
145
- {
146
- position : e . latLng ,
147
- map : map ,
148
- title : displayName
149
- } ) ;
150
- } ) ;
151
- } ,
152
- scope : this
153
- }
154
- } ) ;
155
- this . modules . geotag . show ( ) ;
156
- }
40
+ fn : function DL_onActionGeotag ( asset ) {
41
+
42
+ var me = this ;
43
+ Extras . GeotagActionCallback = function DL_GeotagActionCallback ( )
44
+ {
45
+ var nodeRef = asset . nodeRef ,
46
+ lat = "" , lon = "" ,
47
+ displayName = asset . displayName ,
48
+ actionUrl = Alfresco . constants . PROXY_URI + $combine ( "slingshot/doclib/action/geotag/node" , nodeRef . replace ( ":/" , "" ) ) ;
49
+
50
+ if ( typeof asset . node == "object" &&
51
+ typeof asset . node . properties == "object" &&
52
+ typeof asset . node . properties [ "cm:latitude" ] != "undefined" &&
53
+ typeof asset . node . properties [ "cm:longitude" ] != "undefined" )
54
+ {
55
+ lat = asset . node . properties [ "cm:latitude" ] ;
56
+ lon = asset . node . properties [ "cm:longitude" ] ;
57
+ }
58
+
59
+ // Validation
60
+ var fnValidate = function fnValidate ( field , args , event , form , silent , message )
61
+ {
62
+ return field . value !== "" ;
63
+ } ;
64
+
65
+ // Always create a new instance
66
+ me . modules . geotag = new Alfresco . module . SimpleDialog ( me . id + "-geotag" ) . setOptions (
67
+ {
68
+ width : "50em" ,
69
+ templateUrl : Alfresco . constants . URL_SERVICECONTEXT + "extras/modules/documentlibrary/geotag" ,
70
+ actionUrl : actionUrl ,
71
+ onSuccess :
72
+ {
73
+ fn : function dlA_onActionChangeType_success ( response )
74
+ {
75
+ YAHOO . Bubbling . fire ( "metadataRefresh" ,
76
+ {
77
+ highlightFile : displayName
78
+ } ) ;
79
+ Alfresco . util . PopupManager . displayMessage (
80
+ {
81
+ text : me . msg ( "message.geotag.success" , displayName )
82
+ } ) ;
83
+ } ,
84
+ scope : me
85
+ } ,
86
+ onFailure :
87
+ {
88
+ fn : function dlA_onActionChangeType_failure ( response )
89
+ {
90
+ Alfresco . util . PopupManager . displayMessage (
91
+ {
92
+ text : me . msg ( "message.geotag.failure" , displayName )
93
+ } ) ;
94
+ } ,
95
+ scope : me
96
+ } ,
97
+ doSetupFormsValidation :
98
+ {
99
+ fn : function dlA_onActionChangeType_doSetupFormsValidation ( p_form )
100
+ {
101
+ // Add validation
102
+ p_form . addValidation ( me . id + "-geotag-lat" , fnValidate , null , "change" ) ;
103
+ p_form . addValidation ( me . id + "-geotag-lon" , fnValidate , null , "change" ) ;
104
+ p_form . setShowSubmitStateDynamically ( true , false ) ;
105
+
106
+ var marker = null ;
107
+ // Set up the GMap
108
+ var latLng = new google . maps . LatLng ( lat !== "" ? lat : 0.0 , lon !== "" ? lon : 0.0 ) ;
109
+ var myOptions =
110
+ {
111
+ zoom : 1 ,
112
+ center : latLng ,
113
+ mapTypeId : google . maps . MapTypeId . ROADMAP ,
114
+ draggableCursor : "crosshair"
115
+ }
116
+ var map = new google . maps . Map ( Dom . get ( me . modules . geotag . id + "-map" ) , myOptions ) ;
117
+ if ( lat !== "" && lon !== "" )
118
+ {
119
+ marker = new google . maps . Marker (
120
+ {
121
+ position : latLng ,
122
+ map : map ,
123
+ title : displayName
124
+ } ) ;
125
+ map . setZoom ( 10 ) ;
126
+ }
127
+ // Add click listener to the map to update coordinates
128
+ google . maps . event . addListener ( map , "click" , function ( e ) {
129
+ // Update the coordiates stored in the form
130
+ Dom . get ( me . modules . geotag . id + "-lat" ) . value = e . latLng . lat ( ) ;
131
+ Dom . get ( me . modules . geotag . id + "-lon" ) . value = e . latLng . lng ( ) ;
132
+
133
+ // Update the local copy of the node data
134
+ asset . node . properties [ "cm:latitude" ] = e . latLng . lat ( ) ;
135
+ asset . node . properties [ "cm:longitude" ] = e . latLng . lng ( ) ;
136
+
137
+ // Trigger re-validation of the form
138
+ p_form . updateSubmitElements ( ) ;
139
+
140
+ // Remove the old marker if present
141
+ if ( marker !== null )
142
+ {
143
+ marker . setMap ( null )
144
+ marker = null ;
145
+ }
146
+
147
+ // Centre the map on the new coordinates and add a new marker
148
+ map . panTo ( e . latLng ) ;
149
+ marker = new google . maps . Marker (
150
+ {
151
+ position : e . latLng ,
152
+ map : map ,
153
+ title : displayName
154
+ } ) ;
155
+ } ) ;
156
+ } ,
157
+ scope : me
158
+ }
159
+ } ) ;
160
+ me . modules . geotag . show ( ) ;
161
+ } ;
162
+
163
+ // Load maps API if not already loaded
164
+ if ( typeof google == "object" && typeof google . maps == "object" )
165
+ {
166
+ Extras . GeotagActionCallback . call ( this ) ;
167
+ }
168
+ else
169
+ {
170
+ // Async load the Google Maps API. Need to do this, as it breaks the YUI Loader otherwise
171
+ var script = document . createElement ( "script" ) ;
172
+ script . type = "text/javascript" ;
173
+ script . src = "http://maps.google.com/maps/api/js?sensor=false&callback=Extras.GeotagActionCallback" ;
174
+ document . body . appendChild ( script ) ;
175
+ }
176
+
177
+ }
157
178
} ) ;
179
+
180
+
158
181
} ) ( ) ;
0 commit comments