summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Maps/resources/geojson.new.page.js
blob: 30980a7aa019dad5cbd6e4dc87aa1c2df42d5b37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$( document ).ready( function() {
	function getErrorMessageForFailure(failureReason) {
		if (failureReason === 'assertuserfailed') {
			return 'Could not create page because your session expired. The page will be reloaded';
		}

		return 'Failed to create the page: ' + failureReason;
	}

	$('#maps-geojson-new').click(
		function() {
			$(this).prop('disabled', true);
			$(this).text(mw.msg('maps-geo-json-create-page-creating'));

			new mw.Api().create(
				mw.config.get('wgPageName'),
				{
					summary: mw.msg('maps-geo-json-create-page-summary')
				},
				'{"type": "FeatureCollection", "features": []}'
			).then(
				function(editData) {
					if (editData.result !== 'Success') {
						console.log(editData);
						alert('Failed to create the page');
					}

					location.reload();
				}
			).fail(
				function(reason) {
					alert(getErrorMessageForFailure(reason));
					location.reload();
				}
			);
		}
	);
} );