User:Ugochimobi/globe.js

$(document).ready(function{ var feature = (function { test = function { var d = "Change parameter globe in item " ; d += " "; d += "item: "; d += " globe: "; d += " "; d += "enter item and globe "; d += " "; d += " " ; $('#mw-content-text').append ( d ) ;

$('#go').click(function {	console.log ('#go: ' + item.value + ' ' + globe.value);	$.post ('/w/api.php', { action:'query', meta:'tokens', type:'csrf', titles: item.value, format: 'json' }, function ( data ) { console.log(data); var mytoken = data.query.tokens.csrftoken ; if ( undefined === mytoken ) { console.log ( "Cannot get edit token for " + entity ); return; } $.post ('/w/api.php', { action: 'wbgetclaims', entity: item.value, property: 'P134', format: 'json' }, 		function ( data ) {			console.log(data);			var id = data.claims.P134[0].id;			var lat = data.claims.P134[0].mainsnak.datavalue.value.latitude;			var long = data.claims.P134[0].mainsnak.datavalue.value.longitude;			var prec = data.claims.P134[0].mainsnak.datavalue.value.precision;           var glob = data.claims.P134[0].mainsnak.datavalue.value.globe;            var alt = data.claims.P134[0].mainsnak.datavalue.value.altitude;		    var x = '{"id":"'+id+'","type":"statement", "mainsnak":{"snaktype":"value","property":"P134","datatype":"globe-coordinate",';			    x += '"datavalue":{"type":"globecoordinate", "value": {"latitude":'+lat + ',"longitude":'+ long;                x += ', "altitude":'+ alt + ', "precision":'+ prec+ ', "globe": "http://gratisdata.miraheze.org/entity/'+globe.value+'"}}}}'; //console.log (x); $.post ('/w/api.php', { action:'wbsetclaim', claim: x, token: mytoken, format: 'json' }, 		   function ( data ) {				console.log(data);				if (data.error !== undefined ) { 					console.log("Error-code: "+data.error.code ); 					$('#message').val('Can´t create claim: '+data.error.code);				}				if (data.success === 1) {                    console.log ( "Creating data" ) ;                    $('#message').val('Creating data');  				 }     		}, 'json' ) ; }, 'json' ) ;	  }); });

}; // end function test return { test: test };    });

feature.test ; });